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


Python Volume.create_snapshot方法代码示例

本文整理汇总了Python中boto.ec2.volume.Volume.create_snapshot方法的典型用法代码示例。如果您正苦于以下问题:Python Volume.create_snapshot方法的具体用法?Python Volume.create_snapshot怎么用?Python Volume.create_snapshot使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在boto.ec2.volume.Volume的用法示例。


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

示例1: VolumeTests

# 需要导入模块: from boto.ec2.volume import Volume [as 别名]
# 或者: from boto.ec2.volume.Volume import create_snapshot [as 别名]

#.........这里部分代码省略.........
            self.check_that_attribute_has_been_set(arguments[0], arguments[1], arguments[2])

    def test_endElement_with_name_status_and_empty_string_value_doesnt_set_status(self):
        volume = Volume()
        volume.endElement("status", "", None)
        self.assertNotEqual(volume.status, "")

    def test_update_with_result_set_greater_than_0_updates_dict(self):
        self.volume_two.connection.get_all_volumes.return_value = [self.volume_one]
        self.volume_two.update()

        assert all([self.volume_two.create_time == 5,
                    self.volume_two.status == "one_status",
                    self.volume_two.size == "one_size",
                    self.volume_two.snapshot_id == 1,
                    self.volume_two.attach_data == self.attach_data,
                    self.volume_two.zone == "one_zone"])

    def test_update_with_validate_true_raises_value_error(self):
        self.volume_one.connection = mock.Mock()
        self.volume_one.connection.get_all_volumes.return_value = []
        with self.assertRaisesRegexp(ValueError, "^1 is not a valid Volume ID$"):
            self.volume_one.update(True)

    def test_update_returns_status(self):
        self.volume_one.connection = mock.Mock()
        self.volume_one.connection.get_all_volumes.return_value = [self.volume_two]
        retval = self.volume_one.update()
        self.assertEqual(retval, "two_status")

    def test_delete_calls_delete_volume(self):
        self.volume_one.connection = mock.Mock()
        self.volume_one.delete()
        self.volume_one.connection.delete_volume.assert_called_with(1)

    def test_attach_calls_attach_volume(self):
        self.volume_one.connection = mock.Mock()
        self.volume_one.attach("instance_id", "/dev/null")
        self.volume_one.connection.attach_volume.assert_called_with(1, "instance_id", "/dev/null")

    def test_detach_calls_detach_volume(self):
        self.volume_one.connection = mock.Mock()
        self.volume_one.detach()
        self.volume_one.connection.detach_volume.assert_called_with(
                1, 2, "/dev/null", False)

    def test_detach_with_no_attach_data(self):
        self.volume_two.connection = mock.Mock()
        self.volume_two.detach()
        self.volume_two.connection.detach_volume.assert_called_with(
                1, None, None, False)

    def test_detach_with_force_calls_detach_volume_with_force(self):
        self.volume_one.connection = mock.Mock()
        self.volume_one.detach(True)
        self.volume_one.connection.detach_volume.assert_called_with(
                1, 2, "/dev/null", True)


    def test_create_snapshot_calls_connection_create_snapshot(self):
        self.volume_one.connection = mock.Mock()
        self.volume_one.create_snapshot()
        self.volume_one.connection.create_snapshot.assert_called_with(
                1, None)

    def test_create_snapshot_with_description(self):
        self.volume_one.connection = mock.Mock()
        self.volume_one.create_snapshot("some description")
        self.volume_one.connection.create_snapshot.assert_called_with(
                1, "some description")

    def test_volume_state_returns_status(self):
        retval = self.volume_one.volume_state()
        self.assertEqual(retval, "one_status")

    def test_attachment_state_returns_state(self):
        retval = self.volume_one.attachment_state()
        self.assertEqual(retval, "some status")

    def test_attachment_state_no_attach_data_returns_None(self):
        retval = self.volume_two.attachment_state()
        self.assertEqual(retval, None)

    def test_snapshots_returns_snapshots(self):
        snapshot_one = Snapshot()
        snapshot_one.volume_id = 1
        snapshot_two = Snapshot()
        snapshot_two.volume_id = 2

        self.volume_one.connection = mock.Mock()
        self.volume_one.connection.get_all_snapshots.return_value = [snapshot_one, snapshot_two]
        retval = self.volume_one.snapshots()
        self.assertEqual(retval, [snapshot_one])

    def test_snapshots__with_owner_and_restorable_by(self):
        self.volume_one.connection = mock.Mock()
        self.volume_one.connection.get_all_snapshots.return_value = []
        self.volume_one.snapshots("owner", "restorable_by")
        self.volume_one.connection.get_all_snapshots.assert_called_with(
                owner="owner", restorable_by="restorable_by")
开发者ID:Timus1712,项目名称:boto,代码行数:104,代码来源:test_volume.py

示例2: EC2CloudPlugin

# 需要导入模块: from boto.ec2.volume import Volume [as 别名]
# 或者: from boto.ec2.volume.Volume import create_snapshot [as 别名]
class EC2CloudPlugin(BaseCloudPlugin):
    _name = 'ec2'

    def add_metrics(self, metric_base_name, cls, func_name):
        newfunc = succeeds("{0}.count".format(metric_base_name), self)(raises("{0}.error".format(metric_base_name), self)(timer("{0}.duration".format(metric_base_name), self)(getattr(cls, func_name))))
        setattr(cls, func_name, newfunc)

    def __init__(self):
        super(EC2CloudPlugin, self).__init__()
        # wrap each of the functions so we can get timer and error metrics
        for ec2func in ["create_volume", "create_tags", "register_image", "get_all_images"]:
            self.add_metrics("aminator.cloud.ec2.connection.{0}".format(ec2func), EC2Connection, ec2func)
        for volfunc in ["add_tag", "attach", "create_snapshot", "delete", "detach", "update"]:
            self.add_metrics("aminator.cloud.ec2.volume.{0}".format(volfunc), Volume, volfunc)
        for imgfunc in ["update"]:
            self.add_metrics("aminator.cloud.ec2.image.{0}".format(imgfunc), Image, imgfunc)
        for insfunc in ["update"]:
            self.add_metrics("aminator.cloud.ec2.instance.{0}".format(insfunc), Instance, insfunc)

    def add_plugin_args(self, *args, **kwargs):
        context = self._config.context
        base_ami = self._parser.add_argument_group(
            title='Base AMI', description='EITHER AMI id OR name, not both!')
        base_ami_mutex = base_ami.add_mutually_exclusive_group(required=True)
        base_ami_mutex.add_argument(
            '-b', '--base-ami-name', dest='base_ami_name',
            action=conf_action(config=context.ami),
            help='The name of the base AMI used in provisioning')
        base_ami_mutex.add_argument(
            '-B', '--base-ami-id', dest='base_ami_id',
            action=conf_action(config=context.ami),
            help='The id of the base AMI used in provisioning')
        cloud = self._parser.add_argument_group(
            title='EC2 Options', description='EC2 Connection Information')
        cloud.add_argument(
            '-r', '--region', dest='region',
            help='EC2 region (default: us-east-1)',
            action=conf_action(config=context.cloud))
        cloud.add_argument(
            '--boto-secure', dest='is_secure', help='Connect via https',
            action=conf_action(config=context.cloud, action='store_true'))
        cloud.add_argument(
            '--boto-debug', dest='boto_debug', help='Boto debug output',
            action=conf_action(config=context.cloud, action='store_true'))
        volume_mutex = cloud.add_mutually_exclusive_group()
        volume_mutex.add_argument(
            '-V', '--volume-id', dest='volume_id',
            action=conf_action(config=context.ami),
            help='The Base AMI volume id already attached to the system')
        volume_mutex.add_argument(
            '--provisioner-ebs-type', dest='provisioner_ebs_type',
            action=conf_action(config=context.cloud),
            help='The type of EBS volume to create from the Base AMI snapshot')
        cloud.add_argument(
            '--register-ebs-type', dest='register_ebs_type',
            action=conf_action(config=context.cloud),
            help='The root volume EBS type for AMI registration')
        cloud.add_argument(
            '--root-volume-size', dest='root_volume_size',
            action=conf_action(config=context.ami),
            help='Root volume size (in GB). The default is to inherit from the base AMI.')

    def configure(self, config, parser):
        super(EC2CloudPlugin, self).configure(config, parser)
        host = config.context.web_log.get('host', False)
        if not host:
            md = get_instance_metadata()
            pub, ipv4 = 'public-hostname', 'local-ipv4'
            config.context.web_log['host'] = md[pub] if pub in md else md[ipv4]

    def connect(self, **kwargs):
        if self._connection:
            log.warn('Already connected to EC2')
        else:
            log.info('Connecting to EC2')
            self._connect(**kwargs)

    def _connect(self, **kwargs):
        cloud_config = self._config.plugins[self.full_name]
        context = self._config.context
        self._instance_metadata = get_instance_metadata()
        instance_region = self._instance_metadata['placement']['availability-zone'][:-1]
        region = kwargs.pop('region', context.get('region', cloud_config.get('region', instance_region)))
        log.debug('Establishing connection to region: {0}'.format(region))

        context.cloud.setdefault('boto_debug', False)
        if context.cloud.boto_debug:
            from aminator.config import configure_datetime_logfile
            configure_datetime_logfile(self._config, 'boto')
            kwargs['debug'] = 1
            log.debug('Boto debug logging enabled')
        else:
            logging.getLogger('boto').setLevel(logging.INFO)
        if 'is_secure' not in kwargs:
            kwargs['is_secure'] = context.get('is_secure', cloud_config.get('is_secure', True))
        self._connection = connect_to_region(region, **kwargs)
        log.info('Aminating in region {0}'.format(region))

    def allocate_base_volume(self, tag=True):
        cloud_config = self._config.plugins[self.full_name]
#.........这里部分代码省略.........
开发者ID:Netflix,项目名称:aminator,代码行数:103,代码来源:ec2.py


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