def attach_subscription(): """Attach a specific subscription to the registered OS. If no subscription ID has been provided through command line, let the user interactively choose one. """ # TODO: Support attaching multiple pool IDs. if tool_opts.activation_key: loggerinst.info( "Using the activation key provided through the command line...") return True pool = ["subscription-manager", "attach"] if tool_opts.auto_attach: pool.append("--auto") loggerinst.info( "Auto-attaching compatible subscriptions to the system ...") elif tool_opts.pool: # The subscription pool ID has been passed through a command line # option pool.extend(["--pool", tool_opts.pool]) loggerinst.info( "Attaching provided subscription pool ID to the system ...") else: subs_list = get_avail_subs() if len(subs_list) == 0: loggerinst.warning("No subscription available for the conversion.") return False elif len(subs_list) == 1: sub_num = 0 loggerinst.info( " %s is the only subscription available, it will automatically be selected for the conversion." % subs_list[0].pool_id) else: # Let the user choose the subscription appropriate for the conversion loggerinst.info( "Manually select subscription appropriate for the conversion") print_avail_subs(subs_list) sub_num = utils.let_user_choose_item(len(subs_list), "subscription") loggerinst.info( "Attaching subscription with pool ID %s to the system ..." % subs_list[sub_num].pool_id) pool.extend(["--pool", subs_list[sub_num].pool_id]) _, ret_code = utils.run_subprocess(pool) if ret_code != 0: # Unsuccessful attachment, e.g. the pool ID is incorrect or the # number of purchased attachments has been depleted. loggerinst.critical("Unsuccessful attachment of a subscription.") return True
def _user_to_choose_rhel_variant(): """RHEL variant to be converted to. Currently supported variants are Server, Client, Workstation and ComputeNode. RHEL for PowerPC is released as Server variant only. """ count = len(get_supported_variants()) variant_num = 0 if count > 1: print_supported_variants() variant_num = utils.let_user_choose_item(count, "RHEL variant") chosen_variant = get_supported_variants()[variant_num] return chosen_variant
def attach_subscription(): """Attach a specific subscription to the registered OS. If no subscription ID has been provided through command line, let the user interactively choose one. """ # TODO: Support attaching multiple pool IDs. # TODO: Support the scenario when the passed activation key attaches # all the appropriate subscriptions during registration already. loggerinst = logging.getLogger(__name__) if tool_opts.activation_key: loggerinst.info( "Using the activation key provided through the command line...") return True if tool_opts.auto_attach: pool = "--auto" tool_opts.pool = "-a" loggerinst.info( "Auto-attaching compatible subscriptions to the system ...") elif tool_opts.pool: # The subscription pool ID has been passed through a command line # option pool = "--pool %s" % tool_opts.pool tool_opts.pool = pool loggerinst.info("Attaching provided subscription pool ID to the" " system ...") else: # Let the user choose the subscription appropriate for the conversion loggerinst.info( "Manually select subscription appropriate for the conversion") subs_list = get_avail_subs() if len(subs_list) == 0: loggerinst.warning("No subscription available for the conversion.") return False print_avail_subs(subs_list) sub_num = utils.let_user_choose_item(len(subs_list), "subscription") pool = "--pool " + subs_list[sub_num].pool_id tool_opts.pool = pool loggerinst.info( "Attaching subscription with pool ID %s to the system ..." % subs_list[sub_num].pool_id) _, ret_code = utils.run_subprocess("subscription-manager attach %s" % pool) if ret_code != 0: # Unsuccessful attachment, e.g. the pool ID is incorrect or the # number of purchased attachments has been depleted. loggerinst.critical("Unsuccessful attachment of a subscription.") return True