You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@libcloud.apache.org by an...@apache.org on 2018/12/13 11:26:44 UTC
[35/45] libcloud git commit: removed changes made and will create new
branch
removed changes made and will create new branch
Project: http://git-wip-us.apache.org/repos/asf/libcloud/repo
Commit: http://git-wip-us.apache.org/repos/asf/libcloud/commit/aa6ad8f5
Tree: http://git-wip-us.apache.org/repos/asf/libcloud/tree/aa6ad8f5
Diff: http://git-wip-us.apache.org/repos/asf/libcloud/diff/aa6ad8f5
Branch: refs/heads/trunk
Commit: aa6ad8f559ec0435adc18913c804c10d70c35e9a
Parents: ec05af9
Author: mitch <mi...@itaas.dimensiondata.com>
Authored: Mon Nov 26 17:32:11 2018 -0500
Committer: mitch <mi...@itaas.dimensiondata.com>
Committed: Mon Nov 26 17:32:11 2018 -0500
----------------------------------------------------------------------
libcloud/common/nttcis.py | 55 +++++++++++++++++++++++++++----
libcloud/compute/drivers/nttcis.py | 29 +++-------------
libcloud/test/compute/test_nttcis.py | 13 --------
3 files changed, 54 insertions(+), 43 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/libcloud/blob/aa6ad8f5/libcloud/common/nttcis.py
----------------------------------------------------------------------
diff --git a/libcloud/common/nttcis.py b/libcloud/common/nttcis.py
index aac16fa..faf6650 100644
--- a/libcloud/common/nttcis.py
+++ b/libcloud/common/nttcis.py
@@ -1965,14 +1965,25 @@ def processor(mapping, name=None):
Closure that keeps the deepcopy of the original dict
converted to XML current.
:param mapping: The converted XML to dict/lists
+ :type mapping: ``dict``
:param name: (Optional) what becomes the class name if provided
+ :type: ``str``
:return: Nothing
"""
mapping = mapping
-
+ # the map_copy will have keys deleted after the key and value are processed
map_copy = deepcopy(mapping)
def add_items(key, value, name=None):
+ """
+ Add items to the global attr dict, then delete key, value from map copy
+ :param key: from the process function becomes the attribute name
+ :type key: ``str``
+ :param value: The value of the property and may be a dict
+ :type value: ``str``
+ :param name: Name of class, often same as key
+ :type: name" ``str``
+ """
if name in attrs:
attrs[name].update({key: value})
elif name is not None:
@@ -2033,7 +2044,6 @@ def processor(mapping, name=None):
tmp_list = [build_class(k.capitalize(), i)
for i in v]
tmp[k] = tmp_list
- print()
elif isinstance(v, str):
tmp.update({k: v})
return tmp
@@ -2042,7 +2052,12 @@ def processor(mapping, name=None):
klass = class_factory(key.capitalize(), value)
return klass(value)
- def process(mapping, name):
+ def process(mapping):
+ """
+ This function is recursive, creating attributes for the class factory.
+ :param mapping: the dictionary converted from XML
+ :return: itself (recursive)
+ """
for k1, v1 in mapping.items():
if isinstance(v1, Mapping):
types = [type(v) for v in v1.values()]
@@ -2075,11 +2090,21 @@ def processor(mapping, name=None):
if len(map_copy) == 0:
return 1
- return process(mapping, name)
+ return process(mapping)
def class_factory(cls_name, attrs):
-
+ """
+ This class takes a name and a dictionary to create a class.
+ The clkass has an init method, an iter for retrieving properties,
+ and, finally, a repr for returning the instance
+ :param cls_name: The name to be tacked onto the suffix NttCis
+ :type cls_name: ``str``
+ :param attrs: The attributes and values for an instance
+ :type attrs: ``dict``
+ :return: a class that inherits from ClassFactory
+ :rtype: ``ClassFactory``
+ """
def __init__(self, *args, **kwargs):
for key in attrs:
setattr(self, key, attrs[key])
@@ -2104,6 +2129,10 @@ def class_factory(cls_name, attrs):
class XmlListConfig(list):
+ """
+ Creates a class from XML elements that make a list. If a list of
+ XML elements with attributes, the attributes are passed to XmlDictConfig.
+ """
def __init__(self, elem_list):
for element in elem_list:
if element is not None:
@@ -2126,7 +2155,11 @@ class XmlListConfig(list):
class XmlDictConfig(dict):
-
+ """
+ Inherits from dict. Looks for XML elements, such as attrib, that
+ can be converted to a dictionary. Any XML element that contains
+ other XML elements, will be passed to XmlListConfig
+ """
def __init__(self, parent_element):
if parent_element.items():
if 'property' in parent_element.tag:
@@ -2187,6 +2220,16 @@ class XmlDictConfig(dict):
def process_xml(xml):
+ """
+ Take the xml and put it into a dictionary. The process the dictionary
+ recursively. This returns a class based on the XML API. Thus, properties
+ will have the camel case found in the Java XML. This a trade-off
+ to reduce the number of "static" classes that all have to be synchronized
+ with any changes in the API.
+ :param xml: The serialized version of the XML returned from Cloud Control
+ :return: a dynamic class that inherits from ClassFactory
+ :rtype: `ClassFactory`
+ """
global attrs
tree = etree.parse(BytesIO(xml))
root = tree.getroot()
http://git-wip-us.apache.org/repos/asf/libcloud/blob/aa6ad8f5/libcloud/compute/drivers/nttcis.py
----------------------------------------------------------------------
diff --git a/libcloud/compute/drivers/nttcis.py b/libcloud/compute/drivers/nttcis.py
index c788124..9810958 100644
--- a/libcloud/compute/drivers/nttcis.py
+++ b/libcloud/compute/drivers/nttcis.py
@@ -52,7 +52,6 @@ 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
@@ -864,19 +863,6 @@ 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
@@ -4989,7 +4975,11 @@ class NttCisNodeDriver(NodeDriver):
return locations
def _to_location(self, element):
- return process_xml(ET.tostring(element))
+ l = NodeLocation(id=element.get('id'),
+ name=findtext(element, 'displayName', TYPES_URN),
+ country=findtext(element, 'country', TYPES_URN),
+ driver=self)
+ return l
def _to_cpu_spec(self, element):
return NttCisServerCpuSpecification(
@@ -5060,15 +5050,6 @@ 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/aa6ad8f5/libcloud/test/compute/test_nttcis.py
----------------------------------------------------------------------
diff --git a/libcloud/test/compute/test_nttcis.py b/libcloud/test/compute/test_nttcis.py
index 9068edd..cff7094 100644
--- a/libcloud/test/compute/test_nttcis.py
+++ b/libcloud/test/compute/test_nttcis.py
@@ -61,12 +61,6 @@ 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()
@@ -2900,11 +2894,4 @@ 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