libcloud-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From to...@apache.org
Subject [libcloud] 01/03: Merge branch 'digital_ocean_optimizations' of https://github.com/mgogoulos/libcloud into mgogoulos-digital_ocean_optimizations
Date Thu, 18 Jul 2019 08:57:00 GMT
This is an automated email from the ASF dual-hosted git repository.

tomaz pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/libcloud.git

commit 9bceab6d46009d3488be54207054c85b5f4514d5
Merge: 593ab3a 541caa8
Author: Tomaz Muraus <tomaz@tomaz.me>
AuthorDate: Thu Jul 18 10:41:21 2019 +0200

    Merge branch 'digital_ocean_optimizations' of https://github.com/mgogoulos/libcloud into
mgogoulos-digital_ocean_optimizations

 libcloud/compute/base.py                 |  4 ++++
 libcloud/compute/drivers/digitalocean.py | 32 ++++++++++++++++++++++++++------
 2 files changed, 30 insertions(+), 6 deletions(-)

diff --cc libcloud/compute/drivers/digitalocean.py
index 631f8d9,603f4b5..441c24c
--- a/libcloud/compute/drivers/digitalocean.py
+++ b/libcloud/compute/drivers/digitalocean.py
@@@ -495,129 -471,21 +513,129 @@@ class DigitalOcean_v2_NodeDriver(Digita
                                        method='DELETE')
          return res.status == httplib.NO_CONTENT
  
 -    def ex_resize_node(self, node, size):
 -        """Resizes a Droplet from one plan to another
 +    def ex_get_node_details(self, node_id):
 +        """
 +        Lists details of the specified server.
  
 -        Droplet needs to be down
 +        :param       node_id: ID of the node which should be used
 +        :type        node_id: ``str``
  
 +        :rtype: :class:`Node`
          """
 -        params = {"type": "resize", "size": size}
 -        res = self.connection.request('/v2/droplets/%s/actions/' % node.id,
 -                                      params=params, method='POST')
 -        return res.status in [httplib.OK, httplib.CREATED, httplib.ACCEPTED]
 +        data = self._paginated_request(
 +            '/v2/droplets/{}'.format(node_id), 'droplet'
 +        )
 +        return self._to_node(data)
 +
 +    def ex_create_floating_ip(self, location):
 +        """
 +        Create new floating IP reserved to a region.
 +
 +        The newly created floating IP will not be associated to a Droplet.
 +
 +        See https://developers.digitalocean.com/documentation/v2/#floating-ips
 +
 +        :param location: Which data center to create the floating IP in.
 +        :type location: :class:`.NodeLocation`
 +
 +        :rtype: :class:`DigitalOcean_v2_FloatingIpAddress`
 +        """
 +        attr = {'region': location.id}
 +        resp = self.connection.request('/v2/floating_ips',
 +                                       data=json.dumps(attr), method='POST')
 +        return self._to_floating_ip(resp.object['floating_ip'])
 +
 +    def ex_delete_floating_ip(self, ip):
 +        """
 +        Delete specified floating IP
 +
 +        :param      ip: floating IP to remove
 +        :type       ip: :class:`DigitalOcean_v2_FloatingIpAddress`
 +
 +        :rtype: ``bool``
 +        """
 +        resp = self.connection.request('/v2/floating_ips/{}'.format(ip.id),
 +                                       method='DELETE')
 +        return resp.status == httplib.NO_CONTENT
 +
 +    def ex_list_floating_ips(self):
 +        """
 +        List floating IPs
 +
 +        :rtype: ``list`` of :class:`DigitalOcean_v2_FloatingIpAddress`
 +        """
 +        return self._to_floating_ips(
 +            self._paginated_request('/v2/floating_ips', 'floating_ips')
 +        )
 +
 +    def ex_get_floating_ip(self, ip):
 +        """
 +        Get specified floating IP
 +
 +        :param      ip: floating IP to get
 +        :type       ip: ``str``
 +
 +        :rtype: :class:`DigitalOcean_v2_FloatingIpAddress`
 +        """
 +        floating_ips = self.ex_list_floating_ips()
 +        matching_ips = [x for x in floating_ips if x.ip_address == ip]
 +        if not matching_ips:
 +            raise ValueError('Floating ip %s not found' % ip)
 +        return matching_ips[0]
 +
 +    def ex_attach_floating_ip_to_node(self, node, ip):
 +        """
 +        Attach the floating IP to the node
 +
 +        :param      node: node
 +        :type       node: :class:`Node`
 +
 +        :param      ip: floating IP to attach
 +        :type       ip: ``str`` or :class:`DigitalOcean_v2_FloatingIpAddress`
 +
 +        :rtype: ``bool``
 +        """
 +        data = {
 +            'type': 'assign',
 +            'droplet_id': node.id
 +        }
 +        resp = self.connection.request(
 +            '/v2/floating_ips/%s/actions' % ip.ip_address,
 +            data=json.dumps(data), method='POST'
 +        )
 +        return resp.status == httplib.CREATED
 +
 +    def ex_detach_floating_ip_from_node(self, node, ip):
 +        """
 +        Detach a floating IP from the given node
 +
 +        Note: the 'node' object is not used in this method but it is added
 +        to the signature of ex_detach_floating_ip_from_node anyway so it
 +        conforms to the interface of the method of the same name for other
 +        drivers like for example OpenStack.
 +
 +        :param      node: Node from which the IP should be detached
 +        :type       node: :class:`Node`
 +
 +        :param      ip: Floating IP to detach
 +        :type       ip: :class:`DigitalOcean_v2_FloatingIpAddress`
 +
 +        :rtype: ``bool``
 +        """
 +        data = {
 +            'type': 'unassign'
 +        }
 +        resp = self.connection.request(
 +            '/v2/floating_ips/%s/actions' % ip.ip_address,
 +            data=json.dumps(data), method='POST'
 +        )
 +        return resp.status == httplib.CREATED
  
      def _to_node(self, data):
-         extra_keys = ['memory', 'vcpus', 'disk', 'region', 'image',
+         extra_keys = ['memory', 'vcpus', 'disk', 'image', 'size',
                        'size_slug', 'locked', 'created_at', 'networks',
 -                      'kernel', 'backup_ids', 'snapshot_ids', 'features']
 +                      'kernel', 'backup_ids', 'snapshot_ids', 'features',
 +                      'tags']
          if 'status' in data:
              state = self.NODE_STATE_MAP.get(data['status'], NodeState.UNKNOWN)
          else:


Mime
View raw message