- subprocess.check_output([IPA_COMMAND, 'service-add', princ],
- stderr=subprocess.STDOUT)
- except subprocess.CalledProcessError, e:
- # hopefully this means the service already exists
- # otherwise we'll fail later again
- logger.info('Error trying to create HTTP service:')
- logger.info('Cmd> %s\n%s', e.cmd, e.output)
+ api.Backend.rpcclient.connect()
+ logger.debug('Try RPC connection')
+ api.Backend.rpcclient.forward('ping')
+ print >> sys.stdout, "... Succeeded!"
+ except ipaerrors.KerberosError as e:
+ print >> sys.stderr, NO_CREDS_FOR_KEYTAB
+ logger.error('Invalid credentials: [%s]', repr(e))
+ if api.Backend.rpcclient.isconnected():
+ api.Backend.rpcclient.disconnect()
+ raise Exception('Invalid credentials: [%s]' % e)
+ except ipaerrors.PublicError as e:
+ print >> sys.stderr, "Can't connect to any IPA server"
+ logger.error(
+ 'Cannot connect to the server due to generic error: %s', e)
+ if api.Backend.rpcclient.isconnected():
+ api.Backend.rpcclient.disconnect()
+ raise Exception('Unable to connect to IPA server: %s' % e)
+
+ # Specify an older version to work on nearly any master. Force is
+ # set to True so a DNS A record is not required for adding the
+ # service.
+ try:
+ api.Backend.rpcclient.forward(
+ 'service_add',
+ unicode(princ),
+ force=True,
+ version=u'2.0',
+ )
+ except ipaerrors.DuplicateEntry:
+ logger.debug('Principal %s already exists' % princ)
+ except ipaerrors.NotFound as e:
+ print >> sys.stderr, "%s" % e
+ logger.error('%s' % e)
+ raise Exception('%s' % e)
+ except ipaerrors.ACIError as e:
+ print >> sys.stderr, NO_CREDS_FOR_KEYTAB
+ logger.error('Invalid credentials: [%s]', repr(e))
+ raise Exception('Invalid credentials: [%s]' % e)
+ finally:
+ server = api.Backend.rpcclient.api.env.server
+ if api.Backend.rpcclient.isconnected():
+ api.Backend.rpcclient.disconnect()