From notifications-return-15768-archive-asf-public=cust-asf.ponee.io@libcloud.apache.org Thu Jul 18 08:57:03 2019 Return-Path: X-Original-To: archive-asf-public@cust-asf.ponee.io Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [207.244.88.153]) by mx-eu-01.ponee.io (Postfix) with SMTP id E5C7218063F for ; Thu, 18 Jul 2019 10:57:02 +0200 (CEST) Received: (qmail 77507 invoked by uid 500); 18 Jul 2019 08:56:59 -0000 Mailing-List: contact notifications-help@libcloud.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@libcloud.apache.org Delivered-To: mailing list notifications@libcloud.apache.org Received: (qmail 77410 invoked by uid 500); 18 Jul 2019 08:56:59 -0000 Delivered-To: apmail-libcloud-commits@libcloud.apache.org Received: (qmail 77375 invoked by uid 99); 18 Jul 2019 08:56:59 -0000 Received: from ec2-52-202-80-70.compute-1.amazonaws.com (HELO gitbox.apache.org) (52.202.80.70) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 18 Jul 2019 08:56:59 +0000 Received: by gitbox.apache.org (ASF Mail Server at gitbox.apache.org, from userid 33) id 7C75085E1D; Thu, 18 Jul 2019 08:56:59 +0000 (UTC) Date: Thu, 18 Jul 2019 08:57:00 +0000 To: "commits@libcloud.apache.org" Subject: [libcloud] 01/03: Merge branch 'digital_ocean_optimizations' of https://github.com/mgogoulos/libcloud into mgogoulos-digital_ocean_optimizations MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit From: tomaz@apache.org In-Reply-To: <156344021924.17865.7503754223834313775@gitbox.apache.org> References: <156344021924.17865.7503754223834313775@gitbox.apache.org> X-Git-Host: gitbox.apache.org X-Git-Repo: libcloud X-Git-Refname: refs/heads/trunk X-Git-Reftype: branch X-Git-Rev: 9bceab6d46009d3488be54207054c85b5f4514d5 X-Git-NotificationType: diff X-Git-Multimail-Version: 1.5.dev Auto-Submitted: auto-generated Message-Id: <20190718085659.7C75085E1D@gitbox.apache.org> 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 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: