def main():
  argument_spec = vmware_argument_spec()
  argument_spec.update(timeout=dict(type='int', required=False),
                      component_type=dict(required=True, choices=['mp', 'host', 'edge']))

  module = AnsibleModule(argument_spec=argument_spec, supports_check_mode=True)
  state = module.params['state']
  mgr_hostname = module.params['hostname']
  mgr_username = module.params['username']
  mgr_password = module.params['password']
  validate_certs = module.params['validate_certs']
  timeout = module.params['timeout']
  component_type= module.params['component_type']

  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)

  #if state == 'present':
  # Runs pre upgrade checks
  if module.check_mode:
    module.exit_json(changed=False, debug_out='Post upgrade checks will be executed.', 
                     id='Pre upgrade checks')
  try:
    (rc, resp) = request(manager_url + '/upgrade/%s?action=execute_post_upgrade_'
                        'checks' % component_type.upper(), 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 execute post upgrade checks. Error[%s]." % to_native(err))

  try:
    if timeout is None:
      wait_for_post_upgrade_checks_to_execute(manager_url, '/upgrade/upgrade-unit-groups'
                                             '/aggregate-info', mgr_username, mgr_password, 
                                             validate_certs, component_type)
    else:
      wait_for_post_upgrade_checks_to_execute(manager_url, '/upgrade/upgrade-unit-groups'
                                             '/aggregate-info', mgr_username, mgr_password,
                                             validate_certs, component_type, timeout)
  except Exception as err:
      module.fail_json(msg='Error while polling for execution of post upgrade'
                             ' checks. Error [%s]' % to_native(err))
  time.sleep(5)
  changed = True
  try:
    (rc, resp) = request(manager_url+ '/upgrade/upgrade-unit-groups/aggregate-info', 
                         url_username=mgr_username, url_password=mgr_password, 
                         validate_certs=validate_certs)
  except Exception as err:
    module.fail_json(msg='Post upgrade checks were executed successfully but error'
                  ' occured while retrieving the results. Error [%s]' % (to_native(err)))
  module.exit_json(changed=changed, message='Post upgrade checks are performed successfully:\n'
                     '----------------------------\n' + str(resp))
def main():
  argument_spec = vmware_argument_spec()
  argument_spec.update(component_type=dict(type='str', required=True, choices=['host', 'edge', 'mp']),
                       parallel=dict(type='bool', required=False),
                       pause_after_each_group=dict(type='bool', required=False),
                       pause_on_error=dict(type='bool', required=False),
                    state=dict(required=True, choices=['present', 'absent']))

  module = AnsibleModule(argument_spec=argument_spec, supports_check_mode=True)
  upgrade_plan_params = clean_and_get_params(module.params.copy(), ['component_type'])
  state = module.params['state']
  mgr_hostname = module.params['hostname']
  mgr_username = module.params['username']
  mgr_password = module.params['password']
  validate_certs = module.params['validate_certs']
  component_type = module.params['component_type']

  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)

  if state == 'present':
    # update the default upgrade plan
    if module.check_mode:
      module.exit_json(changed=False, debug_out='Upgrade Plan will be modified.'
        ' parallel: %s, pause_after_each_group: %s, pause_on_error: %s' % 
        (module.params['parallel'], module.params['pause_after_each_group'], 
        module.params['pause_on_error']), id=module.params['component_type'])
    request_data = json.dumps(upgrade_plan_params)
    try:
      (rc, resp) = request(manager_url+ '/upgrade/plan/%s/settings' % component_type.upper(), 
                           data=request_data, headers=headers, method='PUT', 
                           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 update upgrade plan. Error[%s]." % to_native(err))

    time.sleep(5)
    module.exit_json(changed=True, message="Upgrade plan is updated.")

  elif state == 'absent':
    # reset to default upgrade plan
    try:
       (rc, resp) = request(manager_url+ '/upgrade/plan?action=reset&'
                            'component_type=%s' % component_type.upper(), 
                            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 while reseting the upgrade plan. Error[%s]." % to_native(err))

    time.sleep(5)
    module.exit_json(changed=True, message="Upgrade plan is reset.")
def wait_for_pre_upgrade_checks_to_execute(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'] != '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.')
Example #4
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_sectionid_by_section_display_name(module, manager_url, mgr_username,
                                          mgr_password, validate_certs,
                                          section_name):
    try:
        (rc, resp) = request(manager_url + '/firewall/sections',
                             method='GET',
                             url_username=mgr_username,
                             url_password=mgr_password,
                             validate_certs=validate_certs,
                             ignore_errors=False)
    except Exception as err:
        module.fail_json(msg="%s" % to_native(err))

    section_id = ""
    revision = ""
    for section in resp['results']:
        if (section['display_name'] == section_name):
            section_id = section['id']
            revision = section['_revision']
        if (section_id and revision):
            break

    if (not (section_id) or not (revision)):
        module.fail_json(msg="Error")

    return section_id, revision
Example #6
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
Example #7
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.')
Example #8
0
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
def main():
    argument_spec = vmware_argument_spec()
    argument_spec.update(wait_time=dict(required=False, type='int'))
    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
    wait_time = 10  # wait till 30 min
    while wait_time < (module.params['wait_time'] * 60):
        try:
            current_time = datetime.now()
            (rc, resp) = request(manager_url + '/reverse-proxy/node/health',
                                 headers=dict(Accept='application/json'),
                                 url_username=mgr_username,
                                 url_password=mgr_password,
                                 validate_certs=validate_certs,
                                 ignore_errors=True)
            if 'healthy' in resp.keys() and resp['healthy'] == True:
                module.exit_json(changed=changed, msg="NSX Manager is Up")
            else:
                raise Exception("NSX Manager is not healthy")
        except Exception as err:
            time_diff = datetime.now() - current_time
            time.sleep(10)
            wait_time = time_diff.seconds + wait_time + 10
    module.fail_json(changed=changed,
                     msg=" Error accessing NSX Manager. Timed out")
Example #10
0
def wait_till_create(id, module, manager_url, mgr_username, mgr_password,
                     validate_certs):
    DEPLOYMENT_PROGRESS = [
        'INSTALL_IN_PROGRESS', 'VM_DEPLOYMENT_IN_PROGRESS',
        'VM_DEPLOYMENT_QUEUED', 'VM_POWER_ON_IN_PROGRESS', 'NODE_NOT_READY',
        'REGISTRATION_PENDING'
    ]
    DEPLOYMENT_SUCCESS = ['NODE_READY', 'INSTALL_SUCCESSFUL']
    try:
        while True:
            (rc, resp) = request(manager_url + '/fabric/nodes/%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['host_node_deployment_status'] in DEPLOYMENT_PROGRESS:
                time.sleep(10)
            elif resp['host_node_deployment_status'] in DEPLOYMENT_SUCCESS:
                time.sleep(5)
                return
            else:
                module.fail_json(msg='Error in fabric node status: %s' %
                                 (str(resp['host_node_deployment_status'])))
    except Exception as err:
        module.fail_json(msg='Error accessing fabric node status. Error [%s]' %
                         (to_native(err)))
Example #11
0
def get_attribute_from_endpoint(module,
                                manager_url,
                                endpoint,
                                mgr_username,
                                mgr_password,
                                validate_certs,
                                attribute_name,
                                fail_on_error=True):
    '''
    params:
    - endpoint: API endpoint.
    - attribute_name: Name of attribute whose value is required
    result:
    attribute value of the attribute name provided.
    '''
    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:
        if fail_on_error:
            module.fail_json(msg='Error while retrieving'
                             ' %s. Error [%s]' %
                             (attribute_name, to_native(err)))
        else:
            pass
    if resp.__contains__(attribute_name):
        return resp[attribute_name]
    return None
def get_transport_node_profiles(module, manager_url, mgr_username, mgr_password, validate_certs):
    try:
      (rc, resp) = request(manager_url+ '/transport-node-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 transport node profiles. Error [%s]' % (to_native(err)))
    return resp
def get_compute_collection_transport_templates(module, manager_url, mgr_username, mgr_password, validate_certs):
    try:
      (rc, resp) = request(manager_url+ '/compute-collection-transport-node-templates', 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 compute collection transport template. Error [%s]' % (to_native(err)))
    return resp
Example #14
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)
 
  # Accept the upgrade EULA

  if module.check_mode:
    module.exit_json(changed=False, debug_out='Upgrade EULA will be'
                                     ' accepted.', id=mgr_hostname)
  try:
    (rc, resp) = request(manager_url+ '/upgrade/eula/accept', 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 accept end user license'
                          ' agreement. Error[%s].' % to_native(err))

  time.sleep(5)
  module.exit_json(changed=True, result=resp, message='End user license agreement'
                                                      ' is accepted.')
Example #15
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 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)

  headers = dict(Accept="application/json")
  headers['Content-Type'] = 'application/json'
 
  # Synchronize the repository data between nsx managers

  if module.check_mode:
    module.exit_json(changed=False, debug_out='The repository data between NSX'
                     ' managers will be synchronized.', id=mgr_hostname)
  try:
    (rc, resp) = request(manager_url+ '/cluster/node?action=repo_sync', 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 synchronize repositories of NSX '
                          'managers. Error[%s].' % to_native(err))

  time.sleep(5)
  module.exit_json(changed=True, result=resp, message='NSX Manager repositories'
                                                      ' synchronization started.')
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)
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 + '/transport-node-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 transport node profiles. Error [%s]' %
            (to_native(err)))

    module.exit_json(changed=changed, **resp)
def wait_till_create(id, module, manager_url, mgr_username, mgr_password,
                     validate_certs):
    try:
        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"] == "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)))
Example #20
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 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_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)
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)))
def get_fabric_compute_managers(module, manager_url, mgr_username, mgr_password, validate_certs):
    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)))
    return resp
Example #25
0
def get_compute_collecting_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))
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)
Example #27
0
def wait_till_create(node_id, module, manager_url, mgr_username, mgr_password,
                     validate_certs):
    try:
        count = 0
        while True:
            (rc, resp) = request(manager_url +
                                 '/transport-nodes/%s/state' % node_id,
                                 headers=dict(Accept='application/json'),
                                 url_username=mgr_username,
                                 url_password=mgr_password,
                                 validate_certs=validate_certs,
                                 ignore_errors=True)
            if any(resp['state'] in progress_status
                   for progress_status in IN_PROGRESS_STATES):
                time.sleep(10)
                count = count + 1
                if count == 90:
                    #Wait for max 15 minutes for host to realize
                    module.fail_json(msg='Error creating transport node: %s' %
                                     (str(resp['state'])))
            elif any(resp['state'] in progress_status
                     for progress_status in SUCCESS_STATES):
                time.sleep(5)
                return
            else:
                module.fail_json(msg='Error creating transport node: %s' %
                                 (str(resp['state'])))
    except Exception as err:
        module.fail_json(msg='Error accessing transport node. Error [%s]' %
                         (to_native(err)))
Example #28
0
def wait_till_create(module, url, mgr_username, mgr_password, validate_certs):
    retry_counter = 0
    try:
        while True:

            try:
                (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'] != "ALL_OK":
                    if retry_counter < 6:
                        time.sleep(5)
                        retry_counter = retry_counter + 1
                    else:
                        module.fail_json(
                            msg='Failed to register vIDM. runtime state is : %s' % (str(resp["runtime_state"])))
                else:
                    break;
            except Exception as err:
                # When registration is in progress and status is not yet accessible then it can throw error.
                #  {'error_code': 36514, 'error_message': 'Error when requesting to verify VMware Identity Manager user access client',
                # So retry is needed in error case as well.
                if retry_counter < 6:
                    retry_counter = retry_counter + 1
                    time.sleep(5)
                else:
                    module.fail_json(msg='Failed to register vIDM. runtime state is : %s' % (to_native(err)))
    except Exception as err:
        module.fail_json(msg='Error accessing vIDM status. Error [%s]' % (to_native(err)))
    return
Example #29
0
def get_vidm(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 vidm details. 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+ '/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)
          time.sleep(10)
    except Exception as err:
      time.sleep(5)
      return