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(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(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))
 def __init__(self, module):
     self.module = module
     self.host_system = None
     self.migrate_switch_name = self.module.params['migrate_switch_name']
     self.migrate_portgroup_name = self.module.params[
         'migrate_portgroup_name']
     self.device = self.module.params['device']
     self.esxi_hostname = self.module.params['esxi_hostname']
     self.current_portgroup_name = self.module.params[
         'current_portgroup_name']
     self.current_switch_name = self.module.params['current_switch_name']
     self.content = connect_to_api(module)
Ejemplo n.º 5
0
    def __init__(self, module):
        self.si = connect_to_api(module)
        self.module = module
        self.params = module.params

        self.datastore = None
        self.datacenter = None
        self.resource_pool = None
        self.network_mappings = []

        self.ovf_descriptor = None
        self.tar = None

        self.lease = None
        self.import_spec = None
        self.entity = None
 def __init__(self, module):
     self.module = module
     self.datacenter = module.params['datacenter']
     self.cluster = module.params['cluster']
     self.resource_pool = module.params['resource_pool']
     self.hostname = module.params['hostname']
     self.username = module.params['username']
     self.password = module.params['password']
     self.state = module.params['state']
     self.mem_shares = module.params['mem_shares']
     self.mem_limit = module.params['mem_limit']
     self.mem_reservation = module.params['mem_reservation']
     self.mem_expandable_reservations = module.params[
         'cpu_expandable_reservations']
     self.cpu_shares = module.params['cpu_shares']
     self.cpu_limit = module.params['cpu_limit']
     self.cpu_reservation = module.params['cpu_reservation']
     self.cpu_expandable_reservations = module.params[
         'cpu_expandable_reservations']
     self.dc_obj = None
     self.cluster_obj = None
     self.host_obj = None
     self.resource_pool_obj = None
     self.content = connect_to_api(module)
def main():
    argument_spec = vmware_argument_spec()
    argument_spec.update(
        dict(
            extension_key=dict(type='str', required=True),
            version=dict(type='str', required=True),
            email=dict(type='str', required=False),
            description=dict(type='str', required=False),
            company=dict(type='str', required=False),
            name=dict(type='str', required=False),
            url=dict(type='str', required=False),
            ssl_thumbprint=dict(type='str', required=False),
            client_type=dict(type='str',
                             default='vsphere-client-serenity',
                             required=False),
            server_type=dict(type='str',
                             default='vsphere-client-serenity',
                             required=False),
            visible=dict(type='bool', default='True', required=False),
            state=dict(type='str',
                       default='present',
                       choices=['absent', 'present']),
        ))

    module = AnsibleModule(argument_spec=argument_spec,
                           supports_check_mode=False,
                           required_if=[[
                               'state', 'present',
                               [
                                   'email', 'description', 'company', 'name',
                                   'url', 'ssl_thumbprint', 'server_type',
                                   'client_type'
                               ]
                           ]])

    state = module.params['state']
    extension_key = module.params['extension_key']
    version = module.params['version']
    email = module.params['email']
    desc = module.params['description']
    name = module.params['name']
    company = module.params['company']
    client_type = module.params['client_type']
    server_type = module.params['server_type']
    url = module.params['url']
    visible = module.params['visible']
    thumbprint = module.params['ssl_thumbprint']

    content = connect_to_api(module, False)
    em = content.extensionManager
    key_check = em.FindExtension(extension_key)
    results = dict(changed=False, installed=dict())

    if state == 'present' and key_check:
        results['changed'] = False
        results['installed'] = "'%s' is already installed" % (extension_key)

    elif state == 'present' and not key_check:
        extension = vim.Extension()
        extension.key = extension_key
        extension.company = company
        extension.version = version
        extension.lastHeartbeatTime = datetime.datetime.now()
        description = vim.Description()
        description.label = name
        description.summary = desc
        extension.description = description
        extension.shownInSolutionManager = visible

        client = vim.Extension.ClientInfo()
        client.company = company
        client.version = version
        client.description = description
        client.type = client_type
        client.url = url
        extension.client = [client]

        server = vim.Extension.ServerInfo()
        server.company = company
        server.description = description
        server.type = server_type
        server.adminEmail = email
        server.serverThumbprint = thumbprint
        server.url = url
        extension.server = [server]

        em.RegisterExtension(extension)
        results['changed'] = True
        results['installed'] = "'%s' installed." % (extension_key)

    elif state == 'absent' and key_check:
        em.UnregisterExtension(extension_key)
        results['changed'] = True
        results['installed'] = "'%s' uninstalled." % (extension_key)

    elif state == 'absent' and not key_check:
        results['changed'] = False
        results['installed'] = "'%s' is not installed." % (extension_key)

    module.exit_json(**results)
 def __init__(self, module):
     self.module = module
     self.content = connect_to_api(module)
     self.vm = None
     self.vm_name = module.params['vm_name']
     self.dvportgroup_name = module.params['dvportgroup_name']