You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@libcloud.apache.org by GitBox <gi...@apache.org> on 2019/07/15 07:49:05 UTC

[GitHub] [libcloud] PrinceSydney commented on a change in pull request #1305: adding gridscale driver to libcloud

PrinceSydney commented on a change in pull request #1305: adding gridscale driver to libcloud
URL: https://github.com/apache/libcloud/pull/1305#discussion_r303316790
 
 

 ##########
 File path: libcloud/compute/drivers/gridscale.py
 ##########
 @@ -0,0 +1,977 @@
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+import json
+import time
+
+from libcloud.common.gridscale import GridscaleBaseDriver
+from libcloud.common.gridscale import GridscaleConnection
+from libcloud.compute.base import NodeImage, NodeLocation, VolumeSnapshot, \
+    Node, StorageVolume, KeyPair, NodeState, StorageVolumeState, NodeAuthSSHKey
+from libcloud.compute.providers import Provider
+from libcloud.utils.iso8601 import parse_date
+
+
+class GridscaleIp(object):
+    """
+    Ip Object
+
+    :param id: uuid
+    :type id: ``str``
+    :param family: family of ip (v4 or v6)
+    :type family: ``str``
+    :param prefix: prefix of ip
+    :type prefix: ``str``
+    :param ip_address: Ip address
+    :type ip_address: ``str``
+    :param create_time: Time ip was created
+    :type create_time: ``str``
+    """
+
+    def __init__(self, id, family, prefix, create_time, address):
+        self.id = id
+        self.family = family
+        self.prefix = prefix
+        self.create_time = create_time
+        self.ip_address = address
+
+    def __repr__(self):
+        return ('Ip: id={}, family={}, prefix={}, create_time={},Ip_address={}'
+                .format(self.id, self.family,
+                        self.prefix,
+                        self.create_time,
+                        self.ip_address))
+
+
+class GridscaleNetwork(object):
+    """
+    Network Object
+
+    :param id: uuid
+    :type id: ``str``
+    :param name: Name of Network
+    :type name: ``str``
+    :param status: Network status
+    :type status: ``str``
+    :param relations: object related to network
+    :type relations: ``object``
+    :param create_time: Time Network was created
+    :type create_time: ``str``
+    """
+
+    def __init__(self, id, name, status, create_time, relations):
+        self.id = id
+        self.name = name
+        self.status = status
+        self.create_time = create_time
+        self.relations = relations
+
+    def __repr__(self):
+        return ('Network: id={}, name={}, status={}, create_time={}, '
+                'relations={}'.format(self.id, self.name, self.status,
+                                      self.create_time, self.relations))
+
+
+class GridscaleNodeDriver(GridscaleBaseDriver):
+    """
+    create and entry in libcloud/compute/providers for gridscale
+    """
+    connectionCls = GridscaleConnection
+    type = Provider.GRIDSCALE
+    name = 'gridscale'
+    website = 'https://gridscale.io'
+
+    def __init__(self, user_id, key, **kwargs):
+        super(GridscaleNodeDriver, self).__init__(user_id, key, **kwargs)
+
+    def list_nodes(self):
+        """
+        List all nodes.
+
+        :return: List of node objects
+        :rtype: ``list`` of :class:`.Node`
+        """
+        result = self._sync_request(data=None, endpoint='objects/servers/')
+        nodes = []
+        for key, value in self._get_response_dict(result).items():
+            node = self._to_node(value)
+            nodes.append(node)
+            continue
+
+        return sorted(nodes, key=lambda sort: sort.created_at)
+
+    def list_locations(self):
+        """
+        List all available data centers.
+
+        :return: List of node location objects
+        :rtype: ``list`` of :class:`.NodeLocation`
+        """
+        locations = []
+        result = self._sync_request(endpoint='objects/locations/')
+        for key, value in self._get_response_dict(result).items():
+            location = self._to_location(value)
+            locations.append(location)
+            continue
+        return sorted(locations, key=lambda nod: nod.id)
+
+    def list_volumes(self):
+        """
+        List all volumes.
+
+        :return: List of StorageVolume object
+        :rtype: ``list`` of :class:`.StorageVolume`
+        """
+        volumes = []
+        result = self._sync_request(endpoint='objects/storages/')
+        for key, value in self._get_response_dict(result).items():
+            volume = self._to_volume(value)
+            volumes.append(volume)
+        return sorted(volumes, key=lambda sort: sort.extra['create_time'])
+
+    def ex_list_networks(self):
+        """
+        List all networks.
+
+        :return: List of objects.
+        :rtype: ``list`` of :class:`.GridscaleNetwork`
+        """
+        networks = []
+        result = self._sync_request(endpoint='objects/networks/')
+        for key, value in self._get_response_dict(result).items():
+            network = self._to_network(value)
+            networks.append(network)
+        return sorted(networks, key=lambda sort: sort.create_time)
+
+    def list_volume_snapshots(self, volume):
+        """
+        Lists all snapshots for storage volume.
+
+        :param volume: storage the snapshot is attached to
+        :type volume: :class:`.StorageVolume`
+
+        :return: Snapshots
+        :rtype: ``list`` of :class:`.VolumeSnapshot`
+        """
+        snapshots = []
+        result = self._sync_request(
+            endpoint='objects/storages/'
+                     '{}/snapshots'.format(volume.id))
+        for key, value in self._get_response_dict(result).items():
+            snapshot = self._to_volume_snapshot(value)
+            snapshots.append(snapshot)
+        return sorted(snapshots, key=lambda snapshot: snapshot.created)
+
+    def ex_list_ips(self):
+        """
+        Lists all IPs available.
+
+        :return: List of IP objects.
+        :rtype: ``list`` of :class:`.GridscaleIp`
+        """
+        ips = []
+        result = self._sync_request(endpoint='objects/ips/')
+        for key, value in self._get_response_dict(result).items():
+            ip = self._to_ip(value)
+            ips.append(ip)
+        return ips
+
+    def list_images(self):
+        """
+        List images.
+
+        :return: List of node image objects
+        :rtype: ``list`` of :class:`.NodeImage`
+        """
+        templates = []
+        result = self._sync_request(endpoint='objects/templates')
+        for key, value in self._get_response_dict(result).items():
+            template = self._to_node_image(value)
+            templates.append(template)
+        return sorted(templates, key=lambda sort: sort.name)
+
+    def create_node(self, name, size, image, location, auth):
+        """
+        Create a simple node  with a name, cores, memory at the designated
+        location.
+
+        :param name: Name of the server.
+        :type name: ``str``
+
+        :param size: Nodesize object.
+        :type size: :class:`.NodeSize`
+
+        :param image: OS image to attach to the storage.
+        :type image: :class:`.GridscaleTemplate`
+
+        :param location: The data center to create a node in.
+        :type location: :class:`.NodeLocation`
+
+        :param auth: sshkey uuid.
+        :type auth: :class:`.NodeAuthSSHKey`
 
 Review comment:
   The ssh key UUID is required to be able to attach an image to a node, while in the process of creating this node.

----------------------------------------------------------------
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