You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@libcloud.apache.org by an...@apache.org on 2017/04/01 00:38:31 UTC

[3/5] libcloud git commit: Gcloud: allow delete instances from managed group

Gcloud: allow delete instances from managed group


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

Branch: refs/heads/trunk
Commit: 3e25c2c786222fc5a10b4a48178f22cf9d53e41a
Parents: 516018d
Author: zacharya19 <za...@gmail.com>
Authored: Thu Jan 12 20:58:16 2017 +0200
Committer: Anthony Shaw <an...@apache.org>
Committed: Sat Apr 1 11:36:28 2017 +1100

----------------------------------------------------------------------
 libcloud/compute/drivers/gce.py | 50 ++++++++++++++++++++++++++++++++++++
 1 file changed, 50 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/libcloud/blob/3e25c2c7/libcloud/compute/drivers/gce.py
----------------------------------------------------------------------
diff --git a/libcloud/compute/drivers/gce.py b/libcloud/compute/drivers/gce.py
index 5eccac5..404a6d7 100644
--- a/libcloud/compute/drivers/gce.py
+++ b/libcloud/compute/drivers/gce.py
@@ -1371,6 +1371,25 @@ class GCEInstanceGroupManager(UuidMixin):
         return self.driver.ex_instancegroupmanager_recreate_instances(
             manager=self)
 
+    def delete_instances(self, node_list):
+        """
+        Removes one or more instances from the specified instance group,
+        and delete those instances.
+
+        Scopes needed - one of the following:
+        * https://www.googleapis.com/auth/cloud-platform
+        * https://www.googleapis.com/auth/compute
+
+        :param  node_list: List of nodes to delete.
+        :type   node_list: ``list`` of :class:`Node` or ``list`` of
+                           :class:`GCENode`
+
+        :return:  Return True if successful.
+        :rtype: ``bool``
+        """
+        return self.driver.ex_instancegroupmanager_delete_instances(
+            manager=self, node_list=node_list)
+
     def resize(self, size):
         """
         Set the number of instances for this Instance Group.  An increase in
@@ -5731,6 +5750,37 @@ class GCENodeDriver(NodeDriver):
 
         return self.ex_instancegroupmanager_list_managed_instances(manager)
 
+    def ex_instancegroupmanager_delete_instances(self, manager,
+                                                   node_list):
+        """
+        Remove instances from GCEInstanceGroupManager and destry
+        the instance
+
+        Scopes needed - one of the following:
+        * https://www.googleapis.com/auth/cloud-platform
+        * https://www.googleapis.com/auth/compute
+
+        :param  manager:  Required. The name of the managed instance group. The
+                       name must be 1-63 characters long, and comply with
+                       RFC1035.
+        :type   manager: ``str`` or :class: `GCEInstanceGroupManager`
+
+        :keyword  node_list:  list of Node objects to delete.
+        :type   :type   node_list: ``list`` of :class:`Node`
+
+        :return:  True if successful
+        :rtype: ``bool``
+        """
+
+        request = "/zones/%s/instanceGroupManagers/%s/deleteInstances" % (
+            manager.zone.name, manager.name)
+        request_data = {'instances': [x.extra['selfLink']
+                                      for x in node_list]}
+        self.connection.request(request, method='POST',
+                                data=request_data).object
+
+        return True
+
     def ex_instancegroupmanager_resize(self, manager, size):
         """
         Set the Instance Template for this Instance Group.