Пример #1
0
    def delete_async(self):
        LOG.debug("prepare delete instance %s" % self.id)
        deleted_at = utils.utcnow()
        # Delete guest queue.
        _item = InstanceGroupItem.get_by_instance_id(self.context,self.id)
        group_id = _item.group_id

        if _item.type == DBInstanceType.MASTER:
            standby = None
            try:
                standby = InstanceGroupItem.get_by_gid_type(self.context, group_id,DBInstanceType.STANDBY)
            except exception.ModelNotFoundError:
                pass
            if standby is not None:

                standby.delete()
                standby_inst_id = standby.instance_id
                standby_tasks = self.load(self.context,standby_inst_id)
                standby_tasks.update_db(deleted=True, deleted_at=deleted_at,
                                        task_status=InstanceTasks.NONE)
                standby_tasks.set_servicestatus_deleted()
                standby_tasks._delete_instance_config()

        item_list = InstanceGroupItem.list_by_gid(self.context,group_id)
        if len(item_list)==1:
            # Delete associated security group
            if CONF.trove_security_groups_support:
                try:
                    SecurityGroup.delete_for_group(self.group_id,
                                                   self.context)
                except Exception as e:
                    LOG.error(utils.get_traceback_stack())

            LOG.info("send notify to monitor when delete instance %s" % self.id)
            group_rpcapi.API(self.context).group_update(group_id,notify_when_delete=True)

            LOG.info("Delete group %s" % group_id)
            InstanceGroup.delete(self.context,group_id)

        if _item.type in [DBInstanceType.MASTER,DBInstanceType.SINGLE]:
            try:
                LOG.info("Delete autobackup_setting of group_id %s" % group_id)
                AutoBackup.delete(self.context,group_id)
            except:
                LOG.error(utils.get_traceback_stack())


        _item.delete()
        self.update_db(deleted=True, deleted_at=deleted_at,
                       task_status=InstanceTasks.NONE)
        self.set_servicestatus_deleted()
Пример #2
0
    def delete_async(self, fake):
        LOG.debug("prepare delete instance %s, fake: %s " % (self.id, fake))
        modified_group_id = self.group_id
        self._delete_resources(fake)
        # Delete guest queue.
        _item = InstanceGroupItem.get_by_instance_id(self.context, self.id)
        group_id = _item.group_id
        del_instance_type = _item.type

        # if size of item_list equal 1,then we will delete last instance in group
        item_list = InstanceGroupItem.list_by_gid(self.context, modified_group_id)
        if len(item_list) == 1:
            if CONF.trove_security_groups_support:
                if fake is True:
                    LOG.debug("fake is True, %s skip delete secgroup rules", self.group_id)
                else:
                    # Delete associated security group
                    self.update_db(task_status=InstanceTasks.DELETEING_SECURITY_GROUP)
                    try:
                        SecurityGroup.delete_for_group(modified_group_id, self.context)
                    except Exception as e:
                        LOG.error(utils.get_traceback_stack())

        self.set_servicestatus_deleted()

        # zs: configuration is needed for restore deleted instance, DO NOT DELETE!
        # self._delete_instance_config()

        LOG.info("Delete instance_group_item for instance %s" % self.id)
        _type = self.type
        InstanceGroupItem.delete(self.context, self.id)
        deleted_at = utils.utcnow()
        if fake is True and _type == DBInstanceType.MASTER:
            LOG.debug("fake is True, %s is MASTER, set task_status :%s ", self.id, InstanceTasks.FAKE_DELETED)
            self.update_db(deleted=True, deleted_at=deleted_at, task_status=InstanceTasks.FAKE_DELETED)
        else:
            self.update_db(deleted=True, deleted_at=deleted_at, task_status=InstanceTasks.NONE)

        LOG.info("send notify to monitor when delete instance %s" % self.id)
        group_rpcapi.API(self.context).group_update(group_id, notify_when_delete=True)

        if len(item_list) == 1:
            LOG.info("Delete group %s" % group_id)
            InstanceGroup.delete(self.context, group_id)

        self._send_usage_event(self.server, utils.utcnow())
Пример #3
0
    def fake_deleted_instance_delete(cls, context, instance_id):
        base_msg = " instance_id: %s " % instance_id
        success = True
        msg = " fake_deleted_instance_delete %s " % base_msg

        deleted_at = utils.utcnow()
        db_info = None
        try:
            db_info = DBInstance.find_by(context=context, id=instance_id, task_id=InstanceTasks.FAKE_DELETED.code,
                                         deleted=True)
            db_info.update(task_status=InstanceTasks.DELETING)
            LOG.debug("fake_deleted_instance_delete, load instance ok, %s " % base_msg)
        except Exception:
            LOG.debug("fake_deleted_instance_delete failed, deleted instance not found, %s " % base_msg)
        if db_info is None:
            success = False
            msg = " fake_deleted_instance_delete failed, load instance error %s " % base_msg
            return success, msg

        try:
            server = load_server(context, db_info.id, db_info.compute_instance_id)
            LOG.debug("fake_deleted_instance_delete, load server: %s ok, %s ", db_info.compute_instance_id, base_msg)
            nova_client = create_nova_client(context)

            def server_is_finished():
                try:
                    server_id = db_info.compute_instance_id
                    _server = nova_client.servers.get(server_id)
                    if _server.status not in ['SHUTDOWN', 'ACTIVE']:
                        _msg = "Server %s got into %s status during delete " \
                               "of instance %s!" % (server.id, server.status, instance_id)
                        LOG.error(_msg)
                    return False
                except nova_exceptions.NotFound:
                    return True

            try:
                LOG.debug("Delete compute server %s" % server.id)
                server.delete()
                poll_until(server_is_finished, sleep_time=1, time_out=CONF.server_delete_time_out)
                guest = create_guest_client(context, db_info.id)
                guest.delete_queue()
                LOG.debug("fake_deleted_instance_delete, delete server: %s ok, %s ", db_info.compute_instance_id,
                          base_msg)
            except Exception as ex:
                LOG.error(utils.get_traceback_stack())
                success = False
                msg += " ,deleted server error, compute_instance_id: %s, ex:%s, %s " \
                       % (db_info.compute_instance_id, str(ex), base_msg)
        except Exception as ex:
            LOG.error("COMPUTE ID = %s" % db_info.compute_instance_id)
            success = False
            msg += " ,load server error, compute_instance_id: %s, %s " % (db_info.compute_instance_id, base_msg)

        if CONF.trove_vip_support:
            try:
                db_info.update(task_status=InstanceTasks.RELEASE_VIP)
                instance_vip = DBInstanceVip.find_by(context, instance_id=instance_id, deleted=False)
                vip_info = DBVips.find_by(context, id=instance_vip.vip_id, deleted=False)
                InstanceVip.release_vip(context, vip_info.vip)
                LOG.debug("fake_deleted_instance_delete, release_vip: %s ok, %s " % (vip_info.vip, base_msg))
            except Exception as ex:
                LOG.error(utils.get_traceback_stack())
                success = False
                msg += " ,release_vip error, ex:%s, %s " % (str(ex), base_msg)

        if CONF.trove_security_groups_support:
            db_info.update(task_status=InstanceTasks.DELETEING_SECURITY_GROUP)
            try:
                SecurityGroup.delete_for_group(db_info.group_id, context)
                LOG.debug(
                    "fake_deleted_instance_delete, delete SecurityGroup: %s ok, %s " % (db_info.group_id, base_msg))
            except Exception as ex:
                LOG.error(utils.get_traceback_stack())
                success = False
                msg += " ,delete SecurityGroup error, ex:%s, %s " % (str(ex), base_msg)

        db_info.update(deleted_at=deleted_at, task_status=InstanceTasks.NONE)

        if success is True:
            msg = "fake_deleted_instance_delete finished, %s " % base_msg

        return success, msg