3 from __future__ import absolute_import, print_function
13 from apiclient import errors as apierror
15 from .baseactor import BaseNodeManagerActor
17 # IOError is the base class for socket.error, ssl.SSLError, and friends.
18 # It seems like it hits the sweet spot for operations we want to retry:
19 # it's low-level, but unlikely to catch code bugs.
20 NETWORK_ERRORS = (IOError,)
21 ARVADOS_ERRORS = NETWORK_ERRORS + (apierror.Error,)
23 actor_class = BaseNodeManagerActor
25 class NodeManagerConfig(ConfigParser.SafeConfigParser):
26 """Node Manager Configuration class.
28 This a standard Python ConfigParser, with additional helper methods to
29 create objects instantiated with configuration information.
32 LOGGING_NONLEVELS = frozenset(['file'])
34 def __init__(self, *args, **kwargs):
35 # Can't use super() because SafeConfigParser is an old-style class.
36 ConfigParser.SafeConfigParser.__init__(self, *args, **kwargs)
37 for sec_name, settings in {
38 'Arvados': {'insecure': 'no',
40 'Daemon': {'min_nodes': '0',
43 'max_poll_time': '300',
44 'poll_stale_after': '600',
45 'max_total_price': '0',
46 'boot_fail_after': str(sys.maxint),
47 'node_stale_after': str(60 * 60 * 2),
49 'Logging': {'file': '/dev/stderr',
52 if not self.has_section(sec_name):
53 self.add_section(sec_name)
54 for opt_name, value in settings.iteritems():
55 if not self.has_option(sec_name, opt_name):
56 self.set(sec_name, opt_name, value)
58 def get_section(self, section, transformer=None):
60 for key, value in self.items(section):
61 if transformer is not None:
63 value = transformer(value)
64 except (TypeError, ValueError):
70 return {key: getattr(logging, self.get('Logging', key).upper())
71 for key in self.options('Logging')
72 if key not in self.LOGGING_NONLEVELS}
74 def dispatch_classes(self):
75 mod_name = 'arvnodeman.computenode.dispatch'
76 if self.has_option('Daemon', 'dispatcher'):
77 mod_name = '{}.{}'.format(mod_name,
78 self.get('Daemon', 'dispatcher'))
79 module = importlib.import_module(mod_name)
80 return (module.ComputeNodeSetupActor,
81 module.ComputeNodeShutdownActor,
82 module.ComputeNodeUpdateActor,
83 module.ComputeNodeMonitorActor)
85 def new_arvados_client(self):
86 if self.has_option('Daemon', 'certs_file'):
87 certs_file = self.get('Daemon', 'certs_file')
90 insecure = self.getboolean('Arvados', 'insecure')
91 http = httplib2.Http(timeout=self.getint('Arvados', 'timeout'),
93 disable_ssl_certificate_validation=insecure)
94 return arvados.api(version='v1',
95 host=self.get('Arvados', 'host'),
96 token=self.get('Arvados', 'token'),
100 def new_cloud_client(self):
101 module = importlib.import_module('arvnodeman.computenode.driver.' +
102 self.get('Cloud', 'provider'))
103 auth_kwargs = self.get_section('Cloud Credentials')
104 if 'timeout' in auth_kwargs:
105 auth_kwargs['timeout'] = int(auth_kwargs['timeout'])
106 return module.ComputeNodeDriver(auth_kwargs,
107 self.get_section('Cloud List'),
108 self.get_section('Cloud Create'))
110 def node_sizes(self, all_sizes):
111 """Finds all acceptable NodeSizes for our installation.
113 Returns a list of (NodeSize, kwargs) pairs for each NodeSize object
114 returned by libcloud that matches a size listed in our config file.
118 for sec_name in self.sections():
119 sec_words = sec_name.split(None, 2)
120 if sec_words[0] != 'Size':
122 size_spec = self.get_section(sec_name, int)
123 if 'price' in size_spec:
124 size_spec['price'] = float(size_spec['price'])
125 size_kwargs[sec_words[1]] = size_spec
126 # EC2 node sizes are identified by id. GCE sizes are identified by name.
128 for size in all_sizes:
129 if size.id in size_kwargs:
130 matching_sizes.append((size, size_kwargs[size.id]))
131 elif size.name in size_kwargs:
132 matching_sizes.append((size, size_kwargs[size.name]))
133 return matching_sizes
135 def shutdown_windows(self):
137 for n in self.get('Cloud', 'shutdown_windows').split(',')]