Example #1
0
 def get_gateway(self, vdc_name, gateway_name):
     gateway = None
     vdc = self.get_vdc(vdc_name)
     if not vdc: return gateway
     link = filter(lambda link: link.get_rel() == "edgeGateways",
                   vdc.get_Link())
     self.response = requests.get(
         link[0].get_href(),
         headers=self.vcloud_session.get_vcloud_headers(),
         verify=self.verify)
     if self.response.status_code == requests.codes.ok:
         queryResultRecords = queryRecordViewType.parseString(
             self.response.content, True)
         if queryResultRecords.get_Record():
             for edgeGatewayRecord in queryResultRecords.get_Record():
                 if edgeGatewayRecord.get_name() == gateway_name:
                     self.response = requests.get(
                         edgeGatewayRecord.get_href(),
                         headers=self.vcloud_session.get_vcloud_headers(),
                         verify=self.verify)
                     if self.response.status_code == requests.codes.ok:
                         gateway = Gateway(networkType.parseString(
                             self.response.content, True),
                                           headers=self.vcloud_session.
                                           get_vcloud_headers(),
                                           verify=self.verify)
                         break
     return gateway
    def create_isolated_vdc_network(
        self,
        vdc_name,
        network_name,
        gateway_name,
        start_address,
        end_address,
        gateway_ip,
        netmask,
        dns1=None,
        dns2=None,
        dns_suffix=None,
    ):
        vdc = self.get_vdc(vdc_name)
        if vdc is None:
            LOG.error("Create isolated vdc network error, cannot get vdc:" "%s info", vdc_name)
            raise exceptions.VCloudDriverException(
                "Create isolated vdc" " network error, cannot" "find the vdc_name:" + vdc_name
            )
        iprange = IpRangeType(StartAddress=start_address, EndAddress=end_address)
        ipranges = IpRangesType(IpRange=[iprange])
        ipscope = IpScopeType(
            IsInherited=False,
            Gateway=gateway_ip,
            Netmask=netmask,
            Dns1=dns1,
            Dns2=dns2,
            DnsSuffix=dns_suffix,
            IpRanges=ipranges,
        )
        ipscopes = IpScopesType(IpScope=[ipscope])

        configuration = NetworkConfigurationType(IpScopes=ipscopes, FenceMode="isolated")
        net = OrgVdcNetworkType(
            name=network_name,
            Description="Network created name is " + network_name,
            EdgeGateway=None,
            Configuration=configuration,
            IsShared=False,
        )
        namespacedef = 'xmlns="http://www.vmware.com/vcloud/v1.5"'
        content_type = "application/vnd.vmware.vcloud.orgVdcNetwork+xml"
        body = '<?xml version="1.0" encoding="UTF-8"?>{0}'.format(
            CommonUtils.convertPythonObjToStr(net, name="OrgVdcNetwork", namespacedef=namespacedef)
        )
        postlink = filter(lambda link: link.get_type() == content_type, vdc.get_Link())[0].href
        headers = self.vcloud_session.get_vcloud_headers()
        headers["Content-Type"] = content_type
        response = self._invoke_api(requests, "post", postlink, data=body, headers=headers, verify=self.verify)

        if response.status_code == requests.codes.forbidden:
            raise exceptions.ForbiddenException("Create_isolated_vdc_network" "error, network_name:" + network_name)
        if response.status_code == requests.codes.created:
            network = networkType.parseString(response.content, True)
            task = network.get_Tasks().get_Task()[0]
            return (True, task)
        else:
            return (False, response.content)
    def create_isolated_vdc_network(self, vdc_name, network_name, gateway_name,
                                    start_address, end_address, gateway_ip,
                                    netmask, dns1=None, dns2=None,
                                    dns_suffix=None):
        vdc = self.get_vdc(vdc_name)
        if vdc is None:
            LOG.error("Create isolated vdc network error, cannot get vdc:"
                      "%s info", vdc_name)
            raise exceptions.VCloudDriverException("Create isolated vdc"
                                                   " network error, cannot"
                                                   "find the vdc_name:" +
                                                   vdc_name)
        iprange = IpRangeType(StartAddress=start_address,
                              EndAddress=end_address)
        ipranges = IpRangesType(IpRange=[iprange])
        ipscope = IpScopeType(IsInherited=False,
                              Gateway=gateway_ip,
                              Netmask=netmask,
                              Dns1=dns1,
                              Dns2=dns2,
                              DnsSuffix=dns_suffix,
                              IpRanges=ipranges)
        ipscopes = IpScopesType(IpScope=[ipscope])

        configuration = NetworkConfigurationType(IpScopes=ipscopes,
                                                 FenceMode="isolated")
        net = OrgVdcNetworkType(name=network_name,
                                Description="Network created name is " +
                                network_name,
                                EdgeGateway=None, Configuration=configuration,
                                IsShared=False)
        namespacedef = 'xmlns="http://www.vmware.com/vcloud/v1.5"'
        content_type = "application/vnd.vmware.vcloud.orgVdcNetwork+xml"
        body = '<?xml version="1.0" encoding="UTF-8"?>{0}'.format(
            CommonUtils.convertPythonObjToStr(net, name='OrgVdcNetwork',
                                              namespacedef=namespacedef))
        postlink = filter(lambda link: link.get_type() == content_type,
                          vdc.get_Link())[0].href
        headers = self.vcloud_session.get_vcloud_headers()
        headers["Content-Type"] = content_type
        response = self._invoke_api(requests, 'post',
                                    postlink,
                                    data=body,
                                    headers=headers,
                                    verify=self.verify)

        if response.status_code == requests.codes.forbidden:
            raise exceptions.ForbiddenException("Create_isolated_vdc_network"
                                                "error, network_name:" +
                                                network_name)
        if response.status_code == requests.codes.created:
            network = networkType.parseString(response.content, True)
            task = network.get_Tasks().get_Task()[0]
            return (True, task)
        else:
            return (False, response.content)
Example #4
0
 def get_networks(self, vdc_name):
     result = []
     vdc = self.get_vdc(vdc_name)
     if not vdc: return result
     networks = vdc.get_AvailableNetworks().get_Network()
     for n in networks:
         self.response = requests.get(n.get_href(), headers=self.vcloud_session.get_vcloud_headers(), verify=self.verify)
         if self.response.status_code == requests.codes.ok:
             network = networkType.parseString(self.response.content, True)
             result.append(network)
     return result
Example #5
0
 def get_networks(self, vdc_name):
     result = []
     vdc = self.get_vdc(vdc_name)
     if not vdc: return result
     networks = vdc.get_AvailableNetworks().get_Network()
     for n in networks:
         self.response = requests.get(n.get_href(), headers=self.vcloud_session.get_vcloud_headers(), verify=self.verify)
         if self.response.status_code == requests.codes.ok:
             network = networkType.parseString(self.response.content, True)
             result.append(network)
     return result
Example #6
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')
Example #7
0
 def get_gateways(self, vdc_name):
     gateways = []
     vdc = self.get_vdc(vdc_name)
     if not vdc: return gateways
     link = filter(lambda link: link.get_rel() == "edgeGateways", vdc.get_Link())
     self.response = requests.get(link[0].get_href(), headers=self.vcloud_session.get_vcloud_headers(), verify=self.verify)
     if self.response.status_code == requests.codes.ok:
         queryResultRecords = queryRecordViewType.parseString(self.response.content, True)
         if queryResultRecords.get_Record():
             for edgeGatewayRecord in queryResultRecords.get_Record():
                 self.response = requests.get(edgeGatewayRecord.get_href(), headers=self.vcloud_session.get_vcloud_headers(), verify=self.verify)
                 if self.response.status_code == requests.codes.ok:
                     gateway = Gateway(networkType.parseString(self.response.content, True), headers=self.vcloud_session.get_vcloud_headers(), verify=self.verify)
                     gateways.append(gateway)
     return gateways
Example #8
0
 def get_gateway(self, vdc_name, gateway_name):
     gateway = None
     vdc = self.get_vdc(vdc_name)
     if not vdc: return gateway
     link = filter(lambda link: link.get_rel() == "edgeGateways", vdc.get_Link())
     self.response = Http.get(link[0].get_href(), headers=self.vcloud_session.get_vcloud_headers(), verify=self.verify, logger=self.logger)
     if self.response.status_code == requests.codes.ok:
         queryResultRecords = queryRecordViewType.parseString(self.response.content, True)
         if queryResultRecords.get_Record():
             for edgeGatewayRecord in queryResultRecords.get_Record():
                 if edgeGatewayRecord.get_name() == gateway_name:
                     self.response = Http.get(edgeGatewayRecord.get_href(), headers=self.vcloud_session.get_vcloud_headers(), verify=self.verify, logger=self.logger)
                     if self.response.status_code == requests.codes.ok:
                         gateway = Gateway(networkType.parseString(self.response.content, True), headers=self.vcloud_session.get_vcloud_headers(), verify=self.verify, log=self.log)
                         break
     return gateway
Example #9
0
    def create_vdc_network(self, vdc_name, network_name, gateway_name,
                           start_address, end_address, gateway_ip, netmask,
                           dns1, dns2, dns_suffix):
        vdc = self.get_vdc(vdc_name)
        gateway = ReferenceType(
            href=self.get_gateway(vdc_name, gateway_name).me.href)
        gateway.original_tagname_ = "EdgeGateway"

        iprange = IpRangeType(StartAddress=start_address,
                              EndAddress=end_address)
        ipranges = IpRangesType(IpRange=[iprange])
        ipscope = IpScopeType(IsInherited=False,
                              Gateway=gateway_ip,
                              Netmask=netmask,
                              Dns1=dns1,
                              Dns2=dns2,
                              DnsSuffix=dns_suffix,
                              IpRanges=ipranges)
        ipscopes = IpScopesType(IpScope=[ipscope])

        configuration = NetworkConfigurationType(IpScopes=ipscopes,
                                                 FenceMode="natRouted")
        net = OrgVdcNetworkType(name=network_name,
                                Description="Network created by pyvcloud",
                                EdgeGateway=gateway,
                                Configuration=configuration,
                                IsShared=False)
        namespacedef = 'xmlns="http://www.vmware.com/vcloud/v1.5"'
        content_type = "application/vnd.vmware.vcloud.orgVdcNetwork+xml"
        body = '<?xml version="1.0" encoding="UTF-8"?>{0}'.format(
            CommonUtils.convertPythonObjToStr(net,
                                              name='OrgVdcNetwork',
                                              namespacedef=namespacedef))
        postlink = filter(lambda link: link.get_type() == content_type,
                          vdc.get_Link())[0].href
        headers = self.vcloud_session.get_vcloud_headers()
        headers["Content-Type"] = content_type
        self.response = requests.post(postlink,
                                      data=body,
                                      headers=headers,
                                      verify=self.verify)
        if self.response.status_code == requests.codes.created:
            network = networkType.parseString(self.response.content, True)
            task = network.get_Tasks().get_Task()[0]
            return (True, task)
        else:
            return (False, self.response.content)
Example #10
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'])
Example #11
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)
Example #12
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)
Example #13
0
    def create_vdc_network(self, vdc_name, network_name, gateway_name, start_address,
                           end_address, gateway_ip, netmask,
                           dns1, dns2, dns_suffix):
        vdc = self.get_vdc(vdc_name)
        gateway = ReferenceType(href=self.get_gateway(vdc_name, gateway_name).me.href)
        gateway.original_tagname_ = "EdgeGateway"

        iprange = IpRangeType(StartAddress=start_address,
                              EndAddress=end_address)
        ipranges = IpRangesType(IpRange=[iprange])
        ipscope = IpScopeType(IsInherited=False,
                              Gateway=gateway_ip,
                              Netmask=netmask,
                              Dns1=dns1,
                              Dns2=dns2,
                              DnsSuffix=dns_suffix,
                              IpRanges=ipranges)
        ipscopes = IpScopesType(IpScope=[ipscope])

        configuration = NetworkConfigurationType(IpScopes=ipscopes,
                                                 FenceMode="natRouted")
        net = OrgVdcNetworkType(name=network_name, Description="Network created by pyvcloud",
                                EdgeGateway=gateway, Configuration=configuration,
                                IsShared=False)
        namespacedef = 'xmlns="http://www.vmware.com/vcloud/v1.5"'
        content_type = "application/vnd.vmware.vcloud.orgVdcNetwork+xml"
        body = '<?xml version="1.0" encoding="UTF-8"?>{0}'.format(
            CommonUtils.convertPythonObjToStr(net, name='OrgVdcNetwork',
                                              namespacedef=namespacedef))
        postlink = filter(lambda link: link.get_type() == content_type,
                          vdc.get_Link())[0].href
        headers = self.vcloud_session.get_vcloud_headers()
        headers["Content-Type"] = content_type
        self.response = requests.post(postlink, data=body, headers=headers, verify=self.verify)
        if self.response.status_code == requests.codes.created:
            network = networkType.parseString(self.response.content, True)
            task = network.get_Tasks().get_Task()[0]
            return (True, task)
        else:
            return (False, self.response.content)