Пример #1
0
    def create(self, req, body, tenant_id):
        LOG.info("Creating a backup for tenant %s", tenant_id)
        context = req.environ[wsgi.CONTEXT_KEY]
        policy.authorize_on_tenant(context, 'backup:create')
        data = body['backup']
        instance = data['instance']
        name = data['name']
        desc = data.get('description')
        parent = data.get('parent_id')
        incremental = data.get('incremental')
        swift_container = data.get('swift_container')

        context.notification = notification.DBaaSBackupCreate(context,
                                                              request=req)

        if not swift_container:
            instance_id = utils.get_id_from_href(instance)
            backup_strategy = BackupStrategy.get(context, instance_id)
            if backup_strategy:
                swift_container = backup_strategy.swift_container

        with StartNotification(context,
                               name=name,
                               instance_id=instance,
                               description=desc,
                               parent_id=parent):
            backup = Backup.create(context,
                                   instance,
                                   name,
                                   desc,
                                   parent_id=parent,
                                   incremental=incremental,
                                   swift_container=swift_container)

        return wsgi.Result(views.BackupView(backup).data(), 202)
Пример #2
0
 def create(self, req, body, tenant_id):
     LOG.debug("Creating a Backup for tenant '%s'" % tenant_id)
     context = req.environ[wsgi.CONTEXT_KEY]
     data = body["backup"]
     instance = data["instance"]
     name = data["name"]
     desc = data.get("description")
     backup = Backup.create(context, instance, name, desc)
     return wsgi.Result(views.BackupView(backup).data(), 202)
Пример #3
0
 def create(self, req, body, tenant_id):
     LOG.debug("Creating a Backup for tenant '%s'" % tenant_id)
     context = req.environ[wsgi.CONTEXT_KEY]
     data = body['backup']
     instance = data['instance']
     name = data['name']
     desc = data.get('description')
     backup = Backup.create(context, instance, name, desc)
     return wsgi.Result(views.BackupView(backup).data(), 202)
Пример #4
0
 def create(self, req, body, tenant_id):
     LOG.debug("Creating a Backup for tenant '%s'" % tenant_id)
     context = req.environ[wsgi.CONTEXT_KEY]
     data = body['backup']
     instance = data['instance']
     name = data['name']
     desc = data.get('description')
     parent = data.get('parent_id')
     backup = Backup.create(context, instance, name, desc, parent_id=parent)
     return wsgi.Result(views.BackupView(backup).data(), 202)
Пример #5
0
 def create(self, req, body, tenant_id):
     LOG.info(_("Creating a backup for tenant %s"), tenant_id)
     context = req.environ[wsgi.CONTEXT_KEY]
     data = body['backup']
     instance = data['instance']
     name = data['name']
     desc = data.get('description')
     parent = data.get('parent_id')
     backup = Backup.create(context, instance, name, desc, parent_id=parent)
     return wsgi.Result(views.BackupView(backup).data(), 202)
Пример #6
0
 def create(self, req, body, tenant_id):
     LOG.info(_("Creating a backup for tenant %s"), tenant_id)
     context = req.environ[wsgi.CONTEXT_KEY]
     data = body['backup']
     instance = data['instance']
     name = data['name']
     desc = data.get('description')
     parent = data.get('parent_id')
     context.notification = notification.DBaaSBackupCreate(context,
                                                           request=req)
     with StartNotification(context, name=name, instance_id=instance,
                            description=desc, parent_id=parent):
         backup = Backup.create(context, instance, name, desc,
                                parent_id=parent)
     return wsgi.Result(views.BackupView(backup).data(), 202)
Пример #7
0
 def create(self, req, body, tenant_id):
     LOG.info(_("Creating a backup for tenant %s"), tenant_id)
     context = req.environ[wsgi.CONTEXT_KEY]
     data = body['backup']
     instance = data['instance']
     name = data['name']
     desc = data.get('description')
     parent = data.get('parent_id')
     incremental = data.get('incremental')
     context.notification = notification.DBaaSBackupCreate(context,
                                                           request=req)
     with StartNotification(context, name=name, instance_id=instance,
                            description=desc, parent_id=parent):
         backup = Backup.create(context, instance, name, desc,
                                parent_id=parent, incremental=incremental)
     return wsgi.Result(views.BackupView(backup).data(), 202)
Пример #8
0
    def create_instance(self, flavor, image_id, databases, users,
                        service_type, volume_size, security_groups,
                        backup_id, instance_type, ignore_hosts=None,
                        master_id=None, extend=None):

        if instance_type==DBInstanceType.STANDBY or instance_type==DBInstanceType.READ_REPLI:
            if master_id is None:
                raise Exception("when instance_type is STANDBY or RR, The master_id can't none")

        availability_zone=None
        overrides = {}
        if extend != None:
            availability_zone=extend.get('availability_zone', None)
            ds_version_id = extend.get('datastore_version_id', None)
            overrides = extend.get('overrides', {})

        self.update_db(task_status=InstanceTasks.BUILDING_SERVER)
        try:
            server, volume_info = self._create_server_volume_individually(
                flavor,
                image_id,
                security_groups,
                service_type,
                ignore_hosts, availability_zone)
        except Exception as e:
            self.set_servicestatus(ServiceStatuses.UNKNOWN)
            raise e

        try:
            configuration_id =self.db_info.configuration_id
            LOG.debug("Prepare task  instance id = %s,  configuration id =%s" % (self.id, configuration_id))
            overrides = KSC_Configuration.get_configuration_overrides(self.context, configuration_id)
        except Exception:
            pass

        self.update_db(task_status=InstanceTasks.GUEST_PREPARE)
        LOG.info("======= > groupid %s" % self.group_id)
        group = InstanceGroup.get_by_groupid(self.context, self.group_id)
        sys_variables = {"port" : group.db_port, "read_only" : "OFF" if instance_type in (DBInstanceType.MASTER, DBInstanceType.SINGLE) else "ON"}
        overrides.update(sys_variables)
        config = self._render_config(flavor)
        overrides_config = self._render_override_config(flavor, overrides)

        self._guest_prepare(server, flavor['ram'], volume_info,
                            databases, users, backup_id,
                            config.config_contents,
                            overrides_contents = overrides_config.config_contents)

        try:
            utils.poll_until(self._service_is_active,
                             sleep_time=USAGE_SLEEP_TIME,
                             time_out=USAGE_TIMEOUT)
        except Exception as e:
            self.set_servicestatus(ServiceStatuses.UNKNOWN)
            raise e

        group_item = InstanceGroupItem.get_by_instance_id(self.context, self.id)
        group_id = group_item.group_id

        self.update_db(task_status=InstanceTasks.CONFIG_MYSQL)
        if instance_type==DBInstanceType.STANDBY or instance_type==DBInstanceType.READ_REPLI:
            if instance_type==DBInstanceType.STANDBY:
                self._update_instance_type(master_id, DBInstanceType.MASTER)

            self._update_instance_type(self.id, instance_type)
            self._relocate_master(master_id,self.id,backup_id)

            #when upgrade single to ha
            if instance_type == DBInstanceType.STANDBY:
                master_group_item = InstanceGroupItem.get_by_instance_id(self.context,master_id)
                InstanceGroupItem.update_type(self.context, item_id=master_group_item.id, type=DBInstanceType.MASTER)

        if instance_type==DBInstanceType.SINGLE or instance_type==DBInstanceType.MASTER:
            self._create_master_user(instance_id=self.id, user=extend.get('admin_user'), \
                                     password=extend.get('admin_password'))

            self._update_instance_type(self.id, instance_type)


        if instance_type==DBInstanceType.SINGLE or instance_type==DBInstanceType.MASTER:
            try:
                self.update_db(task_status=InstanceTasks.BACKUPING)
                expiretime = AutoBackup.get_autobackup_expiretime(self.context, group_id)
                backup_name = self._backup_name(instance_id=self.id)


                # Fore. 2014/07/02 Get Service Image ID from datastore version 
                #                 _type = self.service_type
                #                 _image = ServiceImage.find_by(self.context,service_name=_type)
                #ds, ds_version = ds_models.get_datastore_version(type = None, version = ds_version_id)
                #service_image_id = image_id

                desc = 'Init backup for new instance'
                Backup.create(context=self.context, instance=self.id,
                              name=backup_name, description=desc, group_id=group_id,
                              backup_type=BackupType.AUTOBACKUP, expire_at=expiretime,init=True,service_image_id=image_id)
            except Exception as e:
                msg = "Error creating backup for instance %s %s" % (self.id,utils.get_traceback_stack())
                LOG.error(msg)

        self.update_db(task_status=InstanceTasks.SETIOTUNE)
        LOG.debug("Set block iotune for instance %s ." % self.id)

        self._set_blkiotune(flavor)

        if instance_type!=DBInstanceType.STANDBY:
            if CONF.trove_vip_support:
                self.update_db(task_status=InstanceTasks.ALLOCATE_VIP)
                try:
                    rip = self._get_instance_ip(self.id)
                    vip = InstanceVip.allocate(self.context,instance_id=self.id,rip = rip)
                    LOG.debug("Allocated vip %s for instance %s"%(vip, self.id))
                except Exception as e:
                    self.set_servicestatus(ServiceStatuses.UNKNOWN)
                    raise e

        self.update_db(deleted=False,task_status=InstanceTasks.NONE)

        LOG.info("create instance_id:%s,notify monitor,autobackup" % self.id)
        group_rpcapi.API(self.context).group_update(group_id)
        self.send_usage_event('create', instance_size=flavor['ram'])
Пример #9
0
    def create(self, req, body, tenant_id):
        LOG.debug("Creating a Backup for tenant '%s'" % tenant_id)
        context = req.environ[wsgi.CONTEXT_KEY]
        data = body['backup']
        instance = data.get('instance',None)
        group = data.get('group',None)
        name = data['name']
        type = data.get("type", "snapshot")
        #expire_at = data.get("expire_after", 7)
        desc = data.get('description')
        parent_id = data.get('parent_id')
        LOG.info("parent_id:%s", parent_id)

        if group is None and instance is None:
            raise exception.BadRequest("you must specify group or instance")

        instance_id = None

        if group is not None:
            try:
                instance_id = InstanceGroupItem.get_by_gid_type(context, group, DBInstanceType.STANDBY).instance_id
            except:
                instance_id = InstanceGroupItem.get_by_gid_type(context, group, DBInstanceType.SINGLE).instance_id

        if instance_id is None and instance is not None:
            instance_id = inst_utils.virtual_instid_2_origin_instid(instance)

        _instance = DBInstance.find_by(context,id=instance_id)
        _type = _instance.service_type
        #_image = ServiceImage.find_by(context,service_name=_type)
        #service_image_id = _image.id
        ds,ds_version = ds_models.get_datastore_version(_type)
        service_image_id = ds_version.image_id

        grp_item = InstanceGroupItem.get_by_instance_id(context, _instance.id)
        group_id = grp_item.group_id

        # get this group's autobackup config and set the expire_after default
        _autobackup = AutoBackup.get_by_gid(context, group_id)
        expire_after = data.get("expire_after", _autobackup.expire_after)
        duration = _autobackup.duration
        expire_at = AutoBackup.calculate_expire_at(expire_after, duration)
        LOG.info("group_id %s, expire_at :%s", group_id, time.ctime(expire_at))

        if grp_item.type == DBInstanceType.MASTER:
            try:
                instance_id = InstanceGroupItem.get_by_gid_type(context, group_id, DBInstanceType.STANDBY).instance_id
            except Exception as e:
                LOG.error(e)

        backup = Backup.create(context, instance_id, name, description=desc,group_id=group_id,backup_type=type,expire_at=expire_at,service_image_id=service_image_id,parent_id=parent_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).data(), 202)