当前位置: 首页>>代码示例>>Python>>正文


Python utils.instance_ids_from_querystring函数代码示例

本文整理汇总了Python中moto.ec2.utils.instance_ids_from_querystring函数的典型用法代码示例。如果您正苦于以下问题:Python instance_ids_from_querystring函数的具体用法?Python instance_ids_from_querystring怎么用?Python instance_ids_from_querystring使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了instance_ids_from_querystring函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: create_image

    def create_image(self):
        name = self.querystring.get('Name')[0]
        block_devices = []
        instance_ids = instance_ids_from_querystring(self.querystring)
        instance_id = instance_ids[0]
        instance = self.ec2_backend.get_instance(instance_id)

        if "Description" in self.querystring:
            description = self.querystring.get('Description')[0]
        else:
            description = ""

        volume = self.ec2_backend.get_volume(instance.block_device_mapping['/dev/sda1'].volume_id)
        for device in self._get_list_prefix('BlockDeviceMapping'):
            storage = {
                'device_name': device['device_name'],
                'virtual_name': device.get('virtual_name', None),
                'ebs': {
                    'delete': device.get('ebs._delete_on_termination', True),
                    'iops': device.get('ebs._iops', None),
                    'volume_type': device.get('ebs._volume_type', volume.volume_type if device['device_name'] == '/dev/sda1' else 'standard'),
                    'volume_size': device.get('ebs._volume_size', volume.size if device['device_name'] == '/dev/sda1' else 8),
                    'volume_id': None
                }
            }
            block_devices.append(storage)

        image = self.ec2_backend.create_image(instance_id, name, description, block_device_mapping=block_devices)
        template = self.response_template(CREATE_IMAGE_RESPONSE)
        return template.render(image=image)
开发者ID:Scalr,项目名称:moto,代码行数:30,代码来源:amis.py

示例2: describe_instance_attribute

 def describe_instance_attribute(self):
     # TODO this and modify below should raise IncorrectInstanceState if instance not in stopped state
     attribute = self.querystring.get("Attribute")[0]
     key = camelcase_to_underscores(attribute)
     instance_ids = instance_ids_from_querystring(self.querystring)
     instance_id = instance_ids[0]
     instance, value = ec2_backend.describe_instance_attribute(instance_id, key)
     template = Template(EC2_DESCRIBE_INSTANCE_ATTRIBUTE)
     return template.render(instance=instance, attribute=attribute, value=value)
开发者ID:flozano,项目名称:moto,代码行数:9,代码来源:instances.py

示例3: get_console_output

 def get_console_output(self):
     self.instance_ids = instance_ids_from_querystring(self.querystring)
     instance_id = self.instance_ids[0]
     instance = ec2_backend.get_instance(instance_id)
     if instance:
         template = Template(GET_CONSOLE_OUTPUT_RESULT)
         return template.render(instance=instance)
     else:
         return "", dict(status=404)
开发者ID:NarrativeTeam,项目名称:moto,代码行数:9,代码来源:general.py

示例4: create_image

 def create_image(self):
     name = self.querystring.get('Name')[0]
     description = self.querystring.get('Description')[0]
     instance_ids = instance_ids_from_querystring(self.querystring)
     instance_id = instance_ids[0]
     image = ec2_backend.create_image(instance_id, name, description)
     if not image:
         return "There is not instance with id {}".format(instance_id), dict(status=404)
     template = Template(CREATE_IMAGE_RESPONSE)
     return template.render(image=image)
开发者ID:NarrativeTeam,项目名称:moto,代码行数:10,代码来源:amis.py

示例5: _security_grp_instance_attribute_handler

    def _security_grp_instance_attribute_handler(self):
        new_security_grp_list = []
        for key, value in self.querystring.items():
            if 'GroupId.' in key:
                new_security_grp_list.append(self.querystring.get(key)[0])

        instance_ids = instance_ids_from_querystring(self.querystring)
        instance_id = instance_ids[0]
        self.ec2_backend.modify_instance_security_groups(instance_id, new_security_grp_list)
        return EC2_MODIFY_INSTANCE_ATTRIBUTE
开发者ID:rouge8,项目名称:moto,代码行数:10,代码来源:instances.py

示例6: describe_instances

    def describe_instances(self):
        filter_dict = filters_from_querystring(self.querystring)
        instance_ids = instance_ids_from_querystring(self.querystring)
        if instance_ids:
            reservations = self.ec2_backend.get_reservations_by_instance_ids(instance_ids, filters=filter_dict)
        else:
            reservations = self.ec2_backend.all_reservations(make_copy=True, filters=filter_dict)

        template = self.response_template(EC2_DESCRIBE_INSTANCES)
        return template.render(reservations=reservations)
开发者ID:rouge8,项目名称:moto,代码行数:10,代码来源:instances.py

示例7: describe_instance_status

    def describe_instance_status(self):
        instance_ids = instance_ids_from_querystring(self.querystring)

        if instance_ids:
            instances = self.ec2_backend.get_multi_instances_by_id(instance_ids)
        else:
            instances = self.ec2_backend.all_instances()

        template = Template(EC2_INSTANCE_STATUS)
        return template.render(instances=instances)
开发者ID:bobbyi,项目名称:moto,代码行数:10,代码来源:instances.py

示例8: modify_instance_attribute

    def modify_instance_attribute(self):
        for key, value in self.querystring.iteritems():
            if '.Value' in key:
                break

        value = self.querystring.get(key)[0]
        normalized_attribute = camelcase_to_underscores(key.split(".")[0])
        instance_ids = instance_ids_from_querystring(self.querystring)
        instance_id = instance_ids[0]
        ec2_backend.modify_instance_attribute(instance_id, normalized_attribute, value)
        return EC2_MODIFY_INSTANCE_ATTRIBUTE
开发者ID:flozano,项目名称:moto,代码行数:11,代码来源:instances.py

示例9: create_image

 def create_image(self):
     name = self.querystring.get('Name')[0]
     if "Description" in self.querystring:
         description = self.querystring.get('Description')[0]
     else:
         description = ""
     instance_ids = instance_ids_from_querystring(self.querystring)
     instance_id = instance_ids[0]
     image = self.ec2_backend.create_image(instance_id, name, description)
     template = self.response_template(CREATE_IMAGE_RESPONSE)
     return template.render(image=image)
开发者ID:DarthLorenzo,项目名称:moto,代码行数:11,代码来源:amis.py

示例10: describe_instance_status

    def describe_instance_status(self):
        instance_ids = instance_ids_from_querystring(self.querystring)
        include_all_instances = optional_from_querystring("IncludeAllInstances", self.querystring) == "true"

        if instance_ids:
            instances = self.ec2_backend.get_multi_instances_by_id(instance_ids)
        elif include_all_instances:
            instances = self.ec2_backend.all_instances()
        else:
            instances = self.ec2_backend.all_running_instances()

        template = self.response_template(EC2_INSTANCE_STATUS)
        return template.render(instances=instances)
开发者ID:Scalr,项目名称:moto,代码行数:13,代码来源:instances.py

示例11: describe_instances

    def describe_instances(self):
        instance_ids = instance_ids_from_querystring(self.querystring)
        if instance_ids:
            try:
                reservations = ec2_backend.get_reservations_by_instance_ids(instance_ids)
            except InvalidIdError as exc:
                template = Template(EC2_INVALID_INSTANCE_ID)
                return template.render(instance_id=exc.instance_id), dict(status=400)
        else:
            reservations = ec2_backend.all_reservations(make_copy=True)

        filter_dict = filters_from_querystring(self.querystring)
        reservations = filter_reservations(reservations, filter_dict)

        template = Template(EC2_DESCRIBE_INSTANCES)
        return template.render(reservations=reservations)
开发者ID:flozano,项目名称:moto,代码行数:16,代码来源:instances.py

示例12: _dot_value_instance_attribute_handler

    def _dot_value_instance_attribute_handler(self):
        attribute_key = None
        for key, value in self.querystring.items():
            if '.Value' in key:
                attribute_key = key
                break

        if not attribute_key:
            return

        value = self.querystring.get(attribute_key)[0]
        normalized_attribute = camelcase_to_underscores(attribute_key.split(".")[0])
        instance_ids = instance_ids_from_querystring(self.querystring)
        instance_id = instance_ids[0]
        self.ec2_backend.modify_instance_attribute(instance_id, normalized_attribute, value)
        return EC2_MODIFY_INSTANCE_ATTRIBUTE
开发者ID:rouge8,项目名称:moto,代码行数:16,代码来源:instances.py

示例13: _block_device_mapping_handler

    def _block_device_mapping_handler(self):
        """
        Handles requests which are generated by code similar to:

            instance.modify_attribute('blockDeviceMapping', {'/dev/sda1': True})

        The querystring contains information similar to:

            BlockDeviceMapping.1.Ebs.DeleteOnTermination : ['true']
            BlockDeviceMapping.1.DeviceName : ['/dev/sda1']

        For now we only support the "BlockDeviceMapping.1.Ebs.DeleteOnTermination"
        configuration, but it should be trivial to add anything else.
        """
        mapping_counter = 1
        mapping_device_name_fmt = 'BlockDeviceMapping.%s.DeviceName'
        mapping_del_on_term_fmt = 'BlockDeviceMapping.%s.Ebs.DeleteOnTermination'
        while True:
            mapping_device_name = mapping_device_name_fmt % mapping_counter
            if mapping_device_name not in self.querystring.keys():
                break

            mapping_del_on_term = mapping_del_on_term_fmt % mapping_counter
            del_on_term_value_str = self.querystring[mapping_del_on_term][0]
            del_on_term_value = True if 'true' == del_on_term_value_str else False
            device_name_value = self.querystring[mapping_device_name][0]

            instance_ids = instance_ids_from_querystring(self.querystring)
            instance_id = instance_ids[0]
            instance = self.ec2_backend.get_instance(instance_id)

            if self.is_not_dryrun('ModifyInstanceAttribute'):
                block_device_type = instance.block_device_mapping[
                    device_name_value]
                block_device_type.delete_on_termination = del_on_term_value

            # +1 for the next device
            mapping_counter += 1

        if mapping_counter > 1:
            return EC2_MODIFY_INSTANCE_ATTRIBUTE
开发者ID:2rs2ts,项目名称:moto,代码行数:41,代码来源:instances.py

示例14: describe_instances

    def describe_instances(self):
        filter_dict = filters_from_querystring(self.querystring)
        instance_ids = instance_ids_from_querystring(self.querystring)
        token = self._get_param("NextToken")
        if instance_ids:
            reservations = self.ec2_backend.get_reservations_by_instance_ids(
                instance_ids, filters=filter_dict)
        else:
            reservations = self.ec2_backend.all_reservations(
                make_copy=True, filters=filter_dict)

        reservation_ids = [reservation.id for reservation in reservations]
        if token:
            start = reservation_ids.index(token) + 1
        else:
            start = 0
        max_results = int(self._get_param('MaxResults', 100))
        reservations_resp = reservations[start:start + max_results]
        next_token = None
        if max_results and len(reservations) > (start + max_results):
            next_token = reservations_resp[-1].id
        template = self.response_template(EC2_DESCRIBE_INSTANCES)
        return template.render(reservations=reservations_resp, next_token=next_token)
开发者ID:netors,项目名称:moto,代码行数:23,代码来源:instances.py

示例15: __init__

 def __init__(self, querystring):
     self.querystring = querystring
     self.instance_ids = instance_ids_from_querystring(querystring)
开发者ID:Katafalkas,项目名称:moto,代码行数:3,代码来源:general.py


注:本文中的moto.ec2.utils.instance_ids_from_querystring函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。