• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python quota.run_with_quotas函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: test_run_with_quotas

    def test_run_with_quotas(self):

        f = Mock()
        run_with_quotas(FAKE_TENANT1, {'instances': 1, 'volumes': 5}, f)

        self.assertTrue(QUOTAS.reserve.called)
        self.assertTrue(QUOTAS.commit.called)
        self.assertFalse(QUOTAS.rollback.called)
        self.assertTrue(f.called)
开发者ID:CiscoSystems,项目名称:openstack-trove,代码行数:9,代码来源:test_quota.py


示例2: delete

    def delete(cls, context, backup_id):
        """
        update Backup table on deleted flag for given Backup
        :param cls:
        :param context: context containing the tenant id and token
        :param backup_id: Backup uuid
        :return:
        """

        # Recursively delete all children and grandchildren of this backup.
        query = DBBackup.query()
        query = query.filter_by(parent_id=backup_id, deleted=False)
        for child in query.all():
            cls.delete(context, child.id)

        def _delete_resources():
            backup = cls.get_by_id(context, backup_id)
            if backup.is_running:
                msg = _("Backup %s cannot be deleted because it is running.")
                raise exception.UnprocessableEntity(msg % backup_id)
            cls.verify_swift_auth_token(context)
            api.API(context).delete_backup(backup_id)

        return run_with_quotas(context.tenant,
                               {'backups': -1},
                               _delete_resources)
开发者ID:Hopebaytech,项目名称:trove,代码行数:26,代码来源:models.py


示例3: delete

    def delete(self):
        def _delete_resources():
            if self.is_building:
                raise exception.UnprocessableEntity("Instance %s is not ready."
                                                    % self.id)
            LOG.debug("Deleting instance with compute id = %s.",
                      self.db_info.compute_instance_id)

            from trove.cluster.models import is_cluster_deleting
            if (self.db_info.cluster_id is not None and not
               is_cluster_deleting(self.context, self.db_info.cluster_id)):
                raise exception.ClusterInstanceOperationNotSupported()

            if self.slaves:
                msg = _("Detach replicas before deleting replica source.")
                LOG.warn(msg)
                raise exception.ReplicaSourceDeleteForbidden(msg)

            self.update_db(task_status=InstanceTasks.DELETING,
                           configuration_id=None)
            task_api.API(self.context).delete_instance(self.id)

        deltas = {'instances': -1}
        if self.volume_support:
            deltas['volumes'] = -self.volume_size
        return run_with_quotas(self.tenant_id,
                               deltas,
                               _delete_resources)
开发者ID:cretta,项目名称:trove,代码行数:28,代码来源:models.py


示例4: create

    def create(cls, context, instance, name, description=None, parent_id=None):
        """
        create db record for Backup
        :param cls:
        :param context: tenant_id included
        :param instance:
        :param name:
        :param description:
        :return:
        """

        def _create_resources():
            # parse the ID from the Ref
            instance_id = utils.get_id_from_href(instance)

            # verify that the instance exists and can perform actions
            from trove.instance.models import Instance
            instance_model = Instance.load(context, instance_id)
            instance_model.validate_can_perform_action()
            cls.validate_can_perform_action(
                instance_model, 'backup_create')
            cls.verify_swift_auth_token(context)

            parent = None
            if parent_id:
                # Look up the parent info or fail early if not found or if
                # the user does not have access to the parent.
                _parent = cls.get_by_id(context, parent_id)
                parent = {
                    'location': _parent.location,
                    'checksum': _parent.checksum,
                }
            try:
                db_info = DBBackup.create(name=name,
                                          description=description,
                                          tenant_id=context.tenant,
                                          state=BackupState.NEW,
                                          instance_id=instance_id,
                                          parent_id=parent_id,
                                          deleted=False)
            except exception.InvalidModelError as ex:
                LOG.exception("Unable to create Backup record:")
                raise exception.BackupCreationError(str(ex))

            backup_info = {'id': db_info.id,
                           'name': name,
                           'description': description,
                           'instance_id': instance_id,
                           'backup_type': db_info.backup_type,
                           'checksum': db_info.checksum,
                           'parent': parent,
                           }
            api.API(context).create_backup(backup_info, instance_id)
            return db_info

        return run_with_quotas(context.tenant,
                               {'backups': 1},
                               _create_resources)
开发者ID:imsplitbit,项目名称:trove,代码行数:58,代码来源:models.py


示例5: delete

    def delete(self):
        def _delete_resources():
            if self.is_building:
                raise exception.UnprocessableEntity("Instance %s is not ready." % self.id)
            LOG.debug(_("  ... deleting compute id = %s") % self.db_info.compute_instance_id)
            LOG.debug(_(" ... setting status to DELETING."))
            self.update_db(task_status=InstanceTasks.DELETING)
            task_api.API(self.context).delete_instance(self.id)

        deltas = {"instances": -1}
        if CONF.trove_volume_support:
            deltas["volumes"] = -self.volume_size
        return run_with_quotas(self.tenant_id, deltas, _delete_resources)
开发者ID:CiscoSystems,项目名称:openstack-trove,代码行数:13,代码来源:models.py


示例6: delete

    def delete(self):
        def _delete_resources():
            if self.is_building:
                raise exception.UnprocessableEntity("Instance %s is not ready."
                                                    % self.id)
            LOG.debug("Deleting instance with compute id = %s." %
                      self.db_info.compute_instance_id)
            self.update_db(task_status=InstanceTasks.DELETING,
                           configuration_id=None)
            task_api.API(self.context).delete_instance(self.id)

        deltas = {'instances': -1}
        if self.volume_support:
            deltas['volumes'] = -self.volume_size
        return run_with_quotas(self.tenant_id,
                               deltas,
                               _delete_resources)
开发者ID:mahak,项目名称:trove,代码行数:17,代码来源:models.py


示例7: resize_volume

    def resize_volume(self, new_size):
        def _resize_resources():
            self.validate_can_perform_action()
            LOG.info("Resizing volume of instance %s..." % self.id)
            if not self.volume_size:
                raise exception.BadRequest("Instance %s has no volume." % self.id)
            old_size = self.volume_size
            if int(new_size) <= old_size:
                msg = "The new volume 'size' must be larger than the current " "volume size of '%s'"
                raise exception.BadRequest(msg % old_size)
            # Set the task to Resizing before sending off to the taskmanager
            self.update_db(task_status=InstanceTasks.RESIZING)
            task_api.API(self.context).resize_volume(new_size, self.id)

        new_size_l = long(new_size)
        validate_volume_size(new_size_l)
        return run_with_quotas(self.tenant_id, {"volumes": new_size_l - self.volume_size}, _resize_resources)
开发者ID:CiscoSystems,项目名称:openstack-trove,代码行数:17,代码来源:models.py


示例8: delete

    def delete(self):
        def _delete_resources():
            if self.is_building:
                raise exception.UnprocessableEntity("Instance %s is not ready." % self.id)
            LOG.debug("Deleting instance with compute id = %s." % self.db_info.compute_instance_id)

            from trove.cluster.models import is_cluster_deleting

            if self.db_info.cluster_id is not None and not is_cluster_deleting(self.context, self.db_info.cluster_id):
                raise exception.ClusterInstanceOperationNotSupported()

            self.update_db(task_status=InstanceTasks.DELETING, configuration_id=None)
            task_api.API(self.context).delete_instance(self.id)

        deltas = {"instances": -1}
        if self.volume_support:
            deltas["volumes"] = -self.volume_size
        return run_with_quotas(self.tenant_id, deltas, _delete_resources)
开发者ID:rumale,项目名称:trove,代码行数:18,代码来源:models.py


示例9: delete

    def delete(cls, context, backup_id):
        """
        update Backup table on deleted flag for given Backup
        :param cls:
        :param context: context containing the tenant id and token
        :param backup_id: Backup uuid
        :return:
        """

        def _delete_resources():
            backup = cls.get_by_id(context, backup_id)
            if backup.is_running:
                msg = "Backup %s cannot be delete because it is running." % backup_id
                raise exception.UnprocessableEntity(msg)
            cls.verify_swift_auth_token(context)
            api.API(context).delete_backup(backup_id)

        return run_with_quotas(context.tenant, {"backups": -1}, _delete_resources)
开发者ID:zhujzhuo,项目名称:trove-1.0.10.4,代码行数:18,代码来源:models.py


示例10: resize_volume

    def resize_volume(self, new_size):
        def _resize_resources():
            self.validate_can_perform_action()
            LOG.info(_LI("Resizing volume of instance %s."), self.id)
            if self.db_info.cluster_id is not None:
                raise exception.ClusterInstanceOperationNotSupported()
            old_size = self.volume_size
            if int(new_size) <= old_size:
                raise exception.BadRequest(
                    _("The new volume 'size' must be " "larger than the current volume " "size of '%s'.") % old_size
                )
            # Set the task to Resizing before sending off to the taskmanager
            self.update_db(task_status=InstanceTasks.RESIZING)
            task_api.API(self.context).resize_volume(new_size, self.id)

        if not self.volume_size:
            raise exception.BadRequest(_("Instance %s has no volume.") % self.id)
        new_size_l = long(new_size)
        validate_volume_size(new_size_l)
        return run_with_quotas(self.tenant_id, {"volumes": new_size_l - self.volume_size}, _resize_resources)
开发者ID:zjtheone,项目名称:trove,代码行数:20,代码来源:models.py


示例11: create

    def create(cls, context, instance, name, description=None):
        """
        create db record for Backup
        :param cls:
        :param context: tenant_id included
        :param instance:
        :param name:
        :param description:
        :return:
        """

        def _create_resources():
            # parse the ID from the Ref
            instance_id = utils.get_id_from_href(instance)

            # verify that the instance exist and can perform actions
            from trove.instance.models import Instance

            instance_model = Instance.load(context, instance_id)
            instance_model.validate_can_perform_action()

            cls.verify_swift_auth_token(context)

            try:
                db_info = DBBackup.create(
                    name=name,
                    description=description,
                    tenant_id=context.tenant,
                    state=BackupState.NEW,
                    instance_id=instance_id,
                    deleted=False,
                )
            except exception.InvalidModelError as ex:
                LOG.exception("Unable to create Backup record:")
                raise exception.BackupCreationError(str(ex))

            api.API(context).create_backup(db_info.id, instance_id)
            return db_info

        return run_with_quotas(context.tenant, {"backups": 1}, _create_resources)
开发者ID:zhujzhuo,项目名称:trove-1.0.10.4,代码行数:40,代码来源:models.py


示例12: create


#.........这里部分代码省略.........
        if volume_support:
            validate_volume_size(volume_size)
            deltas['volumes'] = volume_size
        else:
            if volume_size is not None:
                raise exception.VolumeNotSupported()
            ephemeral_support = datastore_cfg.device_path
            if ephemeral_support:
                if flavor.ephemeral == 0:
                    raise exception.LocalStorageNotSpecified(flavor=flavor_id)

        if backup_id is not None:
            backup_info = Backup.get_by_id(context, backup_id)
            if backup_info.is_running:
                raise exception.BackupNotCompleteError(backup_id=backup_id)

            if not backup_info.check_swift_object_exist(
                    context,
                    verify_checksum=CONF.verify_swift_checksum_on_restore):
                raise exception.BackupFileNotFound(
                    location=backup_info.location)

            if (backup_info.datastore_version_id
                    and backup_info.datastore.name != datastore.name):
                raise exception.BackupDatastoreMismatchError(
                    datastore1=backup_info.datastore.name,
                    datastore2=datastore.name)

        if slave_of_id:
            replication_support = datastore_cfg.replication_strategy
            if not replication_support:
                raise exception.ReplicationNotSupported(
                    datastore=datastore.name)

        if not nics:
            nics = []
        if CONF.default_neutron_networks:
            nics = [{"net-id": net_id}
                    for net_id in CONF.default_neutron_networks] + nics

        def _create_resources():

            if cluster_config:
                cluster_id = cluster_config.get("id", None)
                shard_id = cluster_config.get("shard_id", None)
                instance_type = cluster_config.get("instance_type", None)
            else:
                cluster_id = shard_id = instance_type = None

            db_info = DBInstance.create(name=name, flavor_id=flavor_id,
                                        tenant_id=context.tenant,
                                        volume_size=volume_size,
                                        datastore_version_id=
                                        datastore_version.id,
                                        task_status=InstanceTasks.BUILDING,
                                        configuration_id=configuration_id,
                                        slave_of_id=slave_of_id,
                                        cluster_id=cluster_id,
                                        shard_id=shard_id,
                                        type=instance_type)
            LOG.debug("Tenant %(tenant)s created new Trove instance %(db)s."
                      % {'tenant': context.tenant, 'db': db_info.id})

            # if a configuration group is associated with an instance,
            # generate an overrides dict to pass into the instance creation
            # method

            config = Configuration(context, configuration_id)
            overrides = config.get_configuration_overrides()
            service_status = InstanceServiceStatus.create(
                instance_id=db_info.id,
                status=tr_instance.ServiceStatuses.NEW)

            if CONF.trove_dns_support:
                dns_client = create_dns_client(context)
                hostname = dns_client.determine_hostname(db_info.id)
                db_info.hostname = hostname
                db_info.save()

            root_password = None
            if cls.get_root_on_create(
                    datastore_version.manager) and not backup_id:
                root_password = utils.generate_random_password()

            task_api.API(context).create_instance(db_info.id, name, flavor,
                                                  image_id, databases, users,
                                                  datastore_version.manager,
                                                  datastore_version.packages,
                                                  volume_size, backup_id,
                                                  availability_zone,
                                                  root_password, nics,
                                                  overrides, slave_of_id,
                                                  cluster_config)

            return SimpleInstance(context, db_info, service_status,
                                  root_password)

        return run_with_quotas(context.tenant,
                               deltas,
                               _create_resources)
开发者ID:ShaguftaMethwani,项目名称:trove,代码行数:101,代码来源:models.py


示例13: create


#.........这里部分代码省略.........
                    context, replica_source,
                    None,
                    InstanceServiceStatus.find_by(
                        context,
                        instance_id=slave_of_id))
                replica_source_instance.validate_can_perform_action()
            except exception.ModelNotFoundError:
                LOG.exception(
                    _("Cannot create a replica of %(id)s "
                      "as that instance could not be found.")
                    % {'id': slave_of_id})
                raise exception.NotFound(uuid=slave_of_id)
        elif replica_count and replica_count != 1:
            raise exception.Forbidden(_(
                "Replica count only valid when creating replicas. Cannot "
                "create %(count)d instances.") % {'count': replica_count})
        multi_replica = slave_of_id and replica_count and replica_count > 1
        instance_count = replica_count if multi_replica else 1

        if not nics:
            nics = []
        if CONF.default_neutron_networks:
            nics = [{"net-id": net_id}
                    for net_id in CONF.default_neutron_networks] + nics

        def _create_resources():

            if cluster_config:
                cluster_id = cluster_config.get("id", None)
                shard_id = cluster_config.get("shard_id", None)
                instance_type = cluster_config.get("instance_type", None)
            else:
                cluster_id = shard_id = instance_type = None

            ids = []
            names = []
            root_passwords = []
            root_password = None
            for instance_index in range(0, instance_count):
                db_info = DBInstance.create(
                    name=name, flavor_id=flavor_id, tenant_id=context.tenant,
                    volume_size=volume_size,
                    datastore_version_id=datastore_version.id,
                    task_status=InstanceTasks.BUILDING,
                    configuration_id=configuration_id,
                    slave_of_id=slave_of_id, cluster_id=cluster_id,
                    shard_id=shard_id, type=instance_type)
                LOG.debug("Tenant %(tenant)s created new Trove instance "
                          "%(db)s.",
                          {'tenant': context.tenant, 'db': db_info.id})

                instance_id = db_info.id
                instance_name = name
                ids.append(instance_id)
                names.append(instance_name)
                root_passwords.append(None)
                # change the name to be name + replica_number if more than one
                if multi_replica:
                    replica_number = instance_index + 1
                    names[instance_index] += '-' + str(replica_number)
                    setattr(db_info, 'name', names[instance_index])
                    db_info.save()

                # if a configuration group is associated with an instance,
                # generate an overrides dict to pass into the instance creation
                # method

                config = Configuration(context, configuration_id)
                overrides = config.get_configuration_overrides()
                service_status = InstanceServiceStatus.create(
                    instance_id=instance_id,
                    status=tr_instance.ServiceStatuses.NEW)

                if CONF.trove_dns_support:
                    dns_client = create_dns_client(context)
                    hostname = dns_client.determine_hostname(instance_id)
                    db_info.hostname = hostname
                    db_info.save()

                if cls.get_root_on_create(
                        datastore_version.manager) and not backup_id:
                    root_password = utils.generate_random_password()
                    root_passwords[instance_index] = root_password

            if instance_count > 1:
                instance_id = ids
                instance_name = names
                root_password = root_passwords
            task_api.API(context).create_instance(
                instance_id, instance_name, flavor, image_id, databases, users,
                datastore_version.manager, datastore_version.packages,
                volume_size, backup_id, availability_zone, root_password,
                nics, overrides, slave_of_id, cluster_config)

            return SimpleInstance(context, db_info, service_status,
                                  root_password)

        return run_with_quotas(context.tenant,
                               deltas,
                               _create_resources)
开发者ID:cretta,项目名称:trove,代码行数:101,代码来源:models.py


示例14: create

    def create(cls, context, name, flavor_id, image_id, databases, users,
               datastore, datastore_version, volume_size, backup_id,
               availability_zone=None, nics=None, configuration_id=None):

        client = create_nova_client(context)
        try:
            flavor = client.flavors.get(flavor_id)
        except nova_exceptions.NotFound:
            raise exception.FlavorNotFound(uuid=flavor_id)

        deltas = {'instances': 1}
        if CONF.trove_volume_support:
            validate_volume_size(volume_size)
            deltas['volumes'] = volume_size
        else:
            if volume_size is not None:
                raise exception.VolumeNotSupported()
            ephemeral_support = CONF.device_path
            if ephemeral_support and flavor.ephemeral == 0:
                raise exception.LocalStorageNotSpecified(flavor=flavor_id)

        if backup_id is not None:
            backup_info = Backup.get_by_id(context, backup_id)
            if backup_info.is_running:
                raise exception.BackupNotCompleteError(backup_id=backup_id)

            if not backup_info.check_swift_object_exist(
                    context,
                    verify_checksum=CONF.verify_swift_checksum_on_restore):
                raise exception.BackupFileNotFound(
                    location=backup_info.location)

            backup_db_info = DBInstance.find_by(
                context=context, id=backup_info.instance_id)
            if (backup_db_info.datastore_version_id
                    != datastore_version.id):
                ds_version = (datastore_models.DatastoreVersion.
                              load_by_uuid(backup_db_info.datastore_version_id)
                              )
                raise exception.BackupDatastoreVersionMismatchError(
                    version1=ds_version.name,
                    version2=datastore_version.name)

        if not nics and CONF.default_neutron_networks:
            nics = []
            for net_id in CONF.default_neutron_networks:
                nics.append({"net-id": net_id})

        def _create_resources():

            db_info = DBInstance.create(name=name, flavor_id=flavor_id,
                                        tenant_id=context.tenant,
                                        volume_size=volume_size,
                                        datastore_version_id=
                                        datastore_version.id,
                                        task_status=InstanceTasks.BUILDING,
                                        configuration_id=configuration_id)
            LOG.debug(_("Tenant %(tenant)s created new "
                        "Trove instance %(db)s...") %
                      {'tenant': context.tenant, 'db': db_info.id})

            # if a configuration group is associated with an instance,
            # generate an overrides dict to pass into the instance creation
            # method

            overrides = Configuration.get_configuration_overrides(
                context, configuration_id)
            datastore_status = InstanceServiceStatus.create(
                instance_id=db_info.id,
                status=tr_instance.ServiceStatuses.NEW)

            if CONF.trove_dns_support:
                dns_client = create_dns_client(context)
                hostname = dns_client.determine_hostname(db_info.id)
                db_info.hostname = hostname
                db_info.save()

            root_password = None
            if cls.get_root_on_create(
                    datastore_version.manager) and not backup_id:
                root_password = utils.generate_random_password()

            task_api.API(context).create_instance(db_info.id, name, flavor,
                                                  image_id, databases, users,
                                                  datastore_version.manager,
                                                  datastore_version.packages,
                                                  volume_size, backup_id,
                                                  availability_zone,
                                                  root_password,
                                                  nics,
                                                  overrides)

            return SimpleInstance(context, db_info, datastore_status,
                                  root_password)

        return run_with_quotas(context.tenant,
                               deltas,
                               _create_resources)
开发者ID:wrongfan,项目名称:trove,代码行数:98,代码来源:models.py


示例15: create

    def create(
        cls,
        context,
        name,
        flavor_id,
        image_id,
        databases,
        users,
        service_type,
        volume_size,
        backup_id,
        availability_zone=None,
    ):

        client = create_nova_client(context)
        try:
            flavor = client.flavors.get(flavor_id)
        except nova_exceptions.NotFound:
            raise exception.FlavorNotFound(uuid=flavor_id)

        deltas = {"instances": 1}
        if CONF.trove_volume_support:
            validate_volume_size(volume_size)
            deltas["volumes"] = volume_size
        else:
            if volume_size is not None:
                raise exception.VolumeNotSupported()
            ephemeral_support = CONF.device_path
            if ephemeral_support and flavor.ephemeral == 0:
                raise exception.LocalStorageNotSpecified(flavor=flavor_id)

        def _create_resources():
            security_groups = None

            if backup_id is not None:
                backup_info = Backup.get_by_id(context, backup_id)
                if backup_info.is_running:
                    raise exception.BackupNotCompleteError(backup_id=backup_id)

                location = backup_info.location
                LOG.info(_("Checking if backup exist in '%s'") % location)
                if not Backup.check_object_exist(context, location):
                    raise exception.BackupFileNotFound(location=location)

            db_info = DBInstance.create(
                name=name,
                flavor_id=flavor_id,
                tenant_id=context.tenant,
                volume_size=volume_size,
                service_type=service_type,
                task_status=InstanceTasks.BUILDING,
            )
            LOG.debug(
                _("Tenant %(tenant)s created new " "Trove instance %(db)s...")
                % {"tenant": context.tenant, "db": db_info.id}
            )

            service_status = InstanceServiceStatus.create(instance_id=db_info.id, status=ServiceStatuses.NEW)

            if CONF.trove_dns_support:
                dns_client = create_dns_client(context)
                hostname = dns_client.determine_hostname(db_info.id)
                db_info.hostname = hostname
                db_info.save()

            if CONF.trove_security_groups_support:
                security_group = SecurityGroup.create_for_instance(db_info.id, context)
                if CONF.trove_security_groups_rules_support:
                    SecurityGroupRule.create_sec_group_rule(
                        security_group,
                        CONF.trove_security_group_rule_protocol,
                        CONF.trove_security_group_rule_port,
                        CONF.trove_security_group_rule_port,
                        CONF.trove_security_group_rule_cidr,
                        context,
                    )
                security_groups = [security_group["name"]]

            task_api.API(context).create_instance(
                db_info.id,
                name,
                flavor,
                image_id,
                databases,
                users,
                service_type,
                volume_size,
                security_groups,
                backup_id,
                availability_zone,
            )

            return SimpleInstance(context, db_info, service_status)

        return run_with_quotas(context.tenant, deltas, _create_resources)
开发者ID:CiscoSystems,项目名称:openstack-trove,代码行数:95,代码来源:models.py


示例16: create

    def create(cls, context, instance, name, description=None,
               parent_id=None, incremental=False):
        """
        create db record for Backup
        :param cls:
        :param context: tenant_id included
        :param instance:
        :param name:
        :param description:
        :param parent_id:
        :param incremental: flag to indicate incremental backup
        based on previous backup
        :return:
        """

        def _create_resources():
            # parse the ID from the Ref
            instance_id = utils.get_id_from_href(instance)

            # verify that the instance exists and can perform actions
            from trove.instance.models import Instance
            instance_model = Instance.load(context, instance_id)
            instance_model.validate_can_perform_action()
            cls.validate_can_perform_action(
                instance_model, 'backup_create')
            cls.verify_swift_auth_token(context)

            ds = instance_model.datastore
            ds_version = instance_model.datastore_version

            manager = (datastore_models.DatastoreVersion.load_by_uuid(
                ds_version.id).manager)
            if (not CONF.get(manager).enable_cluster_instance_backup
                    and instance_model.cluster_id is not None):
                raise exception.ClusterInstanceOperationNotSupported()

            parent = None
            parent_backup = None
            parent_backup_id = None
            last_backup_id = None
            if parent_id:
                # Look up the parent info or fail early if not found or if
                # the user does not have access to the parent.
                if parent_id == 'last':
                    # Need to assign parent_id to a new variable
                    # parent_backup_id, otherwise an unbound variable error
                    # will be thrown
                    parent_backup = Backup.get_last_completed(context,
                                                              instance_id,
                                                              True)
                    if parent_backup is None:
                        raise exception.NotFound()
                    parent_backup_id = parent_backup.id
                else:
                    parent_backup_id = parent_id
                _parent = cls.get_by_id(context, parent_backup_id)
                parent = {
                    'id': parent_backup_id,
                    'location': _parent.location,
                    'checksum': _parent.checksum,
                }
            elif incremental:
                _parent = Backup.get_last_completed(context, instance_id)
                if _parent:
                    parent = {
                        'location': _parent.location,
                        'checksum': _parent.checksum
                    }
                    last_backup_id = _parent.id
            try:
                db_info = DBBackup.create(name=name,
                                          description=description,
                                          tenant_id=context.tenant,
                                          state=BackupState.NEW,
                                          instance_id=instance_id,
                                          parent_id=parent_backup_id or
                                          last_backup_id,
                                          datastore_version_id=ds_version.id,
                                          deleted=False)
            except exception.InvalidModelError as ex:
                LOG.exception(_("Unable to create backup record for "
                                "instance: %s"), instance_id)
                raise exception.BackupCreationError(str(ex))

            backup_info = {'id': db_info.id,
                           'name': name,
                           'description': description,
                           'instance_id': instance_id,
                           'backup_type': db_info.backup_type,
                           'checksum': db_info.checksum,
                           'parent': parent,
                           'datastore': ds.name,
                           'datastore_version': ds_version.name,
                           }
            api.API(context).create_backup(backup_info, instance_id)
            return db_info
        return run_with_quotas(context.tenant,
                               {'backups': 1},
                               _create_resources)
开发者ID:Tesora,项目名称:tesora-trove,代码行数:99,代码来源:models.py


示例17: create

    def create(cls, context, name, flavor_id, image_id,
               databases, users, service_type, volume_size, backup_id,
               availability_zone=None):

        client = create_nova_client(context)
        try:
            flavor = client.flavors.get(flavor_id)
        except nova_exceptions.NotFound:
            raise exception.FlavorNotFound(uuid=flavor_id)

        deltas = {'instances': 1}
        if CONF.trove_volume_support:
            validate_volume_size(volume_size)
            deltas['volumes'] = volume_size
        else:
            if volume_size is not None:
                raise exception.VolumeNotSupported()
            ephemeral_support = CONF.device_path
            if ephemeral_support and flavor.ephemeral == 0:
                raise exception.LocalStorageNotSpecified(flavor=flavor_id)

        if backup_id is not None:
            backup_info = Backup.get_by_id(context, backup_id)
            if backup_info.is_running:
                raise exception.BackupNotCompleteError(backup_id=backup_id)

            if not backup_info.check_swift_object_exist(
                    context,
                    verify_checksum=CONF.verify_swift_checksum_on_restore):
                raise exception.BackupFileNotFound(
                    location=backup_info.location)

        def _create_resources():

            db_info = DBInstance.create(name=name, flavor_id=flavor_id,
                                        tenant_id=context.tenant,
                                        volume_size=volume_size,
                                        service_type=service_type,
                                        task_status=InstanceTasks.BUILDING)
            LOG.debug(_("Tenant %(tenant)s created new "
                        "Trove instance %(db)s...") %
                      {'tenant': context.tenant, 'db': db_info.id})

            service_status = InstanceServiceStatus.create(
                instance_id=db_info.id,
                status=rd_instance.ServiceStatuses.NEW)

            if CONF.trove_dns_support:
                dns_client = create_dns_client(context)
                hostname = dns_client.determine_hostname(db_info.id)
                db_info.hostname = hostname
                db_info.save()

            root_password = None
            if CONF.root_on_create and not backup_id:
                root_password = uuidutils.generate_uuid()

            task_api.API(context).create_instance(db_info.id, name, flavor,
                                                  image_id, databases, users,
                                                  service_type, volume_size,
                                                  backup_id,
                                                  availability_zone,
                                                  root_password)

            return SimpleInstance(context, db_info, service_status,
                                  root_password)

        return run_with_quotas(context.tenant,
                               deltas,
                               _create_resources)
开发者ID:VinodKrGupta,项目名称:trove,代码行数:70,代码来源:models.py


示例18: create


#.........这里部分代码省略.........
        if init:
            if instance_model.db_info.server_status != 'ACTIVE':
                msg = ("Instance is not currently available for an action to be "
                       "performed (server_status was %s).", instance_model.db_info.server_status)
                LOG.error(msg)
                raise exception.UnprocessableEntity(msg)
        else:
            instance_model.validate_can_perform_action()

        if instance_model.type == DBInstanceType.MASTER:
            try:
                standby_id = InstanceGroupItem.get_by_gid_type(context, instance_model.group_id, DBInstanceType.STANDBY).instance_id
                instance_model = Instance.load(context, standby_id)
                instance_model.validate_can_perform_action()
                instance_id = standby_id
            except Exception as e:
                LOG.error(e)
                raise e

        if group_id is None:
            raise exception.TroveError("group_id can't None")
        if backup_type is None or backup_type not in [Type.SNAPSHOT, Type.AUTOBACKUP]:
            raise exception.TroveError("instType can't None, only accept value: snapshot or autobackup ")

        if backup_type == Type.SNAPSHOT:
            expire_time = 0
            _parent_id = None  # force full
        elif backup_type == Type.AUTOBACKUP:
            expire_time = int(expire_at)
            if parent_id and parent_id == '0':
                _parent_id = None  # force full
            elif parent_id and parent_id != '0':
                try:
                    backup_parent = cls.get_by_id(context, parent_id)
                    LOG.debug("backup_parent:%s", backup_parent)
                except:
                    raise exception.NotFound("not found backup with parent_id: %s" % parent_id)
                if not backup_parent:
                    raise exception.NotFound("not found backup with parent_id: %s" % parent_id)
            elif parent_id is None:
                LOG.debug("parent_id is None:%s", parent_id)
                last_backup_chain = cls.get_last_backup_chain(group_id)
           

鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python api.load函数代码示例发布时间:2022-05-27
下一篇:
Python models.QuotaUsage类代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap