def sync_tools_repos_to_upgrade(client_os, hosts): """This syncs tools repo in Satellite server and also attaches the new tools repo subscription onto each client :param string client_os: The client OS of which tools repo to be synced e.g: rhel6, rhel7 :param list hosts: The list of capsule hostnames to which new capsule repo subscription will be attached Following environment variable affects this function: TOOLS_URL_{client_os} The url of tools repo from latest satellite compose. FROM_VERSION Current Satellite version - to differentiate default organization. e.g. '6.1', '6.0' Personal Upgrade Env Vars: CLIENT_SUBSCRIPTION List of cv_name, environment, ak_name attached to subscription of client in defined sequence Rhevm upgrade Env Vars: RHEV_CLIENT_CV The CV name used in client subscription RHEV_CLIENT_ENVIRONMENT The environment name used in client subscription RHEV_CLIENT_AK The AK name used in client subscription """ client_os = client_os.upper() tools_repo = os.environ.get('TOOLS_URL_{}'.format(client_os)) if tools_repo is None: print('The Tools Repo URL for {} is not provided ' 'to perform Client Upgrade !'.format(client_os)) sys.exit(1) cv_name, env_name, ak_name = [ os.environ.get(env_var) for env_var in ( 'RHEV_CLIENT_CV', 'RHEV_CLIENT_ENVIRONMENT', 'RHEV_CLIENT_AK') ] details = os.environ.get('CLIENT_SUBSCRIPTION') if details is not None: cv_name, env_name, ak_name = [ item.strip() for item in details.split(',')] elif not all([cv_name, env_name, ak_name]): print('Error! The CV, Env and AK details are not provided for Client' 'upgrade!') sys.exit(1) # Set hammer configuration set_hammer_config() hammer_product_create('tools6_latest', '1') time.sleep(2) hammer_repository_create( 'tools6_latest_repo', '1', 'tools6_latest', tools_repo) hammer_repository_synchronize( 'tools6_latest_repo', '1', 'tools6_latest') hammer_content_view_add_repository( cv_name, '1', 'tools6_latest', 'tools6_latest_repo') hammer_content_view_publish(cv_name, '1') # Promote cv lc_env_id = get_attribute_value( hammer('lifecycle-environment list --organization-id 1 ' '--name {}'.format(env_name)), env_name, 'id') cv_version_data = hammer( 'content-view version list --content-view {} ' '--organization-id 1'.format(cv_name)) latest_cv_ver = sorted([float(data['name'].split( '{} '.format(cv_name))[1]) for data in cv_version_data]).pop() cv_ver_id = get_attribute_value(cv_version_data, '{0} {1}'.format( cv_name, latest_cv_ver), 'id') hammer_content_view_promote_version(cv_name, cv_ver_id, lc_env_id, '1') # Add new product subscriptions to AK hammer_activation_key_add_subscription(ak_name, '1', 'tools6_latest') # Add this latest tools repo to hosts to upgrade for host in hosts: attach_subscription_to_host('1', 'tools6_latest', host)
def sync_capsule_repos_to_upgrade(capsules): """This syncs capsule repo in Satellite server and also attaches the capsule repo subscription to each capsule :param list capsules: The list of capsule hostnames to which new capsule repo subscription will be attached Following environment variable affects this function: CAPSULE_URL The url for capsule repo from latest satellite compose. FROM_VERSION Current Satellite version - to differentiate default organization. e.g. '6.1', '6.0' Personal Upgrade Env Vars: CAPSULE_SUBSCRIPTION List of cv_name, environment, ak_name attached to subscription of capsule in defined sequence Rhevm upgrade Env Vars: RHEV_CAPSULE_CV The CV name used in capsule subscription RHEV_CAPSULE_ENVIRONMENT The environment name used in capsule subscription RHEV_CAPSULE_AK The AK name used in capsule subscription """ capsule_repo = os.environ.get('CAPSULE_URL') if capsule_repo is None: print('The Capsule repo URL is not provided ' 'to perform Capsule Upgrade in feature!') sys.exit(1) cv_name, env_name, ak_name = [ os.environ.get(env_var) for env_var in ( 'RHEV_CAPSULE_CV', 'RHEV_CAPSULE_ENVIRONMENT', 'RHEV_CAPSULE_AK') ] details = os.environ.get('CAPSULE_SUBSCRIPTION') if details is not None: cv_name, env_name, ak_name = [ item.strip() for item in details.split(',')] elif not all([cv_name, env_name, ak_name]): print('Error! The CV, Env and AK details are not provided for Capsule' 'upgrade!') sys.exit(1) set_hammer_config() # Create product capsule hammer_product_create('capsule6_latest', '1') time.sleep(2) hammer_repository_create( 'capsule6_latest_repo', '1', 'capsule6_latest', capsule_repo) hammer_repository_synchronize( 'capsule6_latest_repo', '1', 'capsule6_latest') # Add repos to CV hammer_content_view_add_repository( cv_name, '1', 'capsule6_latest', 'capsule6_latest_repo') hammer_content_view_publish(cv_name, '1') # Promote cv lc_env_id = get_attribute_value( hammer('lifecycle-environment list --organization-id 1 ' '--name {}'.format(env_name)), env_name, 'id') cv_version_data = hammer( 'content-view version list --content-view {} ' '--organization-id 1'.format(cv_name)) latest_cv_ver = sorted([float(data['name'].split( '{} '.format(cv_name))[1]) for data in cv_version_data]).pop() cv_ver_id = get_attribute_value(cv_version_data, '{0} {1}'.format( cv_name, latest_cv_ver), 'id') hammer_content_view_promote_version(cv_name, cv_ver_id, lc_env_id, '1') # Add new product subscriptions to AK hammer_activation_key_add_subscription(ak_name, '1', 'capsule6_latest') # Add this latest capsule repo to capsules to upgrade for capsule in capsules: attach_subscription_to_host('1', 'capsule6_latest', capsule)