added listing geographical regions
Project: http://git-wip-us.apache.org/repos/asf/libcloud/repo Commit: http://git-wip-us.apache.org/repos/asf/libcloud/commit/ec05af99 Tree: http://git-wip-us.apache.org/repos/asf/libcloud/tree/ec05af99 Diff: http://git-wip-us.apache.org/repos/asf/libcloud/diff/ec05af99 Branch: refs/heads/trunk Commit: ec05af99dd3a80d92f673ad988e511fd240dfbda Parents: b58c770 Author: mitch <[email protected]> Authored: Mon Nov 26 14:03:06 2018 -0500 Committer: mitch <[email protected]> Committed: Mon Nov 26 14:03:06 2018 -0500 ---------------------------------------------------------------------- libcloud/compute/drivers/nttcis.py | 51 +++++++------ .../fixtures/nttcis/geographic_regions.xml | 75 ++++++++++++++++++++ libcloud/test/compute/test_nttcis.py | 13 ++++ 3 files changed, 113 insertions(+), 26 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/libcloud/blob/ec05af99/libcloud/compute/drivers/nttcis.py ---------------------------------------------------------------------- diff --git a/libcloud/compute/drivers/nttcis.py b/libcloud/compute/drivers/nttcis.py index 0fc651d..c788124 100644 --- a/libcloud/compute/drivers/nttcis.py +++ b/libcloud/compute/drivers/nttcis.py @@ -52,6 +52,7 @@ from libcloud.common.nttcis import NttCisTagKey from libcloud.common.nttcis import NttCisTag from libcloud.common.nttcis import API_ENDPOINTS, DEFAULT_REGION from libcloud.common.nttcis import TYPES_URN +from libcloud.common.nttcis import process_xml from libcloud.common.nttcis import NETWORK_NS, GENERAL_NS from libcloud.utils.py3 import urlencode, ensure_string from libcloud.utils.xml import fixxpath, findtext, findall @@ -863,6 +864,19 @@ class NttCisNodeDriver(NodeDriver): driver=self.connection.driver), ] + def list_geographic_regions(self, params={}): + """ + Return all geographic regions available to the organization + + :return: List of regions + :rtype: ``list`` of :class:`NttCisGeographicregion` + """ + return self._to_geographic_regions( + self.connection.request_with_orgId_api_2( + "infrastructure/geographicRegion", + method="GET", + params=params).object) + def list_locations(self, ex_id=None): """ List locations (datacenters) available for instantiating servers and @@ -872,7 +886,7 @@ class NttCisNodeDriver(NodeDriver): :type ex_id: ``str`` :return: List of locations - :rtype: ``list`` of :class:`NodeLocation` + :rtype: ``list`` of :class:`NttCisDatacenter` """ params = {} @@ -887,26 +901,6 @@ class NttCisNodeDriver(NodeDriver): ).object ) - def ex_get_datacneter(self, ex_id): - """ - List locations (datacenters) available for instantiating servers and - networks. - - :keyword ex_id: Filters the location list to this id - :type ex_id: ``str`` - - :return: List of locations - :rtype: ``list`` of :class:`NodeLocation` - """ - - params = {} - if ex_id is not None: - params['id'] = ex_id - - return self.connection.\ - request_with_orgId_api_2('infrastructure/datacenter', - params=params) - def list_snapshot_windows(self, location, plan): """ List snapshot windows in a given location @@ -4995,11 +4989,7 @@ class NttCisNodeDriver(NodeDriver): return locations def _to_location(self, element): - l = NodeLocation(id=element.get('id'), - name=findtext(element, 'displayName', TYPES_URN), - country=findtext(element, 'country', TYPES_URN), - driver=self) - return l + return process_xml(ET.tostring(element)) def _to_cpu_spec(self, element): return NttCisServerCpuSpecification( @@ -5070,6 +5060,15 @@ class NttCisNodeDriver(NodeDriver): } + def _to_geographic_regions(self, object): + regions = [] + for region in object.findall(fixxpath('geographicRegion', TYPES_URN)): + regions.append(self._to_geographic_region(region)) + return regions + + def _to_geographic_region(self, el): + return process_xml(ET.tostring(el)) + def _to_ipv4_addresses(self, object): ipv4_address_elements = object.findall(fixxpath('ipv4', TYPES_URN)) return [self._to_ipv4_6_address(el) for el in ipv4_address_elements] http://git-wip-us.apache.org/repos/asf/libcloud/blob/ec05af99/libcloud/test/compute/fixtures/nttcis/geographic_regions.xml ---------------------------------------------------------------------- diff --git a/libcloud/test/compute/fixtures/nttcis/geographic_regions.xml b/libcloud/test/compute/fixtures/nttcis/geographic_regions.xml new file mode 100644 index 0000000..1ac025a --- /dev/null +++ b/libcloud/test/compute/fixtures/nttcis/geographic_regions.xml @@ -0,0 +1,75 @@ +<?xml version="1.0" encoding="UTF-8"?> +<geographicRegions xmlns="urn:didata.com:api:cloud:types" pageNumber="1" pageCount="8" totalCount="8" pageSize="250"> + <geographicRegion id="africa" isHome="false"> + <name>Africa</name> + <cloudApiHost>afapi.opsourcecloud.net</cloudApiHost> + <cloudUiUrl>https://mea.mcp-services.net</cloudUiUrl> + <monitoringUrl>https://af-monitoring.mcp-services.net</monitoringUrl> + <ftpsHost>ftps-af.cloud-vpn.net</ftpsHost> + <timeZone>Africa/Johannesburg</timeZone> + <state>ENABLED</state> + </geographicRegion> + <geographicRegion id="asiapacific" isHome="false"> + <name>Asia Pacific</name> + <cloudApiHost>apapi.opsourcecloud.net</cloudApiHost> + <cloudUiUrl>https://ap.mcp-services.net</cloudUiUrl> + <monitoringUrl>https://ap-monitoring.mcp-services.net</monitoringUrl> + <ftpsHost>ftps-ap.cloud-vpn.net</ftpsHost> + <timeZone>Asia/Tokyo</timeZone> + <state>ENABLED</state> + </geographicRegion> + <geographicRegion id="australia" isHome="false"> + <name>Australia</name> + <cloudApiHost>auapi.opsourcecloud.net</cloudApiHost> + <cloudUiUrl>https://au.mcp-services.net</cloudUiUrl> + <monitoringUrl>https://au-monitoring.mcp-services.net</monitoringUrl> + <ftpsHost>ftps-au.cloud-vpn.net</ftpsHost> + <timeZone>Australia/Sydney</timeZone> + <state>ENABLED</state> + </geographicRegion> + <geographicRegion id="canada" isHome="false"> + <name>Canada</name> + <cloudApiHost>api-canada.dimensiondata.com</cloudApiHost> + <cloudUiUrl>https://canada.mcp-services.net</cloudUiUrl> + <monitoringUrl>https://ca-monitoring.mcp-services.net</monitoringUrl> + <ftpsHost>ftps-canada.cloud-vpn.net</ftpsHost> + <timeZone>America/Toronto</timeZone> + <state>ENABLED</state> + </geographicRegion> + <geographicRegion id="europe" isHome="false"> + <name>Europe</name> + <cloudApiHost>euapi.opsourcecloud.net</cloudApiHost> + <cloudUiUrl>https://eu.mcp-services.net</cloudUiUrl> + <monitoringUrl>https://eu-monitoring.mcp-services.net</monitoringUrl> + <ftpsHost>ftps-eu.cloud-vpn.net</ftpsHost> + <timeZone>Europe/Amsterdam</timeZone> + <state>ENABLED</state> + </geographicRegion> + <geographicRegion id="indonesia" isHome="false"> + <name>Indonesia</name> + <cloudApiHost>idapi.opsourcecloud.net</cloudApiHost> + <cloudUiUrl>https://id.mcp-services.net</cloudUiUrl> + <monitoringUrl>https://id-monitoring.mcp-services.net</monitoringUrl> + <ftpsHost>ftps-id.cloud-vpn.net</ftpsHost> + <timeZone>Asia/Jakarta</timeZone> + <state>NOT_ENABLED</state> + </geographicRegion> + <geographicRegion id="israel" isHome="false"> + <name>Israel</name> + <cloudApiHost>ilapi.opsourcecloud.net</cloudApiHost> + <cloudUiUrl>https://il.mcp-services.net</cloudUiUrl> + <monitoringUrl>https://il-monitoring.mcp-services.net</monitoringUrl> + <ftpsHost>ftps-med-1.cloud-vpn.net</ftpsHost> + <timeZone>Asia/Jerusalem</timeZone> + <state>NOT_ENABLED</state> + </geographicRegion> + <geographicRegion id="northamerica" isHome="true"> + <name>North America</name> + <cloudApiHost>api.opsourcecloud.net</cloudApiHost> + <cloudUiUrl>https://na.mcp-services.net</cloudUiUrl> + <monitoringUrl>https://na-monitoring.mcp-services.net</monitoringUrl> + <ftpsHost>ftps-na.cloud-vpn.net</ftpsHost> + <timeZone>America/New_York</timeZone> + <state>ENABLED</state> + </geographicRegion> +</geographicRegions> \ No newline at end of file http://git-wip-us.apache.org/repos/asf/libcloud/blob/ec05af99/libcloud/test/compute/test_nttcis.py ---------------------------------------------------------------------- diff --git a/libcloud/test/compute/test_nttcis.py b/libcloud/test/compute/test_nttcis.py index cff7094..9068edd 100644 --- a/libcloud/test/compute/test_nttcis.py +++ b/libcloud/test/compute/test_nttcis.py @@ -61,6 +61,12 @@ def test_list_locations_response(driver): assert first_loc.country == 'US' +def test_list_geograhic_regions(driver): + ret = driver.list_geographic_regions() + assert isinstance(ret, list) + assert ret[7].isHome == 'true' + + def test_list_nodes_response(driver): NttCisMockHttp.type = None ret = driver.list_nodes() @@ -2894,4 +2900,11 @@ class NttCisMockHttp(MockHttp): body = self.fixtures.load( 'deploy_customised_server.xml' ) + return httplib.OK, body, {}, httplib.responses[httplib.OK] + + def _caas_2_7_8a8f6abc_2745_4d8a_9cbc_8dabe5a7d0e4_infrastructure_geographicRegion( + self, method, url, body, headers): + body = self.fixtures.load( + 'geographic_regions.xml' + ) return httplib.OK, body, {}, httplib.responses[httplib.OK] \ No newline at end of file
