3 from __future__ import absolute_import, print_function
7 import libcloud.compute.base as cloud_base
8 import libcloud.compute.providers as cloud_provider
9 import libcloud.compute.types as cloud_types
10 from libcloud.common.exceptions import BaseHTTPError
12 from . import BaseComputeNodeDriver
13 from .. import arvados_node_fqdn, arvados_timestamp, ARVADOS_TIMEFMT
15 class ComputeNodeDriver(BaseComputeNodeDriver):
17 DEFAULT_DRIVER = cloud_provider.get_driver(cloud_types.Provider.AZURE_ARM)
19 CLOUD_ERRORS = BaseComputeNodeDriver.CLOUD_ERRORS + (BaseHTTPError,)
21 def __init__(self, auth_kwargs, list_kwargs, create_kwargs,
22 driver_class=DEFAULT_DRIVER):
24 if not list_kwargs.get("ex_resource_group"):
25 raise Exception("Must include ex_resource_group in Cloud List configuration (list_kwargs)")
27 create_kwargs["ex_resource_group"] = list_kwargs["ex_resource_group"]
29 self.tags = {key[4:]: value
30 for key, value in create_kwargs.iteritems()
31 if key.startswith('tag_')}
32 # filter out tags from create_kwargs
33 create_kwargs = {key: value
34 for key, value in create_kwargs.iteritems()
35 if not key.startswith('tag_')}
36 super(ComputeNodeDriver, self).__init__(
37 auth_kwargs, list_kwargs, create_kwargs,
40 def arvados_create_kwargs(self, arvados_node):
41 cluster_id, _, node_id = arvados_node['uuid'].split('-')
42 name = 'compute-{}-{}'.format(node_id, cluster_id)
44 'booted_at': time.strftime(ARVADOS_TIMEFMT, time.gmtime()),
45 'arv-ping-url': self._make_ping_url(arvados_node)
47 tags.update(self.tags)
51 'ex_customdata': tags['arv-ping-url']
54 def sync_node(self, cloud_node, arvados_node):
56 self.real.ex_create_tags(cloud_node,
57 {'hostname': arvados_node_fqdn(arvados_node)})
59 except BaseHTTPError as b:
62 def _init_image(self, urn):
63 return "image", self.get_image(urn)
66 # Azure only supports filtering node lists by resource group.
67 # Do our own filtering based on tag.
68 nodes = [node for node in
69 super(ComputeNodeDriver, self).list_nodes()
70 if node.extra["tags"].get("arvados-class") == self.tags["arvados-class"]]
72 # Need to populate Node.size
74 n.size = self.sizes[n.extra["properties"]["hardwareProfile"]["vmSize"]]
77 def broken(self, cloud_node):
78 """Return true if libcloud has indicated the node is in a "broken" state."""
79 # UNKNOWN means the node state is unrecognized, which in practice means some combination
80 # of failure that the Azure libcloud driver doesn't know how to interpret.
81 return (cloud_node.state in (cloud_types.NodeState.ERROR, cloud_types.NodeState.UNKNOWN))
84 def node_fqdn(cls, node):
85 return node.extra["tags"].get("hostname")
88 def node_start_time(cls, node):
89 return arvados_timestamp(node.extra["tags"].get("booted_at"))