Merge branch 'master' into 6702-gce-node-create-fix
[arvados.git] / services / nodemanager / arvnodeman / computenode / driver / azure.py
index 2d189788a51b3d13e02e3fbdf67e4f43ff56f3cb..fbae522499651653158463d1e8debc0c34294600 100644 (file)
@@ -2,6 +2,7 @@
 
 from __future__ import absolute_import, print_function
 
+import pipes
 import time
 
 import libcloud.compute.base as cloud_base
@@ -37,7 +38,7 @@ class ComputeNodeDriver(BaseComputeNodeDriver):
             auth_kwargs, list_kwargs, create_kwargs,
             driver_class)
 
-    def arvados_create_kwargs(self, arvados_node):
+    def arvados_create_kwargs(self, size, arvados_node):
         cluster_id, _, node_id = arvados_node['uuid'].split('-')
         name = 'compute-{}-{}'.format(node_id, cluster_id)
         tags = {
@@ -45,10 +46,20 @@ class ComputeNodeDriver(BaseComputeNodeDriver):
             'arv-ping-url': self._make_ping_url(arvados_node)
         }
         tags.update(self.tags)
+
+        customdata = """#!/bin/sh
+mkdir -p    /var/tmp/arv-node-data/meta-data
+echo %s > /var/tmp/arv-node-data/arv-ping-url
+echo %s > /var/tmp/arv-node-data/meta-data/instance-id
+echo %s > /var/tmp/arv-node-data/meta-data/instance-type
+""" % (pipes.quote(tags['arv-ping-url']),
+       pipes.quote(name),
+       pipes.quote(size.id))
+
         return {
             'name': name,
             'ex_tags': tags,
-            'ex_customdata': tags['arv-ping-url']
+            'ex_customdata': customdata
         }
 
     def sync_node(self, cloud_node, arvados_node):
@@ -65,12 +76,19 @@ class ComputeNodeDriver(BaseComputeNodeDriver):
     def list_nodes(self):
         # Azure only supports filtering node lists by resource group.
         # Do our own filtering based on tag.
-        return [node for node in
+        nodes = [node for node in
                 super(ComputeNodeDriver, self).list_nodes()
                 if node.extra["tags"].get("arvados-class") == self.tags["arvados-class"]]
+        for n in nodes:
+            # Need to populate Node.size
+            if not n.size:
+                n.size = self.sizes[n.extra["properties"]["hardwareProfile"]["vmSize"]]
+        return nodes
 
     def broken(self, cloud_node):
         """Return true if libcloud has indicated the node is in a "broken" state."""
+        # UNKNOWN means the node state is unrecognized, which in practice means some combination
+        # of failure that the Azure libcloud driver doesn't know how to interpret.
         return (cloud_node.state in (cloud_types.NodeState.ERROR, cloud_types.NodeState.UNKNOWN))
 
     @classmethod