Merge branch 'LIBCLOUD-761_Network_and_monitoring_support' into trunk
Conflicts:
libcloud/compute/drivers/dimensiondata.py
libcloud/test/compute/test_dimensiondata.py
Project: http://git-wip-us.apache.org/repos/asf/libcloud/repo
Commit: http://git-wip-us.apache.org/repos/asf/libcloud/commit/8abaf891
Tree: http://git-wip-us.apache.org/repos/asf/libcloud/tree/8abaf891
Diff: http://git-wip-us.apache.org/repos/asf/libcloud/diff/8abaf891
Branch: refs/heads/trunk
Commit: 8abaf891c17c984a6bda5d7cd7d785dc4545826d
Parents: 2a415a8 cd24ef2
Author: Anthony Shaw <[email protected]>
Authored: Wed Nov 18 18:50:14 2015 +1100
Committer: Anthony Shaw <[email protected]>
Committed: Wed Nov 18 18:50:14 2015 +1100
----------------------------------------------------------------------
libcloud/common/dimensiondata.py | 1 +
libcloud/compute/drivers/dimensiondata.py | 309 ++++++++++++++++++-
...9cbc_8dabe5a7d0e4_report_usageMonitoring.xml | 8 +
...a7d0e4_server_changeServerMonitoringPlan.xml | 8 +
...be5a7d0e4_server_disableServerMonitoring.xml | 8 +
...abe5a7d0e4_server_enableServerMonitoring.xml | 8 +
...8a_9cbc_8dabe5a7d0e4_networkWithLocation.xml | 2 +-
...ork_4bba37be_506f_11e3_b29c_001517c4643e.xml | 16 +
libcloud/test/compute/test_dimensiondata.py | 65 ++++
9 files changed, 414 insertions(+), 11 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/libcloud/blob/8abaf891/libcloud/common/dimensiondata.py
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/libcloud/blob/8abaf891/libcloud/compute/drivers/dimensiondata.py
----------------------------------------------------------------------
diff --cc libcloud/compute/drivers/dimensiondata.py
index 3ee8a11,270a7ca..72defdc
--- a/libcloud/compute/drivers/dimensiondata.py
+++ b/libcloud/compute/drivers/dimensiondata.py
@@@ -816,35 -1034,76 +1035,105 @@@ class DimensionDataNodeDriver(NodeDrive
filter(lambda x: x.id == id, self.list_locations()))[0]
return location
+ def ex_wait_for_state(self, state, func, poll_interval=2,
+ timeout=60, *args, **kwargs):
+ """
+ Wait for the function which returns a instance
+ with field status to match
+
+ Keep polling func until one of the desired states is matched
+
+ :param state: Either the desired state (`str`) or a `list` of states
+ :type state: ``str`` or ``list``
+
+ :param func: The function to call, e.g. ex_get_vlan
+ :type func: ``function``
+
+ :param poll_interval: The number of seconds to wait between checks
+ :type poll_interval: `int`
+
+ :param timeout: The total number of seconds to wait to reach a state
+ :type timeout: `int`
+
+ :param args: The arguments for func
+ :type args: Positional arguments
+
+ :param kwargs: The arguments for func
+ :type kwargs: Keyword arguments
+ """
+ return self.connection.wait_for_state(state, func, poll_interval,
+ timeout, *args, **kwargs)
+
+ def ex_enable_monitoring(self, node, service_plan="ESSENTIALS"):
+ """
+ Enables cloud monitoring on a node
+
+ :param node: The node to monitor
+ :type node: :class:`Node`
+
+ :param service_plan: The service plan, one of ESSENTIALS or
+ ADVANCED
+ :type service_plan: ``str``
+
+ :rtype: ``bool``
+ """
+ update_node = ET.Element('enableServerMonitoring',
+ {'xmlns': TYPES_URN})
+ update_node.set('id', node.id)
+ ET.SubElement(update_node, 'servicePlan').text = service_plan
+ result = self.connection.request_with_orgId_api_2(
+ 'server/enableServerMonitoring',
+ method='POST',
+ data=ET.tostring(update_node)).object
+
+ response_code = findtext(result, 'responseCode', TYPES_URN)
+ return response_code in ['IN_PROGRESS', 'OK']
+
+ def ex_update_monitoring_plan(self, node, service_plan="ESSENTIALS"):
+ """
+ Updates the service plan on a node with monitoring
+
+ :param node: The node to monitor
+ :type node: :class:`Node`
+
+ :param service_plan: The service plan, one of ESSENTIALS or
+ ADVANCED
+ :type service_plan: ``str``
+
+ :rtype: ``bool``
+ """
+ update_node = ET.Element('changeServerMonitoringPlan',
+ {'xmlns': TYPES_URN})
+ update_node.set('id', node.id)
+ ET.SubElement(update_node, 'servicePlan').text = service_plan
+ result = self.connection.request_with_orgId_api_2(
+ 'server/changeServerMonitoringPlan',
+ method='POST',
+ data=ET.tostring(update_node)).object
+
+ response_code = findtext(result, 'responseCode', TYPES_URN)
+ return response_code in ['IN_PROGRESS', 'OK']
+
+ def ex_disable_monitoring(self, node):
+ """
+ Disables cloud monitoring for a node
+
+ :param node: The node to stop monitoring
+ :type node: :class:`Node`
+
+ :rtype: ``bool``
+ """
+ update_node = ET.Element('disableServerMonitoring',
+ {'xmlns': TYPES_URN})
+ update_node.set('id', node.id)
+ result = self.connection.request_with_orgId_api_2(
+ 'server/disableServerMonitoring',
+ method='POST',
+ data=ET.tostring(update_node)).object
+
+ response_code = findtext(result, 'responseCode', TYPES_URN)
+ return response_code in ['IN_PROGRESS', 'OK']
+
def _to_nat_rules(self, object, network_domain):
rules = []
for element in findall(object, 'natRule', TYPES_URN):
http://git-wip-us.apache.org/repos/asf/libcloud/blob/8abaf891/libcloud/test/compute/test_dimensiondata.py
----------------------------------------------------------------------
diff --cc libcloud/test/compute/test_dimensiondata.py
index 8841c7a,14be92c..8fbe89c
--- a/libcloud/test/compute/test_dimensiondata.py
+++ b/libcloud/test/compute/test_dimensiondata.py
@@@ -783,5 -818,30 +824,29 @@@ class DimensionDataMockHttp(MockHttp)
'caas_2_0_8a8f6abc_2745_4d8a_9cbc_8dabe5a7d0e4_server_removeNic.xml')
return (httplib.OK, body, {}, httplib.responses[httplib.OK])
+ def
_caas_2_0_8a8f6abc_2745_4d8a_9cbc_8dabe5a7d0e4_server_disableServerMonitoring(self,
method, url, body, headers):
+ request = ET.fromstring(body)
+ if request.tag !=
"{urn:didata.com:api:cloud:types}disableServerMonitoring":
+ raise InvalidRequestError(request.tag)
+ body = self.fixtures.load(
+
'caas_2_0_8a8f6abc_2745_4d8a_9cbc_8dabe5a7d0e4_server_disableServerMonitoring.xml')
+ return (httplib.OK, body, {}, httplib.responses[httplib.OK])
+
+ def
_caas_2_0_8a8f6abc_2745_4d8a_9cbc_8dabe5a7d0e4_server_enableServerMonitoring(self,
method, url, body, headers):
+ request = ET.fromstring(body)
+ if request.tag !=
"{urn:didata.com:api:cloud:types}enableServerMonitoring":
+ raise InvalidRequestError(request.tag)
+ body = self.fixtures.load(
+
'caas_2_0_8a8f6abc_2745_4d8a_9cbc_8dabe5a7d0e4_server_enableServerMonitoring.xml')
+ return (httplib.OK, body, {}, httplib.responses[httplib.OK])
+
+ def
_caas_2_0_8a8f6abc_2745_4d8a_9cbc_8dabe5a7d0e4_server_changeServerMonitoringPlan(self,
method, url, body, headers):
+ request = ET.fromstring(body)
+ if request.tag !=
"{urn:didata.com:api:cloud:types}changeServerMonitoringPlan":
+ raise InvalidRequestError(request.tag)
+ body = self.fixtures.load(
+
'caas_2_0_8a8f6abc_2745_4d8a_9cbc_8dabe5a7d0e4_server_changeServerMonitoringPlan.xml')
+ return (httplib.OK, body, {}, httplib.responses[httplib.OK])
+
-
if __name__ == '__main__':
sys.exit(unittest.main())