def create_backup(self, backup_id): from reddwarf.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 reddwarf.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 delete(self, req, tenant_id, id): context = req.environ[wsgi.CONTEXT_KEY] # verify that this backup is not running backup = Backup.get_by_id(id) if backup.state != BackupState.COMPLETED and backup.state != \ BackupState.FAILED: raise exception.BackupAlreadyRunning(action='delete', backup_id=id) self._verify_swift_auth_token(context) api.API(context).delete_backup(id) Backup.delete(id) return wsgi.Result(None, 202)
def _create_resources(): client = create_nova_client(context) security_groups = None try: flavor = client.flavors.get(flavor_id) except nova_exceptions.NotFound: raise exception.FlavorNotFound(uuid=flavor_id) if backup_id is not None: backup_info = Backup.get_by_id(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, task_status=InstanceTasks.BUILDING) LOG.debug(_("Tenant %s created new Reddwarf instance %s...") % (context.tenant, db_info.id)) service_status = InstanceServiceStatus.create( instance_id=db_info.id, status=ServiceStatuses.NEW) if CONF.reddwarf_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.reddwarf_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_id, flavor.ram, image_id, databases, users, service_type, volume_size, security_groups, backup_id) return SimpleInstance(context, db_info, service_status)
def _create_resources(): client = create_nova_client(context) security_groups = None try: flavor = client.flavors.get(flavor_id) except nova_exceptions.NotFound: raise exception.FlavorNotFound(uuid=flavor_id) if backup_id is not None: backup_info = Backup.get_by_id(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, task_status=InstanceTasks.BUILDING) LOG.debug( _("Tenant %s created new Reddwarf instance %s...") % (context.tenant, db_info.id)) service_status = InstanceServiceStatus.create( instance_id=db_info.id, status=ServiceStatuses.NEW) if CONF.reddwarf_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.reddwarf_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_id, flavor.ram, image_id, databases, users, service_type, volume_size, security_groups, backup_id) return SimpleInstance(context, db_info, service_status)
def create(self, req, body, tenant_id): # TODO(hub-cap): turn this into middleware LOG.info(_("Creating a database instance for tenant '%s'") % tenant_id) LOG.info(_("req : '%s'\n\n") % req) LOG.info(_("body : '%s'\n\n") % body) context = req.environ[wsgi.CONTEXT_KEY] # Set the service type to mysql if its not in the request service_type = (body['instance'].get('service_type') or CONF.service_type) service = models.ServiceImage.find_by(service_name=service_type) image_id = service['image_id'] name = body['instance']['name'] flavor_ref = body['instance']['flavorRef'] flavor_id = utils.get_id_from_href(flavor_ref) databases = populate_databases(body['instance'].get('databases', [])) users = populate_users(body['instance'].get('users', [])) if body['instance'].get('volume', None) is not None: try: volume_size = int(body['instance']['volume']['size']) except ValueError as e: raise exception.BadValue(msg=e) else: volume_size = None if body['instance'].get('restorePoint', None) is not None: backup_id = body['instance']['restorePoint']['backupId'] backup_info = backup_model.get_by_id(backup_id) if not backup_info.state == BackupState.COMPLETED: raise exception.BackupNotCompleteError(backup_id=backup_id) # verify backup file exist in swift location = backup_info.location if not InstanceController._check_object_exist(context, location): raise exception.BackupFileNotFound(location=location) else: backup_id = None instance = models.Instance.create(context, name, flavor_id, image_id, databases, users, service_type, volume_size, backup_id) view = views.InstanceDetailView(instance, req=req) return wsgi.Result(view.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) backup = Backup.get_by_id(id) return wsgi.Result(views.BackupView(backup).data(), 200)