def main():
    argument_spec = vmware_argument_spec()
    argument_spec.update(
        name=dict(type='str'),
        uuid=dict(type='str'),
        moid=dict(type='str'),
        use_instance_uuid=dict(type='bool', default=False),
        name_match=dict(choices=['first', 'last'], default='first',
                        type='str'),
        folder=dict(type='str'),
        datacenter=dict(type='str'),
    )

    module = AnsibleModule(
        argument_spec=argument_spec,
        required_one_of=[['name', 'uuid', 'moid']],
        mutually_exclusive=[['name', 'uuid', 'moid']],
        supports_check_mode=True,
    )

    pyv = PyVmomiHelper(module)
    vm = pyv.get_vm()
    if not vm:
        vm_id = (module.params.get('uuid') or module.params.get('name')
                 or module.params.get('moid'))
        module.fail_json(
            msg='Unable to find the specified virtual machine using: %s' %
            vm_id)
    results = pyv.gather_vmtools_info()
    module.exit_json(**results)
Beispiel #2
0
def main():
    """Main"""
    argument_spec = vmware_argument_spec()
    argument_spec.update(
        ad_domain=dict(type='str',
                       default='',
                       aliases=['domain', 'domain_name']),
        ad_user=dict(type='str', default=''),
        ad_password=dict(type='str', default='', no_log=True),
        ad_state=dict(default='absent',
                      choices=['present', 'absent'],
                      aliases=['state']),
        esxi_hostname=dict(type='str', required=False),
        cluster_name=dict(type='str', required=False),
    )

    module = AnsibleModule(
        argument_spec=argument_spec,
        required_one_of=[
            ['cluster_name', 'esxi_hostname'],
        ],
        required_if=[
            ['ad_state', 'present', ['ad_domain', 'ad_user', 'ad_password']],
        ],
        supports_check_mode=True)

    ad_auth = VmwareHostAdAuthentication(module)
    ad_auth.ensure()
def main():
    """Main"""
    argument_spec = vmware_argument_spec()
    argument_spec.update(type=dict(required=True,
                                   type='str',
                                   choices=['dhcp', 'static']),
                         device=dict(type='str'),
                         host_name=dict(required=False, type='str'),
                         domain=dict(required=False, type='str'),
                         dns_servers=dict(required=False, type='list'),
                         search_domains=dict(required=False, type='list'),
                         esxi_hostname=dict(required=False, type='str'),
                         cluster_name=dict(required=False, type='str'),
                         verbose=dict(type='bool',
                                      default=False,
                                      required=False))

    module = AnsibleModule(argument_spec=argument_spec,
                           required_if=[
                               ['type', 'dhcp', ['device']],
                           ],
                           mutually_exclusive=[
                               ['cluster_name', 'host_name'],
                               ['cluster_name', 'esxi_host_name'],
                               ['static', 'device'],
                               ['dhcp', 'host_name'],
                               ['dhcp', 'domain'],
                               ['dhcp', 'dns_servers'],
                               ['dhcp', 'search_domains'],
                           ],
                           supports_check_mode=True)

    dns = VmwareHostDNS(module)
    dns.ensure()
def main():
    argument_spec = vmware_argument_spec()
    argument_spec.update(
        name=dict(type='str'),
        uuid=dict(type='str'),
        use_instance_uuid=dict(type='bool', default=False),
        datacenter=dict(removed_in_version=2.9, type='str')
    )

    module = AnsibleModule(argument_spec=argument_spec,
                           required_one_of=[['name', 'uuid']],
                           mutually_exclusive=[['name', 'uuid']],
                           )

    pyv = PyVmomiHelper(module)
    # Check if the VM exists before continuing
    folders = pyv.getvm_folder_paths()

    # VM already exists
    if folders:
        try:
            module.exit_json(folders=folders)
        except Exception as exc:
            module.fail_json(msg="Folder enumeration failed with exception %s" % to_native(exc))
    else:
        module.fail_json(msg="Unable to find folders for virtual machine %s" % (module.params.get('name') or
                                                                                module.params.get('uuid')))
Beispiel #5
0
def main():
    argument_spec = vmware_argument_spec()
    argument_spec.update(
        name=dict(type='str'),
        uuid=dict(type='str'),
        moid=dict(type='str'),
        folder=dict(type='str'),
        datacenter=dict(type='str'),
        esxi_hostname=dict(type='str'),
        cluster=dict(type='str'),
        keys_send=dict(type='list', default=[]),
        string_send=dict(type='str')
    )

    module = AnsibleModule(
        argument_spec=argument_spec,
        required_one_of=[
            ['name', 'uuid', 'moid']
        ]
    )

    pyv = PyVmomiHelper(module)
    vm = pyv.get_vm()
    if not vm:
        vm_id = (module.params.get('uuid') or module.params.get('name') or module.params.get('moid'))
        module.fail_json(msg='Unable to find the specified virtual machine : %s ' % vm_id)

    result = pyv.send_key_to_vm(vm)
    if result['failed']:
        module.fail_json(**result)
    else:
        module.exit_json(**result)
Beispiel #6
0
def main():
    spec = vmware_argument_spec()
    spec.update(
        dict(esxi_hostname=dict(type='str', required=True),
             vsan=dict(
                 type='str',
                 choices=[
                     'ensureObjectAccessibility', 'evacuateAllData', 'noAction'
                 ],
                 aliases=['vsan_mode'],
             ),
             evacuate=dict(type='bool', default=False),
             timeout=dict(default=0, type='int'),
             state=dict(required=False,
                        default='present',
                        choices=['present', 'absent'])))

    module = AnsibleModule(argument_spec=spec)

    host_maintenance_mgr = VmwareMaintenanceMgr(module=module)

    if module.params['state'] == 'present':
        host_maintenance_mgr.EnterMaintenanceMode()
    elif module.params['state'] == 'absent':
        host_maintenance_mgr.ExitMaintenanceMode()
Beispiel #7
0
def main():
    """Main"""
    argument_spec = vmware_argument_spec()
    module = AnsibleModule(argument_spec=argument_spec,
                           supports_check_mode=True)
    vmware_local_user_facts = VMwareUserFactsManager(module)
    vmware_local_user_facts.gather_user_facts()
Beispiel #8
0
def main():

    argument_spec = vmware_argument_spec()
    argument_spec.update(dict(change_hostname_to=dict(required=True, type='str'),
                              domainname=dict(required=True, type='str'),
                              dns_servers=dict(required=True, type='list')))

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

    if not HAS_PYVMOMI:
        module.fail_json(msg='pyvmomi is required for this module')

    change_hostname_to = module.params['change_hostname_to']
    domainname = module.params['domainname']
    dns_servers = module.params['dns_servers']
    try:
        content = connect_to_api(module)
        host = get_all_objs(content, [vim.HostSystem])
        if not host:
            module.fail_json(msg="Unable to locate Physical Host.")
        host_system = list(host)[0]
        changed = configure_dns(host_system, change_hostname_to, domainname, dns_servers)
        module.exit_json(changed=changed)
    except vmodl.RuntimeFault as runtime_fault:
        module.fail_json(msg=runtime_fault.msg)
    except vmodl.MethodFault as method_fault:
        module.fail_json(msg=method_fault.msg)
    except Exception as e:
        module.fail_json(msg=str(e))
Beispiel #9
0
def main():

    argument_spec = vmware_argument_spec()
    argument_spec.update(
        dict(vmk_name=dict(required=True, type='str'),
             ip_address=dict(required=True, type='str'),
             subnet_mask=dict(required=True, type='str')))

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

    if not HAS_PYVMOMI:
        module.fail_json(msg='pyvmomi is required for this module')

    vmk_name = module.params['vmk_name']
    ip_address = module.params['ip_address']
    subnet_mask = module.params['subnet_mask']

    try:
        content = connect_to_api(module, False)
        host = get_all_objs(content, [vim.HostSystem])
        if not host:
            module.fail_json(msg="Unable to locate Physical Host.")
        host_system = list(host)[0]
        changed = configure_vmkernel_ip_address(host_system, vmk_name,
                                                ip_address, subnet_mask)
        module.exit_json(changed=changed)
    except vmodl.RuntimeFault as runtime_fault:
        module.fail_json(msg=runtime_fault.msg)
    except vmodl.MethodFault as method_fault:
        module.fail_json(msg=method_fault.msg)
    except Exception as e:
        module.fail_json(msg=str(e))
def main():
    argument_spec = vmware_argument_spec()

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

    spbm_client = SPBMClient(module)
    spbm_client.get_storage_policy_info()
def main():
    argument_spec = vmware_argument_spec()
    argument_spec.update(
        datacenter=dict(type='str', required=True,
                        aliases=['datacenter_name']),
        folder_name=dict(type='str', required=True),
        parent_folder=dict(type='str', required=False),
        state=dict(type='str',
                   choices=['present', 'absent'],
                   default='present'),
        folder_type=dict(type='str',
                         default='vm',
                         choices=['datastore', 'host', 'network', 'vm'],
                         required=False),
    )

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

    if len(module.params.get('folder_name')) > 79:
        module.fail_json(
            msg=
            "Failed to manage folder as folder_name can only contain 80 characters."
        )

    vcenter_folder_mgr = VmwareFolderManager(module)
    if not vcenter_folder_mgr.is_vcenter():
        module.fail_json(
            msg="Module vcenter_folder is meant for vCenter, hostname %s "
            "is not vCenter server." % module.params.get('hostname'))
    vcenter_folder_mgr.ensure()
Beispiel #12
0
def main():
    argument_spec = vmware_argument_spec()
    argument_spec.update(
        dict(
            esxi_hostname=dict(required=True, type='str'),
            switch_name=dict(required=True, type='str'),
            vmnics=dict(required=True, type='list'),
            state=dict(default='present',
                       choices=['present', 'absent'],
                       type='str'),
            vendor_specific_config=dict(
                type='list',
                elements='dict',
                required=False,
                options=dict(
                    key=dict(type='str', required=True),
                    value=dict(type='str', required=True),
                ),
            ),
        ))

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

    if not HAS_COLLECTIONS_COUNTER:
        module.fail_json(
            msg=
            'collections.Counter from Python-2.7 is required for this module')

    vmware_dvs_host = VMwareDvsHost(module)
    vmware_dvs_host.process_state()
Beispiel #13
0
def main():
    argument_spec = vmware_argument_spec()
    argument_spec.update(
        name=dict(type='str'),
        uuid=dict(type='str'),
        moid=dict(type='str'),
        folder=dict(type='str'),
        datacenter=dict(type='str', default='ha-datacenter'),
        export_dir=dict(type='path', required=True),
        export_with_images=dict(type='bool', default=False),
        download_timeout=dict(type='int', default=10),
    )

    module = AnsibleModule(
        argument_spec=argument_spec,
        supports_check_mode=True,
        required_one_of=[
            ['name', 'uuid', 'moid'],
        ],
    )
    pyv = VMwareExportVmOvf(module)
    vm = pyv.get_vm()
    if vm:
        vm_facts = pyv.gather_facts(vm)
        vm_power_state = vm_facts['hw_power_status'].lower()
        if vm_power_state != 'poweredoff':
            module.fail_json(msg='VM state should be poweredoff to export')
        results = pyv.export_to_ovf_files(vm_obj=vm)
        module.exit_json(**results)
    else:
        module.fail_json(msg='The specified virtual machine not found')
Beispiel #14
0
def main():
    argument_spec = vmware_argument_spec()
    argument_spec.update(
        dict(datacenter=dict(required=True, type='str'),
             cluster=dict(required=True, type='str'),
             resource_pool=dict(required=True, type='str'),
             mem_shares=dict(type='str',
                             default="normal",
                             choices=['high', 'custom', 'normal', 'low']),
             mem_limit=dict(type='int', default=-1),
             mem_reservation=dict(type='int', default=0),
             mem_expandable_reservations=dict(type='bool', default="True"),
             cpu_shares=dict(type='str',
                             default="normal",
                             choices=['high', 'custom', 'normal', 'low']),
             cpu_limit=dict(type='int', default=-1),
             cpu_reservation=dict(type='int', default=0),
             cpu_expandable_reservations=dict(type='bool', default="True"),
             state=dict(default='present',
                        choices=['present', 'absent'],
                        type='str')))

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

    if not HAS_PYVMOMI:
        module.fail_json(msg='pyvmomi is required for this module')

    vmware_rp = VMwareResourcePool(module)
    vmware_rp.process_state()
def main():
    argument_spec = vmware_argument_spec()
    argument_spec.update(
        cluster_name=dict(type='str', required=False),
        esxi_hostname=dict(type='str', required=False),
        rules=dict(type='list', default=list(), required=False),
    )

    module = AnsibleModule(argument_spec=argument_spec,
                           required_one_of=[
                               ['cluster_name', 'esxi_hostname'],
                           ],
                           supports_check_mode=True)

    for rule_option in module.params.get("rules", []):
        if 'allowed_hosts' in rule_option:
            if isinstance(rule_option['allowed_hosts'], list):
                if len(rule_option['allowed_hosts']) == 1:
                    allowed_hosts = rule_option['allowed_hosts'][0]
                    rule_option['allowed_hosts'] = allowed_hosts
                    module.deprecate(
                        'allowed_hosts should be a dict, not a list', '2.13')

    vmware_firewall_manager = VmwareFirewallManager(module)
    vmware_firewall_manager.check_params()
    vmware_firewall_manager.ensure()
Beispiel #16
0
def main():
    argument_spec = vmware_argument_spec()
    argument_spec.update(
        dict(
            cluster_name=dict(type='str', required=True),
            datacenter=dict(type='str',
                            required=True,
                            aliases=['datacenter_name']),
            # DRS
            enable_drs=dict(type='bool', default=False),
            drs_enable_vm_behavior_overrides=dict(type='bool', default=True),
            drs_default_vm_behavior=dict(
                type='str',
                choices=['fullyAutomated', 'manual', 'partiallyAutomated'],
                default='fullyAutomated'),
            drs_vmotion_rate=dict(type='int', choices=range(1, 6), default=3),
            advanced_settings=dict(type='dict', default=dict(),
                                   required=False),
        ))

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

    vmware_cluster_drs = VMwareCluster(module)
    vmware_cluster_drs.configure_drs()
Beispiel #17
0
def main():
    argument_spec = vmware_argument_spec()
    argument_spec.update(
        dict(
            datacenter=dict(type='str'),
            cluster=dict(type='str'),
            folder=dict(type='str'),
            vm_id=dict(type='str', required=True),
            vm_id_type=dict(default='vm_name', type='str',
                            choices=['inventory_path',
                                     'uuid',
                                     'instance_uuid',
                                     'dns_name',
                                     'vm_name']),
            vm_username=dict(type='str', required=True),
            vm_password=dict(type='str', no_log=True, required=True),
            vm_shell=dict(type='str', required=True),
            vm_shell_args=dict(default=" ", type='str'),
            vm_shell_env=dict(type='list'),
            vm_shell_cwd=dict(type='str'),
            wait_for_process=dict(type='bool', default=False),
            timeout=dict(type='int', default=3600),
        )
    )

    module = AnsibleModule(
        argument_spec=argument_spec,
        supports_check_mode=False,
        required_if=[
            ['vm_id_type', 'inventory_path', ['folder']]
        ],
    )

    vm_shell_mgr = VMwareShellManager(module)
Beispiel #18
0
def main():
    """Main"""
    argument_spec = vmware_argument_spec()
    argument_spec.update(
        state=dict(type='str',
                   default='disabled',
                   choices=['enabled', 'disabled', 'reset']),
        snmp_port=dict(type='int', default=161),
        community=dict(type='list', default=[]),
        trap_targets=dict(type='list', default=list()),
        trap_filter=dict(type='list'),
        hw_source=dict(type='str',
                       default='indications',
                       choices=['indications', 'sensors']),
        log_level=dict(type='str',
                       default='info',
                       choices=['debug', 'info', 'warning', 'error']),
        send_trap=dict(type='bool', default=False),
    )

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

    host_snmp = VmwareHostSnmp(module)
    host_snmp.ensure()
Beispiel #19
0
def main():
    argument_spec = vmware_argument_spec()
    # add the arguments we're going to use for this module
    argument_spec.update(
        cluster_name=dict(type='str', required=False),
        esxi_hostname=dict(type='str', required=False),
        kernel_module_name=dict(type='str', required=True),
        kernel_module_option=dict(type='str', required=True),
    )

    # make sure we have a valid target cluster_name or esxi_hostname (not both)
    # and also enable check mode
    module = AnsibleModule(
        argument_spec=argument_spec,
        supports_check_mode=True,
        required_one_of=[
            ['cluster_name', 'esxi_hostname'],
        ],
        mutually_exclusive=[
            ['cluster_name', 'esxi_hostname'],
        ],
    )

    vmware_host_config = VmwareKernelManager(module)
    vmware_host_config.check_host_configuration_state()
Beispiel #20
0
def main():
    argument_spec = vmware_argument_spec()
    argument_spec.update(
        dict(
            state=dict(type='str',
                       default='present',
                       choices=['absent', 'present']),
            vms=dict(type='list'),
            cluster_name=dict(type='str', required=True),
            drs_rule_name=dict(type='str', required=True),
            enabled=dict(type='bool', default=False),
            mandatory=dict(type='bool', default=False),
            affinity_rule=dict(type='bool', default=True),
        ))

    required_if = [['state', 'present', ['vms']]]
    module = AnsibleModule(argument_spec=argument_spec,
                           required_if=required_if,
                           supports_check_mode=True)

    results = dict(failed=False, changed=False)
    state = module.params['state']
    vm_drs = VmwareDrs(module)

    if state == 'present':
        # Add Rule
        if module.check_mode:
            results['changed'] = True
            module.exit_json(**results)
        changed, result = vm_drs.create()
        if changed:
            results['changed'] = changed
        else:
            results['failed'] = True
            results['msg'] = "Failed to create DRS rule %s" % vm_drs.rule_name
        results['result'] = result
    elif state == 'absent':
        # Delete Rule
        if module.check_mode:
            results['changed'] = True
            module.exit_json(**results)
        changed, result = vm_drs.delete()
        if changed:
            results['changed'] = changed
            results[
                'msg'] = "DRS rule %s deleted successfully." % vm_drs.rule_name
        else:
            if "No rule named" in result:
                results['msg'] = result
                module.exit_json(**results)

            results['failed'] = True
            results['msg'] = "Failed to delete DRS rule %s" % vm_drs.rule_name
        results['result'] = result

    if results['changed']:
        module.exit_json(**results)
    if results['failed']:
        module.fail_json(**results)
Beispiel #21
0
def main():
    """Main"""
    argument_spec = vmware_argument_spec()
    module = AnsibleModule(argument_spec=argument_spec,
                           supports_check_mode=True)

    vmware_local_role_info = VMwareLocalRoleInfo(module)
    vmware_local_role_info.gather_local_role_info()
Beispiel #22
0
def main():
    argument_spec = vmware_argument_spec()
    module = AnsibleModule(argument_spec=argument_spec,
                           supports_check_mode=True)

    vmware_rp_mgr = ResourcePoolFactsManager(module)
    module.exit_json(changed=False,
                     resource_pool_facts=vmware_rp_mgr.gather_rp_facts())
Beispiel #23
0
def main():
    """
    Main function
    """

    argument_spec = vmware_argument_spec()

    argument_spec.update(
        state=dict(type='str', default='present', choices=['present', 'absent']),
        datacenter=dict(type='str', required=False, aliases=['datacenter_name']),
        cluster_name=dict(type='str', required=True),
        group_name=dict(type='str', required=True),
        vms=dict(type='list'),
        hosts=dict(type='list')
    )

    required_if = [
        ['state', 'absent', ['group_name']]
    ]

    module = AnsibleModule(
        argument_spec=argument_spec,
        required_if=required_if,
        supports_check_mode=True,
        mutually_exclusive=[['vms', 'hosts']],
        required_one_of=[['vms', 'hosts']]
    )

    try:
        # Create instance of VmwareDrsGroupManager
        vmware_drs_group = VmwareDrsGroupManager(module=module,
                                                 datacenter_name=module.params.get('datacenter', None),
                                                 cluster_name=module.params['cluster_name'],
                                                 group_name=module.params['group_name'],
                                                 vm_list=module.params['vms'],
                                                 host_list=module.params['hosts'],
                                                 state=module.params['state'])

        if module.params['state'] == 'present':
            # Add DRS group
            vmware_drs_group.create_drs_group()
        elif module.params['state'] == 'absent':
            # Delete DRS group
            vmware_drs_group.delete_drs_group()

        # Set results
        results = dict(msg=vmware_drs_group.get_msg(),
                       failed=False,
                       changed=vmware_drs_group.get_changed(),
                       result=vmware_drs_group.get_result())

    except Exception as error:
        results = dict(failed=True, msg="Error: %s" % error)

    if results['failed']:
        module.fail_json(**results)
    else:
        module.exit_json(**results)
Beispiel #24
0
def main():
    argument_spec = vmware_argument_spec()
    argument_spec.update(cluster_name=dict(required=True, type='str'),
                         fetch_from_cache=dict(required=False, type='bool'))

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

    if not HAS_PYVMOMI:
        module.fail_json(msg=missing_required_lib('PyVmomi'),
                         exception=PYVMOMI_IMP_ERR)

    if not HAS_VSANPYTHONSDK:
        module.fail_json(
            msg=missing_required_lib('vSAN Management SDK for Python'),
            exception=VSANPYTHONSDK_IMP_ERR)

    if not HAS_PYVMOMIJSON:
        module.fail_json(
            msg=
            'The installed version of pyvmomi lacks JSON output support; need pyvmomi>6.7.1'
        )

    try:
        si, content = connect_to_api(module, True, True)
    except Exception as e:
        module.fail_json(msg=e.msg)

    client_stub = si._GetStub()
    ssl_context = client_stub.schemeArgs.get('context')

    cluster = find_cluster_by_name(content, module.params['cluster_name'])

    if not cluster:
        module.fail_json(msg="Failed to find cluster %s" %
                         module.params['cluster_name'])

    apiVersion = vsanapiutils.GetLatestVmodlVersion(module.params['hostname'])
    vcMos = vsanapiutils.GetVsanVcMos(client_stub,
                                      context=ssl_context,
                                      version=apiVersion)

    vsanClusterHealthSystem = vcMos['vsan-cluster-health-system']

    try:
        clusterHealth = vsanClusterHealthSystem.VsanQueryVcClusterHealthSummary(
            cluster=cluster, fetchFromCache=module.params['fetch_from_cache'])
    except vmodl.fault.NotFound as not_found:
        module.fail_json(msg=not_found.msg)
    except vmodl.fault.RuntimeFault as runtime_fault:
        module.fail_json(msg=runtime_fault.msg)

    health = json.dumps(clusterHealth,
                        cls=VmomiSupport.VmomiJSONEncoder,
                        sort_keys=True,
                        strip_dynamic=True)

    module.exit_json(changed=False, vsan_health_info=health)
def main():
    argument_spec = vmware_argument_spec()

    argument_spec.update(
        dict(
            switch=dict(required=True, type='str', aliases=['dvswitch']),
            version=dict(type='str', choices=['version2', 'version3']),
            state=dict(default='present', choices=['present', 'absent'], type='str'),
            resources=dict(
                type='list',
                default=list(),
                elements='dict',
                options=dict(
                    name=dict(
                        type='str',
                        required=True,
                        choices=[
                            'faultTolerance',
                            'hbr',
                            'iSCSI',
                            'management',
                            'nfs',
                            'vdp',
                            'virtualMachine',
                            'vmotion',
                            'vsan'
                        ]
                    ),
                    limit=dict(type='int', default=-1),
                    shares_level=dict(
                        type='str',
                        required=False,
                        choices=[
                            'low',
                            'normal',
                            'high',
                            'custom'
                        ]
                    ),
                    shares=dict(type='int', required=False),
                    reservation=dict(type='int', default=0)
                )
            ),
        )
    )

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

    try:
        vmware_dvswitch_nioc = VMwareDVSwitchNIOC(module)
        vmware_dvswitch_nioc.process_state()
    except vmodl.RuntimeFault as runtime_fault:
        module.fail_json(msg=to_native(runtime_fault.msg))
    except vmodl.MethodFault as method_fault:
        module.fail_json(msg=to_native(method_fault.msg))
    except Exception as e:
        module.fail_json(msg=to_native(e))
Beispiel #26
0
def main():
    argument_spec = vmware_argument_spec()
    argument_spec.update(
        dict(
            cluster_name=dict(type='str', required=True),
            datacenter=dict(type='str',
                            required=True,
                            aliases=['datacenter_name']),
            state=dict(type='str',
                       default='present',
                       choices=['absent', 'present']),
            # DRS
            ignore_drs=dict(type='bool', default=False),
            enable_drs=dict(type='bool', default=False),
            drs_enable_vm_behavior_overrides=dict(type='bool', default=True),
            drs_default_vm_behavior=dict(
                type='str',
                choices=['fullyAutomated', 'manual', 'partiallyAutomated'],
                default='fullyAutomated'),
            drs_vmotion_rate=dict(type='int', choices=range(1, 6), default=3),
            # HA
            ignore_ha=dict(type='bool', default=False),
            enable_ha=dict(type='bool', default=False),
            ha_failover_level=dict(type='int', default=2),
            ha_host_monitoring=dict(type='str',
                                    default='enabled',
                                    choices=['enabled', 'disabled']),
            # HA VM Monitoring related parameters
            ha_vm_monitoring=dict(type='str',
                                  choices=[
                                      'vmAndAppMonitoring', 'vmMonitoringOnly',
                                      'vmMonitoringDisabled'
                                  ],
                                  default='vmMonitoringDisabled'),
            ha_vm_failure_interval=dict(type='int', default=30),
            ha_vm_min_up_time=dict(type='int', default=120),
            ha_vm_max_failures=dict(type='int', default=3),
            ha_vm_max_failure_window=dict(type='int', default=-1),
            ha_restart_priority=dict(
                type='str',
                choices=['high', 'low', 'medium', 'disabled'],
                default='medium'),
            ha_admission_control_enabled=dict(type='bool', default=True),
            # VSAN
            ignore_vsan=dict(type='bool', default=False),
            enable_vsan=dict(type='bool', default=False),
            vsan_auto_claim_storage=dict(type='bool', default=False),
        ))

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

    vmware_cluster = VMwareCluster(module)
    vmware_cluster.process_state()
def main():
    argument_spec = vmware_argument_spec()

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

    vmware_about_info_mgr = VmwareAboutManager(module)
    vmware_about_info_mgr.gather_about_info()
def main():
    argument_spec = vmware_argument_spec()

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

    vcenter_extension_facts_mgr = VmwareExtManager(module)
    vcenter_extension_facts_mgr.gather_plugin_facts()
Beispiel #29
0
def main():
    argument_spec = vmware_argument_spec()
    argument_spec.update(
        state=dict(default='present', choices=['present', 'absent', 'revert', 'remove_all']),
        name=dict(type='str'),
        name_match=dict(type='str', choices=['first', 'last'], default='first'),
        uuid=dict(type='str'),
        moid=dict(type='str'),
        use_instance_uuid=dict(type='bool', default=False),
        folder=dict(type='str'),
        datacenter=dict(required=True, type='str'),
        snapshot_name=dict(type='str'),
        description=dict(type='str', default=''),
        quiesce=dict(type='bool', default=False),
        memory_dump=dict(type='bool', default=False),
        remove_children=dict(type='bool', default=False),
        new_snapshot_name=dict(type='str'),
        new_description=dict(type='str'),
    )
    module = AnsibleModule(
        argument_spec=argument_spec,
        required_together=[
            ['name', 'folder']
        ],
        required_one_of=[
            ['name', 'uuid', 'moid']
        ],
    )

    if module.params['folder']:
        # FindByInventoryPath() does not require an absolute path
        # so we should leave the input folder path unmodified
        module.params['folder'] = module.params['folder'].rstrip('/')

    pyv = PyVmomiHelper(module)
    # Check if the VM exists before continuing
    vm = pyv.get_vm()

    if not vm:
        vm_id = (module.params.get('uuid') or module.params.get('name') or module.params.get('moid'))
        module.fail_json(msg="Unable to manage snapshots for non-existing VM %s" % vm_id)

    if not module.params['snapshot_name'] and module.params['state'] != 'remove_all':
        module.fail_json(msg="snapshot_name param is required when state is '%(state)s'" % module.params)

    result = pyv.apply_snapshot_op(vm)

    if 'failed' not in result:
        result['failed'] = False

    if result['failed']:
        module.fail_json(**result)
    else:
        module.exit_json(**result)
def main():
    """Main"""
    argument_spec = vmware_argument_spec()
    argument_spec.update(
        interval_past_day=dict(
            type='dict',
            options=dict(
                enabled=dict(type='bool', default=True),
                interval_minutes=dict(type='int',
                                      choices=[1, 2, 3, 4, 5],
                                      default=5),
                save_for_days=dict(type='int',
                                   choices=[1, 2, 3, 4, 5],
                                   default=1),
                level=dict(type='int', choices=[1, 2, 3, 4], default=1),
            ),
        ),
        interval_past_week=dict(
            type='dict',
            options=dict(
                enabled=dict(type='bool', default=True),
                interval_minutes=dict(type='int', choices=[30], default=30),
                save_for_weeks=dict(type='int', choices=[1], default=1),
                level=dict(type='int', choices=[1, 2, 3, 4], default=1),
            ),
        ),
        interval_past_month=dict(
            type='dict',
            options=dict(
                enabled=dict(type='bool', default=True),
                interval_hours=dict(type='int', choices=[2], default=2),
                save_for_months=dict(type='int', choices=[1], default=1),
                level=dict(type='int', choices=[1, 2, 3, 4], default=1),
            ),
        ),
        interval_past_year=dict(
            type='dict',
            options=dict(
                enabled=dict(type='bool', default=True),
                interval_days=dict(type='int', choices=[1], default=1),
                save_for_years=dict(type='int',
                                    choices=[1, 2, 3, 4, 5],
                                    default=1),
                level=dict(type='int', choices=[1, 2, 3, 4], default=1),
            ),
        ),
    )

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

    host_snmp = VmwareVcenterStatistics(module)
    host_snmp.ensure()