Ejemplo n.º 1
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.')
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.')
Ejemplo n.º 3
0
def main():
    argument_spec = vmware_argument_spec()
    argument_spec.update(description=dict(type='str', required=False),
                         display_name=dict(type='str', required=True),
                         enabled=dict(type='bool',
                                      required=False,
                                      default=True),
                         extended_configuration=dict(type='list',
                                                     required=False),
                         parallel=dict(type='bool',
                                       required=False,
                                       default=True),
                         resource_type=dict(type='str', required=False),
                         tags=dict(type='list', required=False),
                         type=dict(type='str', required=True),
                         upgrade_unit_count=dict(type='int', required=False),
                         upgrade_units=dict(type='list', required=False),
                         state=dict(required=True,
                                    choices=['present', 'absent']))

    module = AnsibleModule(argument_spec=argument_spec,
                           supports_check_mode=True)
    upgrade_group_params = clean_and_get_params(module.params.copy())
    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']

    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_group_params = update_group_parameters(module, manager_url,
                                                   mgr_username, mgr_password,
                                                   validate_certs,
                                                   upgrade_group_params)

    upgrade_unit_group_id = get_id_from_display_name_results(
        module, manager_url, '/upgrade/upgrade-unit-groups', mgr_username,
        mgr_password, validate_certs, ['display_name'], ['id'],
        upgrade_group_params['display_name'], False)
    if state == 'present':
        # create a new upgrade group or modify the existing one
        if module.check_mode:
            module.exit_json(
                changed=False,
                debug_out='A new upgrade unit will be created with'
                ' name: %s' % module.params['display_name'])
        request_data = json.dumps(upgrade_group_params)
        if upgrade_unit_group_id is None:
            try:
                (rc,
                 resp) = request(manager_url + '/upgrade/upgrade-unit-groups',
                                 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="Failed to add upgrade group. Error[%s]." %
                    to_native(err))

            time.sleep(5)
            module.exit_json(changed=True,
                             message="Upgrade group is added successfully.")
        else:
            try:
                (rc, resp) = request(manager_url + '/upgrade/upgrade-unit-'
                                     'groups/%s' % upgrade_unit_group_id,
                                     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 modify upgrade group. Error[%s]." %
                    to_native(err))

            time.sleep(5)
            module.exit_json(changed=True,
                             message='Upgrade group with group id '
                             '%s is updated.' % upgrade_unit_group_id)
    elif state == 'absent':
        # remove an existing upgrade group
        try:
            (rc, resp) = request(manager_url + '/upgrade/upgrade-unit-groups'
                                 '/%s' % upgrade_unit_group_id,
                                 data='',
                                 headers=headers,
                                 method='DELETE',
                                 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 deleting the upgrade'
                             ' group. Error[%s].' % to_native(err))

        time.sleep(5)
        module.exit_json(changed=True,
                         message='Upgrade group with group id '
                         '%s is deleted.' % upgrade_unit_group_id)
Ejemplo n.º 4
0
def main():
  argument_spec = vmware_argument_spec()
  argument_spec.update(paused_upgrade=dict(type='bool', required=True))

  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']
  paused_upgrade = module.params['paused_upgrade']
  
  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 module.check_mode:
    if paused_upgrade:
      module.exit_json(changed=False, debug_out='NSX-T will upgrade with pauses.')
    else:
      module.exit_json(changed=False, debug_out='NSX-T will upgrade without pauses.')

  # If paused_upgrade is not true i.e auto mode
  if not paused_upgrade:
    while True:
      upgrade_status = get_upgrade_status(module, manager_url, mgr_username,
                                          mgr_password, validate_certs)
      if upgrade_status == 'NOT_STARTED':
        try:
          (rc, resp) = request(manager_url+ '/upgrade/plan?action=start', 
                         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 upgrading. Error[%s]." % to_native(err))
      else:
        try:
          (rc, resp) = request(manager_url+ '/upgrade/plan?action=continue', 
                         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 upgrading. Error[%s]." % to_native(err))

      time.sleep(10)
      while True:
        try:
          can_continue, is_failed = check_continuity(module, manager_url, mgr_username,
                                                     mgr_password, validate_certs)
          decide_next_step(module, manager_url, mgr_username, mgr_password, 
                           validate_certs, can_continue, is_failed)
          if can_continue and not is_failed:
            break
          time.sleep(10)
        except Exception as err:
          module.fail_json(msg='Upgrade failed. Error: [%s]' % to_native(err))
  else:
    # Paused upgrade i.e manual mode
    upgrade_status = get_upgrade_status(module, manager_url, mgr_username,
                                          mgr_password, validate_certs)
    if upgrade_status == 'NOT_STARTED':
      try:
        (rc, resp) = request(manager_url+ '/upgrade/plan?action=start', 
                     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 upgrading. Error[%s]." % to_native(err))
    else:
      try:
        (rc, resp) = request(manager_url+ '/upgrade/plan?action=continue', 
                     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 upgrading. Error[%s]." % to_native(err))
    time.sleep(10)
    while True:
      try:
        can_continue, is_failed = check_continuity(module, manager_url, mgr_username,
                                                   mgr_password, validate_certs)
        decide_next_step(module, manager_url, mgr_username, mgr_password, 
                         validate_certs, can_continue, is_failed)
        if can_continue and not is_failed:
          break
        time.sleep(10)
      except Exception as err:
        module.fail_json(msg='Upgrade failed. Error: [%s]' % to_native(err))
    module.exit_json(changed=True, message='A component has been upgraded successfully.'
                                           ' Whole system is not. Please run the module'
                                           ' again till the time whole system is'
                                           ' not upgraded.')
Ejemplo n.º 5
0
def main():
  argument_spec = vmware_argument_spec()
  argument_spec.update(timeout=dict(type='int', required=False),
                      state=dict(required=True, choices=['present', 'absent']))

  module = AnsibleModule(argument_spec=argument_spec, supports_check_mode=True)
  upgrade_prechecks_params = clean_and_get_params(module.params.copy(), ['timeout'])
  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']

  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='Pre upgrade checks will be executed.', 
                       id='Pre upgrade checks')
    request_data = json.dumps(upgrade_prechecks_params)
    try:
      (rc, resp) = request(manager_url + '/upgrade?action=execute_pre_upgrade_checks', 
                           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 pre upgrade checks. Error[%s]." % to_native(err))

    try:
      if timeout is None:
        wait_for_pre_upgrade_checks_to_execute(module, manager_url, '/upgrade/status-summary',
                          mgr_username, mgr_password, validate_certs)
      else:
        wait_for_pre_upgrade_checks_to_execute(module, manager_url, '/upgrade/status-summary',
                          mgr_username, mgr_password, validate_certs, timeout)
    except Exception as err:
        module.fail_json(msg='Error while polling for execution of pre upgrade'
                             ' checks. Error [%s]' % to_native(err))
    time.sleep(5)
    changed = False
    try:
      (rc, resp) = request(manager_url+ '/upgrade/pre-upgrade-checks/failures',
                           url_username=mgr_username, url_password=mgr_password, 
                           validate_certs=validate_certs)
    except Exception as err:
      module.fail_json(msg='Pre upgrade checks were executed successfully but error'
                  ' occured while retrieving the results. Error [%s]' % (to_native(err)))
    # Fail module in case any pre upgrade check fails
    prechecks_failure = False
    if  'results' in resp:
      for result in resp['results']:
        if  'type' in result and result['type'] == 'FAILURE':
          prechecks_failure = True
    if prechecks_failure:
      module.fail_json(msg='Pre upgrade checks are performed successsfully. Found errors. '
                            'Thus, you cannot proceed. To get full report run upgrade groups '
                            'facts module. Precheck results: %s' % str(resp))
    module.exit_json(changed=changed, message='Pre upgrade checks are performed successfully:'
                     ' Failures are listed. To get full report run upgrade groups '
                     'facts module.' + str(resp))
  elif state == 'absent':
    # Aborts pre upgrade checks
    try:
       (rc, resp) = request(manager_url + '/upgrade?action=abort_pre_upgrade_checks', 
                            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 abort running pre upgrade checks. Error[%s]." % to_native(err))

    time.sleep(5)
    module.exit_json(changed=True, message="Upgrade prechecks are aborted.")
Ejemplo n.º 6
0
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.")
Ejemplo n.º 7
0
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)
    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 post upgrade checks
    if module.check_mode:
        module.exit_json(changed=False,
                         debug_out='Post upgrade checks will be executed.',
                         id='Post 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(
                module, manager_url, '/upgrade/upgrade-unit-groups'
                '/aggregate-info', mgr_username, mgr_password, validate_certs,
                component_type)
        else:
            wait_for_post_upgrade_checks_to_execute(
                module, 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))