Beispiel #1
0
    def test_refresh_vms_status(self, get_vdc_details, get_namebyvappid,
                                connect, get_vapp, get_vm_pci_details,
                                get_network_id_by_name):
        headers = {
            'Accept': 'application/*+xml;version=5.9',
            'x-vcloud-authorization': '638bfee6cb5f435abc3480f480817254'
        }
        vm_id = '05e6047b-6938-4275-8940-22d1ea7245b8'

        vapp_resp = xml_resp.vapp_xml_response
        # created vdc object
        vdc_xml_resp = xml_resp.vdc_xml_response
        vdc = vdcType.parseString(vdc_xml_resp, True)
        # assumed return value from VIM connector
        get_vdc_details.return_value = vdc
        connect.return_value = self.vca

        self.vim.vca = self.vim.connect()
        get_namebyvappid.return_value = 'Test1_vm-69a18104-8413-4cb8-bad7-b5afaec6f9fa'
        get_vm_pci_details.return_value = {
            'host_name': 'test-esx-1.corp.local',
            'host_ip': '12.19.24.31'
        }
        get_vapp.return_value = VAPP(vAppType.parseString(vapp_resp, True),
                                     headers, False)
        get_network_id_by_name.return_value = '47d12505-5968-4e16-95a7-18743edb0c8b'
        # call to VIM connector method
        result = self.vim.refresh_vms_status([vm_id])
        for attr in result[vm_id]:
            if attr == 'status':
                # assert verified expected and return result from VIM connector
                self.assertEqual(result[vm_id][attr], 'ACTIVE')
Beispiel #2
0
 def get_vdc(self, vdc_name):
     if self.vcloud_session and self.vcloud_session.organization:
         refs = filter(lambda ref: ref.name == vdc_name and ref.type_ == 'application/vnd.vmware.vcloud.vdc+xml', self.vcloud_session.organization.Link)
         if len(refs) == 1:
             self.response = requests.get(refs[0].href, headers=self.vcloud_session.get_vcloud_headers(), verify=self.verify)
             if self.response.status_code == requests.codes.ok:
                 # print self.response.content
                 return vdcType.parseString(self.response.content, True)
Beispiel #3
0
 def get_vdc(self, vdc_name):
     if self.vcloud_session and self.vcloud_session.organization:
         refs = filter(lambda ref: ref.name == vdc_name and ref.type_ == 'application/vnd.vmware.vcloud.vdc+xml', self.vcloud_session.organization.Link)
         if len(refs) == 1:
             self.response = requests.get(refs[0].href, headers=self.vcloud_session.get_vcloud_headers(), verify=self.verify)
             if self.response.status_code == requests.codes.ok:
                 # print self.response.content
                 return vdcType.parseString(self.response.content, True)
Beispiel #4
0
 def test_get_network_not_found(self, get_networks, connect,
                                get_vdc_details):
     vdc_xml_resp = xml_resp.vdc_xml_response
     # created vdc object
     vdc = vdcType.parseString(vdc_xml_resp, True)
     # assumed return value from VIM connector
     get_vdc_details.return_value = vdc
     self.vim.vca = self.vim.connect()
     network_xml_resp = xml_resp.network_xml_response
     networks = networkType.parseString(network_xml_resp, True)
     (self.vim.vca).get_networks.return_value = [networks]
     # call to VIM connector method with invalid id
     self.assertRaises(vimconnNotFoundException, self.vim.get_network,
                       'mgmt-net')
Beispiel #5
0
 def test_delete_vminstance(self, get_vdc_details, get_namebyvappid,
                            connect, vapp):
     vm_id = '4f6a9b49-e92d-4935-87a1-0e4dc9c3a069'
     vm_name = 'Test1_vm-69a18104-8413-4cb8-bad7-b5afaec6f9fa'
     # created vdc object
     vdc_xml_resp = xml_resp.vdc_xml_response
     vdc = vdcType.parseString(vdc_xml_resp, True)
     # assumed return value from VIM connector
     connect.return_value = self.vca
     self.vim.vca = self.vim.connect()
     get_namebyvappid.return_name = vm_name
     vapp.return_value = None
     # call to VIM connector method
     result = self.vim.delete_vminstance(vm_id)
     # assert verified expected and return result from VIM connector
     self.assertEqual(result, vm_id)
Beispiel #6
0
 def test_get_network(self, get_networks, connect, get_vdc_details):
     net_id = '5c04dc6d-6096-47c6-b72b-68f19013d491'
     vdc_xml_resp = xml_resp.vdc_xml_response
     # created vdc object
     vdc = vdcType.parseString(vdc_xml_resp, True)
     # created network object
     network_xml_resp = xml_resp.network_xml_response
     networks = networkType.parseString(network_xml_resp, True)
     # assumed return value from VIM connector
     get_vdc_details.return_value = vdc
     self.vim.vca = self.vim.connect()
     # assumed return value from VIM connector
     (self.vim.vca).get_networks.return_value = [networks]
     # call to VIM connector method with network_id
     result = self.vim.get_network(net_id)
     # assert verified expected and return result from VIM connector
     self.assertEqual(net_id, result['id'])
Beispiel #7
0
    def test_get_network_list_not_found(self, get_networks, connect,
                                        get_vdc_details):
        vdc_xml_resp = xml_resp.vdc_xml_response
        # created vdc object
        vdc = vdcType.parseString(vdc_xml_resp, True)
        # assumed return value from VIM connector
        get_vdc_details.return_value = vdc
        self.vim.vca = self.vim.connect()

        network_xml_resp = xml_resp.network_xml_response
        networks = networkType.parseString(network_xml_resp, True)
        (self.vim.vca).get_networks.return_value = [networks]
        # call to VIM connector method with network_id
        result = self.vim.get_network_list({'id': '45hdfg-345nb-345'})

        # assert verified expected and return result from VIM connector
        self.assertEqual(list(), result)
 def get_vdc(self, vdc_name):
     if self.vcloud_session and self.vcloud_session.organization:
         refs = filter(
             lambda ref: ref.name == vdc_name and ref.type_ == "application/vnd.vmware.vcloud.vdc+xml",
             self.vcloud_session.organization.Link,
         )
         if len(refs) == 1:
             headers = self.vcloud_session.get_vcloud_headers()
             response = self._invoke_api(requests, "get", refs[0].href, headers=headers, verify=self.verify)
             if response.status_code == requests.codes.ok:
                 return vdcType.parseString(response.content, True)
             elif response.status_code == requests.codes.forbidden:
                 excep_msg = "Get_vdc forbidden, vdc_name:%s" % (vdc_name)
                 raise exceptions.ForbiddenException(excep_msg)
             else:
                 excep_msg = "Get_vdc failed, response:%s" % (response)
                 raise exceptions.VCloudDriverException(excep_msg)
Beispiel #9
0
 def get_vdc(self, vdc_name):
     if self.vcloud_session and self.vcloud_session.organization:
         refs = filter(lambda ref: ref.name == vdc_name and ref.type_ ==
                       'application/vnd.vmware.vcloud.vdc+xml',
                       self.vcloud_session.organization.Link)
         if len(refs) == 1:
             self.response = requests.get(
                 refs[0].href,
                 headers=self.vcloud_session.get_vcloud_headers(),
                 verify=self.verify)
             if self.response.status_code == requests.codes.ok:
                 # print self.response.content
                 return vdcType.parseString(self.response.content, True)
         elif response.status_code == requests.codes.forbidden:
             raise exception.Forbidden("Get_vdc forbidden, " +
                                       "vdc_name:" + vdc_name)
         else:
             raise exception.NovaException("Get_vdc error, " +
                                           "response:" + response)
 def get_vdc(self, vdc_name):
     if self.vcloud_session and self.vcloud_session.organization:
         refs = filter(lambda ref: ref.name == vdc_name and ref.type_ ==
                       'application/vnd.vmware.vcloud.vdc+xml',
                       self.vcloud_session.organization.Link)
         if len(refs) == 1:
             headers = self.vcloud_session.get_vcloud_headers()
             response = self._invoke_api(requests, 'get',
                                         refs[0].href,
                                         headers=headers,
                                         verify=self.verify)
             if response.status_code == requests.codes.ok:
                 return vdcType.parseString(response.content, True)
             elif response.status_code == requests.codes.forbidden:
                 excep_msg = "Get_vdc forbidden, vdc_name:%s" % (vdc_name)
                 raise exceptions.ForbiddenException(excep_msg)
             else:
                 excep_msg = "Get_vdc failed, response:%s" % (response)
                 raise exceptions.VCloudDriverException(excep_msg)
Beispiel #11
0
 def test_action_vminstance(self, get_vdc_details, get_namebyvappid,
                            connect, get_vapp, block):
     task_resp = xml_resp.task_xml
     vm_id = '05e6047b-6938-4275-8940-22d1ea7245b8'
     # created vdc object
     vdc_xml_resp = xml_resp.vdc_xml_response
     vdc = vdcType.parseString(vdc_xml_resp, True)
     # assumed return value from VIM connector
     get_vdc_details.return_value = vdc
     get_namebyvappid.return_value = 'Test1_vm-69a18104-8413-4cb8-bad7-b5afaec6f9fa'
     connect.return_value = self.vca
     self.vim.vca = self.vim.connect()
     get_vapp.return_value.undeploy.return_value = taskType.parseString(
         task_resp, True)
     block.return_value = True
     # call to VIM connector method
     result = self.vim.action_vminstance(vm_id, {'shutdown': None})
     # assert verified expected and return result from VIM connector
     self.assertEqual(result, None)
Beispiel #12
0
 def get_vdc(self, vdc_name):
     if self.vcloud_session and self.vcloud_session.organization:
         refs = filter(
             lambda ref: ref.name == vdc_name and ref.type_ ==
             'application/vnd.vmware.vcloud.vdc+xml',
             self.vcloud_session.organization.Link)
         if len(refs) == 1:
             self.response = requests.get(
                 refs[0].href,
                 headers=self.vcloud_session.get_vcloud_headers(),
                 verify=self.verify)
             if self.response.status_code == requests.codes.ok:
                 # print self.response.content
                 return vdcType.parseString(self.response.content, True)
         elif response.status_code == requests.codes.forbidden:
             raise exception.Forbidden("Get_vdc forbidden, " + "vdc_name:" +
                                       vdc_name)
         else:
             raise exception.NovaException("Get_vdc error, " + "response:" +
                                           response)
Beispiel #13
0
    def test_get_network_list(self, get_networks, connect, get_vdc_details):
        vdc_xml_resp = xml_resp.vdc_xml_response
        net_id = '5c04dc6d-6096-47c6-b72b-68f19013d491'
        vdc = vdcType.parseString(vdc_xml_resp, True)
        # created network object
        network_xml_resp = xml_resp.network_xml_response
        networks = networkType.parseString(network_xml_resp, True)
        # assumed return value from VIM connector
        get_vdc_details.return_value = vdc
        self.vim.vca = self.vim.connect()
        # assumed return value from VIM connector
        (self.vim.vca).get_networks.return_value = [networks]

        # call to VIM connector method with network_id
        result = self.vim.get_network_list({'id': net_id})
        # assert verified expected and return result from VIM connector
        for item in result:
            self.assertEqual(item.get('id'), net_id)
            self.assertEqual(item.get('status'), 'ACTIVE')
            self.assertEqual(item.get('shared'), False)
Beispiel #14
0
 def login_to_org(self, service, org_name):
     vdcReference = self.get_vdc_reference(service, org_name)
     if vdcReference:
         link = filter(lambda link: link.get_type() == "application/xml;class=vnd.vmware.vchs.vcloudsession", vdcReference.get_Link())[0]
         self.response = requests.post(link.get_href(), headers=self._get_vcloud_headers(), verify=self.verify)
         if self.response.status_code == requests.codes.created:
             vchs = vchsType.parseString(self.response.content, True)
             vdcLink = vchs.get_VdcLink()
             headers = {}
             headers[vdcLink.authorizationHeader] = vdcLink.authorizationToken
             headers["Accept"] = "application/*+xml;version=" + self.version
             self.response = requests.get(vdcLink.href, headers=headers, verify=self.verify)
             if self.response.status_code == requests.codes.ok:
                 self.vdc = vdcType.parseString(self.response.content, True)
                 self.org = self.vdc.name
                 org_url = filter(lambda link: link.get_type() == "application/vnd.vmware.vcloud.org+xml", self.vdc.get_Link())[0].href
                 vcloud_session = VCS(org_url, self.username, self.org, None, org_url, org_url, version=self.version, verify=self.verify)
                 if vcloud_session.login(password=None, token=vdcLink.authorizationToken):
                     self.vcloud_session = vcloud_session
                     return True
     return False
Beispiel #15
0
 def login_to_org(self, service, org_name):
     vdcReference = self.get_vdc_reference(service, org_name)
     if vdcReference:
         link = filter(lambda link: link.get_type() == "application/xml;class=vnd.vmware.vchs.vcloudsession", vdcReference.get_Link())[0]
         self.response = requests.post(link.get_href(), headers=self._get_vcloud_headers(), verify=self.verify)
         if self.response.status_code == requests.codes.created:
             vchs = vchsType.parseString(self.response.content, True)
             vdcLink = vchs.get_VdcLink()
             headers = {}
             headers[vdcLink.authorizationHeader] = vdcLink.authorizationToken
             headers["Accept"] = "application/*+xml;version=" + self.version
             self.response = requests.get(vdcLink.href, headers=headers, verify=self.verify)
             if self.response.status_code == requests.codes.ok:
                 self.vdc = vdcType.parseString(self.response.content, True)
                 self.org = self.vdc.name
                 org_url = filter(lambda link: link.get_type() == "application/vnd.vmware.vcloud.org+xml", self.vdc.get_Link())[0].href
                 vcloud_session = VCS(org_url, self.username, self.org, None, org_url, org_url, version=self.version, verify=self.verify)
                 if vcloud_session.login(password=None, token=vdcLink.authorizationToken):
                     self.vcloud_session = vcloud_session
                     return True
     return False
Beispiel #16
0
    def test_get_vminstance(self, get_vdc_details, get_vapp_details_rest):
        vapp_info = {
            'status':
            '4',
            'acquireMksTicket': {
                'href':
                'https://localhost/api/vApp/vm-47d12505-5968-4e16-95a7-18743edb0c8b/screen/action/acquireMksTicket',
                'type': 'application/vnd.vmware.vcloud.mksTicket+xml',
                'rel': 'screen:acquireMksTicket'
            },
            'vm_virtual_hardware': {
                'disk_edit_href':
                'https://localhost/api/vApp/vm-47d12505-5968-4e16-95a7-18743edb0c8b/virtualHardwareSection/disks',
                'disk_size': '40960'
            },
            'name':
            'Test1_vm-69a18104-8413-4cb8-bad7-b5afaec6f9fa',
            'created':
            '2017-09-21T01:15:31.627-07:00',
            'IsEnabled':
            'true',
            'EndAddress':
            '12.16.24.199',
            'interfaces': [{
                'MACAddress': '00:50:56:01:12:a2',
                'NetworkConnectionIndex': '0',
                'network':
                'testing_T6nODiW4-68f68d93-0350-4d86-b40b-6e74dedf994d',
                'IpAddressAllocationMode': 'DHCP',
                'IsConnected': 'true',
                'IpAddress': '12.16.24.200'
            }],
            'ovfDescriptorUploaded':
            'true',
            'nestedHypervisorEnabled':
            'false',
            'Gateway':
            '12.16.24.1',
            'acquireTicket': {
                'href':
                'https://localhost/api/vApp/vm-47d12505-5968-4e16-95a7-18743edb0c8b/screen/action/acquireTicket',
                'rel': 'screen:acquireTicket'
            },
            'vmuuid':
            '47d12505-5968-4e16-95a7-18743edb0c8b',
            'Netmask':
            '255.255.255.0',
            'StartAddress':
            '12.16.24.100',
            'primarynetwork':
            '0',
            'networkname':
            'External-Network-1074',
            'IsInherited':
            'false',
            'deployed':
            'true'
        }
        # created vdc object
        vdc_xml_resp = xml_resp.vdc_xml_response
        vdc = vdcType.parseString(vdc_xml_resp, True)
        # assumed return value from VIM connector
        get_vdc_details.return_value = vdc
        get_vapp_details_rest.return_value = vapp_info

        result = self.vim.get_vminstance(
            '47d12505-5968-4e16-95a7-18743edb0c8b')
        # assert verified expected and return result from VIM connector
        self.assertEqual(result['status'], 'ACTIVE')
        self.assertEqual(result['hostId'],
                         '47d12505-5968-4e16-95a7-18743edb0c8b')