本文整理汇总了Python中subscription_manager.cli.system_exit函数的典型用法代码示例。如果您正苦于以下问题:Python system_exit函数的具体用法?Python system_exit怎么用?Python system_exit使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了system_exit函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: register
def register(self, credentials, org, environment):
# For registering the machine, use the CLI tool to reuse the username/password (because the GUI will prompt for them again)
# Prepended a \n so translation can proceed without hitch
print ("")
print _("Attempting to register system to Red Hat Subscription Management...")
cmd = [
"subscription-manager",
"register",
"--username=" + credentials.username,
"--password=" + credentials.password,
]
if self.options.serverurl:
cmd.insert(2, "--serverurl=" + self.options.serverurl)
if org:
cmd.append("--org=" + org)
if environment:
cmd.append("--environment=" + environment)
result = subprocess.call(cmd)
identity = inj.require(inj.IDENTITY)
identity.reload()
if result != 0:
system_exit(
2, _("\nUnable to register.\nFor further assistance, please contact Red Hat Global Support Services.")
)
else:
print _("System '%s' successfully registered to Red Hat Subscription Management.\n") % identity.name
return identity
示例2: get_subscribed_channels_list
def get_subscribed_channels_list(self):
try:
subscribed_channels = map(lambda x: x["label"], getChannels().channels())
except Exception:
log.error(traceback.format_exc())
system_exit(1, _("Problem encountered getting the list of subscribed channels. Exiting."))
return subscribed_channels
示例3: get_org
def get_org(self, username):
try:
owner_list = self.cp.getOwnerList(username)
except Exception, e:
log.error(e)
log.error(traceback.format_exc())
system_exit(1, CONNECTION_FAILURE % e)
示例4: legacy_purge
def legacy_purge(self, rpc_session, session_key):
system_id_path = self.rhncfg["systemIdPath"]
log.info("Deleting system %s from legacy server...", self.system_id)
try:
result = rpc_session.system.deleteSystems(session_key, self.system_id)
except Exception:
log.exception("Could not delete system %s from legacy server" % self.system_id)
# If we time out or get a network error, log it and keep going.
shutil.move(system_id_path, system_id_path + ".save")
print(_("Did not receive a completed unregistration message from legacy server for system %s.") % self.system_id)
if self.is_hosted:
print(_("Please investigate on the Customer Portal at https://access.redhat.com."))
return
if result:
log.info("System %s deleted. Removing system id file and disabling rhnplugin.conf", self.system_id)
os.remove(system_id_path)
try:
self.disable_yum_rhn_plugin()
except Exception:
pass
print(_("System successfully unregistered from legacy server."))
else:
# If the legacy server reports that deletion just failed, then quit.
system_exit(1, _("Unable to unregister system from legacy server. ") + SEE_LOG_FILE)
示例5: __init__
def __init__(self, options):
self.rhncfg = initUp2dateConfig()
self.rhsmcfg = config.Config(initConfig())
# Sometimes we need to send up the entire contents of the system id file
# which is referred to in Satellite 5 nomenclature as a "certificate"
# although it is not an X509 certificate.
try:
self.system_id_contents = open(self.rhncfg["systemIdPath"], 'r').read()
except IOError:
system_exit(os.EX_IOERR, _("Could not read legacy system id at %s") % self.rhncfg["systemIdPath"])
self.system_id = self.get_system_id(self.system_id_contents)
self.proxy_host = None
self.proxy_port = None
self.proxy_user = None
self.proxy_pass = None
self.cp = None
self.db = ProductDatabase()
self.consumer_id = None
self.options = options
self.is_hosted = is_hosted()
示例6: load_transition_data
def load_transition_data(self, rpc_session):
try:
transition_data = rpc_session.system.transitionDataForSystem(self.system_id_contents)
self.consumer_id = transition_data['uuid']
except Exception as e:
log.exception(e)
system_exit(1, _("Could not retrieve system migration data from legacy server. ") + SEE_LOG_FILE)
示例7: register
def register(self, credentials, org, environment):
# For registering the machine, use the CLI tool to reuse the username/password (because the GUI will prompt for them again)
# Prepended a \n so translation can proceed without hitch
print ("")
print _("Attempting to register system to destination server...")
cmd = ['subscription-manager', 'register', '--username=' + credentials.username, '--password=' + credentials.password]
if self.options.destination_url:
cmd.append('--serverurl=' + self.options.destination_url)
if org:
cmd.append('--org=' + org)
if environment:
cmd.append('--environment=' + environment)
if self.options.five_to_six:
if self.consumer_exists(self.consumer_id):
cmd.append('--consumerid=' + self.consumer_id)
if self.options.auto:
cmd.append('--auto-attach')
if self.options.service_level:
servicelevel = self.select_service_level(org, self.options.service_level)
cmd.append('--servicelevel=' + servicelevel)
subprocess.call(cmd)
identity = inj.require(inj.IDENTITY)
identity.reload()
if not identity.is_valid():
system_exit(2, _("\nUnable to register.\nFor further assistance, please contact Red Hat Global Support Services."))
print _("System '%s' successfully registered.\n") % identity.name
return identity
示例8: transfer_http_proxy_settings
def transfer_http_proxy_settings(self):
if self.rhncfg["enableProxy"]:
http_proxy = self.rhncfg["httpProxy"]
if http_proxy[:7] == "http://":
http_proxy = http_proxy[7:]
try:
self.proxy_host, self.proxy_port = http_proxy.split(":")
except ValueError, e:
log.exception(e)
system_exit(1, _("Unable to read RHN proxy settings."))
if self.rhncfg["enableProxyAuth"]:
self.proxy_user = self.rhncfg["proxyUser"]
self.proxy_pass = self.rhncfg["proxyPassword"]
log.info("Using proxy %s:%s" % (self.proxy_host, self.proxy_port))
if self.options.noproxy:
# If the user doesn't want to use a proxy to connect to their subscription
# management server, then remove any proxy information that may have crept in.
self.rhsmcfg.set("server", "proxy_hostname", "")
self.rhsmcfg.set("server", "proxy_port", "")
self.rhsmcfg.set("server", "proxy_user", "")
self.rhsmcfg.set("server", "proxy_password", "")
else:
self.rhsmcfg.set("server", "proxy_hostname", self.proxy_host)
self.rhsmcfg.set("server", "proxy_port", self.proxy_port)
self.rhsmcfg.set("server", "proxy_user", self.proxy_user or "")
self.rhsmcfg.set("server", "proxy_password", self.proxy_pass or "")
self.rhsmcfg.save()
示例9: transfer_http_proxy_settings
def transfer_http_proxy_settings(self):
if self.rhncfg['enableProxy']:
http_proxy = self.rhncfg['httpProxy']
if http_proxy[:7] == "http://":
http_proxy = http_proxy[7:]
try:
self.proxy_host, self.proxy_port = http_proxy.split(':')
except ValueError as e:
log.exception(e)
system_exit(os.EX_CONFIG, _("Could not read legacy proxy settings. ") + SEE_LOG_FILE)
if self.rhncfg['enableProxyAuth']:
self.proxy_user = self.rhncfg['proxyUser']
self.proxy_pass = self.rhncfg['proxyPassword']
log.info("Using proxy %s:%s" % (self.proxy_host, self.proxy_port))
if self.options.noproxy:
# If the user doesn't want to use a proxy to connect to their subscription
# management server, then remove any proxy information that may have crept in.
self.rhsmcfg['server']['proxy_hostname'] = ''
self.rhsmcfg['server']['proxy_port'] = ''
self.rhsmcfg['server']['proxy_user'] = ''
self.rhsmcfg['server']['proxy_password'] = ''
else:
self.rhsmcfg['server']['proxy_hostname'] = self.proxy_host
self.rhsmcfg['server']['proxy_port'] = self.proxy_port
self.rhsmcfg['server']['proxy_user'] = self.proxy_user or ''
self.rhsmcfg['server']['proxy_password'] = self.proxy_pass or ''
self.rhsmcfg.persist()
示例10: legacy_unentitle
def legacy_unentitle(self, rpc_session):
system_id = open(self.rhncfg["systemIdPath"], 'r').read()
try:
rpc_session.system.unentitle(system_id)
except Exception, e:
log.exception("Could not unentitle system on Satellite 5.", e)
system_exit(1, _("Could not unentitle system on legacy server. ") + SEE_LOG_FILE)
示例11: connect_to_rhn
def connect_to_rhn(self, credentials):
hostname = self.rhncfg['serverURL'].split('/')[2]
server_url = 'https://%s/rpc/api' % (hostname)
try:
if self.rhncfg['enableProxy']:
proxy = "%s:%s" % (self.proxy_host, self.proxy_port)
log.info("Using proxy %s for legacy API methods" % (proxy))
if self.rhncfg['enableProxyAuth']:
proxy = "@".join(["%s:%s" % (self.proxy_user, self.proxy_pass), proxy])
else:
proxy = None
rpc_session = rpclib.Server(server_url, proxy=proxy)
ca = self.rhncfg["sslCACert"]
rpc_session.add_trusted_cert(ca)
if credentials.username and credentials.password:
session_key = rpc_session.auth.login(credentials.username, credentials.password)
else:
session_key = None
return (rpc_session, session_key)
except Exception as e:
log.exception(e)
system_exit(1, _("Unable to authenticate to legacy server. ") + SEE_LOG_FILE)
示例12: unregister_system_from_rhn_classic
def unregister_system_from_rhn_classic(self, sc, sk):
system_id_path = self.rhncfg["systemIdPath"]
system_id = self.get_system_id()
log.info("Deleting system %s from RHN Classic...", system_id)
try:
result = sc.system.deleteSystems(sk, system_id)
except Exception:
log.error("Could not delete system %s from RHN Classic" % system_id)
log.error(traceback.format_exc())
shutil.move(system_id_path, system_id_path + ".save")
self.disable_yum_rhn_plugin()
print _(
"Did not receive a completed unregistration message from RHN Classic for system %s.\n"
"Please investigate on the Customer Portal at https://access.redhat.com."
) % system_id
return
if result:
log.info("System %s deleted. Removing systemid file and disabling rhnplugin.conf", system_id)
os.remove(system_id_path)
self.disable_yum_rhn_plugin()
print _("System successfully unregistered from RHN Classic.")
else:
system_exit(1, _("Unable to unregister system from RHN Classic. Exiting."))
示例13: select_service_level
def select_service_level(self, org, servicelevel):
not_supported = _("Error: The service-level command is not supported by the server.")
try:
levels = self.cp.getServiceLevelList(org)
except RemoteServerException as e:
system_exit(-1, not_supported)
except RestlibException as e:
if e.code == 404:
# no need to die, just skip it
print(not_supported)
return None
else:
# server supports it but something went wrong, die.
raise e
# Create the sla tuple before appending the empty string to the list of
# valid slas.
slas = [(sla, sla) for sla in levels]
# Display an actual message for the empty string level.
slas.append((_("No service level preference"), ""))
# The empty string is a valid level so append it to the list.
levels.append("")
if servicelevel is None or \
servicelevel.upper() not in (level.upper() for level in levels):
if servicelevel is not None:
print(_("\nService level \"%s\" is not available.") % servicelevel)
menu = Menu(slas, _("Please select a service level agreement for this system."))
servicelevel = menu.choose()
return servicelevel
示例14: check_is_org_admin
def check_is_org_admin(self, sc, sk, username):
try:
roles = sc.user.listRoles(sk, username)
except Exception:
log.error(traceback.format_exc())
system_exit(1, _("Problem encountered determining user roles in RHN Classic. Exiting."))
if "org_admin" not in roles:
system_exit(1, _("You must be an org admin to successfully run this script."))
示例15: check_for_conflicting_channels
def check_for_conflicting_channels(self, subscribed_channels):
jboss_channel = False
for channel in subscribed_channels:
if channel.startswith("jbappplatform"):
if jboss_channel:
system_exit(1, _("You are subscribed to more than one jbappplatform channel."
" This script does not support that configuration."))
jboss_channel = True