VMware: Cleanup vCloud references (#56268)
Signed-off-by: Abhijeet Kasurde <akasurde@redhat.com>
This commit is contained in:
parent
61e476b908
commit
499355fc13
10 changed files with 74 additions and 62 deletions
|
@ -32,7 +32,6 @@ requirements:
|
|||
- python >= 2.6
|
||||
- PyVmomi
|
||||
- vSphere Automation SDK
|
||||
- vCloud Suite SDK
|
||||
options:
|
||||
category_name:
|
||||
description:
|
||||
|
|
|
@ -32,7 +32,6 @@ requirements:
|
|||
- python >= 2.6
|
||||
- PyVmomi
|
||||
- vSphere Automation SDK
|
||||
- vCloud Suite SDK
|
||||
extends_documentation_fragment: vmware_rest_client.documentation
|
||||
'''
|
||||
|
||||
|
|
|
@ -30,7 +30,6 @@ requirements:
|
|||
- python >= 2.6
|
||||
- PyVmomi
|
||||
- vSphere Automation SDK
|
||||
- vCloud Suite SDK
|
||||
options:
|
||||
tag_name:
|
||||
description:
|
||||
|
|
|
@ -32,7 +32,6 @@ requirements:
|
|||
- python >= 2.6
|
||||
- PyVmomi
|
||||
- vSphere Automation SDK
|
||||
- vCloud Suite SDK
|
||||
extends_documentation_fragment: vmware_rest_client.documentation
|
||||
'''
|
||||
|
||||
|
|
|
@ -31,7 +31,6 @@ requirements:
|
|||
- python >= 2.6
|
||||
- PyVmomi
|
||||
- vSphere Automation SDK
|
||||
- vCloud Suite SDK
|
||||
options:
|
||||
tag_names:
|
||||
description:
|
||||
|
|
|
@ -55,10 +55,9 @@ DOCUMENTATION = '''
|
|||
with_tags:
|
||||
description:
|
||||
- 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
|
||||
- 'https://code.vmware.com/web/sdk/65/vsphere-automation-python'
|
||||
- 'https://code.vmware.com/web/sdk/60/vcloudsuite-python'
|
||||
default: False
|
||||
type: boolean
|
||||
'''
|
||||
|
@ -93,22 +92,13 @@ except ImportError:
|
|||
HAS_PYVMOMI = False
|
||||
|
||||
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.cis.tagging_client import Tag, TagAssociation
|
||||
HAS_VCLOUD = True
|
||||
except ImportError:
|
||||
HAS_VCLOUD = False
|
||||
|
||||
try:
|
||||
from vmware.vapi.stdlib.client.factories import StubConfigurationFactory
|
||||
from vmware.vapi.vsphere.client import create_vsphere_client
|
||||
HAS_VSPHERE = True
|
||||
except ImportError:
|
||||
HAS_VSPHERE = False
|
||||
|
||||
|
||||
from ansible.plugins.inventory import BaseInventoryPlugin, Cacheable
|
||||
|
||||
|
||||
|
@ -144,28 +134,13 @@ class BaseVMwareInventory:
|
|||
# Disable warning shown at stdout
|
||||
requests.packages.urllib3.disable_warnings()
|
||||
|
||||
vcenter_url = "https://%s/api" % self.hostname
|
||||
|
||||
# Get request connector
|
||||
connector = get_requests_connector(session=session, url=vcenter_url)
|
||||
# Create standard Configuration
|
||||
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:
|
||||
client = create_vsphere_client(server=self.hostname,
|
||||
username=self.username,
|
||||
password=self.password,
|
||||
session=session)
|
||||
if client is None:
|
||||
raise AnsibleError("Failed to login to %s using %s" % (self.hostname, self.username))
|
||||
return stub_config
|
||||
return client
|
||||
|
||||
def _login(self):
|
||||
"""
|
||||
|
@ -235,11 +210,6 @@ class BaseVMwareInventory:
|
|||
" Please refer this URL for installation steps"
|
||||
" - 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]):
|
||||
raise AnsibleError("Missing one of the following : hostname, username, password. Please read "
|
||||
"the documentation for more information.")
|
||||
|
@ -394,8 +364,8 @@ class InventoryModule(BaseInventoryPlugin, Cacheable):
|
|||
properties=['name'])
|
||||
|
||||
if self.pyv.with_tags:
|
||||
tag_svc = Tag(self.pyv.rest_content)
|
||||
tag_association = TagAssociation(self.pyv.rest_content)
|
||||
tag_svc = self.pyv.rest_content.tagging.Tag
|
||||
tag_association = self.pyv.rest_content.tagging.TagAssociation
|
||||
|
||||
tags_info = dict()
|
||||
tags = tag_svc.list()
|
||||
|
@ -428,7 +398,7 @@ class InventoryModule(BaseInventoryPlugin, Cacheable):
|
|||
self._populate_host_properties(vm_obj, current_host)
|
||||
|
||||
# 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
|
||||
vm_mo_id = vm_obj.obj._GetMoId()
|
||||
vm_dynamic_id = DynamicID(type='VirtualMachine', id=vm_mo_id)
|
||||
|
|
|
@ -1,2 +1,2 @@
|
|||
cloud/vcenter
|
||||
unsupported
|
||||
unsupported
|
||||
|
|
|
@ -3,4 +3,4 @@
|
|||
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||
|
||||
- include: tag_crud_ops.yml
|
||||
- include: tag_manager_ops.yml
|
||||
- include: tag_manager_ops.yml
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
# Test code for the vmware_tag CRUD Operations.
|
||||
# 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)
|
||||
|
||||
- when: vcsim is not defined
|
||||
block:
|
||||
|
||||
# Testcase Create Category
|
||||
- name: Create Category
|
||||
- &cat_create
|
||||
name: Create Category
|
||||
vmware_category:
|
||||
hostname: '{{ vcenter_hostname }}'
|
||||
username: '{{ vcenter_username }}'
|
||||
|
@ -23,11 +23,20 @@
|
|||
that:
|
||||
- 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
|
||||
set_fact: Cat_ID={{ category_create['category_results']['category_id'] }}
|
||||
|
||||
# Testcase Create Tag
|
||||
- name: Create a tag
|
||||
- &tag_create
|
||||
name: Create a tag
|
||||
vmware_tag:
|
||||
hostname: '{{ vcenter_hostname }}'
|
||||
username: '{{ vcenter_username }}'
|
||||
|
@ -44,8 +53,17 @@
|
|||
that:
|
||||
- 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)
|
||||
- name: Update Tag Description
|
||||
- &tag_update
|
||||
name: Update Tag Description
|
||||
vmware_tag:
|
||||
hostname: '{{ vcenter_hostname }}'
|
||||
username: '{{ vcenter_username }}'
|
||||
|
@ -61,8 +79,17 @@
|
|||
that:
|
||||
- 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
|
||||
- name: Delete Tag
|
||||
- &tag_delete
|
||||
name: Delete Tag
|
||||
vmware_tag:
|
||||
hostname: '{{ vcenter_hostname }}'
|
||||
username: '{{ vcenter_username }}'
|
||||
|
@ -75,4 +102,11 @@
|
|||
- name: Check Tag is Deleted
|
||||
assert:
|
||||
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.
|
||||
# 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)
|
||||
|
||||
- when: vcsim is not defined
|
||||
block:
|
||||
|
||||
# Get VM name to attach the tag
|
||||
- name: Get VM Facts
|
||||
vmware_vm_facts:
|
||||
hostname: '{{ vcenter_hostname }}'
|
||||
|
@ -17,7 +16,8 @@
|
|||
- set_fact: vm_name="{{ vm_facts['virtual_machines'][0]['guest_name'] }}"
|
||||
|
||||
# Get Tagname
|
||||
- name: Get facts about tag
|
||||
- &tag_fact
|
||||
name: Get facts about tag
|
||||
vmware_tag_facts:
|
||||
hostname: '{{ vcenter_hostname }}'
|
||||
username: '{{ vcenter_username }}'
|
||||
|
@ -25,12 +25,17 @@
|
|||
validate_certs: False
|
||||
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 }}
|
||||
|
||||
- debug: var=Tag_Name
|
||||
|
||||
# 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:
|
||||
hostname: '{{ vcenter_hostname }}'
|
||||
username: '{{ vcenter_username }}'
|
||||
|
@ -43,7 +48,15 @@
|
|||
state: add
|
||||
register: tag_manager_ops
|
||||
|
||||
- name: Check Category is created
|
||||
- name: Check tag is assign to virtual machine
|
||||
assert:
|
||||
that:
|
||||
- tag_manager_ops.changed"
|
||||
- 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:
|
||||
that:
|
||||
- not tag_manager_ops.changed
|
||||
|
|
Loading…
Reference in a new issue