Просмотр исходного кода

Adding vm_default_username property to GCE

almahmoud 7 лет назад
Родитель
Сommit
5a4120e219

+ 5 - 1
cloudbridge/cloud/providers/gce/provider.py

@@ -205,10 +205,14 @@ class GCECloudProvider(BaseCloudProvider):
         # Initialize cloud connection fields
         # Initialize cloud connection fields
         self.credentials_file = self._get_config_value(
         self.credentials_file = self._get_config_value(
                 'gce_service_creds_file',
                 'gce_service_creds_file',
-                os.environ.get('GCE_SERVICE_CREDS_FILE'))
+                os.getenv('GCE_SERVICE_CREDS_FILE'))
         self.credentials_dict = self._get_config_value(
         self.credentials_dict = self._get_config_value(
                 'gce_service_creds_dict',
                 'gce_service_creds_dict',
                 json.loads(os.getenv('GCE_SERVICE_CREDS_DICT', '{}')))
                 json.loads(os.getenv('GCE_SERVICE_CREDS_DICT', '{}')))
+        self.vm_default_user_name = self._get_config_value(
+            'gce_vm_default_username',
+            os.getenv('GCE_VM_DEFAULT_USERNAME', "cbuser"))
+
         # If 'gce_service_creds_dict' is not passed in from config and
         # If 'gce_service_creds_dict' is not passed in from config and
         # self.credentials_file is available, read and parse the json file to
         # self.credentials_file is available, read and parse the json file to
         # self.credentials_dict.
         # self.credentials_dict.

+ 4 - 4
cloudbridge/cloud/providers/gce/resources.py

@@ -1085,10 +1085,10 @@ class GCEInstance(BaseInstance):
             kp = key_pair._key_pair
             kp = key_pair._key_pair
             kp_items = [{
             kp_items = [{
                 "key": "ssh-keys",
                 "key": "ssh-keys",
-                # FIXME: ssh username & key format are fixed here while they
-                # should correspond to the operating system, or be customizable
-                "value": "ubuntu:{0} {1}".format(kp.public_key,
-                                                 kp.name)
+                # Format is not removed from public key portion
+                "value": "{}:{} {}".format(self._provider.vm_default_user_name,
+                                           kp.public_key,
+                                           kp.name)
             }]
             }]
             config = {
             config = {
                 "items": kp_items,
                 "items": kp_items,

+ 1 - 0
cloudbridge/cloud/providers/gce/services.py

@@ -117,6 +117,7 @@ class GCEKeyPairService(BaseKeyPairService):
         private_key = None
         private_key = None
         if not public_key_material:
         if not public_key_material:
             public_key_material, private_key = cb_helpers.generate_key_pair()
             public_key_material, private_key = cb_helpers.generate_key_pair()
+        # TODO: Add support for other formats not assume ssh-rsa
         elif "ssh-rsa" not in public_key_material:
         elif "ssh-rsa" not in public_key_material:
             public_key_material = "ssh-rsa {}".format(public_key_material)
             public_key_material = "ssh-rsa {}".format(public_key_material)
         kp_info = str(GCEKeyPair.GCEKeyInfo(name, public_key_material))
         kp_info = str(GCEKeyPair.GCEKeyInfo(name, public_key_material))