Prechádzať zdrojové kódy

Merge pull request #203 from CloudVE/add_iam_handling

Added IAM handling for AWS and GCP
Enis Afgan 7 rokov pred
rodič
commit
122e1a252e

+ 14 - 12
cloudbridge/providers/aws/services.py

@@ -756,18 +756,20 @@ class AWSInstanceService(BaseInstanceService):
             self._resolve_launch_options(subnet, zone_name, vm_firewalls)
 
         placement = {'AvailabilityZone': zone_id} if zone_id else None
-        inst = self.svc.create('create_instances',
-                               ImageId=image_id,
-                               MinCount=1,
-                               MaxCount=1,
-                               KeyName=key_pair_name,
-                               SecurityGroupIds=vm_firewall_ids or None,
-                               UserData=str(user_data) or None,
-                               InstanceType=vm_size,
-                               Placement=placement,
-                               BlockDeviceMappings=bdm,
-                               SubnetId=subnet_id
-                               )
+        inst = self.svc.create(
+            'create_instances',
+            ImageId=image_id,
+            MinCount=1,
+            MaxCount=1,
+            KeyName=key_pair_name,
+            SecurityGroupIds=vm_firewall_ids or None,
+            UserData=str(user_data) or None,
+            InstanceType=vm_size,
+            Placement=placement,
+            BlockDeviceMappings=bdm,
+            SubnetId=subnet_id,
+            IamInstanceProfile=kwargs.pop('iam_instance_profile', None)
+        )
         if inst and len(inst) == 1:
             # Wait until the resource exists
             # pylint:disable=protected-access

+ 4 - 0
cloudbridge/providers/gcp/services.py

@@ -562,6 +562,10 @@ class GCPInstanceService(BaseInstanceService):
             'networkInterfaces': [network_interface]
         }
 
+        service_accounts = kwargs.pop('service_accounts', None)
+        if service_accounts:
+            config['serviceAccounts'] = service_accounts
+
         if vm_firewalls and isinstance(vm_firewalls, list):
             vm_firewall_names = []
             if isinstance(vm_firewalls[0], VMFirewall):