2 # Copyright (C) The Arvados Authors. All rights reserved.
4 # SPDX-License-Identifier: AGPL-3.0
6 from __future__ import absolute_import, print_function
10 import libcloud.compute.providers as cloud_provider
11 import libcloud.compute.types as cloud_types
13 from . import BaseComputeNodeDriver
14 from .. import arvados_node_fqdn
16 class ComputeNodeDriver(BaseComputeNodeDriver):
17 """Compute node driver wrapper for libcloud's dummy driver.
19 This class provides the glue necessary to run the node manager with a
20 dummy cloud. It's useful for testing.
22 DEFAULT_DRIVER = cloud_provider.get_driver(cloud_types.Provider.DUMMY)
23 DEFAULT_REAL = DEFAULT_DRIVER('ComputeNodeDriver')
24 DUMMY_START_TIME = time.time()
26 def __init__(self, auth_kwargs, list_kwargs, create_kwargs,
27 driver_class=DEFAULT_DRIVER):
28 super(ComputeNodeDriver, self).__init__(
29 auth_kwargs, list_kwargs, create_kwargs, driver_class)
30 if driver_class is self.DEFAULT_DRIVER:
31 self.real = self.DEFAULT_REAL
33 def _ensure_private_ip(self, node):
34 if not node.private_ips:
35 node.private_ips = ['10.10.0.{}'.format(node.id)]
37 def arvados_create_kwargs(self, size, arvados_node):
41 nodelist = super(ComputeNodeDriver, self).list_nodes()
43 self._ensure_private_ip(node)
44 node.size = self.sizes["1"]
47 def create_node(self, size, arvados_node):
48 node = super(ComputeNodeDriver, self).create_node(size, arvados_node)
49 self._ensure_private_ip(node)
52 def sync_node(self, cloud_node, arvados_node):
53 cloud_node.name = arvados_node_fqdn(arvados_node)
56 def node_fqdn(cls, node):
60 def node_start_time(cls, node):
61 return cls.DUMMY_START_TIME