mirror of
https://github.com/ansible-collections/community.general.git
synced 2026-05-08 06:12:51 +00:00
VMware: Modifying Rest Client to use vSphere-Api-Client instead of individual service(#55804)
* Same api client can be used for other service as well * Incorporated Review comments. Modified Category and Guest Fact modules which are also dependent on vmware_rest_client module util * Adding Integration Tests for vmware_rest_client changes * Changes to incroporate changes in vcsim testware * Change to get vm name to attach the tag
This commit is contained in:
committed by
Abhijeet Kasurde
parent
0bead3672f
commit
34a8594c91
@@ -119,7 +119,7 @@ category_results:
|
||||
from ansible.module_utils.basic import AnsibleModule
|
||||
from ansible.module_utils.vmware_rest_client import VmwareRestClient
|
||||
try:
|
||||
from com.vmware.cis.tagging_client import Category, CategoryModel
|
||||
from com.vmware.cis.tagging_client import CategoryModel
|
||||
except ImportError:
|
||||
pass
|
||||
|
||||
@@ -127,7 +127,7 @@ except ImportError:
|
||||
class VmwareCategory(VmwareRestClient):
|
||||
def __init__(self, module):
|
||||
super(VmwareCategory, self).__init__(module)
|
||||
self.category_service = Category(self.connect)
|
||||
self.category_service = self.api_client.tagging.Category
|
||||
self.global_categories = dict()
|
||||
self.category_name = self.params.get('category_name')
|
||||
self.get_all_categories()
|
||||
|
||||
@@ -91,16 +91,12 @@ tag_category_facts:
|
||||
|
||||
from ansible.module_utils.basic import AnsibleModule
|
||||
from ansible.module_utils.vmware_rest_client import VmwareRestClient
|
||||
try:
|
||||
from com.vmware.cis.tagging_client import Category
|
||||
except ImportError:
|
||||
pass
|
||||
|
||||
|
||||
class VmwareCategoryFactsManager(VmwareRestClient):
|
||||
def __init__(self, module):
|
||||
super(VmwareCategoryFactsManager, self).__init__(module)
|
||||
self.category_service = Category(self.connect)
|
||||
self.category_service = self.api_client.tagging.Category
|
||||
|
||||
def get_all_tag_categories(self):
|
||||
"""Retrieve all tag category information."""
|
||||
|
||||
@@ -218,17 +218,16 @@ from ansible.module_utils.vmware import PyVmomi, vmware_argument_spec
|
||||
from ansible.module_utils.vmware_rest_client import VmwareRestClient
|
||||
try:
|
||||
from com.vmware.vapi.std_client import DynamicID
|
||||
from com.vmware.cis.tagging_client import Tag, TagAssociation
|
||||
HAS_VCLOUD = True
|
||||
HAS_VSPHERE = True
|
||||
except ImportError:
|
||||
HAS_VCLOUD = False
|
||||
HAS_VSPHERE = False
|
||||
|
||||
|
||||
class VmwareTag(VmwareRestClient):
|
||||
def __init__(self, module):
|
||||
super(VmwareTag, self).__init__(module)
|
||||
self.tag_service = Tag(self.connect)
|
||||
self.tag_association_svc = TagAssociation(self.connect)
|
||||
self.tag_service = self.api_client.tagging.Tag
|
||||
self.tag_association_svc = self.api_client.tagging.TagAssociation
|
||||
|
||||
|
||||
def main():
|
||||
@@ -268,7 +267,7 @@ def main():
|
||||
else:
|
||||
instance = pyv.to_json(vm, module.params['properties'])
|
||||
if module.params.get('tags'):
|
||||
if not HAS_VCLOUD:
|
||||
if not HAS_VSPHERE:
|
||||
module.fail_json(msg="Unable to find 'vCloud Suite SDK' Python library which is required."
|
||||
" Please refer this URL for installation steps"
|
||||
" - https://code.vmware.com/web/sdk/60/vcloudsuite-python")
|
||||
|
||||
@@ -108,20 +108,17 @@ results:
|
||||
|
||||
from ansible.module_utils.basic import AnsibleModule
|
||||
from ansible.module_utils.vmware_rest_client import VmwareRestClient
|
||||
try:
|
||||
from com.vmware.cis.tagging_client import Tag, Category
|
||||
except ImportError:
|
||||
pass
|
||||
|
||||
|
||||
class VmwareTag(VmwareRestClient):
|
||||
def __init__(self, module):
|
||||
super(VmwareTag, self).__init__(module)
|
||||
self.tag_service = Tag(self.connect)
|
||||
self.global_tags = dict()
|
||||
# api_client to call APIs instead of individual service
|
||||
self.tag_service = self.api_client.tagging.Tag
|
||||
self.tag_name = self.params.get('tag_name')
|
||||
self.get_all_tags()
|
||||
self.category_service = Category(self.connect)
|
||||
self.category_service = self.api_client.tagging.Category
|
||||
|
||||
def ensure_state(self):
|
||||
"""
|
||||
|
||||
@@ -86,17 +86,13 @@ results:
|
||||
|
||||
from ansible.module_utils.basic import AnsibleModule
|
||||
from ansible.module_utils.vmware_rest_client import VmwareRestClient
|
||||
try:
|
||||
from com.vmware.cis.tagging_client import Tag
|
||||
except ImportError:
|
||||
pass
|
||||
|
||||
|
||||
class VmTagFactManager(VmwareRestClient):
|
||||
def __init__(self, module):
|
||||
"""Constructor."""
|
||||
super(VmTagFactManager, self).__init__(module)
|
||||
self.tag_service = Tag(self.connect)
|
||||
self.tag_service = self.api_client.tagging.Tag
|
||||
self.global_tags = dict()
|
||||
|
||||
def get_all_tags(self):
|
||||
|
||||
@@ -138,7 +138,6 @@ from ansible.module_utils.vmware_rest_client import VmwareRestClient
|
||||
from ansible.module_utils.vmware import (PyVmomi, find_dvs_by_name, find_dvspg_by_name)
|
||||
try:
|
||||
from com.vmware.vapi.std_client import DynamicID
|
||||
from com.vmware.cis.tagging_client import Tag, TagAssociation, Category
|
||||
except ImportError:
|
||||
pass
|
||||
|
||||
@@ -186,9 +185,9 @@ class VmwareTagManager(VmwareRestClient):
|
||||
|
||||
self.dynamic_managed_object = DynamicID(type=self.object_type, id=self.managed_object._moId)
|
||||
|
||||
self.tag_service = Tag(self.connect)
|
||||
self.category_service = Category(self.connect)
|
||||
self.tag_association_svc = TagAssociation(self.connect)
|
||||
self.tag_service = self.api_client.tagging.Tag
|
||||
self.category_service = self.api_client.tagging.Category
|
||||
self.tag_association_svc = self.api_client.tagging.TagAssociation
|
||||
|
||||
self.tag_names = self.params.get('tag_names')
|
||||
|
||||
|
||||
Reference in New Issue
Block a user