From 3248e3b0a114102fbd421631f749edf64a8b4297 Mon Sep 17 00:00:00 2001 From: Mike Morency Date: Tue, 3 Dec 2024 11:57:55 -0500 Subject: [PATCH 1/6] update pyvmomi method names --- plugins/module_utils/_vmware.py | 86 +++++++++++-------- plugins/modules/cluster.py | 4 +- plugins/modules/cluster_dpm.py | 4 +- plugins/modules/cluster_drs.py | 4 +- .../modules/cluster_drs_recommendations.py | 4 +- plugins/modules/cluster_info.py | 8 +- plugins/modules/cluster_vcls.py | 8 +- plugins/modules/folder_template_from_vm.py | 4 +- plugins/modules/vm_portgroup_info.py | 4 +- 9 files changed, 69 insertions(+), 57 deletions(-) diff --git a/plugins/module_utils/_vmware.py b/plugins/module_utils/_vmware.py index 69f57189..711aeeab 100644 --- a/plugins/module_utils/_vmware.py +++ b/plugins/module_utils/_vmware.py @@ -262,25 +262,31 @@ def get_objs_by_name_or_moid(self, vimtype, name, return_all=False, search_root_ # for backwards-compat return None - def get_standard_portgroup(self, portgroup): + def get_dvs_portgroup_by_name_or_moid(self, identifier, fail_on_missing=False): """ - Get a portgroup from type 'STANDARD_PORTGROUP' + Get a portgroup from type 'STANDARD_PORTGROUP' based on name or MOID Args: - portgroup: The name or the ID of the portgroup + identifier: The name or the ID of the portgroup Returns: The standard portgroup object """ - return self.get_objs_by_name_or_moid([vim.Network], portgroup) + pg = self.get_objs_by_name_or_moid([vim.Network], identifier) + if not pg and fail_on_missing: + self.module.fail_json("Unable to find standard portgroup with name or MOID %s" % identifier) + return pg - def get_dvs_portgroup(self, portgroup): + def get_dvs_portgroup_by_name_or_moid(self, identifier, fail_on_missing=False): """ - Get a portgroup from type 'DISTRIBUTED_PORTGROUP' + Get a portgroup from type 'DISTRIBUTED_PORTGROUP' based on name or MOID Args: - portgroup: The name or the ID of the portgroup + identifier: The name or the ID of the portgroup Returns: The distributed portgroup object """ - return self.get_objs_by_name_or_moid([vim.dvs.DistributedVirtualPortgroup], portgroup) + pg = self.get_objs_by_name_or_moid([vim.dvs.DistributedVirtualPortgroup], identifier) + if not pg and fail_on_missing: + self.module.fail_json("Unable to find distributed portgroup with name or MOID %s" % identifier) + return pg def get_vm_using_params( self, name_param='name', uuid_param='uuid', moid_param='moid', fail_on_missing=False, @@ -336,19 +342,19 @@ def get_vm_using_params( return vms - def get_folder_by_name(self, folder_name, fail_on_missing=False): + def get_folders_by_name_or_moid(self, identifier, fail_on_missing=False): """ Get all folders with the given name. Names are not unique in a given cluster, so multiple folder objects can be returned Args: - folder_name: Name of the folder to search for + folder_identifier: Name or MOID of the folder to search for fail_on_missing: If true, an error will be thrown if no folders are found Returns: list(folder object) or None """ - folder = self.get_objs_by_name_or_moid([vim.Folder], folder_name, return_all=True) + folder = self.get_objs_by_name_or_moid([vim.Folder], identifier, return_all=True) if not folder and fail_on_missing: - self.module.fail_json("Unable to find folder with name %s" % folder_name) + self.module.fail_json("Unable to find folder with name or MOID %s" % identifier) return folder def get_folder_by_absolute_path(self, folder_path, fail_on_missing=False): @@ -368,39 +374,39 @@ def get_folder_by_absolute_path(self, folder_path, fail_on_missing=False): self.module.fail_json("Unable to find folder with absolute path %s" % folder_path) return folder - def get_datastore_by_name(self, ds_name, fail_on_missing=False): + def get_datastore_by_name_or_moid(self, identifier, fail_on_missing=False): """ Get the datastore matching the given name. Datastore names must be unique in a given cluster, so only one object is returned at most. Args: - ds_name: Name of the datastore to search for + identifier: Name or MOID of the datastore to search for fail_on_missing: If true, an error will be thrown if no datastores are found Returns: datastore object or None """ - ds = self.get_objs_by_name_or_moid([vim.Datastore], ds_name) + ds = self.get_objs_by_name_or_moid([vim.Datastore], identifier) if not ds and fail_on_missing: - self.module.fail_json("Unable to find datastore with name %s" % ds_name) + self.module.fail_json("Unable to find datastore with name or MOID %s" % identifier) return ds - def get_resource_pool_by_name(self, pool_name, fail_on_missing=False): + def get_resource_pool_by_name_or_moid(self, identifier, fail_on_missing=False): """ Get the resource pool matching the given name. Pool names must be unique in a given cluster, so only one object is returned at most. Args: - pool_name: Name of the pool to search for + identifier: Name or MOID of the pool to search for fail_on_missing: If true, an error will be thrown if no pools are found Returns: resource pool object or None """ - pool = self.get_objs_by_name_or_moid([vim.ResourcePool], pool_name) + pool = self.get_objs_by_name_or_moid([vim.ResourcePool], identifier) if not pool and fail_on_missing: - self.module.fail_json("Unable to find resource pool with name %s" % pool_name) + self.module.fail_json("Unable to find resource pool with name %s" % identifier) return pool - def list_all_objs_by_type(self, vimtype, folder=None, recurse=True): + def get_all_objs_by_type(self, vimtype, folder=None, recurse=True): """ - Returns a dictionary of all objects matching a given VMWare type. + Returns a list of all objects matching a given VMWare type. You can also limit the search by folder and recurse if desired Args: vimtype: The type of object to search for @@ -408,48 +414,54 @@ def list_all_objs_by_type(self, vimtype, folder=None, recurse=True): none is provided, the datacenter root will be used recurse: If true, the search will recurse through the folder structure Returns: - dicttionary of {obj: str}. The keys are the object while the values are the - object name + list of objs """ if not folder: folder = self.content.rootFolder - obj = {} + objs = [] container = self.content.viewManager.CreateContainerView(folder, vimtype, recurse) for managed_object_ref in container.view: try: - obj.update({managed_object_ref: managed_object_ref.name}) + objs += [managed_object_ref] except vmodl.fault.ManagedObjectNotFound: pass - return obj + return objs def get_all_vms(self, folder=None, recurse=True): """ - Get all virtual machines. + Get all virtual machines in a folder. Can recurse through folder tree if needed. If no folder + is provided, then the datacenter root folder is used + Args: + folder: vim.Folder, the folder object to use as a base for the search. If + none is provided, the datacenter root will be used + recurse: If true, the search will recurse through the folder structure + Returns: + list of vim.VirtualMachine """ - return self.list_all_objs_by_type([vim.VirtualMachine], folder=folder, recurse=recurse) + return self.get_all_objs_by_type([vim.VirtualMachine], folder=folder, recurse=recurse) - def get_datacenter_by_name(self, dc_name, fail_on_missing=False): + def get_datacenter_by_name_or_moid(self, identifier, fail_on_missing=False): """ Get the datacenter matching the given name. Datacenter names must be unique in a given vcenter, so only one object is returned at most. Args: - dc_name: Name of the datacenter to search for + identifier: Name or MOID of the datacenter to search for fail_on_missing: If true, an error will be thrown if no datacenters are found Returns: datacenter object or None """ - ds = self.get_objs_by_name_or_moid([vim.Datacenter], dc_name) + ds = self.get_objs_by_name_or_moid([vim.Datacenter], identifier) if not ds and fail_on_missing: - self.module.fail_json("Unable to find datacenter with name %s" % dc_name) + self.module.fail_json("Unable to find datacenter with name or MOID %s" % identifier) return ds - def get_cluster_by_name(self, cluster_name, fail_on_missing=False, datacenter=None): + def get_cluster_by_name_or_moid(self, identifier, fail_on_missing=False, datacenter=None): """ Get the cluster matching the given name. Cluster names must be unique in a given vcenter, so only one object is returned at most. Args: - cluster_name: Name of the cluster to search for + identifier: Name or MOID of the cluster to search for fail_on_missing: If true, an error will be thrown if no clusters are found Returns: cluster object or None @@ -460,12 +472,12 @@ def get_cluster_by_name(self, cluster_name, fail_on_missing=False, datacenter=No cluster = self.get_objs_by_name_or_moid( [vim.ClusterComputeResource], - cluster_name, + identifier, return_all=False, search_root_folder=search_folder ) if not cluster and fail_on_missing: - self.module.fail_json("Unable to find cluster with name %s" % cluster_name) + self.module.fail_json("Unable to find cluster with name or MOID %s" % identifier) return cluster diff --git a/plugins/modules/cluster.py b/plugins/modules/cluster.py index df75a599..3d67aef9 100644 --- a/plugins/modules/cluster.py +++ b/plugins/modules/cluster.py @@ -152,8 +152,8 @@ def actual_state_matches_desired_state(self): Checks if cluster exists and compares that to the desired state. Returns: True if cluster state matches desired state, False otherwise """ - self.datacenter_obj = self.get_datacenter_by_name(self.params['datacenter'], fail_on_missing=True) - self.cluster_obj = self.get_cluster_by_name( + self.datacenter_obj = self.get_datacenter_by_name_or_moid(self.params['datacenter'], fail_on_missing=True) + self.cluster_obj = self.get_cluster_by_name_or_moid( cluster_name=self.params['cluster'], datacenter=self.datacenter_obj, fail_on_missing=False diff --git a/plugins/modules/cluster_dpm.py b/plugins/modules/cluster_dpm.py index 36437401..14eef3d0 100644 --- a/plugins/modules/cluster_dpm.py +++ b/plugins/modules/cluster_dpm.py @@ -128,8 +128,8 @@ class VMwareCluster(PyVmomi): def __init__(self, module): super(VMwareCluster, self).__init__(module) - datacenter = self.get_datacenter_by_name(self.params.get('datacenter'), fail_on_missing=True) - self.cluster = self.get_cluster_by_name(self.params.get('cluster'), fail_on_missing=True, datacenter=datacenter) + datacenter = self.get_datacenter_by_name_or_moid(self.params.get('datacenter'), fail_on_missing=True) + self.cluster = self.get_cluster_by_name_or_moid(self.params.get('cluster'), fail_on_missing=True, datacenter=datacenter) @property def automation_level(self): diff --git a/plugins/modules/cluster_drs.py b/plugins/modules/cluster_drs.py index b2b093d8..ea0b3360 100644 --- a/plugins/modules/cluster_drs.py +++ b/plugins/modules/cluster_drs.py @@ -156,8 +156,8 @@ class VMwareCluster(PyVmomi): def __init__(self, module): super(VMwareCluster, self).__init__(module) - datacenter = self.get_datacenter_by_name(self.params.get('datacenter'), fail_on_missing=True) - self.cluster = self.get_cluster_by_name(self.params.get('cluster'), fail_on_missing=True, datacenter=datacenter) + datacenter = self.get_datacenter_by_name_or_moid(self.params.get('datacenter'), fail_on_missing=True) + self.cluster = self.get_cluster_by_name_or_moid(self.params.get('cluster'), fail_on_missing=True, datacenter=datacenter) self.enable_drs = self.params.get('enable') self.drs_enable_vm_behavior_overrides = self.params.get('drs_enable_vm_behavior_overrides') diff --git a/plugins/modules/cluster_drs_recommendations.py b/plugins/modules/cluster_drs_recommendations.py index c2c01ed5..61f86e07 100644 --- a/plugins/modules/cluster_drs_recommendations.py +++ b/plugins/modules/cluster_drs_recommendations.py @@ -109,8 +109,8 @@ class VMwareCluster(PyVmomi): def __init__(self, module): super(VMwareCluster, self).__init__(module) - datacenter = self.get_datacenter_by_name(self.params.get('datacenter'), fail_on_missing=True) - self.cluster = self.get_cluster_by_name(self.params.get('cluster'), fail_on_missing=True, datacenter=datacenter) + datacenter = self.get_datacenter_by_name_or_moid(self.params.get('datacenter'), fail_on_missing=True) + self.cluster = self.get_cluster_by_name_or_moid(self.params.get('cluster'), fail_on_missing=True, datacenter=datacenter) def get_recommendations(self): """ diff --git a/plugins/modules/cluster_info.py b/plugins/modules/cluster_info.py index 51e2ffbd..83d826bd 100644 --- a/plugins/modules/cluster_info.py +++ b/plugins/modules/cluster_info.py @@ -177,19 +177,19 @@ def get_clusters(self): """ datacenter, search_folder = None, None if self.params.get('datacenter'): - datacenter = self.get_datacenter_by_name(self.params.get('datacenter'), fail_on_missing=False) + datacenter = self.get_datacenter_by_name_or_moid(self.params.get('datacenter'), fail_on_missing=False) search_folder = datacenter.hostFolder if self.params.get('cluster'): - _cluster = self.get_cluster_by_name(self.params.get('cluster'), fail_on_missing=False, datacenter=datacenter) + _cluster = self.get_cluster_by_name_or_moid(self.params.get('cluster'), fail_on_missing=False, datacenter=datacenter) return [_cluster] if _cluster else [] else: - _clusters = self.list_all_objs_by_type( + _clusters = self.get_all_objs_by_type( [vim.ClusterComputeResource], folder=search_folder, recurse=False ) - return _clusters.keys() + return _clusters def gather_info_for_clusters(self): """ diff --git a/plugins/modules/cluster_vcls.py b/plugins/modules/cluster_vcls.py index 1f0c45ec..eb50d8c8 100644 --- a/plugins/modules/cluster_vcls.py +++ b/plugins/modules/cluster_vcls.py @@ -150,11 +150,11 @@ class VMwareClusterVcls(PyVmomi): def __init__(self, module): super(VMwareClusterVcls, self).__init__(module) if module.params.get('datacenter'): - datacenter = self.get_datacenter_by_name(module.params['datacenter'], fail_on_missing=True) + datacenter = self.get_datacenter_by_name_or_moid(module.params['datacenter'], fail_on_missing=True) else: datacenter = None - self.cluster = self.get_cluster_by_name(module.params['cluster'], datacenter=datacenter, fail_on_missing=True) + self.cluster = self.get_cluster_by_name_or_moid(module.params['cluster'], datacenter=datacenter, fail_on_missing=True) def get_current_configured_datastores(self): """ @@ -198,7 +198,7 @@ def __add_datastore_to_config_spec(self, ds_name, cluster_config_spec): Adds a datastore to the potential new vCLS spec. Causes a failure if the datastore does not exist. """ allowed_datastore_spec = vim.cluster.DatastoreUpdateSpec() - allowed_datastore_spec.datastore = self.get_datastore_by_name(ds_name, fail_on_missing=True) + allowed_datastore_spec.datastore = self.get_datastore_by_name_or_moid(ds_name, fail_on_missing=True) allowed_datastore_spec.operation = 'add' cluster_config_spec.systemVMsConfig.allowedDatastores.append(allowed_datastore_spec) @@ -207,7 +207,7 @@ def __remove_datastore_from_config_spec(self, ds_name, cluster_config_spec): Removes a datastore from the potential new vCLS spec """ allowed_datastore_spec = vim.cluster.DatastoreUpdateSpec() - allowed_datastore_spec.removeKey = self.get_datastore_by_name(ds_name, fail_on_missing=False) + allowed_datastore_spec.removeKey = self.get_datastore_by_name_or_moid(ds_name, fail_on_missing=False) allowed_datastore_spec.operation = 'remove' cluster_config_spec.systemVMsConfig.allowedDatastores.append(allowed_datastore_spec) diff --git a/plugins/modules/folder_template_from_vm.py b/plugins/modules/folder_template_from_vm.py index ec4b6686..6d906f7b 100644 --- a/plugins/modules/folder_template_from_vm.py +++ b/plugins/modules/folder_template_from_vm.py @@ -236,12 +236,12 @@ def create_template_in_folder(self): def __create_template_location_spec(self): template_location_spec = vim.vm.RelocateSpec() if self.params.get("datastore"): - template_location_spec.datastore = self.get_datastore_by_name( + template_location_spec.datastore = self.get_datastore_by_name_or_moid( self.params.get("datastore"), fail_on_missing=True) if self.params.get("resource_pool"): - template_location_spec.pool = self.get_resource_pool_by_name( + template_location_spec.pool = self.get_resource_pool_by_name_or_moid( self.params.get("resource_pool"), fail_on_missing=True) diff --git a/plugins/modules/vm_portgroup_info.py b/plugins/modules/vm_portgroup_info.py index e0c15e96..ad991dde 100644 --- a/plugins/modules/vm_portgroup_info.py +++ b/plugins/modules/vm_portgroup_info.py @@ -77,7 +77,7 @@ def __init__(self, module): self.vms = self.params['vm_names'] def get_dvs_portgroup_detailed(self, pg_id): - dvs_pg = self.get_dvs_portgroup(pg_id) + dvs_pg = self.get_dvs_portgroup_by_name_or_moid(pg_id) pg = {'portgroup_name': dvs_pg.name, 'vswitch_name': dvs_pg.config.distributedVirtualSwitch.name, 'type': 'DISTRIBUTED_PORTGROUP', 'port_id': pg_id, 'port_binding': vmware_network.get_dvs_port_allocation(dvs_pg.config.type), @@ -98,7 +98,7 @@ def get_dvs_portgroup_detailed(self, pg_id): return pg def get_standard_portgroup_detailed(self, pg_id): - pg = self.get_standard_portgroup(pg_id) + pg = self.get_dvs_portgroup_by_name_or_moid(pg_id) pg_name = str(pg.summary.name) ret_pg = vmware_network.get_standard_portgroup_vlan_vswitch(pg, pg_name) ret_pg['port_id'] = pg_id From a66e6f9b0ca179d5508553fe3cb5a4ce0c7ad60f Mon Sep 17 00:00:00 2001 From: Mike Morency Date: Tue, 3 Dec 2024 12:37:08 -0500 Subject: [PATCH 2/6] consolidate arg specs --- plugins/doc_fragments/vmware.py | 173 ++++++------------ plugins/module_utils/_vmware_argument_spec.py | 54 ++++++ .../{_vmware.py => _vmware_pyvmomi.py} | 52 +----- plugins/modules/cluster.py | 8 +- plugins/modules/cluster_dpm.py | 8 +- plugins/modules/cluster_drs.py | 9 +- .../modules/cluster_drs_recommendations.py | 9 +- plugins/modules/cluster_info.py | 7 +- plugins/modules/cluster_vcls.py | 9 +- plugins/modules/folder_template_from_vm.py | 7 +- plugins/modules/guest_info.py | 7 +- plugins/modules/license_info.py | 8 +- plugins/modules/vm_portgroup_info.py | 7 +- 13 files changed, 155 insertions(+), 203 deletions(-) create mode 100644 plugins/module_utils/_vmware_argument_spec.py rename plugins/module_utils/{_vmware.py => _vmware_pyvmomi.py} (91%) diff --git a/plugins/doc_fragments/vmware.py b/plugins/doc_fragments/vmware.py index ed4e14c0..b1702c9e 100644 --- a/plugins/doc_fragments/vmware.py +++ b/plugins/doc_fragments/vmware.py @@ -13,119 +13,62 @@ class ModuleDocFragment(object): # Parameters for VMware modules DOCUMENTATION = r''' -notes: - - All modules require API write access and hence is not supported on a free ESXi license. - - All variables and VMware object names are case sensitive. -options: - hostname: - description: - - The hostname or IP address of the vSphere vCenter or ESXi server. - - If the value is not specified in the task, the value of environment variable E(VMWARE_HOST) will be used instead. - type: str - username: - description: - - The username of the vSphere vCenter or ESXi server. - - If the value is not specified in the task, the value of environment variable E(VMWARE_USER) will be used instead. - type: str - aliases: [ admin, user ] - password: - description: - - The password of the vSphere vCenter or ESXi server. - - If the value is not specified in the task, the value of environment variable E(VMWARE_PASSWORD) will be used instead. - type: str - aliases: [ pass, pwd ] - validate_certs: - description: - - Allows connection when SSL certificates are not valid. Set to V(false) when certificates are not trusted. - - If the value is not specified in the task, the value of environment variable E(VMWARE_VALIDATE_CERTS) will be used instead. - type: bool - default: true - port: - description: - - The port number of the vSphere vCenter or ESXi server. - - If the value is not specified in the task, the value of environment variable E(VMWARE_PORT) will be used instead. - type: int - default: 443 - datacenter: - description: - - The datacenter to use when connecting to a vCenter. - type: str - aliases: [ datacenter_name ] - cluster: - description: - - The cluster to use when connecting to a vCenter. - type: str - aliases: [ cluster_name ] - proxy_host: - description: - - Address of a proxy that will receive all HTTPS requests and relay them. - - The format is a hostname or a IP. - - If the value is not specified in the task, the value of environment variable E(VMWARE_PROXY_HOST) will be used instead. - type: str - required: false - proxy_port: - description: - - Port of the HTTP proxy that will receive all HTTPS requests and relay them. - - If the value is not specified in the task, the value of environment variable E(VMWARE_PROXY_PORT) will be used instead. - type: int - required: false -''' - - # This doc fragment is specific to vcenter modules like vcenter_license - VCENTER_DOCUMENTATION = r''' -notes: - - All modules require API write access and hence is not supported on a free ESXi license. -options: - hostname: - description: - - The hostname or IP address of the vSphere vCenter server. - - If the value is not specified in the task, the value of environment variable E(VMWARE_HOST) will be used instead. - type: str - username: - description: - - The username of the vSphere vCenter server. - - If the value is not specified in the task, the value of environment variable E(VMWARE_USER) will be used instead. - type: str - aliases: [ admin, user ] - password: - description: - - The password of the vSphere vCenter server. - - If the value is not specified in the task, the value of environment variable E(VMWARE_PASSWORD) will be used instead. - type: str - aliases: [ pass, pwd ] - validate_certs: - description: - - Allows connection when SSL certificates are not valid. Set to V(false) when certificates are not trusted. - - If the value is not specified in the task, the value of environment variable E(VMWARE_VALIDATE_CERTS) will be used instead. - type: bool - default: true - port: - description: - - The port number of the vSphere vCenter server. - - If the value is not specified in the task, the value of environment variable E(VMWARE_PORT) will be used instead. - type: int - default: 443 - datacenter: - description: - - The datacenter to use when connecting to a vCenter. - type: str - aliases: [ datacenter_name ] - cluster: - description: - - The cluster to use when connecting to a vCenter. - type: str - aliases: [ cluster_name ] - proxy_host: - description: - - Address of a proxy that will receive all HTTPS requests and relay them. - - The format is a hostname or a IP. - - If the value is not specified in the task, the value of environment variable E(VMWARE_PROXY_HOST) will be used instead. - type: str - required: false - proxy_port: - description: - - Port of the HTTP proxy that will receive all HTTPS requests and relay them. - - If the value is not specified in the task, the value of environment variable E(VMWARE_PROXY_PORT) will be used instead. - type: int - required: false + notes: + - All modules require API write access and hence is not supported on a free ESXi license. + - All variables and VMware object names are case sensitive. + - >- + Modules may rely on the 'requests' python library, which does not use the system certificate store by default. You can + specify the certificate store by setting the REQUESTS_CA_BUNDLE environment variable. + Example: 'export REQUESTS_CA_BUNDLE=/path/to/your/ca_bundle.pem' + options: + hostname: + description: + - The hostname or IP address of the vSphere vCenter server. + - If the value is not specified in the task, the value of environment variable E(VMWARE_HOST) will be used instead. + type: str + username: + description: + - The username of the vSphere vCenter server. + - If the value is not specified in the task, the value of environment variable E(VMWARE_USER) will be used instead. + type: str + aliases: [ admin, user ] + password: + description: + - The password of the vSphere vCenter server. + - If the value is not specified in the task, the value of environment variable E(VMWARE_PASSWORD) will be used instead. + type: str + aliases: [ pass, pwd ] + validate_certs: + description: + - Allows connection when SSL certificates are not valid. Set to V(false) when certificates are not trusted. + - If the value is not specified in the task, the value of environment variable E(VMWARE_VALIDATE_CERTS) will be used instead. + type: bool + default: true + port: + description: + - The port number of the vSphere vCenter server. + - If the value is not specified in the task, the value of environment variable E(VMWARE_PORT) will be used instead. + type: int + default: 443 + proxy_protocol: + description: + - The proxy connection protocol to use. + - This is option is used if the correct proxy protocol cannot be automatically determined. + type: str + choices: [ http, https ] + default: https + aliases: [protocol] + proxy_host: + description: + - Address of a proxy that will receive all HTTPS requests and relay them. + - The format is a hostname or a IP. + - If the value is not specified in the task, the value of environment variable E(VMWARE_PROXY_HOST) will be used instead. + type: str + required: false + proxy_port: + description: + - Port of the HTTP proxy that will receive all HTTPS requests and relay them. + - If the value is not specified in the task, the value of environment variable E(VMWARE_PROXY_PORT) will be used instead. + type: int + required: false ''' diff --git a/plugins/module_utils/_vmware_argument_spec.py b/plugins/module_utils/_vmware_argument_spec.py new file mode 100644 index 00000000..f3ec56ab --- /dev/null +++ b/plugins/module_utils/_vmware_argument_spec.py @@ -0,0 +1,54 @@ +from ansible.module_utils.basic import env_fallback + + +def base_arg_spec(): + return dict( + hostname = dict( + type='str', + required=False, + fallback=(env_fallback, ['VMWARE_HOST']), + ), + username = dict( + type='str', + aliases=['user', 'admin'], + required=False, + fallback=(env_fallback, ['VMWARE_USER']) + ), + password=dict( + type='str', + aliases=['pass', 'pwd'], + required=False, + no_log=True, + fallback=(env_fallback, ['VMWARE_PASSWORD']) + ), + port = dict( + type='int', + default=443, + required=False, + fallback=(env_fallback, ['VMWARE_PORT']) + ), + validate_certs = dict( + type='bool', + required=False, + default=True, + fallback=(env_fallback, ['VMWARE_VALIDATE_CERTS']) + ), + proxy_protocol = dict( + type='str', + default='https', + choices=['https', 'http'], + aliases=['protocol'] + ), + proxy_host = dict( + type='str', + required=False, + default=None, + fallback=(env_fallback, ['VMWARE_PROXY_HOST']) + ), + proxy_port = dict( + type='int', + required=False, + default=None, + fallback=(env_fallback, ['VMWARE_PROXY_PORT']) + ), + ) diff --git a/plugins/module_utils/_vmware.py b/plugins/module_utils/_vmware_pyvmomi.py similarity index 91% rename from plugins/module_utils/_vmware.py rename to plugins/module_utils/_vmware_pyvmomi.py index 711aeeab..8bebf7ba 100644 --- a/plugins/module_utils/_vmware.py +++ b/plugins/module_utils/_vmware_pyvmomi.py @@ -14,25 +14,21 @@ import ssl import traceback +# requests is required for exception handling of the ConnectionError REQUESTS_IMP_ERR = None try: - # requests is required for exception handling of the ConnectionError import requests - HAS_REQUESTS = True except ImportError: REQUESTS_IMP_ERR = traceback.format_exc() - HAS_REQUESTS = False PYVMOMI_IMP_ERR = None try: from pyVim import connect from pyVmomi import vim, vmodl - HAS_PYVMOMI = True except ImportError: PYVMOMI_IMP_ERR = traceback.format_exc() - HAS_PYVMOMI = False -from ansible.module_utils.basic import env_fallback, missing_required_lib +from ansible.module_utils.basic import missing_required_lib class ApiAccessError(Exception): @@ -40,46 +36,6 @@ def __init__(self, *args, **kwargs): super(ApiAccessError, self).__init__(*args, **kwargs) -def vmware_argument_spec(): - return dict( - hostname=dict(type='str', - required=False, - fallback=(env_fallback, ['VMWARE_HOST']), - ), - username=dict(type='str', - aliases=['user', 'admin'], - required=False, - fallback=(env_fallback, ['VMWARE_USER'])), - password=dict(type='str', - aliases=['pass', 'pwd'], - required=False, - no_log=True, - fallback=(env_fallback, ['VMWARE_PASSWORD'])), - cluster=dict(type='str', - aliases=['cluster_name'], - required=False), - datacenter=dict(type='str', - aliases=['datacenter_name'], - required=False), - port=dict(type='int', - default=443, - fallback=(env_fallback, ['VMWARE_PORT'])), - validate_certs=dict(type='bool', - required=False, - default=True, - fallback=(env_fallback, ['VMWARE_VALIDATE_CERTS']) - ), - proxy_host=dict(type='str', - required=False, - default=None, - fallback=(env_fallback, ['VMWARE_PROXY_HOST'])), - proxy_port=dict(type='int', - required=False, - default=None, - fallback=(env_fallback, ['VMWARE_PROXY_PORT'])), - ) - - def connect_to_api(module, disconnect_atexit=True, return_si=False, hostname=None, username=None, password=None, port=None, validate_certs=None, httpProxyHost=None, httpProxyPort=None): @@ -192,11 +148,11 @@ def __init__(self, module): """ Constructor """ - if not HAS_REQUESTS: + if not REQUESTS_IMP_ERR: module.fail_json(msg=missing_required_lib('requests'), exception=REQUESTS_IMP_ERR) - if not HAS_PYVMOMI: + if not PYVMOMI_IMP_ERR: module.fail_json(msg=missing_required_lib('PyVmomi'), exception=PYVMOMI_IMP_ERR) diff --git a/plugins/modules/cluster.py b/plugins/modules/cluster.py index 3d67aef9..8678b0c7 100644 --- a/plugins/modules/cluster.py +++ b/plugins/modules/cluster.py @@ -91,10 +91,8 @@ from ansible.module_utils.basic import AnsibleModule from ansible.module_utils._text import to_native -from ansible_collections.vmware.vmware.plugins.module_utils._vmware import ( - PyVmomi, - vmware_argument_spec -) +from ansible_collections.vmware.vmware.plugins.module_utils._vmware_pymomi import PyVmomi +from ansible_collections.vmware.vmware.plugins.module_utils._vmware_argument_spec import base_arg_spec from ansible_collections.vmware.vmware.plugins.module_utils._vmware_tasks import ( TaskError, RunningTaskMonitor @@ -182,7 +180,7 @@ def get_cluster_outputs(self): def main(): module = AnsibleModule( argument_spec={ - **vmware_argument_spec(), **dict( + **base_arg_spec(), **dict( cluster=dict(type='str', required=True, aliases=['cluster_name', 'name']), datacenter=dict(type='str', required=True, aliases=['datacenter_name']), state=dict(type='str', default='present', choices=['absent', 'present']), diff --git a/plugins/modules/cluster_dpm.py b/plugins/modules/cluster_dpm.py index 14eef3d0..167ee3c3 100644 --- a/plugins/modules/cluster_dpm.py +++ b/plugins/modules/cluster_dpm.py @@ -109,10 +109,8 @@ pass from ansible.module_utils.basic import AnsibleModule -from ansible_collections.vmware.vmware.plugins.module_utils._vmware import ( - PyVmomi, - vmware_argument_spec -) +from ansible_collections.vmware.vmware.plugins.module_utils._vmware_pymomi import PyVmomi +from ansible_collections.vmware.vmware.plugins.module_utils._vmware_argument_spec import base_arg_spec from ansible_collections.vmware.vmware.plugins.module_utils._vmware_tasks import ( TaskError, RunningTaskMonitor @@ -208,7 +206,7 @@ def apply_dpm_configuration(self): def main(): module = AnsibleModule( argument_spec={ - **vmware_argument_spec(), **dict( + **base_arg_spec(), **dict( cluster=dict(type='str', required=True, aliases=['cluster_name']), datacenter=dict(type='str', required=True, aliases=['datacenter_name']), enable=dict(type='bool', default=True), diff --git a/plugins/modules/cluster_drs.py b/plugins/modules/cluster_drs.py index ea0b3360..50e01c3e 100644 --- a/plugins/modules/cluster_drs.py +++ b/plugins/modules/cluster_drs.py @@ -135,10 +135,9 @@ pass from ansible.module_utils.basic import AnsibleModule -from ansible_collections.vmware.vmware.plugins.module_utils._vmware import ( - PyVmomi, - vmware_argument_spec -) +from ansible_collections.vmware.vmware.plugins.module_utils._vmware_pymomi import PyVmomi +from ansible_collections.vmware.vmware.plugins.module_utils._vmware_argument_spec import base_arg_spec + from ansible_collections.vmware.vmware.plugins.module_utils._vmware_tasks import ( TaskError, RunningTaskMonitor @@ -246,7 +245,7 @@ def apply_drs_configuration(self): def main(): module = AnsibleModule( argument_spec={ - **vmware_argument_spec(), **dict( + **base_arg_spec(), **dict( cluster=dict(type='str', required=True, aliases=['cluster_name']), datacenter=dict(type='str', required=True, aliases=['datacenter_name']), enable=dict(type='bool', default=True), diff --git a/plugins/modules/cluster_drs_recommendations.py b/plugins/modules/cluster_drs_recommendations.py index 61f86e07..b2846050 100644 --- a/plugins/modules/cluster_drs_recommendations.py +++ b/plugins/modules/cluster_drs_recommendations.py @@ -95,10 +95,9 @@ from itertools import zip_longest from ansible.module_utils.basic import AnsibleModule -from ansible_collections.vmware.vmware.plugins.module_utils._vmware import ( - PyVmomi, - vmware_argument_spec -) +from ansible_collections.vmware.vmware.plugins.module_utils._vmware_pymomi import PyVmomi +from ansible_collections.vmware.vmware.plugins.module_utils._vmware_argument_spec import base_arg_spec + from ansible_collections.vmware.vmware.plugins.module_utils._vmware_tasks import ( TaskError, RunningTaskMonitor @@ -177,7 +176,7 @@ def __wait_for_recommendation_task_results(self, recommendation_tasks): def main(): module = AnsibleModule( argument_spec={ - **vmware_argument_spec(), **dict( + **base_arg_spec(), **dict( cluster=dict(type='str', required=True, aliases=['cluster_name']), datacenter=dict(type='str', required=True, aliases=['datacenter_name']), ) diff --git a/plugins/modules/cluster_info.py b/plugins/modules/cluster_info.py index 83d826bd..766c8668 100644 --- a/plugins/modules/cluster_info.py +++ b/plugins/modules/cluster_info.py @@ -57,7 +57,7 @@ elements: str extends_documentation_fragment: - - vmware.vmware.vmware.vcenter_documentation + - vmware.vmware.vmware.documentation ''' EXAMPLES = r''' @@ -155,7 +155,8 @@ except ImportError: pass from ansible.module_utils.basic import AnsibleModule -from ansible_collections.vmware.vmware.plugins.module_utils._vmware import PyVmomi, vmware_argument_spec +from ansible_collections.vmware.vmware.plugins.module_utils._vmware_pymomi import PyVmomi +from ansible_collections.vmware.vmware.plugins.module_utils._vmware_argument_spec import base_arg_spec from ansible_collections.vmware.vmware.plugins.module_utils._vmware_rest_client import VmwareRestClient from ansible_collections.vmware.vmware.plugins.module_utils._vmware_facts import ( ClusterFacts, @@ -230,7 +231,7 @@ def _get_tags(self, cluster): def main(): module = AnsibleModule( argument_spec={ - **vmware_argument_spec(), **dict( + **base_arg_spec(), **dict( cluster=dict(type='str', aliases=['cluster_name', 'name']), datacenter=dict(type='str', aliases=['datacenter_name']), gather_tags=dict(type='bool', default=False), diff --git a/plugins/modules/cluster_vcls.py b/plugins/modules/cluster_vcls.py index eb50d8c8..da8dbb49 100644 --- a/plugins/modules/cluster_vcls.py +++ b/plugins/modules/cluster_vcls.py @@ -136,10 +136,9 @@ from ansible.module_utils.basic import AnsibleModule from ansible.module_utils._text import to_native -from ansible_collections.vmware.vmware.plugins.module_utils._vmware import ( - PyVmomi, - vmware_argument_spec -) +from ansible_collections.vmware.vmware.plugins.module_utils._vmware_pymomi import PyVmomi +from ansible_collections.vmware.vmware.plugins.module_utils._vmware_argument_spec import base_arg_spec + from ansible_collections.vmware.vmware.plugins.module_utils._vmware_tasks import ( TaskError, RunningTaskMonitor @@ -246,7 +245,7 @@ def configure_vcls(self, datastores_to_add, datastores_to_remove): def main(): module = AnsibleModule( argument_spec={ - **vmware_argument_spec(), **dict( + **base_arg_spec(), **dict( cluster=dict(type='str', required=True, aliases=['cluster_name']), datacenter=dict(type='str', required=False, aliases=['datacenter_name']), allowed_datastores=dict(type='list', elements='str'), diff --git a/plugins/modules/folder_template_from_vm.py b/plugins/modules/folder_template_from_vm.py index 6d906f7b..9ce9fcba 100644 --- a/plugins/modules/folder_template_from_vm.py +++ b/plugins/modules/folder_template_from_vm.py @@ -99,7 +99,7 @@ description: The check_mode support. support: full extends_documentation_fragment: - - vmware.vmware.vmware.vcenter_documentation + - vmware.vmware.vmware.documentation ''' @@ -143,7 +143,8 @@ import traceback from ansible.module_utils.basic import AnsibleModule -from ansible_collections.vmware.vmware.plugins.module_utils._vmware import PyVmomi, vmware_argument_spec +from ansible_collections.vmware.vmware.plugins.module_utils._vmware_pymomi import PyVmomi +from ansible_collections.vmware.vmware.plugins.module_utils._vmware_argument_spec import base_arg_spec from ansible_collections.vmware.vmware.plugins.module_utils._vmware_folder_paths import format_folder_path_as_vm_fq_path from ansible_collections.vmware.vmware.plugins.module_utils._vmware_tasks import RunningTaskMonitor, TaskError @@ -262,7 +263,7 @@ def custom_validation(module): def main(): module = AnsibleModule( argument_spec={ - **vmware_argument_spec(), **dict( + **base_arg_spec(), **dict( vm_name=dict(type='str', required=False, default=None), vm_name_match=dict(type='str', required=False, choices=['first', 'last']), vm_uuid=dict(type='str', required=False, default=None), diff --git a/plugins/modules/guest_info.py b/plugins/modules/guest_info.py index 603f17f7..68d7e2c2 100644 --- a/plugins/modules/guest_info.py +++ b/plugins/modules/guest_info.py @@ -82,7 +82,7 @@ description: The check_mode support. support: full extends_documentation_fragment: -- vmware.vmware.vmware_rest_client.documentation +- vmware.vmware.vmware.documentation ''' EXAMPLES = r''' @@ -170,7 +170,8 @@ from ansible.module_utils.basic import AnsibleModule -from ansible_collections.vmware.vmware.plugins.module_utils._vmware import PyVmomi +from ansible_collections.vmware.vmware.plugins.module_utils._vmware_pymomi import PyVmomi +from ansible_collections.vmware.vmware.plugins.module_utils._vmware_argument_spec import base_arg_spec from ansible_collections.vmware.vmware.plugins.module_utils._vmware_rest_client import VmwareRestClient from ansible_collections.vmware.vmware.plugins.module_utils._vmware_facts import ( VmFacts, @@ -270,7 +271,7 @@ def _get_tags(self, vm): def main(): - argument_spec = VmwareRestClient.vmware_client_argument_spec() + argument_spec = base_arg_spec() argument_spec.update( dict( name=dict(type='str', aliases=['guest_name']), diff --git a/plugins/modules/license_info.py b/plugins/modules/license_info.py index 3aedeb0a..23b8a0cd 100644 --- a/plugins/modules/license_info.py +++ b/plugins/modules/license_info.py @@ -22,7 +22,7 @@ description: The check_mode support. support: full extends_documentation_fragment: -- vmware.vmware.vmware.vcenter_documentation +- vmware.vmware.vmware.documentation ''' EXAMPLES = r''' @@ -44,7 +44,9 @@ ''' from ansible.module_utils.basic import AnsibleModule -from ansible_collections.vmware.vmware.plugins.module_utils._vmware import PyVmomi, vmware_argument_spec +from ansible_collections.vmware.vmware.plugins.module_utils._vmware_pymomi import PyVmomi +from ansible_collections.vmware.vmware.plugins.module_utils._vmware_argument_spec import base_arg_spec + class VcenterLicenseMgr(PyVmomi): @@ -62,7 +64,7 @@ def list_keys(self, licenses): def main(): module = AnsibleModule( - argument_spec=vmware_argument_spec(), + argument_spec=base_arg_spec(), supports_check_mode=True, ) diff --git a/plugins/modules/vm_portgroup_info.py b/plugins/modules/vm_portgroup_info.py index ad991dde..a66ab79a 100644 --- a/plugins/modules/vm_portgroup_info.py +++ b/plugins/modules/vm_portgroup_info.py @@ -29,7 +29,7 @@ type: list elements: str extends_documentation_fragment: - - vmware.vmware.vmware_rest_client.documentation + - vmware.vmware.vmware.documentation ''' EXAMPLES = r''' @@ -65,7 +65,8 @@ ''' from ansible.module_utils.basic import AnsibleModule -from ansible_collections.vmware.vmware.plugins.module_utils._vmware import PyVmomi +from ansible_collections.vmware.vmware.plugins.module_utils._vmware_pymomi import PyVmomi +from ansible_collections.vmware.vmware.plugins.module_utils._vmware_argument_spec import base_arg_spec from ansible_collections.vmware.vmware.plugins.module_utils import _vmware_network as vmware_network from ansible_collections.vmware.vmware.plugins.module_utils._vmware_rest_client import VmwareRestClient @@ -143,7 +144,7 @@ def get_vm_detailed(self, vm_name): def main(): - argument_spec = VmwareRestClient.vmware_client_argument_spec() + argument_spec = base_arg_spec() argument_spec.update( dict( vm_names=dict(type='list', elements='str', required=True) From 90ade19a7f51725dbf84dbc6af0eb288fbe56861 Mon Sep 17 00:00:00 2001 From: Mike Morency Date: Tue, 3 Dec 2024 12:40:03 -0500 Subject: [PATCH 3/6] update test ref to module utils --- tests/unit/plugins/modules/common/utils.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/unit/plugins/modules/common/utils.py b/tests/unit/plugins/modules/common/utils.py index d5d038e4..26a0205f 100644 --- a/tests/unit/plugins/modules/common/utils.py +++ b/tests/unit/plugins/modules/common/utils.py @@ -6,7 +6,7 @@ from ansible.module_utils import basic from ansible.module_utils._text import to_bytes -from ansible_collections.vmware.vmware.plugins.module_utils import _vmware +from ansible_collections.vmware.vmware.plugins.module_utils import _vmware_pyvmomi import mock @@ -30,7 +30,7 @@ def set_module_args(add_cluster=True, **args): def mock_pyvmomi(mocker): - connect_to_api = mocker.patch.object(_vmware, "connect_to_api") + connect_to_api = mocker.patch.object(_vmware_pyvmomi, "connect_to_api") _content = type('', (), {})() _content.customFieldsManager = False connect_to_api.return_value = None, _content From 7b1a8011180435242330bfb216bcb9be2e655b7c Mon Sep 17 00:00:00 2001 From: Mike Morency Date: Tue, 3 Dec 2024 12:49:31 -0500 Subject: [PATCH 4/6] typos --- plugins/module_utils/_vmware_pyvmomi.py | 2 +- plugins/modules/cluster.py | 2 +- plugins/modules/cluster_dpm.py | 2 +- plugins/modules/cluster_drs.py | 2 +- plugins/modules/cluster_drs_recommendations.py | 2 +- plugins/modules/cluster_info.py | 2 +- plugins/modules/cluster_vcls.py | 2 +- plugins/modules/folder_template_from_vm.py | 2 +- plugins/modules/guest_info.py | 2 +- plugins/modules/license_info.py | 2 +- plugins/modules/vm_portgroup_info.py | 2 +- 11 files changed, 11 insertions(+), 11 deletions(-) diff --git a/plugins/module_utils/_vmware_pyvmomi.py b/plugins/module_utils/_vmware_pyvmomi.py index 8bebf7ba..c16fc0fa 100644 --- a/plugins/module_utils/_vmware_pyvmomi.py +++ b/plugins/module_utils/_vmware_pyvmomi.py @@ -303,7 +303,7 @@ def get_folders_by_name_or_moid(self, identifier, fail_on_missing=False): Get all folders with the given name. Names are not unique in a given cluster, so multiple folder objects can be returned Args: - folder_identifier: Name or MOID of the folder to search for + identifier: Name or MOID of the folder to search for fail_on_missing: If true, an error will be thrown if no folders are found Returns: list(folder object) or None diff --git a/plugins/modules/cluster.py b/plugins/modules/cluster.py index 8678b0c7..9dd06f62 100644 --- a/plugins/modules/cluster.py +++ b/plugins/modules/cluster.py @@ -91,7 +91,7 @@ from ansible.module_utils.basic import AnsibleModule from ansible.module_utils._text import to_native -from ansible_collections.vmware.vmware.plugins.module_utils._vmware_pymomi import PyVmomi +from ansible_collections.vmware.vmware.plugins.module_utils._vmware_pyvmomi import PyVmomi from ansible_collections.vmware.vmware.plugins.module_utils._vmware_argument_spec import base_arg_spec from ansible_collections.vmware.vmware.plugins.module_utils._vmware_tasks import ( TaskError, diff --git a/plugins/modules/cluster_dpm.py b/plugins/modules/cluster_dpm.py index 167ee3c3..9f972733 100644 --- a/plugins/modules/cluster_dpm.py +++ b/plugins/modules/cluster_dpm.py @@ -109,7 +109,7 @@ pass from ansible.module_utils.basic import AnsibleModule -from ansible_collections.vmware.vmware.plugins.module_utils._vmware_pymomi import PyVmomi +from ansible_collections.vmware.vmware.plugins.module_utils._vmware_pyvmomi import PyVmomi from ansible_collections.vmware.vmware.plugins.module_utils._vmware_argument_spec import base_arg_spec from ansible_collections.vmware.vmware.plugins.module_utils._vmware_tasks import ( TaskError, diff --git a/plugins/modules/cluster_drs.py b/plugins/modules/cluster_drs.py index 50e01c3e..8f12ea5d 100644 --- a/plugins/modules/cluster_drs.py +++ b/plugins/modules/cluster_drs.py @@ -135,7 +135,7 @@ pass from ansible.module_utils.basic import AnsibleModule -from ansible_collections.vmware.vmware.plugins.module_utils._vmware_pymomi import PyVmomi +from ansible_collections.vmware.vmware.plugins.module_utils._vmware_pyvmomi import PyVmomi from ansible_collections.vmware.vmware.plugins.module_utils._vmware_argument_spec import base_arg_spec from ansible_collections.vmware.vmware.plugins.module_utils._vmware_tasks import ( diff --git a/plugins/modules/cluster_drs_recommendations.py b/plugins/modules/cluster_drs_recommendations.py index b2846050..fcab2caa 100644 --- a/plugins/modules/cluster_drs_recommendations.py +++ b/plugins/modules/cluster_drs_recommendations.py @@ -95,7 +95,7 @@ from itertools import zip_longest from ansible.module_utils.basic import AnsibleModule -from ansible_collections.vmware.vmware.plugins.module_utils._vmware_pymomi import PyVmomi +from ansible_collections.vmware.vmware.plugins.module_utils._vmware_pyvmomi import PyVmomi from ansible_collections.vmware.vmware.plugins.module_utils._vmware_argument_spec import base_arg_spec from ansible_collections.vmware.vmware.plugins.module_utils._vmware_tasks import ( diff --git a/plugins/modules/cluster_info.py b/plugins/modules/cluster_info.py index 766c8668..842dd51a 100644 --- a/plugins/modules/cluster_info.py +++ b/plugins/modules/cluster_info.py @@ -155,7 +155,7 @@ except ImportError: pass from ansible.module_utils.basic import AnsibleModule -from ansible_collections.vmware.vmware.plugins.module_utils._vmware_pymomi import PyVmomi +from ansible_collections.vmware.vmware.plugins.module_utils._vmware_pyvmomi import PyVmomi from ansible_collections.vmware.vmware.plugins.module_utils._vmware_argument_spec import base_arg_spec from ansible_collections.vmware.vmware.plugins.module_utils._vmware_rest_client import VmwareRestClient from ansible_collections.vmware.vmware.plugins.module_utils._vmware_facts import ( diff --git a/plugins/modules/cluster_vcls.py b/plugins/modules/cluster_vcls.py index da8dbb49..ab666659 100644 --- a/plugins/modules/cluster_vcls.py +++ b/plugins/modules/cluster_vcls.py @@ -136,7 +136,7 @@ from ansible.module_utils.basic import AnsibleModule from ansible.module_utils._text import to_native -from ansible_collections.vmware.vmware.plugins.module_utils._vmware_pymomi import PyVmomi +from ansible_collections.vmware.vmware.plugins.module_utils._vmware_pyvmomi import PyVmomi from ansible_collections.vmware.vmware.plugins.module_utils._vmware_argument_spec import base_arg_spec from ansible_collections.vmware.vmware.plugins.module_utils._vmware_tasks import ( diff --git a/plugins/modules/folder_template_from_vm.py b/plugins/modules/folder_template_from_vm.py index 9ce9fcba..ca86b345 100644 --- a/plugins/modules/folder_template_from_vm.py +++ b/plugins/modules/folder_template_from_vm.py @@ -143,7 +143,7 @@ import traceback from ansible.module_utils.basic import AnsibleModule -from ansible_collections.vmware.vmware.plugins.module_utils._vmware_pymomi import PyVmomi +from ansible_collections.vmware.vmware.plugins.module_utils._vmware_pyvmomi import PyVmomi from ansible_collections.vmware.vmware.plugins.module_utils._vmware_argument_spec import base_arg_spec from ansible_collections.vmware.vmware.plugins.module_utils._vmware_folder_paths import format_folder_path_as_vm_fq_path from ansible_collections.vmware.vmware.plugins.module_utils._vmware_tasks import RunningTaskMonitor, TaskError diff --git a/plugins/modules/guest_info.py b/plugins/modules/guest_info.py index 68d7e2c2..93837309 100644 --- a/plugins/modules/guest_info.py +++ b/plugins/modules/guest_info.py @@ -170,7 +170,7 @@ from ansible.module_utils.basic import AnsibleModule -from ansible_collections.vmware.vmware.plugins.module_utils._vmware_pymomi import PyVmomi +from ansible_collections.vmware.vmware.plugins.module_utils._vmware_pyvmomi import PyVmomi from ansible_collections.vmware.vmware.plugins.module_utils._vmware_argument_spec import base_arg_spec from ansible_collections.vmware.vmware.plugins.module_utils._vmware_rest_client import VmwareRestClient from ansible_collections.vmware.vmware.plugins.module_utils._vmware_facts import ( diff --git a/plugins/modules/license_info.py b/plugins/modules/license_info.py index 23b8a0cd..d0163825 100644 --- a/plugins/modules/license_info.py +++ b/plugins/modules/license_info.py @@ -44,7 +44,7 @@ ''' from ansible.module_utils.basic import AnsibleModule -from ansible_collections.vmware.vmware.plugins.module_utils._vmware_pymomi import PyVmomi +from ansible_collections.vmware.vmware.plugins.module_utils._vmware_pyvmomi import PyVmomi from ansible_collections.vmware.vmware.plugins.module_utils._vmware_argument_spec import base_arg_spec diff --git a/plugins/modules/vm_portgroup_info.py b/plugins/modules/vm_portgroup_info.py index a66ab79a..7139950d 100644 --- a/plugins/modules/vm_portgroup_info.py +++ b/plugins/modules/vm_portgroup_info.py @@ -65,7 +65,7 @@ ''' from ansible.module_utils.basic import AnsibleModule -from ansible_collections.vmware.vmware.plugins.module_utils._vmware_pymomi import PyVmomi +from ansible_collections.vmware.vmware.plugins.module_utils._vmware_pyvmomi import PyVmomi from ansible_collections.vmware.vmware.plugins.module_utils._vmware_argument_spec import base_arg_spec from ansible_collections.vmware.vmware.plugins.module_utils import _vmware_network as vmware_network from ansible_collections.vmware.vmware.plugins.module_utils._vmware_rest_client import VmwareRestClient From a88d6c46b13d31f4af65e5853b4eb83e3165642d Mon Sep 17 00:00:00 2001 From: Mike Morency Date: Tue, 3 Dec 2024 13:09:33 -0500 Subject: [PATCH 5/6] test fixes --- plugins/module_utils/_vmware_argument_spec.py | 14 +++++++------- plugins/module_utils/_vmware_pyvmomi.py | 4 ++-- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/plugins/module_utils/_vmware_argument_spec.py b/plugins/module_utils/_vmware_argument_spec.py index f3ec56ab..9aef7fe0 100644 --- a/plugins/module_utils/_vmware_argument_spec.py +++ b/plugins/module_utils/_vmware_argument_spec.py @@ -3,12 +3,12 @@ def base_arg_spec(): return dict( - hostname = dict( + hostname=dict( type='str', required=False, fallback=(env_fallback, ['VMWARE_HOST']), ), - username = dict( + username=dict( type='str', aliases=['user', 'admin'], required=False, @@ -21,31 +21,31 @@ def base_arg_spec(): no_log=True, fallback=(env_fallback, ['VMWARE_PASSWORD']) ), - port = dict( + port=dict( type='int', default=443, required=False, fallback=(env_fallback, ['VMWARE_PORT']) ), - validate_certs = dict( + validate_certs=dict( type='bool', required=False, default=True, fallback=(env_fallback, ['VMWARE_VALIDATE_CERTS']) ), - proxy_protocol = dict( + proxy_protocol=dict( type='str', default='https', choices=['https', 'http'], aliases=['protocol'] ), - proxy_host = dict( + proxy_host=dict( type='str', required=False, default=None, fallback=(env_fallback, ['VMWARE_PROXY_HOST']) ), - proxy_port = dict( + proxy_port=dict( type='int', required=False, default=None, diff --git a/plugins/module_utils/_vmware_pyvmomi.py b/plugins/module_utils/_vmware_pyvmomi.py index c16fc0fa..9d1bc843 100644 --- a/plugins/module_utils/_vmware_pyvmomi.py +++ b/plugins/module_utils/_vmware_pyvmomi.py @@ -148,11 +148,11 @@ def __init__(self, module): """ Constructor """ - if not REQUESTS_IMP_ERR: + if REQUESTS_IMP_ERR: module.fail_json(msg=missing_required_lib('requests'), exception=REQUESTS_IMP_ERR) - if not PYVMOMI_IMP_ERR: + if PYVMOMI_IMP_ERR: module.fail_json(msg=missing_required_lib('PyVmomi'), exception=PYVMOMI_IMP_ERR) From 21e50894251497140489f76c401fadab45eb756f Mon Sep 17 00:00:00 2001 From: Mike Morency Date: Tue, 3 Dec 2024 13:13:40 -0500 Subject: [PATCH 6/6] test fixes --- plugins/modules/cluster.py | 2 +- plugins/modules/license_info.py | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/plugins/modules/cluster.py b/plugins/modules/cluster.py index 9dd06f62..b634002c 100644 --- a/plugins/modules/cluster.py +++ b/plugins/modules/cluster.py @@ -152,7 +152,7 @@ def actual_state_matches_desired_state(self): """ self.datacenter_obj = self.get_datacenter_by_name_or_moid(self.params['datacenter'], fail_on_missing=True) self.cluster_obj = self.get_cluster_by_name_or_moid( - cluster_name=self.params['cluster'], + identifier=self.params['cluster'], datacenter=self.datacenter_obj, fail_on_missing=False ) diff --git a/plugins/modules/license_info.py b/plugins/modules/license_info.py index d0163825..a072d0a9 100644 --- a/plugins/modules/license_info.py +++ b/plugins/modules/license_info.py @@ -48,7 +48,6 @@ from ansible_collections.vmware.vmware.plugins.module_utils._vmware_argument_spec import base_arg_spec - class VcenterLicenseMgr(PyVmomi): def __init__(self, module): super(VcenterLicenseMgr, self).__init__(module)