You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@libcloud.apache.org by to...@apache.org on 2014/01/03 15:59:26 UTC

[14/44] git commit: Add support for reading/setting node scheduling options.

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/40a18cb9
Tree: http://git-wip-us.apache.org/repos/asf/libcloud/tree/40a18cb9
Diff: http://git-wip-us.apache.org/repos/asf/libcloud/diff/40a18cb9

Branch: refs/heads/trunk
Commit: 40a18cb9f3fc0b1fb5a2e6b765fb5521efa22b6a
Parents: 0b9b7de
Author: Rick Wright <ri...@google.com>
Authored: Tue Dec 17 10:54:13 2013 -0800
Committer: Rick Wright <ri...@google.com>
Committed: Tue Dec 17 10:54:13 2013 -0800

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


http://git-wip-us.apache.org/repos/asf/libcloud/blob/40a18cb9/libcloud/compute/drivers/gce.py
----------------------------------------------------------------------
diff --git a/libcloud/compute/drivers/gce.py b/libcloud/compute/drivers/gce.py
index ca157f6..df865b4 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']: