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 2016/02/29 05:12:23 UTC
[10/19] libcloud git commit: DimensionData: Adding better node states,
more than just running and terminated
DimensionData: Adding better node states, more than just running and terminated
Project: http://git-wip-us.apache.org/repos/asf/libcloud/repo
Commit: http://git-wip-us.apache.org/repos/asf/libcloud/commit/d44fd923
Tree: http://git-wip-us.apache.org/repos/asf/libcloud/tree/d44fd923
Diff: http://git-wip-us.apache.org/repos/asf/libcloud/diff/d44fd923
Branch: refs/heads/trunk
Commit: d44fd923e099f374128813fdbf73d7f5464cee03
Parents: 6d9e820
Author: Jeffrey Dunham <je...@gmail.com>
Authored: Fri Feb 19 21:47:37 2016 -0500
Committer: anthony-shaw <an...@gmail.com>
Committed: Sun Feb 28 16:18:56 2016 +1100
----------------------------------------------------------------------
libcloud/compute/drivers/dimensiondata.py | 37 +++++--
libcloud/compute/types.py | 6 ++
...745_4d8a_9cbc_8dabe5a7d0e4_server_server.xml | 105 ++++++++++++++++++-
libcloud/test/compute/test_dimensiondata.py | 14 ++-
4 files changed, 152 insertions(+), 10 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/libcloud/blob/d44fd923/libcloud/compute/drivers/dimensiondata.py
----------------------------------------------------------------------
diff --git a/libcloud/compute/drivers/dimensiondata.py b/libcloud/compute/drivers/dimensiondata.py
index 651536e..268798f 100644
--- a/libcloud/compute/drivers/dimensiondata.py
+++ b/libcloud/compute/drivers/dimensiondata.py
@@ -42,6 +42,21 @@ from libcloud.utils.xml import fixxpath, findtext, findall
from libcloud.utils.py3 import basestring
from libcloud.compute.types import NodeState, Provider
+# Node state map is a dictionary with the keys as tuples
+# These tuples represent:
+# (<state_of_node_from_didata>, <is node started?>, <action happening>)
+NODE_STATE_MAP = {
+ ('NORMAL', 'true', None): NodeState.RUNNING,
+ ('NORMAL', 'false', None): NodeState.STOPPED,
+ ('PENDING_CHANGE', 'true', 'START_SERVER'): NodeState.STARTING,
+ ('PENDING_ADD', 'true', 'DEPLOY_SERVER'): NodeState.STARTING,
+ ('PENDING_CHANGE', 'true', 'SHUTDOWN_SERVER'): NodeState.STOPPING,
+ ('PENDING_CHANGE', 'true', 'REBOOT_SERVER'): NodeState.REBOOTING,
+ ('PENDING_CHANGE', 'true', 'RESET_SERVER'): NodeState.REBOOTING,
+ ('PENDING_CHANGE', 'true', 'RECONFIGURE_SERVER'): NodeState.RECONFIGURING,
+ ('PENDING_CHANGE', 'true', 'POWER_OFF_SERVER'): NodeState.STOPPING,
+}
+
class DimensionDataNodeDriver(NodeDriver):
"""
@@ -1826,16 +1841,14 @@ class DimensionDataNodeDriver(NodeDriver):
def _to_nodes(self, object):
node_elements = object.findall(fixxpath('server', TYPES_URN))
-
return [self._to_node(el) for el in node_elements]
def _to_node(self, element):
- if findtext(element, 'started', TYPES_URN) == 'true':
- state = NodeState.RUNNING
- else:
- state = NodeState.TERMINATED
-
+ started = findtext(element, 'started', TYPES_URN)
status = self._to_status(element.find(fixxpath('progress', TYPES_URN)))
+ dd_state = findtext(element, 'state', TYPES_URN)
+
+ node_state = self._get_node_state(dd_state, started, status.action)
has_network_info \
= element.find(fixxpath('networkInfo', TYPES_URN)) is not None
@@ -1885,7 +1898,7 @@ class DimensionDataNodeDriver(NodeDriver):
n = Node(id=element.get('id'),
name=findtext(element, 'name', TYPES_URN),
- state=state,
+ state=node_state,
public_ips=[public_ip] if public_ip is not None else [],
private_ips=[private_ip] if private_ip is not None else [],
driver=self.connection.driver,
@@ -1927,6 +1940,16 @@ class DimensionDataNodeDriver(NodeDriver):
return s
@staticmethod
+ def _get_node_state(state, started, action):
+ try:
+ return NODE_STATE_MAP[(state, started, action)]
+ except KeyError:
+ if started == 'true':
+ return NodeState.RUNNING
+ else:
+ return NodeState.TERMINATED
+
+ @staticmethod
def _location_to_location_id(location):
if isinstance(location, NodeLocation):
return location.id
http://git-wip-us.apache.org/repos/asf/libcloud/blob/d44fd923/libcloud/compute/types.py
----------------------------------------------------------------------
diff --git a/libcloud/compute/types.py b/libcloud/compute/types.py
index 1cef29c..32b640c 100644
--- a/libcloud/compute/types.py
+++ b/libcloud/compute/types.py
@@ -222,25 +222,31 @@ class NodeState(Type):
Standard states for a node
:cvar RUNNING: Node is running.
+ :cvar STARTING: Node is starting up.
:cvar REBOOTING: Node is rebooting.
:cvar TERMINATED: Node is terminated. This node can't be started later on.
+ :cvar STOPPING: Node is currently trying to stop.
:cvar STOPPED: Node is stopped. This node can be started later on.
:cvar PENDING: Node is pending.
:cvar SUSPENDED: Node is suspended.
:cvar ERROR: Node is an error state. Usually no operations can be performed
on the node once it ends up in the error state.
:cvar PAUSED: Node is paused.
+ :cvar RECONFIGURING: Node is being reconfigured.
:cvar UNKNOWN: Node state is unknown.
"""
RUNNING = 'running'
+ STARTING = 'starting'
REBOOTING = 'rebooting'
TERMINATED = 'terminated'
PENDING = 'pending'
UNKNOWN = 'unknown'
+ STOPPING = 'stopping'
STOPPED = 'stopped'
SUSPENDED = 'suspended'
ERROR = 'error'
PAUSED = 'paused'
+ RECONFIGURING = 'reconfiguring'
class StorageVolumeState(Type):
http://git-wip-us.apache.org/repos/asf/libcloud/blob/d44fd923/libcloud/test/compute/fixtures/dimensiondata/caas_2_1_8a8f6abc_2745_4d8a_9cbc_8dabe5a7d0e4_server_server.xml
----------------------------------------------------------------------
diff --git a/libcloud/test/compute/fixtures/dimensiondata/caas_2_1_8a8f6abc_2745_4d8a_9cbc_8dabe5a7d0e4_server_server.xml b/libcloud/test/compute/fixtures/dimensiondata/caas_2_1_8a8f6abc_2745_4d8a_9cbc_8dabe5a7d0e4_server_server.xml
index c3d607f..bc333d8 100644
--- a/libcloud/test/compute/fixtures/dimensiondata/caas_2_1_8a8f6abc_2745_4d8a_9cbc_8dabe5a7d0e4_server_server.xml
+++ b/libcloud/test/compute/fixtures/dimensiondata/caas_2_1_8a8f6abc_2745_4d8a_9cbc_8dabe5a7d0e4_server_server.xml
@@ -19,7 +19,7 @@
<vmwareTools versionStatus="NEED_UPGRADE" runningStatus="RUNNING" apiVersion="8389" />
<virtualHardware version="vmx-08" upToDate="false" />
</server>
- <!-- MCP 2.0 Server -->
+ <!-- MCP 2.0 Server State: SHUTTING_DOWN-->
<server id="5a32d6e4-9707-4813-a269-56ab4d989f4d" datacenterId="NA9">
<name>Production Web Server MCP 2</name>
<description>Server to host our main web application.</description>
@@ -46,4 +46,107 @@
<vmwareTools versionStatus="CURRENT" runningStatus="RUNNING" apiVersion="9354" />
<virtualHardware version="vmx-08" upToDate="false" />
</server>
+ <!-- MCP 2.0 Server State: RECONFIGURING-->
+ <server id="5a32d6e4-9707-4813-a269-56ab4d989f4d" datacenterId="NA9">
+ <name>Production Web Server MCP 2</name>
+ <description>Server to host our main web application.</description>
+ <operatingSystem id="WIN2008S32" displayName="WIN2008S/32" family="WINDOWS" />
+ <cpu count="2" speed="STANDARD" coresPerSocket="1" />
+ <memoryGb>4</memoryGb>
+ <disk id="c2e1f199-116e-4dbc-9960-68720b832b0a" scsiId="0" sizeGb="50" speed="STANDARD" state="NORMAL" />
+ <networkInfo networkDomainId="553f26b6-2a73-42c3-a78b-6116f11291d0">
+ <primaryNic id="5e869800-df7b-4626-bcbf-8643b8be11fd" privateIpv4="10.0.4.8" ipv6="2607:f480:1111:1282:2960:fb72:7154:6160" vlanId="bc529e20-dc6f-42ba-be20-0ffe44d1993f" vlanName="Production VLAN" state="NORMAL" />
+ </networkInfo>
+ <backup assetId="91002e08-8dc1-47a1-ad33-04f501c06f87" servicePlan="Advanced" state="NORMAL" />
+ <monitoring monitoringId="11039" servicePlan="ESSENTIALS" state="NORMAL" />
+ <softwareLabel>MSSQL2008R2S</softwareLabel>
+ <sourceImageId>3ebf3c0f-90fe-4a8b-8585-6e65b316592c</sourceImageId>
+ <createTime>2015-12-02T10:31:33.000Z</createTime>
+ <deployed>true</deployed>
+ <started>true</started>
+ <state>PENDING_CHANGE</state>
+ <progress>
+ <action>RECONFIGURE_SERVER</action>
+ <requestTime>2015-12-02T11:07:40.000Z</requestTime>
+ <userName>devuser1</userName>
+ </progress>
+ <vmwareTools versionStatus="CURRENT" runningStatus="RUNNING" apiVersion="9354" />
+ <virtualHardware version="vmx-08" upToDate="false" />
+ </server>
+ <!-- MCP 2.0 Server State: UNKNOWN - running-->
+ <server id="5a32d6e4-9707-4813-a269-56ab4d989f4d" datacenterId="NA9">
+ <name>Production Web Server MCP 2</name>
+ <description>Server to host our main web application.</description>
+ <operatingSystem id="WIN2008S32" displayName="WIN2008S/32" family="WINDOWS" />
+ <cpu count="2" speed="STANDARD" coresPerSocket="1" />
+ <memoryGb>4</memoryGb>
+ <disk id="c2e1f199-116e-4dbc-9960-68720b832b0a" scsiId="0" sizeGb="50" speed="STANDARD" state="NORMAL" />
+ <networkInfo networkDomainId="553f26b6-2a73-42c3-a78b-6116f11291d0">
+ <primaryNic id="5e869800-df7b-4626-bcbf-8643b8be11fd" privateIpv4="10.0.4.8" ipv6="2607:f480:1111:1282:2960:fb72:7154:6160" vlanId="bc529e20-dc6f-42ba-be20-0ffe44d1993f" vlanName="Production VLAN" state="NORMAL" />
+ </networkInfo>
+ <backup assetId="91002e08-8dc1-47a1-ad33-04f501c06f87" servicePlan="Advanced" state="NORMAL" />
+ <monitoring monitoringId="11039" servicePlan="ESSENTIALS" state="NORMAL" />
+ <softwareLabel>MSSQL2008R2S</softwareLabel>
+ <sourceImageId>3ebf3c0f-90fe-4a8b-8585-6e65b316592c</sourceImageId>
+ <createTime>2015-12-02T10:31:33.000Z</createTime>
+ <deployed>true</deployed>
+ <started>true</started>
+ <state>UNKNOWN</state>
+ <progress>
+ <action>SHUTDOWN_SERVER</action>
+ <requestTime>2015-12-02T11:07:40.000Z</requestTime>
+ <userName>devuser1</userName>
+ </progress>
+ <vmwareTools versionStatus="CURRENT" runningStatus="RUNNING" apiVersion="9354" />
+ <virtualHardware version="vmx-08" upToDate="false" />
+ </server>
+ <!-- MCP 2.0 Server State: UNKNOWN-terminated-->
+ <server id="5a32d6e4-9707-4813-a269-56ab4d989f4d" datacenterId="NA9">
+ <name>Production Web Server MCP 21</name>
+ <description>Server to host our main web application.</description>
+ <operatingSystem id="WIN2008S32" displayName="WIN2008S/32" family="WINDOWS" />
+ <cpu count="2" speed="STANDARD" coresPerSocket="1" />
+ <memoryGb>4</memoryGb>
+ <disk id="c2e1f199-116e-4dbc-9960-68720b832b0a" scsiId="0" sizeGb="50" speed="STANDARD" state="NORMAL" />
+ <networkInfo networkDomainId="553f26b6-2a73-42c3-a78b-6116f11291d0">
+ <primaryNic id="5e869800-df7b-4626-bcbf-8643b8be11fd" privateIpv4="10.0.4.8" ipv6="2607:f480:1111:1282:2960:fb72:7154:6160" vlanId="bc529e20-dc6f-42ba-be20-0ffe44d1993f" vlanName="Production VLAN" state="NORMAL" />
+ </networkInfo>
+ <backup assetId="91002e08-8dc1-47a1-ad33-04f501c06f87" servicePlan="Advanced" state="NORMAL" />
+ <monitoring monitoringId="11039" servicePlan="ESSENTIALS" state="NORMAL" />
+ <softwareLabel>MSSQL2008R2S</softwareLabel>
+ <sourceImageId>3ebf3c0f-90fe-4a8b-8585-6e65b316592c</sourceImageId>
+ <createTime>2015-12-02T10:31:33.000Z</createTime>
+ <deployed>true</deployed>
+ <started>false</started>
+ <state>UNKNOWN</state>
+ <progress>
+ <action>SHUTDOWN_SERVER</action>
+ <requestTime>2015-12-02T11:07:40.000Z</requestTime>
+ <userName>devuser1</userName>
+ </progress>
+ <vmwareTools versionStatus="CURRENT" runningStatus="RUNNING" apiVersion="9354" />
+ <virtualHardware version="vmx-08" upToDate="false" />
+ </server>
+ <!-- MCP 2.0 Server State: STOPPED-->
+ <server id="5a32d6e4-9707-4813-a269-56ab4d989f4d" datacenterId="NA9">
+ <name>Production Web Server MCP 2</name>
+ <description>Server to host our main web application.</description>
+ <operatingSystem id="WIN2008S32" displayName="WIN2008S/32" family="WINDOWS" />
+ <cpu count="2" speed="STANDARD" coresPerSocket="1" />
+ <memoryGb>4</memoryGb>
+ <disk id="c2e1f199-116e-4dbc-9960-68720b832b0a" scsiId="0" sizeGb="50" speed="STANDARD" state="NORMAL" />
+ <networkInfo networkDomainId="553f26b6-2a73-42c3-a78b-6116f11291d0">
+ <primaryNic id="5e869800-df7b-4626-bcbf-8643b8be11fd" privateIpv4="10.0.4.8" ipv6="2607:f480:1111:1282:2960:fb72:7154:6160" vlanId="bc529e20-dc6f-42ba-be20-0ffe44d1993f" vlanName="Production VLAN" state="NORMAL" />
+ </networkInfo>
+ <backup assetId="91002e08-8dc1-47a1-ad33-04f501c06f87" servicePlan="Advanced" state="NORMAL" />
+ <monitoring monitoringId="11039" servicePlan="ESSENTIALS" state="NORMAL" />
+ <softwareLabel>MSSQL2008R2S</softwareLabel>
+ <sourceImageId>3ebf3c0f-90fe-4a8b-8585-6e65b316592c</sourceImageId>
+ <createTime>2015-12-02T10:31:33.000Z</createTime>
+ <deployed>true</deployed>
+ <started>false</started>
+ <state>NORMAL</state>
+ <vmwareTools versionStatus="CURRENT" runningStatus="RUNNING" apiVersion="9354" />
+ <virtualHardware version="vmx-08" upToDate="false" />
+ </server>
</servers>
http://git-wip-us.apache.org/repos/asf/libcloud/blob/d44fd923/libcloud/test/compute/test_dimensiondata.py
----------------------------------------------------------------------
diff --git a/libcloud/test/compute/test_dimensiondata.py b/libcloud/test/compute/test_dimensiondata.py
index 3bb0210..2443ea5 100644
--- a/libcloud/test/compute/test_dimensiondata.py
+++ b/libcloud/test/compute/test_dimensiondata.py
@@ -61,12 +61,22 @@ class DimensionDataTests(unittest.TestCase, TestCaseMixin):
def test_list_nodes_response(self):
DimensionDataMockHttp.type = None
ret = self.driver.list_nodes()
- self.assertEqual(len(ret), 2)
+ self.assertEqual(len(ret), 6)
+
+ def test_server_states(self):
+ DimensionDataMockHttp.type = None
+ ret = self.driver.list_nodes()
+ self.assertTrue(ret[0].state == 'running')
+ self.assertTrue(ret[1].state == 'stopping')
+ self.assertTrue(ret[2].state == 'reconfiguring')
+ self.assertTrue(ret[3].state == 'running')
+ self.assertTrue(ret[4].state == 'terminated')
+ self.assertTrue(ret[5].state == 'stopped')
def test_list_nodes_response_PAGINATED(self):
DimensionDataMockHttp.type = 'PAGINATED'
ret = self.driver.list_nodes()
- self.assertEqual(len(ret), 4)
+ self.assertEqual(len(ret), 8)
# We're making sure here the filters make it to the URL
# See _caas_2_1_8a8f6abc_2745_4d8a_9cbc_8dabe5a7d0e4_server_server_ALLFILTERS for asserts