def show(self, req, tenant_id, id): """Return a single backup.""" LOG.debug("Showing a backup for tenant %s ID: '%s'" % (tenant_id, id)) context = req.environ[wsgi.CONTEXT_KEY] backup = Backup.get_by_id(context, id) return wsgi.Result(views.BackupView(backup).data(), 200)
def show(self, req, tenant_id, id): """Return a single backup.""" LOG.info(_("Showing a backup for tenant '%s'") % tenant_id) LOG.info(_("id : '%s'\n\n") % id) context = req.environ[wsgi.CONTEXT_KEY] backup = Backup.get_by_id(context, id) return wsgi.Result(views.BackupView(backup).data(), 200)
def create_backup(self, backup_id): from trove.backup.models import Backup, BackupState backup = Backup.get_by_id(backup_id) def finish_create_backup(): backup.state = BackupState.COMPLETED backup.save() self.event_spawn(1.0, finish_create_backup)
def create_backup(self, backup_id): from trove.backup.models import Backup, BackupState backup = Backup.get_by_id(context=None, backup_id=backup_id) def finish_create_backup(): backup.state = BackupState.COMPLETED backup.save() self.event_spawn(1.0, finish_create_backup)
def show(self, req, tenant_id, id): """Return a single backup.""" LOG.debug("Showing a backup for tenant %s ID: '%s'" % (tenant_id, id)) context = req.environ[wsgi.CONTEXT_KEY] backup = Backup.get_by_id(context, id) policy.authorize_on_target(context, 'backup:show', {'tenant': backup.tenant_id}) return wsgi.Result(views.BackupView(backup).data(), 200)
def create_backup(self, backup_id): from trove.backup.models import Backup, BackupState backup = Backup.get_by_id(context=None, backup_id=backup_id) def finish_create_backup(): backup.state = BackupState.COMPLETED backup.location = 'http://localhost/path/to/backup' backup.save() eventlet.spawn_after(1.0, finish_create_backup)
def show(self, req, tenant_id, id): """Return a single backup.""" LOG.debug("Showing a backup for tenant %s ID: '%s'" % (tenant_id, id)) context = req.environ[wsgi.CONTEXT_KEY] backup = Backup.get_by_id(context, id) instance = get_db_info(context, backup.instance_id, None, True) backup.instance_name = instance.name return wsgi.Result(views.BackupView(backup).data(), 200)
def create_backup(self, backup_id): from trove.backup.models import Backup, BackupState backup = Backup.get_by_id(context=None, backup_id=backup_id) def finish_create_backup(): backup.state = BackupState.COMPLETED backup.location = 'http://localhost/path/to/backup' backup.checksum = 'fake-md5-sum' backup.save() eventlet.spawn_after(1.0, finish_create_backup)
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=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() 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)
def create_backup(self, backup_info): from trove.backup.models import Backup from trove.backup.state import BackupState backup = Backup.get_by_id(context=None, backup_id=backup_info['id']) def finish_create_backup(): backup.state = BackupState.COMPLETED backup.location = 'http://localhost/path/to/backup' backup.checksum = 'fake-md5-sum' backup.size = BACKUP_SIZE backup.save() eventlet.spawn_after(7.5, finish_create_backup)
def delete(self, req, tenant_id, id): LOG.info(_('Deleting backup for tenant %(tenant_id)s ' 'ID: %(backup_id)s') % {'tenant_id': tenant_id, 'backup_id': id}) context = req.environ[wsgi.CONTEXT_KEY] backup = Backup.get_by_id(context, id) policy.authorize_on_target(context, 'backup:delete', {'tenant': backup.tenant_id}) context.notification = notification.DBaaSBackupDelete(context, request=req) with StartNotification(context, backup_id=id): Backup.delete(context, id) return wsgi.Result(None, 202)
def show(self, req, tenant_id, id): """Return a single backup.""" LOG.info(_("Showing a backup for tenant '%s'") % tenant_id) LOG.info(_("id : '%s'\n\n") % id) context = req.environ[wsgi.CONTEXT_KEY] backup = Backup.get_by_id(context, id) try: #service = inst_models.ServiceImage.find_by(id=backup.service_image_id) #backup.db_type = service['service_name'] ds,ds_version = ds_patch_models.find_datastore_by_image_id(backup.service_image_id) backup.db_type = ds.name except Exception as ex: backup.db_type = "" LOG.warn("Failed get db type information of backup %s, %s"%(backup.id, ex)) chain = self._get_chain_ids(context, id) LOG.info(_("chain : '%s'") % chain) return wsgi.Result(views.BackupView(backup, chain=chain).data(), 200)
def _relocate_master(self, master_id, slave_id,backup_id=None): ''' Fore. 2014/9/29 desperated method. don't use it. :param master_id: :param slave_id: :param backup_id: ''' master_group_item = InstanceGroupItem.get_by_instance_id(self.context, master_id) def __show_master_status(inst_id): _instance = self.load(self.context, inst_id) _guest = _instance.get_guest() mStatus = _guest.ksc_show_master_status() log_path, log_pos = mStatus['file'], mStatus['position'] return log_path, log_pos if backup_id is None: log_path, log_pos = __show_master_status(master_id) else: bk_info = Backup.get_by_id(self.context, backup_id) if master_group_item.group_id == bk_info.group_id: log_path, log_pos = Backup.get_binlog_info(self.context, backup_id) else: log_path, log_pos = __show_master_status(master_id) LOG.debug("relocate master instance %s get binlog_path:%s binlog_pos:%s" \ %(master_id, log_path, log_pos)) group_item = master_group_item master_host = self._get_instance_ip(master_id) master_guest = FreshInstanceTasks.load(self.context, master_id).guest master_port = int(master_guest.ksc_list_variables(["port"])["port"]) repl_user = CONF.rds_rpl_user repl_password = self._gen_rpl_user_password(group_item.group_id) master_log_file = log_path master_log_pos = log_pos slave_instance = self.load(self.context, slave_id) slave_guest = slave_instance.get_guest() slave_guest.ksc_relocate_master(master_host=master_host, master_port = master_port, repl_user=repl_user, repl_password=repl_password, master_log_file=master_log_file, master_log_pos=master_log_pos)
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 %s created new Trove instance %s...") % (context.tenant, 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) 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) return SimpleInstance(context, db_info, service_status)
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, slave_of_id=None, cluster_config=None, replica_count=None): datastore_cfg = CONF.get(datastore_version.manager) 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} volume_support = datastore_cfg.volume_support if volume_support: validate_volume_size(volume_size) deltas['volumes'] = volume_size # Instance volume should have enough space for the backup # Backup, and volume sizes are in GBs target_size = volume_size else: target_size = flavor.disk # local_storage if volume_size is not None: raise exception.VolumeNotSupported() if datastore_cfg.device_path: if flavor.ephemeral == 0: raise exception.LocalStorageNotSpecified(flavor=flavor_id) target_size = flavor.ephemeral # ephemeral_Storage if backup_id: backup_info = Backup.get_by_id(context, backup_id) if not backup_info.is_done_successfuly: raise exception.BackupNotCompleteError( backup_id=backup_id, state=backup_info.state) if backup_info.size > target_size: raise exception.BackupTooLarge( backup_size=backup_info.size, disk_size=target_size) 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) try: # looking for replica source replica_source = DBInstance.find_by( context, id=slave_of_id, deleted=False) if replica_source.slave_of_id: raise exception.Forbidden( _("Cannot create a replica of a replica %(id)s.") % {'id': slave_of_id}) # load the replica source status to check if # source is available load_simple_instance_server_status( context, replica_source) replica_source_instance = Instance( 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)
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)
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)
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) 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) 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) return SimpleInstance(context, db_info, service_status, root_password) return run_with_quotas(context.tenant, deltas, _create_resources)
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, slave_of_id=None, cluster_config=None): datastore_cfg = CONF.get(datastore_version.manager) 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} volume_support = datastore_cfg.volume_support 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)
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, slave_of_id=None, cluster_config=None): datastore_cfg = CONF.get(datastore_version.manager) 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} volume_support = datastore_cfg.volume_support if volume_support: validate_volume_size(volume_size) deltas['volumes'] = volume_size # Instance volume should have enough space for the backup # Backup, and volume sizes are in GBs target_size = volume_size else: target_size = flavor.disk # local_storage if volume_size is not None: raise exception.VolumeNotSupported() if datastore_cfg.device_path: if flavor.ephemeral == 0: raise exception.LocalStorageNotSpecified(flavor=flavor_id) target_size = flavor.ephemeral # ephemeral_Storage 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 backup_info.size > target_size: raise exception.BackupTooLarge(backup_size=backup_info.size, disk_size=target_size) 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) try: # looking for replica source replica_source = DBInstance.find_by(context, id=slave_of_id, deleted=False) if replica_source.slave_of_id: raise exception.Forbidden( _("Cannot create a replica of a replica %(id)s.") % {'id': slave_of_id}) 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) 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)
def show(self, req, tenant_id, id): """Return a single backup.""" LOG.info(_("Showing a backup for tenant '%s'") % tenant_id) LOG.info(_("id : '%s'\n\n") % id) backup = Backup.get_by_id(id) return wsgi.Result(views.BackupView(backup).data(), 200)