libcloud-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From GitBox <...@apache.org>
Subject [GitHub] [libcloud] Kami commented on a change in pull request #1298: Maxihost provider
Date Fri, 28 Jun 2019 17:03:22 GMT
Kami commented on a change in pull request #1298: Maxihost provider
URL: https://github.com/apache/libcloud/pull/1298#discussion_r298675534
 
 

 ##########
 File path: libcloud/compute/drivers/maxihost.py
 ##########
 @@ -0,0 +1,218 @@
+import json
+import re
+
+from libcloud.compute.base import Node, NodeDriver, NodeLocation
+from libcloud.compute.base import NodeSize, NodeImage
+from libcloud.compute.base import KeyPair
+from libcloud.common.maxihost import MaxihostConnection
+from libcloud.compute.types import Provider, NodeState
+from libcloud.common.exceptions import BaseHTTPError
+from libcloud.utils.py3 import httplib
+
+
+__all__ = [
+    "MaxihostNodeDriver"
+]
+
+
+class MaxihostNodeDriver(NodeDriver):
+    """
+    Base Maxihost node driver.
+    """
+
+    connectionCls = MaxihostConnection
+    type = Provider.MAXIHOST
+    name = 'Maxihost'
+    website = 'https://www.maxihost.com/'
+
+    def create_node(self, name, size, image, location,
+                    ex_ssh_key_ids=None):
+        """
+        Create a node.
+
+        :return: The newly created node.
+        :rtype: :class:`Node`
+        """
+        attr = {'hostname': name, 'plan': size.id,
+                'operating_system': image.id,
+                'facility': location.id.lower(), 'billing_cycle': 'monthly',
+                'ex_ssh_key_ids': ex_ssh_key_ids}
+        try:
+            res = self.connection.request('/devices',
+                                          params=attr, method='POST')
+        except BaseHTTPError as exc:
+            error_message = exc.message.get('error_messages', '')
+            raise ValueError('Failed to create node: %s' % (error_message))
+
+        return self._to_node(res.object['devices'][0])
+
+    def ex_start_node(self, node):
+        """
+        Start a node.
+        """
+        params = {"type": "power_on"}
+        res = self.connection.request('/devices/%s/actions' % node.id,
+                                      params=params, method='PUT')
+
+        return res.status in [httplib.OK, httplib.CREATED, httplib.ACCEPTED]
+
+    def ex_stop_node(self, node):
+        """
+        Stop a node.
+        """
+        params = {"type": "power_off"}
+        res = self.connection.request('/devices/%s/actions' % node.id,
+                                      params=params, method='PUT')
+
+        return res.status in [httplib.OK, httplib.CREATED, httplib.ACCEPTED]
+
+    def destroy_node(self, node):
+        """
+        Destroy a node.
+        """
+        res = self.connection.request('/devices/%s' % node.id,
+                                      method='DELETE')
+
+        return res.status in [httplib.OK, httplib.CREATED, httplib.ACCEPTED]
+
+    def reboot_node(self, node):
+        """
+        Reboot a node.
+        """
+        params = {"type": "power_cycle"}
+        res = self.connection.request('/devices/%s/actions' % node.id,
+                                      params=params, method='PUT')
+
+        return res.status in [httplib.OK, httplib.CREATED, httplib.ACCEPTED]
+
+    def list_nodes(self):
+        """
+        List nodes
+
+        :rtype: ``list`` of :class:`MaxihostNode`
+        """
+        response = self.connection.request('/devices')
+        nodes = [self._to_node(host)
+                 for host in response.object['devices']]
+        return nodes
+
+    def _to_node(self, data):
+        extra = {}
+        private_ips = []
+        public_ips = []
+        for ip in data['ips']:
+            if 'Private' in ip['ip_description']:
+                private_ips.append(ip['ip_address'])
+            else:
+                public_ips.append(ip['ip_address'])
+
+        if data['power_status']:
+            state = NodeState.RUNNING
+        else:
+            state = NodeState.STOPPED
+
+        for key in data:
+            extra[key] = data[key]
+
+        node = Node(id=data['id'], name=data['description'], state=state,
+                    private_ips=private_ips, public_ips=public_ips,
+                    driver=self, extra=extra)
+        return node
+
+    def list_locations(self, available=True):
 
 Review comment:
   ``available`` -> ``ex_available``.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

Mime
View raw message