libcloud-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From to...@apache.org
Subject [38/44] git commit: Add support for reading/setting node scheduling options.
Date Fri, 03 Jan 2014 14:59:50 GMT
Add support for reading/setting node scheduling options.


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

Branch: refs/heads/trunk
Commit: 02fa6887ca46b377e469da68e70daabe4cf032e1
Parents: 98636e3
Author: Rick Wright <rickw@google.com>
Authored: Tue Dec 17 10:54:13 2013 -0800
Committer: Rick Wright <rickw@google.com>
Committed: Thu Jan 2 23:30:03 2014 -0800

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


http://git-wip-us.apache.org/repos/asf/libcloud/blob/02fa6887/libcloud/compute/drivers/gce.py
----------------------------------------------------------------------
diff --git a/libcloud/compute/drivers/gce.py b/libcloud/compute/drivers/gce.py
index 0f5e13b..8e59d3f 100644
--- a/libcloud/compute/drivers/gce.py
+++ b/libcloud/compute/drivers/gce.py
@@ -1978,6 +1978,70 @@ class GCENodeDriver(NodeDriver):
         node.extra['tags_fingerprint'] = new_node.extra['tags_fingerprint']
         return True
 
+    def ex_set_node_scheduling(self, node, on_host_maintenance=None,
+                               automatic_restart=None):
+        """Set the maintenance behavior for the node.
+
+        See Scheduling_ documentation for more info.
+        _Scheduling:
+        https://developers.google.com/compute/docs/instances#onhostmaintenance
+
+        :param  node: Node object
+        :type   node: :class:`Node`
+
+        :keyword  on_host_maintenance: Defines whether node should be
+                                       terminated or migrated when host machine
+                                       goes down. Acceptable values are:
+                                       'MIGRATE' or 'TERMINATE' (If not
+                                       supplied, value will be reset to GCE
+                                       default value for the instance type.)
+        :type     on_host_maintenance: ``str``
+
+        :keyword  automatic_restart: Defines whether the instance should be
+                                     automatically restarted when it is
+                                     terminated by Compute Engine. (If not
+                                     supplied, value will be set to the GCE
+                                     default value for the instance type.)
+        :type     automatic_restart: ``bool``
+
+        :return:  True if successful.
+        :rtype:   ``bool``
+        """
+        if not hasattr(node, 'name'):
+            node = self.ex_get_node(node, 'all')
+        if on_host_maintenance is not None:
+            on_host_maintenance = on_host_maintenance.upper()
+            ohm_values = ['MIGRATE', 'TERMINATE']
+            if on_host_maintenance not in ohm_values:
+                raise ValueError('on_host_maintenence must be one of %s' %
+                                 ','.join(ohm_values))
+
+        request = '/zones/%s/instances/%s/setScheduling' % (
+            node.extra['zone'].name, node.name)
+
+        scheduling_data = {}
+        if on_host_maintenance is not None:
+            scheduling_data['onHostMaintenance'] = on_host_maintenance
+        if automatic_restart is not None:
+            scheduling_data['automaticRestart'] = automatic_restart
+
+        self.connection.async_request(request, method='POST',
+                                      data=scheduling_data)
+
+        new_node = self.ex_get_node(node.name, node.extra['zone'])
+        node.extra['scheduling'] = new_node.extra['scheduling']
+
+        ohm = node.extra['scheduling'].get('onHostMaintenance')
+        ar = node.extra['scheduling'].get('automaticRestart')
+
+        success = True
+        if on_host_maintenance not in [None, ohm]:
+            success = False
+        if automatic_restart not in [None, ar]:
+            success = False
+
+        return success
+
     def deploy_node(self, name, size, image, script, location=None,
                     ex_network='default', ex_tags=None):
         """
@@ -2771,8 +2835,9 @@ class GCENodeDriver(NodeDriver):
         extra['id'] = node['id']
         extra['selfLink'] = node.get('selfLink')
         extra['name'] = node['name']
-        extra['metadata'] = node.get('metadata')
+        extra['metadata'] = node.get('metadata', {})
         extra['tags_fingerprint'] = node['tags']['fingerprint']
+        extra['scheduling'] = node.get('scheduling', {})
 
         extra['boot_disk'] = None
         for disk in extra['disks']:


Mime
View raw message