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)
Exemplo n.º 2
0
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(
        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'
        ),
    )

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

    pyv = VmBootFactsManager(module)
    pyv.ensure()
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()
Exemplo n.º 5
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()
Exemplo n.º 6
0
def main():
    """ Main """
    argument_spec = vmware_argument_spec()
    argument_spec.update(name=dict(type='str'),
                         datacenter=dict(type='str',
                                         aliases=['datacenter_name']),
                         cluster=dict(type='str'),
                         gather_nfs_mount_info=dict(type='bool',
                                                    default=False),
                         gather_vmfs_mount_info=dict(type='bool',
                                                     default=False))
    module = AnsibleModule(argument_spec=argument_spec,
                           supports_check_mode=True)
    result = dict(changed=False)

    pyv = PyVmomiHelper(module)

    if module.params['cluster']:
        dxs = pyv.lookup_datastore_by_cluster()
    elif module.params['datacenter']:
        dxs = pyv.lookup_datastore(confine_to_datacenter=True)
    else:
        dxs = pyv.lookup_datastore(confine_to_datacenter=False)

    vmware_host_datastore = VMwareHostDatastore(module)
    datastores = vmware_host_datastore.build_datastore_list(dxs)

    result['datastores'] = datastores

    module.exit_json(**result)
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))
Exemplo n.º 8
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'),
                         esxi_hostname=dict(type='str'),
                         cluster=dict(type='str'),
                         gather_network_facts=dict(type='bool', default=False),
                         networks=dict(type='list', default=[]))

    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 using %s' %
            vm_id)

    result = pyv.reconfigure_vm_network(vm)
    if result['failed']:
        module.fail_json(**result)
    else:
        module.exit_json(**result)
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():
    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')))
def main():

    argument_spec = vmware_argument_spec()
    argument_spec.update(dict(cluster_uuid=dict(required=False, 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')

    new_cluster_uuid = module.params['cluster_uuid']

    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, result, cluster_uuid = create_vsan_cluster(
            host_system, new_cluster_uuid)
        module.exit_json(changed=changed,
                         result=result,
                         cluster_uuid=cluster_uuid)

    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()
    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()
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()
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()
    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()
Exemplo n.º 16
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()
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()
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),
        folder=dict(type='str'),
        datacenter=dict(required=True, type='str'),
    )
    module = AnsibleModule(
        argument_spec=argument_spec,
        required_together=[['name', 'folder']],
        required_one_of=[['name', 'uuid']],
        supports_check_mode=True,
    )

    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:
        # If UUID is set, getvm select UUID, show error message accordingly.
        module.fail_json(
            msg="Unable to gather facts about snapshots for"
            " non-existing VM ['%s']" %
            (module.params.get('uuid') or module.params.get('name')))

    results = dict(changed=False,
                   guest_snapshots=pyv.gather_guest_snapshot_facts(vm_obj=vm))
    module.exit_json(**results)
Exemplo n.º 19
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)
    else:
        module.fail_json(msg='The specified virtual machine not found')
    module.exit_json(**results)
Exemplo n.º 20
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)
Exemplo n.º 21
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)
Exemplo n.º 22
0
def main():
    """Main"""
    argument_spec = vmware_argument_spec()
    module = AnsibleModule(argument_spec=argument_spec,
                           supports_check_mode=True)

    vmware_local_role_facts = VMwareLocalRoleFacts(module)
    vmware_local_role_facts.gather_local_role_facts()
Exemplo n.º 23
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())
Exemplo n.º 24
0
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))
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)
Exemplo n.º 26
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(
        dict(
            switch=dict(required=True, aliases=['dvswitch']),
            name=dict(type='str'),
            description=dict(type='str'),
            advanced=dict(
                type='dict',
                options=dict(
                    port_config_reset_at_disconnect=dict(type='bool',
                                                         default=True),
                    block_override=dict(type='bool', default=True),
                    vendor_config_override=dict(type='bool', default=False),
                    vlan_override=dict(type='bool', default=False),
                    netflow_override=dict(type='bool', default=False),
                    traffic_filter_override=dict(type='bool', default=False),
                ),
                default=dict(
                    port_config_reset_at_disconnect=True,
                    block_override=True,
                    vendor_config_override=False,
                    vlan_override=False,
                    netflow_override=False,
                    traffic_filter_override=False,
                ),
                aliases=['port_policy'],
            ),
            lacp=dict(
                type='dict',
                options=dict(
                    status=dict(type='str',
                                choices=['enabled', 'disabled'],
                                default=['disabled']),
                    mode=dict(type='str',
                              choices=['active', 'passive'],
                              default=['passive']),
                ),
                default=dict(
                    status='disabled',
                    mode='passive',
                ),
            ),
            vlan_trunk_range=dict(type='list', default=['0-4094']),
            netflow_enabled=dict(type='bool', default=False),
            block_all_ports=dict(type='bool', default=False),
        ))

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

    vmware_dvswitch_uplink_pg = VMwareDvSwitchUplinkPortgroup(module)
    vmware_dvswitch_uplink_pg.ensure()
def main():
    argument_spec = vmware_argument_spec()
    argument_spec.update(
        esxi_hostname=dict(type='str', required=False),
    )
    module = AnsibleModule(argument_spec=argument_spec,
                           supports_check_mode=True)

    vm_host_manager = VMwareHostFactManager(module)
    vm_host_manager.all_facts()
def main():
    argument_spec = vmware_argument_spec()

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

    vmware_about_facts_mgr = VmwareAboutManager(module)
    vmware_about_facts_mgr.gather_about_facts()
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()