VMware: Cleanup vCloud references (#56268)

Signed-off-by: Abhijeet Kasurde <akasurde@redhat.com>
pull/56306/head
Abhijeet Kasurde 6 years ago committed by Jill R
parent 61e476b908
commit 499355fc13

@ -32,7 +32,6 @@ requirements:
- python >= 2.6 - python >= 2.6
- PyVmomi - PyVmomi
- vSphere Automation SDK - vSphere Automation SDK
- vCloud Suite SDK
options: options:
category_name: category_name:
description: description:

@ -32,7 +32,6 @@ requirements:
- python >= 2.6 - python >= 2.6
- PyVmomi - PyVmomi
- vSphere Automation SDK - vSphere Automation SDK
- vCloud Suite SDK
extends_documentation_fragment: vmware_rest_client.documentation extends_documentation_fragment: vmware_rest_client.documentation
''' '''

@ -30,7 +30,6 @@ requirements:
- python >= 2.6 - python >= 2.6
- PyVmomi - PyVmomi
- vSphere Automation SDK - vSphere Automation SDK
- vCloud Suite SDK
options: options:
tag_name: tag_name:
description: description:

@ -32,7 +32,6 @@ requirements:
- python >= 2.6 - python >= 2.6
- PyVmomi - PyVmomi
- vSphere Automation SDK - vSphere Automation SDK
- vCloud Suite SDK
extends_documentation_fragment: vmware_rest_client.documentation extends_documentation_fragment: vmware_rest_client.documentation
''' '''

@ -31,7 +31,6 @@ requirements:
- python >= 2.6 - python >= 2.6
- PyVmomi - PyVmomi
- vSphere Automation SDK - vSphere Automation SDK
- vCloud Suite SDK
options: options:
tag_names: tag_names:
description: description:

@ -55,10 +55,9 @@ DOCUMENTATION = '''
with_tags: with_tags:
description: description:
- Include tags and associated virtual machines. - Include tags and associated virtual machines.
- Requires 'vSphere Automation SDK' and 'vCloud Suite SDK' libraries to be installed on the given controller machine. - Requires 'vSphere Automation SDK' library to be installed on the given controller machine.
- Please refer following URLs for installation steps - Please refer following URLs for installation steps
- 'https://code.vmware.com/web/sdk/65/vsphere-automation-python' - 'https://code.vmware.com/web/sdk/65/vsphere-automation-python'
- 'https://code.vmware.com/web/sdk/60/vcloudsuite-python'
default: False default: False
type: boolean type: boolean
''' '''
@ -93,22 +92,13 @@ except ImportError:
HAS_PYVMOMI = False HAS_PYVMOMI = False
try: try:
from vmware.vapi.lib.connect import get_requests_connector
from vmware.vapi.security.session import create_session_security_context
from vmware.vapi.security.user_password import create_user_password_security_context
from com.vmware.cis_client import Session
from com.vmware.vapi.std_client import DynamicID from com.vmware.vapi.std_client import DynamicID
from com.vmware.cis.tagging_client import Tag, TagAssociation from vmware.vapi.vsphere.client import create_vsphere_client
HAS_VCLOUD = True
except ImportError:
HAS_VCLOUD = False
try:
from vmware.vapi.stdlib.client.factories import StubConfigurationFactory
HAS_VSPHERE = True HAS_VSPHERE = True
except ImportError: except ImportError:
HAS_VSPHERE = False HAS_VSPHERE = False
from ansible.plugins.inventory import BaseInventoryPlugin, Cacheable from ansible.plugins.inventory import BaseInventoryPlugin, Cacheable
@ -144,28 +134,13 @@ class BaseVMwareInventory:
# Disable warning shown at stdout # Disable warning shown at stdout
requests.packages.urllib3.disable_warnings() requests.packages.urllib3.disable_warnings()
vcenter_url = "https://%s/api" % self.hostname client = create_vsphere_client(server=self.hostname,
username=self.username,
# Get request connector password=self.password,
connector = get_requests_connector(session=session, url=vcenter_url) session=session)
# Create standard Configuration if client is None:
stub_config = StubConfigurationFactory.new_std_configuration(connector)
# Use username and password in the security context to authenticate
security_context = create_user_password_security_context(self.username, self.password)
# Login
stub_config.connector.set_security_context(security_context)
# Create the stub for the session service and login by creating a session.
session_svc = Session(stub_config)
session_id = session_svc.create()
# After successful authentication, store the session identifier in the security
# context of the stub and use that for all subsequent remote requests
session_security_context = create_session_security_context(session_id)
stub_config.connector.set_security_context(session_security_context)
if stub_config is None:
raise AnsibleError("Failed to login to %s using %s" % (self.hostname, self.username)) raise AnsibleError("Failed to login to %s using %s" % (self.hostname, self.username))
return stub_config return client
def _login(self): def _login(self):
""" """
@ -235,11 +210,6 @@ class BaseVMwareInventory:
" Please refer this URL for installation steps" " Please refer this URL for installation steps"
" - https://code.vmware.com/web/sdk/65/vsphere-automation-python") " - https://code.vmware.com/web/sdk/65/vsphere-automation-python")
if not HAS_VCLOUD and self.with_tags:
raise AnsibleError("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")
if not all([self.hostname, self.username, self.password]): if not all([self.hostname, self.username, self.password]):
raise AnsibleError("Missing one of the following : hostname, username, password. Please read " raise AnsibleError("Missing one of the following : hostname, username, password. Please read "
"the documentation for more information.") "the documentation for more information.")
@ -394,8 +364,8 @@ class InventoryModule(BaseInventoryPlugin, Cacheable):
properties=['name']) properties=['name'])
if self.pyv.with_tags: if self.pyv.with_tags:
tag_svc = Tag(self.pyv.rest_content) tag_svc = self.pyv.rest_content.tagging.Tag
tag_association = TagAssociation(self.pyv.rest_content) tag_association = self.pyv.rest_content.tagging.TagAssociation
tags_info = dict() tags_info = dict()
tags = tag_svc.list() tags = tag_svc.list()
@ -428,7 +398,7 @@ class InventoryModule(BaseInventoryPlugin, Cacheable):
self._populate_host_properties(vm_obj, current_host) self._populate_host_properties(vm_obj, current_host)
# Only gather facts related to tag if vCloud and vSphere is installed. # Only gather facts related to tag if vCloud and vSphere is installed.
if HAS_VCLOUD and HAS_VSPHERE and self.pyv.with_tags: if HAS_VSPHERE and self.pyv.with_tags:
# Add virtual machine to appropriate tag group # Add virtual machine to appropriate tag group
vm_mo_id = vm_obj.obj._GetMoId() vm_mo_id = vm_obj.obj._GetMoId()
vm_dynamic_id = DynamicID(type='VirtualMachine', id=vm_mo_id) vm_dynamic_id = DynamicID(type='VirtualMachine', id=vm_mo_id)

@ -1,12 +1,12 @@
# Test code for the vmware_tag CRUD Operations. # Test code for the vmware_tag CRUD Operations.
# Copyright: (c) 2019, Pavan Bidkar <pbidkar@vmware.com> # Copyright: (c) 2019, Pavan Bidkar <pbidkar@vmware.com>
# Copyright: (c) 2019, Abhijeet Kasurde <akasurde@redhat.com>
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
- when: vcsim is not defined - when: vcsim is not defined
block: block:
- &cat_create
# Testcase Create Category name: Create Category
- name: Create Category
vmware_category: vmware_category:
hostname: '{{ vcenter_hostname }}' hostname: '{{ vcenter_hostname }}'
username: '{{ vcenter_username }}' username: '{{ vcenter_username }}'
@ -23,11 +23,20 @@
that: that:
- category_create.changed - category_create.changed
- <<: *cat_create
name: Create category again
- name: Check if no changes are made
assert:
that:
- not category_create.changed
- name: Set Cat_ID Paramter. Required for Tag creation - name: Set Cat_ID Paramter. Required for Tag creation
set_fact: Cat_ID={{ category_create['category_results']['category_id'] }} set_fact: Cat_ID={{ category_create['category_results']['category_id'] }}
# Testcase Create Tag # Testcase Create Tag
- name: Create a tag - &tag_create
name: Create a tag
vmware_tag: vmware_tag:
hostname: '{{ vcenter_hostname }}' hostname: '{{ vcenter_hostname }}'
username: '{{ vcenter_username }}' username: '{{ vcenter_username }}'
@ -44,8 +53,17 @@
that: that:
- tag_creation.changed - tag_creation.changed
- <<: *tag_create
name: Create a tag again
- name: Check if no changes are made
assert:
that:
- not tag_creation.changed
# Testcase Update Tag Description (reconfig) # Testcase Update Tag Description (reconfig)
- name: Update Tag Description - &tag_update
name: Update Tag Description
vmware_tag: vmware_tag:
hostname: '{{ vcenter_hostname }}' hostname: '{{ vcenter_hostname }}'
username: '{{ vcenter_username }}' username: '{{ vcenter_username }}'
@ -61,8 +79,17 @@
that: that:
- update_tag_desc.changed - update_tag_desc.changed
- <<: *tag_update
name: Update tag description again
- name: Check if no changes are made
assert:
that:
- not update_tag_desc.changed
# Testcase Delete the Tag # Testcase Delete the Tag
- name: Delete Tag - &tag_delete
name: Delete Tag
vmware_tag: vmware_tag:
hostname: '{{ vcenter_hostname }}' hostname: '{{ vcenter_hostname }}'
username: '{{ vcenter_username }}' username: '{{ vcenter_username }}'
@ -76,3 +103,10 @@
assert: assert:
that: that:
- delete_tag.changed - delete_tag.changed
- <<: *tag_delete
name: Delete tag again
- name: Check if no changes are made
assert:
that:
- not delete_tag.changed

@ -1,11 +1,10 @@
# Test code for the vmware_tag Manager Operations. # Test code for the vmware_tag Manager Operations.
# Copyright: (c) 2019, Pavan Bidkar <pbidkar@vmware.com> # Copyright: (c) 2019, Pavan Bidkar <pbidkar@vmware.com>
# Copyright: (c) 2019, Abhijeet Kasurde <akasurde@redhat.com>
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
- when: vcsim is not defined - when: vcsim is not defined
block: block:
# Get VM name to attach the tag
- name: Get VM Facts - name: Get VM Facts
vmware_vm_facts: vmware_vm_facts:
hostname: '{{ vcenter_hostname }}' hostname: '{{ vcenter_hostname }}'
@ -17,7 +16,8 @@
- set_fact: vm_name="{{ vm_facts['virtual_machines'][0]['guest_name'] }}" - set_fact: vm_name="{{ vm_facts['virtual_machines'][0]['guest_name'] }}"
# Get Tagname # Get Tagname
- name: Get facts about tag - &tag_fact
name: Get facts about tag
vmware_tag_facts: vmware_tag_facts:
hostname: '{{ vcenter_hostname }}' hostname: '{{ vcenter_hostname }}'
username: '{{ vcenter_username }}' username: '{{ vcenter_username }}'
@ -25,12 +25,17 @@
validate_certs: False validate_certs: False
register: tag_facts register: tag_facts
- <<: *tag_fact
name: Get facts about tag in check mode
check_mode: yes
- set_fact: Tag_Name={{ tag_facts['tag_facts'].keys() | list }} - set_fact: Tag_Name={{ tag_facts['tag_facts'].keys() | list }}
- debug: var=Tag_Name - debug: var=Tag_Name
# Testcase Assign tag to virtual Machine # Testcase Assign tag to virtual Machine
- name: Add tags to a virtual machine - &tag_assign
name: Add tags to a virtual machine
vmware_tag_manager: vmware_tag_manager:
hostname: '{{ vcenter_hostname }}' hostname: '{{ vcenter_hostname }}'
username: '{{ vcenter_username }}' username: '{{ vcenter_username }}'
@ -43,7 +48,15 @@
state: add state: add
register: tag_manager_ops register: tag_manager_ops
- name: Check Category is created - name: Check tag is assign to virtual machine
assert:
that:
- tag_manager_ops.changed
- <<: *tag_assign
name: Add tags to a virtual machine again
- name: Check tag is not assigned to virtual machine again
assert: assert:
that: that:
- tag_manager_ops.changed" - not tag_manager_ops.changed

Loading…
Cancel
Save