def main():
  argument_spec = vmware_argument_spec()
  argument_spec.update(site_connection_info=dict(required=False, type='dict', no_log=True,
                    username=dict(required=False, type='str'),
                    password=dict(required=False, type='str'),
                    thumbprint=dict(required=False, type='str'),
                    fqdn=dict(required=True, type='str')))

  module = AnsibleModule(argument_spec=argument_spec, supports_check_mode=True)
  local_manager_params = get_local_manager_params(module.params.copy())
  mgr_hostname = module.params['hostname']
  mgr_username = module.params['username']
  mgr_password = module.params['password']
  validate_certs = module.params['validate_certs']
  manager_url = 'https://{}/global-manager/api/v1'.format(mgr_hostname)
  check_copmatibility_api_url = manager_url + '/global-infra/onboarding-check-compatibility'
  headers = dict(Accept="application/json")
  headers['Content-Type'] = 'application/json'


  request_data = json.dumps(local_manager_params['site_connection_info'])
  try:
    (rc, resp) = request(check_copmatibility_api_url, data=request_data, headers=headers, method='POST',
                                url_username=mgr_username, url_password=mgr_password, validate_certs=validate_certs, ignore_errors=True)
  except Exception as err:
    module.fail_json(msg='Error accessing local manager. Error [%s]' % (to_native(err)))

  module.exit_json(changed=False, **resp)
Пример #2
0
def get_id_from_display_name_results(module, manager_url, endpoint, mgr_username, 
                                     mgr_password, validate_certs, 
                                     search_attribute_list, return_attribute_list, 
                                     display_name, fail_module=True):
    '''
    params:
    - endpoint: API endpoint.
    - search_attribute_list: List of name attribute the depth to be searched in the result object
    - return_attribute_list: List of name attribute the depth to be returned in the result object
    - display_name: The name to be matched
    - id_attribute: id_attribute whose value is to be returned
    '''
    try:
        (rc, resp) = request(manager_url+ endpoint, headers=dict(Accept='application/json'),
                      url_username=mgr_username, url_password=mgr_password, 
                      validate_certs=validate_certs, ignore_errors=True)
    except Exception as err:
        module.fail_json(msg='Error while converting the passed name to'
                             ' ID. Error [%s]' % to_native(err))
    try:
        for result in resp['results']:
            if traverse_and_retrieve_value(result, search_attribute_list) == display_name:
                return traverse_and_retrieve_value(result, return_attribute_list)
    except Exception as err:
        module.fail_json(msg='Error while getting id from display name. Error [%s]' % to_native(err))
    if fail_module:
        module.fail_json(msg='No id exist with display name %s' % display_name)
    else:
        return None
def main():
    argument_spec = vmware_argument_spec()

    module = AnsibleModule(argument_spec=argument_spec,
                           supports_check_mode=True)

    mgr_hostname = module.params['hostname']
    mgr_username = module.params['username']
    mgr_password = module.params['password']
    validate_certs = module.params['validate_certs']

    manager_url = 'https://{}/api/v1'.format(mgr_hostname)

    changed = False
    try:
        (rc, resp) = request(manager_url + '/fabric/compute-managers',
                             headers=dict(Accept='application/json'),
                             url_username=mgr_username,
                             url_password=mgr_password,
                             validate_certs=validate_certs,
                             ignore_errors=True)
    except Exception as err:
        module.fail_json(
            msg='Error accessing fabric compute manager. Error [%s]' %
            (to_native(err)))

    module.exit_json(changed=changed, **resp)
Пример #4
0
def wait_for_operation_to_execute(manager_url, endpoint, mgr_username, 
                                  mgr_password, validate_certs, attribute_list,
                                  desired_attribute_values, undesired_attribute_values,
                                  time_out=10800):
    '''
    params:
    - endpoint: API endpoint.
    - attribute_list: The attribute whose value should become the desired attribute value
    - desired_attribute_value: The desired attribute value
    
    Function will wait till the attribute value derived from going deep to attribute list
    becomes equal to desired_attribute_value.
    '''
    operation_time = 0
    while True:
        try:
            (rc, resp) = request(manager_url + endpoint, headers=dict(Accept='application/json'),
                                 url_username=mgr_username, url_password=mgr_password, 
                                 validate_certs=validate_certs, ignore_errors=True)
        except Exception as err:
            pass
        try:
            retrieved_value = traverse_and_retrieve_value(resp, attribute_list)
            if retrieved_value in desired_attribute_values:
                return None
            if retrieved_value in undesired_attribute_values:
                raise Exception(resp)
        except Exception as err:
            pass
        time.sleep(10)
        operation_time = operation_time + 10
        if operation_time > time_out:
            raise Exception('Operation timed out.')
Пример #5
0
def get_ip_blocks(module, manager_url, mgr_username, mgr_password, validate_certs):
    try:
      (rc, resp) = request(manager_url+ '/pools/ip-blocks', headers=dict(Accept='application/json'),
                      url_username=mgr_username, url_password=mgr_password, validate_certs=validate_certs, ignore_errors=True)
    except Exception as err:
      module.fail_json(msg='Error accessing ip blocks. Error [%s]' % (to_native(err)))
    return resp
def get_id_from_display_name_uplink(module, manager_url, mgr_username,
                                    mgr_password, validate_certs, endpoint,
                                    uplink_profiles_display_names):
    uplink_profile_display_name1 = uplink_profiles_display_names[0]
    uplink_profile_display_name2 = uplink_profiles_display_names[1]
    try:
        (rc, resp) = request(manager_url + endpoint,
                             headers=dict(Accept='application/json'),
                             url_username=mgr_username,
                             url_password=mgr_password,
                             validate_certs=validate_certs,
                             ignore_errors=True)
    except Exception as err:
        module.fail_json(
            msg='Error accessing id for uplink display names %s, %s. Error [%s]'
            % (uplink_profile_display_name1, uplink_profile_display_name2,
               to_native(err)))

    uplink_profile_ids = []

    for result in resp['results']:
        if result.__contains__('display_name') and (
                result['display_name'] == uplink_profile_display_name1
                or result['display_name'] == uplink_profile_display_name2):
            uplink_profile_ids.append(result['id'])
    if uplink_profile_ids is None or len(uplink_profile_ids) < 2:
        module.fail_json(
            msg='No id exists with uplink display name %s, %s' %
            (uplink_profile_display_name1, uplink_profile_display_name2))
    return uplink_profile_ids
Пример #7
0
def wait_till_switchover_complete(module, url, mgr_username, mgr_password,
                                  validate_certs):
    try:
        retry_count = 0
        while True:
            (rc, resp) = request(url,
                                 headers=dict(Accept='application/json'),
                                 url_username=mgr_username,
                                 url_password=mgr_password,
                                 validate_certs=validate_certs,
                                 ignore_errors=True)
            if (resp['overall_status'] == "ONGOING" or resp['overall_status']
                    == "NOT_STARTED") and retry_count < 100:
                time.sleep(10)
            elif resp['overall_status'] == "COMPLETE":
                return
            else:
                all_errors = ''
                if resp['errors'] is not None:
                    for e in resp['errors']:
                        all_errors = all_errors + e
                module.fail_json(
                    msg='Switchover was not completed due to errors : %s' %
                    all_errors)
    except Exception as err:
        module.fail_json(msg='Error checking switchover status. Error [%s]' %
                         (to_native(err)))
def wait_till_create(id, module, manager_url, mgr_username, mgr_password,
                     validate_certs):
    try:
        down_counter = 0
        while True:
            (rc, resp) = request(manager_url +
                                 '/fabric/compute-managers/%s/status' % id,
                                 headers=dict(Accept='application/json'),
                                 url_username=mgr_username,
                                 url_password=mgr_password,
                                 validate_certs=validate_certs,
                                 ignore_errors=True)
            if resp['registration_status'] == "REGISTERING":
                time.sleep(10)
            elif resp['registration_status'] == "REGISTERED":
                if resp["connection_status"] == "CONNECTING":
                    time.sleep(10)
                elif resp["connection_status"] == "DOWN" and down_counter < 3:
                    time.sleep(10)
                    down_counter = down_counter + 1
                elif resp["connection_status"] == "UP":
                    time.sleep(5)
                    return
                else:
                    module.fail_json(
                        msg=
                        'Error connecting to compute manager. Connection status : %s'
                        % (str(resp["connection_status"])))
            else:
                module.fail_json(msg='Error in compute manager status: %s' %
                                 (str(resp['registration_status'])))
    except Exception as err:
        module.fail_json(
            msg='Error accessing compute manager status. Error [%s]' %
            (to_native(err)))
Пример #9
0
def get_host_switch_profiles(module, manager_url, mgr_username, mgr_password, validate_certs):
    try:
      (rc, resp) = request(manager_url+ '/host-switch-profiles', headers=dict(Accept='application/json'),
                      url_username=mgr_username, url_password=mgr_password, validate_certs=validate_certs, ignore_errors=True)
    except Exception as err:
      module.fail_json(msg='Error accessing host profiles. Error [%s]' % (to_native(err)))
    return resp
def main():
    argument_spec = vmware_argument_spec()
    argument_spec.update(node_name=dict(required=True, type='str'))

    module = AnsibleModule(argument_spec=argument_spec,
                           supports_check_mode=True)

    mgr_hostname = module.params['hostname']
    mgr_username = module.params['username']
    mgr_password = module.params['password']
    validate_certs = module.params['validate_certs']
    manager_node_name = module.params['node_name']

    manager_url = 'https://{}/api/v1'.format(mgr_hostname)

    manager_node_id = get_id_from_display_name_results(
        module, manager_url, '/cluster/nodes/deployments', mgr_username,
        mgr_password, validate_certs, ['deployment_config', 'hostname'],
        ['vm_id'], manager_node_name)

    changed = False
    try:
        (rc, resp) = request(
            manager_url +
            '/cluster/nodes/%s/repo_sync/status' % manager_node_id,
            headers=dict(Accept='application/json'),
            url_username=mgr_username,
            url_password=mgr_password,
            validate_certs=validate_certs,
            ignore_errors=True)
    except Exception as err:
        module.fail_json(msg='Error accessing manager node repo sync '
                         'status. Error [%s]' % (to_native(err)))

    module.exit_json(changed=changed, **resp)
Пример #11
0
def wait_till_delete(module, url, mgr_username, mgr_password, validate_certs):
    retry_counter = 0
    try:
        while True:
            (rc, resp) = request(url + '/status',
                                 headers=dict(Accept='application/json'),
                                 url_username=mgr_username,
                                 url_password=mgr_password,
                                 validate_certs=validate_certs,
                                 ignore_errors=True)
            if resp['runtime_state'] != "NOT_OK" or resp[
                    'vidm_enable'] is not False:
                if retry_counter < 6:
                    time.sleep(10)
                    retry_counter = retry_counter + 1
                else:
                    module.fail_json(
                        msg=
                        'Failed to unregister vIDM. runtime state is : %s registration flag is : %s'
                        %
                        (str(resp["runtime_state"]), str(resp["vidm_enable"])))
            else:
                break
    except Exception as err:
        module.fail_json(msg='Error accessing vIDM status. Error [%s]' %
                         (to_native(err)))
    return
Пример #12
0
def wait_till_create(vm_id, module, manager_url, mgr_username, mgr_password,
                     validate_certs):
    try:
        while True:
            (rc, resp) = request(
                manager_url + '/cluster/nodes/deployments/%s/status' % vm_id,
                headers=dict(Accept='application/json'),
                url_username=mgr_username,
                url_password=mgr_password,
                validate_certs=validate_certs,
                ignore_errors=True)
            if any(resp['status'] in progress_status
                   for progress_status in IN_PROGRESS_STATES):
                time.sleep(10)
            elif any(resp['status'] in progress_status
                     for progress_status in SUCCESS_STATES):
                time.sleep(5)
                return
            else:
                module.fail_json(
                    msg='Error in controller-manager node deployment: %s' %
                    (str(resp['status'])))
    except Exception as err:
        module.fail_json(
            msg='Error accessing controller-manager node status. Error [%s]' %
            (to_native(err)))
Пример #13
0
def wait_for_pre_upgrade_checks_to_execute(module, manager_url, endpoint, mgr_username,
                                  mgr_password, validate_certs, time_out=10800):
  '''
    params:
    - endpoint: API endpoint.
    - attribute_list: The attribute whose value should become the desired attribute value
    - desired_attribute_value: The desired attribute value
    
    Function will wait till the attribute value derived from going deep to attribute list
    becomes equal to desired_attribute_value.
   '''
  operation_time = 0
  while True:
    try:
      (rc, resp) = request(manager_url + endpoint, headers=dict(Accept='application/json'),
                           url_username=mgr_username, url_password=mgr_password, 
                           validate_certs=validate_certs, ignore_errors=True)
    except Exception as err:
       pass
    if resp.__contains__('component_status'):
      flag = True
      component_statuses = resp['component_status']
      for component_status in component_statuses:
        if component_status['pre_upgrade_status']['status'] == 'ABORTED':
          module.exit_json(changed= False, message='Pre upgrade checks started to run,'
                                                   ' but aborted before they could finish.')
        if component_status['pre_upgrade_status']['status'] != 'COMPLETED':
          flag = False
      if flag:
        return None
    time.sleep(15)
    operation_time = operation_time + 15
    if operation_time > time_out:
      raise Exception('Operation timed out.')
Пример #14
0
def main():
    argument_spec = vmware_argument_spec()
    argument_spec.update(component_type=dict(
        required=True, type='str', choices=['host', 'edge', 'mp']))
    module = AnsibleModule(argument_spec=argument_spec,
                           supports_check_mode=True)

    mgr_hostname = module.params['hostname']
    mgr_username = module.params['username']
    mgr_password = module.params['password']
    validate_certs = module.params['validate_certs']
    if module.params['component_type'] is None:
        module.fail_json(msg='Error: parameter component_type not provided')
    else:
        component_type = module.params['component_type']

    manager_url = 'https://{}/api/v1'.format(mgr_hostname)

    changed = False
    try:
        (rc, resp) = request(
            manager_url + '/upgrade/plan/%s/settings' % component_type.upper(),
            headers=dict(Accept='application/json'),
            url_username=mgr_username,
            url_password=mgr_password,
            validate_certs=validate_certs,
            ignore_errors=True)
    except Exception as err:
        module.fail_json(
            msg='Error while retrieving bundle information. Error [%s]' %
            (to_native(err)))

    module.exit_json(changed=changed, **resp)
def get_transport_node_collections(module, manager_url, mgr_username, mgr_password, validate_certs):
    try:
      (rc, resp) = request(manager_url+ '/transport-node-collections', headers=dict(Accept='application/json'),
                      url_username=mgr_username, url_password=mgr_password, validate_certs=validate_certs, ignore_errors=True)
    except Exception as err:
      module.fail_json(msg='Error accessing transport-node-collections. Error [%s]' % (to_native(err)))
    return resp
Пример #16
0
def get_id_from_display_name(module,
                             manager_url,
                             mgr_username,
                             mgr_password,
                             validate_certs,
                             endpoint,
                             display_name,
                             exit_if_not_found=True):
    try:
        (rc, resp) = request(manager_url + endpoint,
                             headers=dict(Accept='application/json'),
                             url_username=mgr_username,
                             url_password=mgr_password,
                             validate_certs=validate_certs,
                             ignore_errors=True)
    except Exception as err:
        module.fail_json(
            msg='Error accessing id for display name %s. Error [%s]' %
            (display_name, to_native(err)))

    for result in resp['results']:
        if result.__contains__(
                'display_name') and result['display_name'] == display_name:
            return result['id']
    if exit_if_not_found:
        module.fail_json(msg='No id exist with display name %s' % display_name)
Пример #17
0
def get_global_managers(module, url, mgr_username, mgr_password, validate_certs):
    try:
        (rc, resp) = request(url, headers=dict(Accept='application/json'),
                             url_username=mgr_username, url_password=mgr_password, validate_certs=validate_certs,
                             ignore_errors=True)
    except Exception as err:
        module.fail_json(msg='Error accessing global manager. Error [%s]' % (to_native(err)))
    return resp
def wait_till_delete(id, module, manager_url, mgr_username, mgr_password, validate_certs):
    try:
      while True:
          (rc, resp) = request(manager_url+ '/transport-node-collections/%s'% id, headers=dict(Accept='application/json'),
                        url_username=mgr_username, url_password=mgr_password, validate_certs=validate_certs, ignore_errors=True)
          time.sleep(10)
    except Exception as err:
      time.sleep(5)
      return
Пример #19
0
def main():
    argument_spec = vmware_argument_spec()
    argument_spec.update(required_info=dict(
        required=True, type='str', choices=['acceptance', 'contents']))

    module = AnsibleModule(argument_spec=argument_spec,
                           supports_check_mode=True)

    mgr_hostname = module.params['hostname']
    mgr_username = module.params['username']
    mgr_password = module.params['password']
    validate_certs = module.params['validate_certs']
    required_info = module.params['required_info']

    manager_url = 'https://{}/api/v1'.format(mgr_hostname)

    if required_info == 'acceptance':
        try:
            (rc, resp) = request(manager_url + '/upgrade/eula/acceptance',
                                 headers=dict(Accept='application/json'),
                                 url_username=mgr_username,
                                 url_password=mgr_password,
                                 validate_certs=validate_certs,
                                 ignore_errors=True)
        except Exception as err:
            module.fail_json(msg='Error accessing upgrade EULA acceptance '
                             'status. Error [%s]' % (to_native(err)))
        module.exit_json(changed=False, **resp)
    elif required_info == 'contents':
        try:
            (rc, resp) = request(manager_url + '/upgrade/eula/content',
                                 headers=dict(Accept='application/json'),
                                 url_username=mgr_username,
                                 url_password=mgr_password,
                                 validate_certs=validate_certs,
                                 ignore_errors=True)
        except Exception as err:
            module.fail_json(msg='Error accessing upgrade EULA contents '
                             'status. Error [%s]' % (to_native(err)))

        module.exit_json(changed=False, **resp)
    else:
        module.fail_json(msg='Invalid value passed for required_info.')
def get_mgr_ip_upgrade_enabled(module, mgr_url, mgr_username, mgr_password,
                               headers, validate_certs):
    try:
        (rc, resp) = request(mgr_url + '/node/services/install-upgrade',
               headers=headers, url_username=mgr_username, url_password=mgr_password, 
                             validate_certs=validate_certs, ignore_errors=True)
    except Exception as err:
        module.fail_json(changed=True, msg='Error getting ip address where '
                        'upgrade is enabled. Error: {}'.format(err))
    return resp['service_properties']['enabled_on'];
Пример #21
0
def main():
    argument_spec = vmware_argument_spec()

    module = AnsibleModule(argument_spec=argument_spec,
                           supports_check_mode=True)

    mgr_hostname = module.params['hostname']
    mgr_username = module.params['username']
    mgr_password = module.params['password']
    validate_certs = module.params['validate_certs']

    headers = dict(Accept="application/json")
    headers['Content-Type'] = 'application/json'

    mgr_hostname = get_upgrade_orchestrator_node(module, mgr_hostname,
                                                 mgr_username, mgr_password,
                                                 headers, validate_certs)

    manager_url = 'https://{}/api/v1'.format(mgr_hostname)

    # Upgrade UC
    if module.check_mode:
        module.exit_json(changed=False,
                         debug_out='Upgrade Coordinator '
                         'will be upgraded.',
                         id=mgr_hostname)

    try:
        (rc, resp) = request(manager_url + '/upgrade?action=upgrade_uc',
                             data='',
                             headers=headers,
                             method='POST',
                             url_username=mgr_username,
                             url_password=mgr_password,
                             validate_certs=validate_certs,
                             ignore_errors=True)
    except Exception as err:
        module.fail_json(msg='Failed to upgrade UC. Error[%s].' %
                         to_native(err))

    time.sleep(5)

    try:
        wait_for_operation_to_execute(manager_url,
                                      '/upgrade/uc-upgrade-status',
                                      mgr_username, mgr_password,
                                      validate_certs, ['state'], ['SUCCESS'],
                                      ['FAILED'])
    except Exception as err:
        module.fail_json(msg='Error while upgrading UC. Error [%s]' %
                         to_native(err))
    module.exit_json(changed=True,
                     result=resp,
                     message='UC is upgraded'
                     ' successfully.')
Пример #22
0
def get_nodes(module, manager_url, mgr_username, mgr_password, validate_certs):
    try:
        (rc, resp) = request(manager_url + '/cluster/nodes/deployments',
                             headers=dict(Accept='application/json'),
                             url_username=mgr_username,
                             url_password=mgr_password,
                             validate_certs=validate_certs,
                             ignore_errors=True)
    except Exception as err:
        module.fail_json(
            msg='Error accessing controller-manager node. Error [%s]' %
            (to_native(err)))
    return resp
def get_compute_collection_id (module, manager_url, mgr_username, mgr_password, validate_certs, manager_name, cluster_name):
    try:
      (rc, resp) = request(manager_url+ '/fabric/compute-collections', headers=dict(Accept='application/json'),
                      url_username=mgr_username, url_password=mgr_password, validate_certs=validate_certs, ignore_errors=True)
      compute_manager_id = get_id_from_display_name (module, manager_url, mgr_username, mgr_password, validate_certs,
                                                        "/fabric/compute-managers", manager_name)
    except Exception as err:
      module.fail_json(msg='Error accessing compute collection id for manager %s, cluster %s. Error [%s]' % (manager_name, cluster_name, to_native(err)))
    for result in resp['results']:
        if result.__contains__('display_name') and result['display_name'] == cluster_name and \
            result['origin_id'] == compute_manager_id:
            return result['external_id']
    module.fail_json(msg='No compute collection id exist with cluster name %s for compute manager %s' % (cluster_name, manager_name))
Пример #24
0
def check_license_exist(module, manager_url, mgr_username, mgr_password,
                        validate_certs):
    id = module.params['license_key']
    try:
        (rc, resp) = request(manager_url + '/licenses/%s' % id,
                             headers=dict(Accept='application/json'),
                             url_username=mgr_username,
                             url_password=mgr_password,
                             validate_certs=validate_certs,
                             ignore_errors=True)
    except Exception as err:
        return False
    return True
def get_logical_router_ports(module, manager_url, mgr_username, mgr_password,
                             validate_certs):
    try:
        (rc, resp) = request(manager_url + '/logical-router-ports',
                             headers=dict(Accept='application/json'),
                             url_username=mgr_username,
                             url_password=mgr_password,
                             validate_certs=validate_certs,
                             ignore_errors=True)
    except Exception as err:
        module.fail_json(
            msg='Error accessing logical router ports. Error [%s]' %
            (to_native(err)))
    return resp
Пример #26
0
def get_principal_ids(module, manager_url, mgr_username, mgr_password,
                      validate_certs):
    try:
        (rc, resp) = request(manager_url +
                             '/trust-management/principal-identities',
                             headers=dict(Accept='application/json'),
                             url_username=mgr_username,
                             url_password=mgr_password,
                             validate_certs=validate_certs,
                             ignore_errors=True)
    except Exception as err:
        module.fail_json(
            msg='Error accessing principal identities. Error [%s]' %
            (to_native(err)))
    return resp
def wait_till_upload_done(module, bundle_id, mgr_url, mgr_username, mgr_password, 
                          headers, validate_certs):
    try:
       while True:
         (rc, resp) = request(mgr_url + '/upgrade/bundles/%s/upload-status'% bundle_id,
                             headers=headers, url_username=mgr_username, 
                             url_password=mgr_password, validate_certs=validate_certs, 
                             ignore_errors=True)
         if resp['status'] == 'FAILED':
             module.fail_json(msg='Failed to upload upgrade bunlde. Error: %s' % 
                              resp['detailed_status'])
         if resp['status'] == 'SUCCESS':
             time.sleep(5)
             return
    except Exception as err:
          module.fail_json(changed=True, msg="Error: %s" % err)
Пример #28
0
def get_upgrade_orchestrator_node(module, mgr_hostname, mgr_username, mgr_password,
                               headers, validate_certs):
    '''
    params:
    - mgr_hostname: Any one of the manager node in manager cluster

    Returns the upgrade orchestrator node  
    '''
    try:
        (rc, resp) = request('https://%s/api/v1/node/services/install-upgrade' % mgr_hostname,
               headers=headers, url_username=mgr_username, url_password=mgr_password, 
                             validate_certs=validate_certs, ignore_errors=True)
    except Exception as err:
        module.fail_json(changed=True, msg='Error getting ip address of the upgrade'
                        ' orchestrator node. Error: {}'.format(err))
    return resp['service_properties']['enabled_on'];
def get_revision(module, manager_url, mgr_username, mgr_password,
                 validate_certs, logical_router_id):
    try:
        (rc, resp) = request(
            manager_url +
            '/logical-routers/%s/routing/advertisement' % logical_router_id,
            headers=dict(Accept='application/json'),
            url_username=mgr_username,
            url_password=mgr_password,
            validate_certs=validate_certs,
            ignore_errors=True)
        return resp['_revision']
    except Exception as err:
        module.fail_json(
            msg='Error accessing current advertisement. Error [%s]' %
            (to_native(err)))
Пример #30
0
def wait_for_post_upgrade_checks_to_execute(module,
                                            manager_url,
                                            endpoint,
                                            mgr_username,
                                            mgr_password,
                                            validate_certs,
                                            component_type,
                                            time_out=10800):
    '''
    params:
    - endpoint: API endpoint.
    - attribute_list: The attribute whose value should become the desired attribute value
    - desired_attribute_value: The desired attribute value
    
    Function will wait till the attribute value derived from going deep to attribute list
    becomes equal to desired_attribute_value.
   '''
    operation_time = 0
    while True:
        try:
            (rc, resp) = request(manager_url + endpoint,
                                 headers=dict(Accept='application/json'),
                                 url_username=mgr_username,
                                 url_password=mgr_password,
                                 validate_certs=validate_certs,
                                 ignore_errors=True)
        except Exception as err:
            module.fail_json(
                msg=
                "Failed while polling for post upgrade checks to complete. Error[%s]."
                % to_native(err))
        if resp.__contains__('results'):
            flag = True
            results = resp['results']
            for result in results:
                if result['post_upgrade_status']['status'] != 'COMPLETED' and \
                   result['type'] == component_type.upper() and \
                   result['upgrade_unit_count'] > 0 and \
                   result['status'] != 'NOT_STARTED':
                    flag = False
            if flag:
                return None
        time.sleep(15)
        operation_time = operation_time + 15
        if operation_time > time_out:
            raise Exception('Operation timed out.')