Merge branch 'master' into 5375-preview-collection-text-files
[arvados.git] / services / nodemanager / arvnodeman / config.py
index f018015717c150b0065212248f35bbfbf3d1d4a7..315df1c3f984e29a0edfc09c71f76051def7480d 100644 (file)
@@ -10,7 +10,6 @@ import sys
 
 import arvados
 import httplib2
-import libcloud.common.types as cloud_types
 import pykka
 from apiclient import errors as apierror
 
@@ -19,7 +18,6 @@ from apiclient import errors as apierror
 # it's low-level, but unlikely to catch code bugs.
 NETWORK_ERRORS = (IOError, ssl.SSLError)
 ARVADOS_ERRORS = NETWORK_ERRORS + (apierror.Error,)
-CLOUD_ERRORS = NETWORK_ERRORS + (cloud_types.LibcloudError,)
 
 actor_class = pykka.ThreadingActor
 
@@ -90,8 +88,7 @@ class NodeManagerConfig(ConfigParser.SafeConfigParser):
         http = httplib2.Http(timeout=self.getint('Arvados', 'timeout'),
                              ca_certs=certs_file,
                              disable_ssl_certificate_validation=insecure)
-        return arvados.api('v1',
-                           cache=False,  # Don't reuse an existing client.
+        return arvados.api(version='v1',
                            host=self.get('Arvados', 'host'),
                            token=self.get('Arvados', 'token'),
                            insecure=insecure,
@@ -108,14 +105,26 @@ class NodeManagerConfig(ConfigParser.SafeConfigParser):
                                         self.get_section('Cloud Create'))
 
     def node_sizes(self, all_sizes):
+        """Finds all acceptable NodeSizes for our installation.
+
+        Returns a list of (NodeSize, kwargs) pairs for each NodeSize object
+        returned by libcloud that matches a size listed in our config file.
+        """
+
         size_kwargs = {}
         for sec_name in self.sections():
             sec_words = sec_name.split(None, 2)
             if sec_words[0] != 'Size':
                 continue
             size_kwargs[sec_words[1]] = self.get_section(sec_name, int)
-        return [(size, size_kwargs[size.id]) for size in all_sizes
-                if size.id in size_kwargs]
+        # EC2 node sizes are identified by id. GCE sizes are identified by name.
+        matching_sizes = []
+        for size in all_sizes:
+            if size.id in size_kwargs:
+                matching_sizes.append((size, size_kwargs[size.id]))
+            elif size.name in size_kwargs:
+                matching_sizes.append((size, size_kwargs[size.name]))
+        return matching_sizes
 
     def shutdown_windows(self):
         return [int(n)