libcloud-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From anthonys...@apache.org
Subject [13/18] libcloud git commit: Monitoring functions and tests for servers in both MCP 1 and 2
Date Wed, 18 Nov 2015 07:52:17 GMT
Monitoring functions and tests for servers in both MCP 1 and 2


Project: http://git-wip-us.apache.org/repos/asf/libcloud/repo
Commit: http://git-wip-us.apache.org/repos/asf/libcloud/commit/cd24ef2c
Tree: http://git-wip-us.apache.org/repos/asf/libcloud/tree/cd24ef2c
Diff: http://git-wip-us.apache.org/repos/asf/libcloud/diff/cd24ef2c

Branch: refs/heads/trunk
Commit: cd24ef2c9d8dac1a96291f69b648324c96c94bc1
Parents: 6229e9d
Author: Anthony Shaw <anthony.p.shaw@gmail.com>
Authored: Fri Oct 30 12:28:52 2015 +1100
Committer: Anthony Shaw <anthony.p.shaw@gmail.com>
Committed: Fri Oct 30 12:28:52 2015 +1100

----------------------------------------------------------------------
 libcloud/compute/drivers/dimensiondata.py       | 78 ++++++++++++++++++++
 ...9cbc_8dabe5a7d0e4_report_usageMonitoring.xml |  8 ++
 ...a7d0e4_server_changeServerMonitoringPlan.xml |  8 ++
 ...be5a7d0e4_server_disableServerMonitoring.xml |  8 ++
 ...abe5a7d0e4_server_enableServerMonitoring.xml |  8 ++
 libcloud/test/compute/test_dimensiondata.py     | 39 ++++++++++
 6 files changed, 149 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/libcloud/blob/cd24ef2c/libcloud/compute/drivers/dimensiondata.py
----------------------------------------------------------------------
diff --git a/libcloud/compute/drivers/dimensiondata.py b/libcloud/compute/drivers/dimensiondata.py
index 5a86875..270a7ca 100644
--- a/libcloud/compute/drivers/dimensiondata.py
+++ b/libcloud/compute/drivers/dimensiondata.py
@@ -1001,6 +1001,14 @@ class DimensionDataNodeDriver(NodeDriver):
         return self._to_nat_rule(rule, network_domain)
 
     def ex_delete_nat_rule(self, rule):
+        """
+        Delete an existing NAT rule
+
+        :param  rule: The rule to delete
+        :type   rule: :class:`DimensionDataNatRule`
+
+        :rtype: ``bool``
+        """
         update_node = ET.Element('deleteNatRule', {'xmlns': TYPES_URN})
         update_node.set('id', rule.id)
         result = self.connection.request_with_orgId_api_2(
@@ -1026,6 +1034,76 @@ class DimensionDataNodeDriver(NodeDriver):
                 filter(lambda x: x.id == id, self.list_locations()))[0]
         return location
 
+    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/cd24ef2c/libcloud/test/compute/fixtures/dimensiondata/caas_2_0_8a8f6abc_2745_4d8a_9cbc_8dabe5a7d0e4_report_usageMonitoring.xml
----------------------------------------------------------------------
diff --git a/libcloud/test/compute/fixtures/dimensiondata/caas_2_0_8a8f6abc_2745_4d8a_9cbc_8dabe5a7d0e4_report_usageMonitoring.xml
b/libcloud/test/compute/fixtures/dimensiondata/caas_2_0_8a8f6abc_2745_4d8a_9cbc_8dabe5a7d0e4_report_usageMonitoring.xml
new file mode 100644
index 0000000..dc32d95
--- /dev/null
+++ b/libcloud/test/compute/fixtures/dimensiondata/caas_2_0_8a8f6abc_2745_4d8a_9cbc_8dabe5a7d0e4_report_usageMonitoring.xml
@@ -0,0 +1,8 @@
+Date,Location,Server,Server ID,Essentials Monitoring Hours,Advanced Monitoring
+Hours
+2/24/15,NA5,Server A,5a2378ba-11de-11e5-ad2a-ca9798323470,14.25,0
+2/24/15,NA5,Server B,6330a644-11de-11e5-ad2a-ca9798323470,0,8.64
+2/25/15,NA5,Server A,5a2378ba-11de-11e5-ad2a-ca9798323470,24,0
+2/25/15,NA5,Server B,6330a644-11de-11e5-ad2a-ca9798323470,0,24
+2/26/15,NA5,Server A,5a2378ba-11de-11e5-ad2a-ca9798323470,17.59,6.41
+2/26/15,NA5,Server B,6330a644-11de-11e5-ad2a-ca9798323470,2.11,21.89
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/libcloud/blob/cd24ef2c/libcloud/test/compute/fixtures/dimensiondata/caas_2_0_8a8f6abc_2745_4d8a_9cbc_8dabe5a7d0e4_server_changeServerMonitoringPlan.xml
----------------------------------------------------------------------
diff --git a/libcloud/test/compute/fixtures/dimensiondata/caas_2_0_8a8f6abc_2745_4d8a_9cbc_8dabe5a7d0e4_server_changeServerMonitoringPlan.xml
b/libcloud/test/compute/fixtures/dimensiondata/caas_2_0_8a8f6abc_2745_4d8a_9cbc_8dabe5a7d0e4_server_changeServerMonitoringPlan.xml
new file mode 100644
index 0000000..654097d
--- /dev/null
+++ b/libcloud/test/compute/fixtures/dimensiondata/caas_2_0_8a8f6abc_2745_4d8a_9cbc_8dabe5a7d0e4_server_changeServerMonitoringPlan.xml
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<response
+xmlns="urn:didata.com:api:cloud:types" requestId="NA9/2015-08-10T09:22:40.684-04:00/c0ca4a5d-3611-417e-8209-fd3046cff1d5">
+<operation>CHANGE_SERVER_MONITORING_PLAN</operation>
+<responseCode>OK</responseCode>
+<message>Monitoring on Server 'Production Server' has been changed to
+Service Plan 'ADVANCED'.</message>
+</response>
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/libcloud/blob/cd24ef2c/libcloud/test/compute/fixtures/dimensiondata/caas_2_0_8a8f6abc_2745_4d8a_9cbc_8dabe5a7d0e4_server_disableServerMonitoring.xml
----------------------------------------------------------------------
diff --git a/libcloud/test/compute/fixtures/dimensiondata/caas_2_0_8a8f6abc_2745_4d8a_9cbc_8dabe5a7d0e4_server_disableServerMonitoring.xml
b/libcloud/test/compute/fixtures/dimensiondata/caas_2_0_8a8f6abc_2745_4d8a_9cbc_8dabe5a7d0e4_server_disableServerMonitoring.xml
new file mode 100644
index 0000000..63609de
--- /dev/null
+++ b/libcloud/test/compute/fixtures/dimensiondata/caas_2_0_8a8f6abc_2745_4d8a_9cbc_8dabe5a7d0e4_server_disableServerMonitoring.xml
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<response
+xmlns="urn:didata.com:api:cloud:types" requestId="NA9/2015-06-10T09:19:48.692-04:00/929c91ac-5377-4dcf-aac6-a89610971139">
+<operation>DISABLE_SERVER_MONITORING</operation>
+<responseCode>OK</responseCode>
+<message>Monitoring on Server 5783e93f-5370-44fc-a772-cd3c29a2ecaa has
+been disabled.</message>
+</response>
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/libcloud/blob/cd24ef2c/libcloud/test/compute/fixtures/dimensiondata/caas_2_0_8a8f6abc_2745_4d8a_9cbc_8dabe5a7d0e4_server_enableServerMonitoring.xml
----------------------------------------------------------------------
diff --git a/libcloud/test/compute/fixtures/dimensiondata/caas_2_0_8a8f6abc_2745_4d8a_9cbc_8dabe5a7d0e4_server_enableServerMonitoring.xml
b/libcloud/test/compute/fixtures/dimensiondata/caas_2_0_8a8f6abc_2745_4d8a_9cbc_8dabe5a7d0e4_server_enableServerMonitoring.xml
new file mode 100644
index 0000000..9b1b555
--- /dev/null
+++ b/libcloud/test/compute/fixtures/dimensiondata/caas_2_0_8a8f6abc_2745_4d8a_9cbc_8dabe5a7d0e4_server_enableServerMonitoring.xml
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<response
+xmlns="urn:didata.com:api:cloud:types" requestId="NA9/2015-06-10T09:22:40.684-04:00/c0ca4a5d-3611-417e-8209-fd3046cff1d5">
+<operation>ENABLE_SERVER_MONITORING</operation>
+<responseCode>OK</responseCode>
+<message>Monitoring on Server 'Production Server' has been
+enabled.</message>
+</response>
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/libcloud/blob/cd24ef2c/libcloud/test/compute/test_dimensiondata.py
----------------------------------------------------------------------
diff --git a/libcloud/test/compute/test_dimensiondata.py b/libcloud/test/compute/test_dimensiondata.py
index d779900..14be92c 100644
--- a/libcloud/test/compute/test_dimensiondata.py
+++ b/libcloud/test/compute/test_dimensiondata.py
@@ -396,6 +396,21 @@ class DimensionDataTests(unittest.TestCase, TestCaseMixin):
         result = self.driver.ex_delete_nat_rule(rule)
         self.assertTrue(result)
 
+    def test_ex_enable_monitoring(self):
+        node = self.driver.list_nodes()[0]
+        result = self.driver.ex_enable_monitoring(node, "ADVANCED")
+        self.assertTrue(result)
+
+    def test_ex_disable_monitoring(self):
+        node = self.driver.list_nodes()[0]
+        result = self.driver.ex_disable_monitoring(node)
+        self.assertTrue(result)
+
+    def test_ex_change_monitoring_plan(self):
+        node = self.driver.list_nodes()[0]
+        result = self.driver.ex_update_monitoring_plan(node, "ESSENTIALS")
+        self.assertTrue(result)
+
 
 class InvalidRequestError(Exception):
     def __init__(self, tag):
@@ -803,6 +818,30 @@ 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())


Mime
View raw message