Exemple #1
0
    def handleRunInstances(self, action, clc, user_data_file):
        image_id = self.get_argument('ImageId')
        min = self.get_argument('MinCount', '1')
        max = self.get_argument('MaxCount', '1')
        key = self.get_argument('KeyName', None)
        groups = self.get_argument_list('SecurityGroup')
        sec_group_ids = self.get_argument_list('SecurityGroupId')
        if user_data_file:
            user_data = user_data_file
        else:
            user_data = self.get_argument('UserData', None)
        addr_type = self.get_argument('AddressingType', None)
        vm_type = self.get_argument('InstanceType', None)
        placement = self.get_argument('Placement.AvailabilityZone', None)
        placement_group = self.get_argument('Placement.GroupName', None)
        tenancy = self.get_argument('Placement.Tenancy', None)
        kernel = self.get_argument('KernelId', None)
        ramdisk = self.get_argument('RamdiskId', None)
        monitoring = False
        if self.get_argument('Monitoring.Enabled', '') == 'true':
            monitoring = True
        subnet = self.get_argument('SubnetId', None)
        private_ip = self.get_argument('PrivateIpAddress', None)
        # get block device mappings
        bdm = BlockDeviceMapping()
        mapping = self.get_argument('BlockDeviceMapping.1.DeviceName', None)
        idx = 1
        while mapping:
            pre = 'BlockDeviceMapping.%d' % idx
            dev_name = mapping
            block_dev_type = BlockDeviceType()
            block_dev_type.ephemeral_name = self.get_argument(
                '%s.VirtualName' % pre, None)
            if not (block_dev_type.ephemeral_name):
                block_dev_type.no_device = \
                    (self.get_argument('%s.NoDevice' % pre, '') == 'true')
                block_dev_type.snapshot_id = \
                        self.get_argument('%s.Ebs.SnapshotId' % pre, None)
                block_dev_type.size = \
                        self.get_argument('%s.Ebs.VolumeSize' % pre, None)
                block_dev_type.delete_on_termination = \
                        (self.get_argument('%s.DeleteOnTermination' % pre, '') == 'true')
            bdm[dev_name] = block_dev_type
            idx += 1
            mapping = self.get_argument(
                'BlockDeviceMapping.%d.DeviceName' % idx, None)
        if len(bdm) == 0:
            bdm = None

        api_termination = False
        if self.get_argument('DisableApiTermination', '') == 'true':
            api_termination = True
        instance_shutdown = False
        if self.get_argument('InstanceInitiatedShutdownBehavior',
                             '') == 'true':
            instance_shutdown = True
        token = self.get_argument('ClientToken', None)
        addition_info = self.get_argument('AdditionInfo', None)
        instance_profile_name = self.get_argument('IamInstanceProfile.Name',
                                                  None)
        instance_profile_arn = self.get_argument('IamInstanceProfile.Arn',
                                                 None)

        return self.__normalize_instances__([
            clc.run_instances(
                image_id,
                min_count=min,
                max_count=max,
                key_name=key,
                security_groups=groups,
                user_data=user_data,
                addressing_type=addr_type,
                instance_type=vm_type,
                placement=placement,
                kernel_id=kernel,
                ramdisk_id=ramdisk,
                monitoring_enabled=monitoring,
                subnet_id=subnet,
                block_device_map=bdm,
                disable_api_termination=api_termination,
                instance_initiated_shutdown_behavior=instance_shutdown,
                private_ip_address=private_ip,
                placement_group=placement_group,
                client_token=token,
                security_group_ids=sec_group_ids,
                additional_info=addition_info,
                instance_profile_name=instance_profile_name,
                instance_profile_arn=instance_profile_arn,
                tenancy=tenancy)
        ])
Exemple #2
0
 def handleImages(self, action, clc):
     if action == 'DescribeImages':
         owner = self.get_argument('Owner', None)
         if not owner:
             owners = None
         else:
             owners = [owner]
         return clc.get_all_images(owners)
     elif action == 'DescribeImageAttribute':
         imageid = self.get_argument('ImageId')
         attribute = self.get_argument('Attribute')
         return clc.get_image_attribute(imageid, attribute)
     elif action == 'ModifyImageAttribute':
         imageid = self.get_argument('ImageId')
         attribute = self.get_argument('Attribute')
         operation = self.get_argument('OperationType')
         users = self.get_argument_list('UserId')
         groups = self.get_argument_list('UserGroup')
         return clc.modify_image_attribute(imageid, attribute, operation,
                                           users, groups)
     elif action == 'ResetImageAttribute':
         imageid = self.get_argument('ImageId')
         attribute = self.get_argument('Attribute')
         return clc.reset_image_attribute(imageid, attribute)
     elif action == 'RegisterImage':
         image_location = self.get_argument('ImageLocation', None)
         name = self.get_argument('Name')
         description = self.get_argument('Description', None)
         description = base64.b64decode(description)
         architecture = self.get_argument('Architecture', None)
         kernel_id = self.get_argument('KernelId', None)
         ramdisk_id = self.get_argument('RamdiskId', None)
         root_dev_name = self.get_argument('RootDeviceName', None)
         snapshot_id = self.get_argument('SnapshotId', None)
         # get block device mappings
         bdm = BlockDeviceMapping()
         mapping = self.get_argument('BlockDeviceMapping.1.DeviceName',
                                     None)
         idx = 1
         while mapping:
             pre = 'BlockDeviceMapping.%d' % idx
             dev_name = mapping
             block_dev_type = BlockDeviceType()
             block_dev_type.ephemeral_name = self.get_argument(
                 '%s.VirtualName' % pre, None)
             if not (block_dev_type.ephemeral_name):
                 block_dev_type.no_device = \
                     (self.get_argument('%s.NoDevice' % pre, '') == 'true')
                 block_dev_type.snapshot_id = \
                         self.get_argument('%s.Ebs.SnapshotId' % pre, None)
                 block_dev_type.size = \
                         self.get_argument('%s.Ebs.VolumeSize' % pre, None)
                 block_dev_type.delete_on_termination = \
                         (self.get_argument('%s.DeleteOnTermination' % pre, '') == 'true')
             bdm[dev_name] = block_dev_type
             idx += 1
             mapping = self.get_argument(
                 'BlockDeviceMapping.%d.DeviceName' % idx, None)
         if snapshot_id:
             rootbdm = BlockDeviceType()
             rootbdm.snapshot_id = snapshot_id
             bdm['/dev/sda1'] = rootbdm
         if len(bdm) == 0:
             bdm = None
         return clc.register_image(name, image_location, description,
                                   architecture, kernel_id, ramdisk_id,
                                   root_dev_name, bdm)
Exemple #3
0
 def handleImages(self, action, clc, callback=None):
     if action == "DescribeImages":
         owner = self.get_argument("Owner", None)
         if not owner:
             owners = None
         else:
             owners = [owner]
         filters = self.get_filter_args()
         return clc.get_all_images(owners, filters, callback)
     elif action == "DescribeImageAttribute":
         imageid = self.get_argument("ImageId")
         attribute = self.get_argument("Attribute")
         return clc.get_image_attribute(imageid, attribute, callback)
     elif action == "ModifyImageAttribute":
         imageid = self.get_argument("ImageId")
         attribute = self.get_argument("Attribute")
         operation = self.get_argument("OperationType")
         users = self.get_argument_list("UserId")
         groups = self.get_argument_list("UserGroup")
         return clc.modify_image_attribute(imageid, attribute, operation, users, groups, callback)
     elif action == "ResetImageAttribute":
         imageid = self.get_argument("ImageId")
         attribute = self.get_argument("Attribute")
         return clc.reset_image_attribute(imageid, attribute, callback)
     elif action == "DeregisterImage":
         image_id = self.get_argument("ImageId")
         return clc.deregister_image(image_id, callback)
     elif action == "RegisterImage":
         image_location = self.get_argument("ImageLocation", None)
         name = self.get_argument("Name")
         description = self.get_argument("Description", None)
         if description != None:
             description = base64.b64decode(description)
         architecture = self.get_argument("Architecture", None)
         kernel_id = self.get_argument("KernelId", None)
         ramdisk_id = self.get_argument("RamdiskId", None)
         root_dev_name = self.get_argument("RootDeviceName", None)
         snapshot_id = self.get_argument("SnapshotId", None)
         # get block device mappings
         bdm = BlockDeviceMapping()
         mapping = self.get_argument("BlockDeviceMapping.1.DeviceName", None)
         idx = 1
         while mapping:
             pre = "BlockDeviceMapping.%d" % idx
             dev_name = mapping
             block_dev_type = BlockDeviceType()
             block_dev_type.ephemeral_name = self.get_argument("%s.VirtualName" % pre, None)
             if not (block_dev_type.ephemeral_name):
                 block_dev_type.no_device = self.get_argument("%s.NoDevice" % pre, "") == "true"
                 block_dev_type.snapshot_id = self.get_argument("%s.Ebs.SnapshotId" % pre, None)
                 block_dev_type.size = self.get_argument("%s.Ebs.VolumeSize" % pre, None)
                 block_dev_type.delete_on_termination = (
                     self.get_argument("%s.Ebs.DeleteOnTermination" % pre, "") == "true"
                 )
             bdm[dev_name] = block_dev_type
             idx += 1
             mapping = self.get_argument("BlockDeviceMapping.%d.DeviceName" % idx, None)
         if snapshot_id:
             rootbdm = BlockDeviceType()
             rootbdm.snapshot_id = snapshot_id
             bdm["/dev/sda1"] = rootbdm
         if len(bdm) == 0:
             bdm = None
         return clc.register_image(
             name, image_location, description, architecture, kernel_id, ramdisk_id, root_dev_name, bdm, callback
         )
Exemple #4
0
    def handleRunInstances(self, action, clc, user_data_file, callback):
        image_id = self.get_argument("ImageId")
        min = self.get_argument("MinCount", "1")
        max = self.get_argument("MaxCount", "1")
        key = self.get_argument("KeyName", None)
        groups = self.get_argument_list("SecurityGroup")
        sec_group_ids = self.get_argument_list("SecurityGroupId")
        if user_data_file:
            user_data = user_data_file
        else:
            user_data = self.get_argument("UserData", "")
            user_data = base64.b64decode(user_data)
        addr_type = self.get_argument("AddressingType", None)
        vm_type = self.get_argument("InstanceType", None)
        placement = self.get_argument("Placement.AvailabilityZone", None)
        placement_group = self.get_argument("Placement.GroupName", None)
        tenancy = self.get_argument("Placement.Tenancy", None)
        kernel = self.get_argument("KernelId", None)
        ramdisk = self.get_argument("RamdiskId", None)
        monitoring = False
        if self.get_argument("Monitoring.Enabled", "") == "true":
            monitoring = True
        subnet = self.get_argument("SubnetId", None)
        private_ip = self.get_argument("PrivateIpAddress", None)
        # get block device mappings
        bdm = BlockDeviceMapping()
        mapping = self.get_argument("BlockDeviceMapping.1.DeviceName", None)
        idx = 1
        while mapping:
            pre = "BlockDeviceMapping.%d" % idx
            dev_name = mapping
            block_dev_type = BlockDeviceType()
            block_dev_type.ephemeral_name = self.get_argument("%s.VirtualName" % pre, None)
            if not (block_dev_type.ephemeral_name):
                block_dev_type.no_device = self.get_argument("%s.NoDevice" % pre, "") == "true"
                block_dev_type.snapshot_id = self.get_argument("%s.Ebs.SnapshotId" % pre, None)
                block_dev_type.size = self.get_argument("%s.Ebs.VolumeSize" % pre, None)
                block_dev_type.delete_on_termination = (
                    self.get_argument("%s.Ebs.DeleteOnTermination" % pre, "") == "true"
                )
            bdm[dev_name] = block_dev_type
            idx += 1
            mapping = self.get_argument("BlockDeviceMapping.%d.DeviceName" % idx, None)
        if len(bdm) == 0:
            bdm = None

        api_termination = False
        if self.get_argument("DisableApiTermination", "") == "true":
            api_termination = True
        instance_shutdown = False
        if self.get_argument("InstanceInitiatedShutdownBehavior", "") == "true":
            instance_shutdown = True
        token = self.get_argument("ClientToken", None)
        addition_info = self.get_argument("AdditionInfo", None)
        instance_profile_name = self.get_argument("IamInstanceProfile.Name", None)
        instance_profile_arn = self.get_argument("IamInstanceProfile.Arn", None)

        return clc.run_instances(
            image_id,
            min_count=min,
            max_count=max,
            key_name=key,
            security_groups=groups,
            user_data=user_data,
            addressing_type=addr_type,
            instance_type=vm_type,
            placement=placement,
            kernel_id=kernel,
            ramdisk_id=ramdisk,
            monitoring_enabled=monitoring,
            subnet_id=subnet,
            block_device_map=bdm,
            disable_api_termination=api_termination,
            instance_initiated_shutdown_behavior=instance_shutdown,
            private_ip_address=private_ip,
            placement_group=placement_group,
            client_token=token,
            security_group_ids=sec_group_ids,
            additional_info=addition_info,
            instance_profile_name=instance_profile_name,
            instance_profile_arn=instance_profile_arn,
            tenancy=tenancy,
            callback=callback,
        )
Exemple #5
0
 def handleImages(self, action, clc, callback=None):
     if action == 'DescribeImages':
         owner = self.get_argument('Owner', None);
         if not owner:
             owners = None
         else:
             owners = [owner]
         filters = self.get_filter_args()
         return clc.get_all_images(owners, filters, callback)
     elif action == 'DescribeImageAttribute':
         imageid = self.get_argument('ImageId')
         attribute = self.get_argument('Attribute')
         return clc.get_image_attribute(imageid, attribute, callback)
     elif action == 'ModifyImageAttribute':
         imageid = self.get_argument('ImageId')
         attribute = self.get_argument('Attribute')
         operation = self.get_argument('OperationType')
         users = self.get_argument_list('UserId')
         groups = self.get_argument_list('UserGroup')
         return clc.modify_image_attribute(imageid, attribute, operation, users, groups, callback)
     elif action == 'ResetImageAttribute':
         imageid = self.get_argument('ImageId')
         attribute = self.get_argument('Attribute')
         return clc.reset_image_attribute(imageid, attribute, callback)
     elif action == 'DeregisterImage':
         image_id = self.get_argument('ImageId')
         return clc.deregister_image(image_id, callback)
     elif action == 'RegisterImage':
         image_location = self.get_argument('ImageLocation', None)
         name = self.get_argument('Name')
         description = self.get_argument('Description', None)
         if description != None:
           description = base64.b64decode(description);
         architecture = self.get_argument('Architecture', None)
         kernel_id = self.get_argument('KernelId', None)
         ramdisk_id = self.get_argument('RamdiskId', None)
         root_dev_name = self.get_argument('RootDeviceName', None)
         snapshot_id = self.get_argument('SnapshotId', None)
         # get block device mappings
         bdm = BlockDeviceMapping()
         mapping = self.get_argument('BlockDeviceMapping.1.DeviceName', None)
         idx = 1
         while mapping:
             pre = 'BlockDeviceMapping.%d' % idx
             dev_name = mapping
             block_dev_type = BlockDeviceType()
             block_dev_type.ephemeral_name = self.get_argument('%s.VirtualName' % pre, None)
             if not(block_dev_type.ephemeral_name):
                 block_dev_type.no_device = \
                     (self.get_argument('%s.NoDevice' % pre, '') == 'true')
                 block_dev_type.snapshot_id = \
                         self.get_argument('%s.Ebs.SnapshotId' % pre, None)
                 block_dev_type.size = \
                         self.get_argument('%s.Ebs.VolumeSize' % pre, None)
                 block_dev_type.delete_on_termination = \
                         (self.get_argument('%s.Ebs.DeleteOnTermination' % pre, '') == 'true')
             bdm[dev_name] = block_dev_type
             idx += 1
             mapping = self.get_argument('BlockDeviceMapping.%d.DeviceName' % idx, None)
         if snapshot_id:
             rootbdm = BlockDeviceType()
             rootbdm.snapshot_id = snapshot_id
             bdm['/dev/sda1'] = rootbdm
         if len(bdm) == 0:
             bdm = None
         return clc.register_image(name, image_location, description, architecture, kernel_id, ramdisk_id, root_dev_name, bdm, callback)
Exemple #6
0
    def handleRunInstances(self, action, clc, user_data_file, callback):
        image_id = self.get_argument('ImageId')
        min = self.get_argument('MinCount', '1')
        max = self.get_argument('MaxCount', '1')
        key = self.get_argument('KeyName', None)
        groups = self.get_argument_list('SecurityGroup')
        sec_group_ids = self.get_argument_list('SecurityGroupId')
        if user_data_file:
            user_data = user_data_file
        else:
            user_data = self.get_argument('UserData', "")
            user_data = base64.b64decode(user_data)
        addr_type = self.get_argument('AddressingType', None)
        vm_type = self.get_argument('InstanceType', None)
        placement = self.get_argument('Placement.AvailabilityZone', None)
        placement_group = self.get_argument('Placement.GroupName', None)
        tenancy = self.get_argument('Placement.Tenancy', None)
        kernel = self.get_argument('KernelId', None)
        ramdisk = self.get_argument('RamdiskId', None)
        monitoring=False
        if self.get_argument('Monitoring.Enabled', '') == 'true':
            monitoring=True
        subnet = self.get_argument('SubnetId', None);
        private_ip = self.get_argument('PrivateIpAddress', None);
        # get block device mappings
        bdm = BlockDeviceMapping()
        mapping = self.get_argument('BlockDeviceMapping.1.DeviceName', None)
        idx = 1
        while mapping:
            pre = 'BlockDeviceMapping.%d' % idx
            dev_name = mapping
            block_dev_type = BlockDeviceType()
            block_dev_type.ephemeral_name = self.get_argument('%s.VirtualName' % pre, None)
            if not(block_dev_type.ephemeral_name):
                block_dev_type.no_device = \
                    (self.get_argument('%s.NoDevice' % pre, '') == 'true')
                block_dev_type.snapshot_id = \
                        self.get_argument('%s.Ebs.SnapshotId' % pre, None)
                block_dev_type.size = \
                        self.get_argument('%s.Ebs.VolumeSize' % pre, None)
                block_dev_type.delete_on_termination = \
                        (self.get_argument('%s.Ebs.DeleteOnTermination' % pre, '') == 'true')
            bdm[dev_name] = block_dev_type
            idx += 1
            mapping = self.get_argument('BlockDeviceMapping.%d.DeviceName' % idx, None)
        if len(bdm) == 0:
            bdm = None
            
        api_termination=False
        if self.get_argument('DisableApiTermination', '') == 'true':
            api_termination=True
        instance_shutdown=False
        if self.get_argument('InstanceInitiatedShutdownBehavior', '') == 'true':
            instance_shutdown=True
        token = self.get_argument('ClientToken', None);
        addition_info = self.get_argument('AdditionInfo', None);
        instance_profile_name = self.get_argument('IamInstanceProfile.Name', None);
        instance_profile_arn = self.get_argument('IamInstanceProfile.Arn', None);

        return clc.run_instances(image_id, min_count=min, max_count=max,
                            key_name=key, security_groups=groups,
                            user_data=user_data, addressing_type=addr_type,
                            instance_type=vm_type, placement=placement,
                            kernel_id=kernel, ramdisk_id=ramdisk,
                            monitoring_enabled=monitoring, subnet_id=subnet,
                            block_device_map=bdm,
                            disable_api_termination=api_termination,
                            instance_initiated_shutdown_behavior=instance_shutdown,
                            private_ip_address=private_ip,
                            placement_group=placement_group, client_token=token,
                            security_group_ids=sec_group_ids,
                            additional_info=addition_info,
                            instance_profile_name=instance_profile_name,
                            instance_profile_arn=instance_profile_arn,
                            tenancy=tenancy, callback=callback)