Пример #1
0
    def admin_user(self, req, tenant_id, id):
        """Return admin user name for the specified instance."""
        LOG.info(_("req : '%s'\n\n") % req)
        LOG.info(_("Get admin user name for instance or group '%s'")%id)

        if False==uuid.is_uuid_like(id):
            msg = (_("Wrong id of instance or group."))
            LOG.error(msg)
            raise exception.BadRequest(msg)

        group_id = None
        context = req.environ[wsgi.CONTEXT_KEY]
        try:
            db_info = models.get_db_info(context, id)
            group_id = db_info.group_id
        except exception.NotFound:
            LOG.debug("Not instance id %s"%id)
            pass

        if group_id==None:
            try:
                InstanceGroup.get_by_groupid(context, id)
                group_id = id
            except exception.NotFound:
                msg = (_("Without find instance or group of the id"))
                LOG.error(msg)
                raise exception.BadRequest(msg)    

        group = InstanceGroup.get_by_groupid(context, group_id)
        ret = {'admin_user': {"admin_user": group.admin_name}}
        return wsgi.Result(ret, 202)
Пример #2
0
    def backups(self, req, tenant_id, id):
        """Return all backups for the specified instance."""
        LOG.info(_("req : '%s'\n\n") % req)
        LOG.info(_("Indexing backups for instance or group '%s'")%id)

        if False==uuid.is_uuid_like(id):
            msg = (_("Wrong id of instance or group."))
            LOG.error(msg)
            raise exception.BadRequest(msg)

        group_id = None
        context = req.environ[wsgi.CONTEXT_KEY]
        try:
            db_info = models.get_db_info(context, id)
            group_id = db_info.group_id
        except exception.NotFound:
            LOG.debug("Not instance id %s"%id)
            pass

        if group_id==None:
            try:
                InstanceGroup.get_by_groupid(context, id)
                group_id = id
            except exception.NotFound:
                msg = (_("Without find instance or group of the id"))
                LOG.error(msg)
                raise exception.BadRequest(msg)    
        else:
            try:
                item = InstanceGroupItem.get_by_instance_id(context, id)
                if item.type==DBInstanceType.READ_REPLI or item.type==DBInstanceType.STANDBY:
                    msg = (_("Without backups for the instance.")) 
                    LOG.error(msg)
                    raise exception.BadRequest(msg)
            except exception.NotFound:
                msg = (_("Without find instance group item information."))
                LOG.error(msg)
                raise exception.BadRequest(msg)   
 
        backups = backup_model.list_autobackup(context, group_id)
        backups += backup_model.list_snapshot(context, group_id)
        bks = []
        #for backup in backups:
        #    instance = models.FreshInstance.load(context, backup.instance_id)
        #    backup.db_type = instance.service_type
        #    bks.append(backup)
        #TODO(ksc-need-discuss) backup.db_type didn't used in backup view, really need it?
        tmp = dict()
        for backup in backups:
            ## autobackup's service_image_id is NULL
            if backup.service_image_id:
                if backup.service_image_id not in tmp:
                    #service_image = models.ServiceImage.find_by(id=backup.service_image_id)
                    #backup.db_type = service_image.service_name
                    #tmp[backup.service_image_id] = service_image.service_name
                    try:
                        #image_id may be is not exists in datastaore
                        datastore, datastore_version = ds_path_models.find_datastore_by_image_id(backup.service_image_id)
                        tmp[backup.service_image_id] = datastore.name
                        backup.db_type = datastore.name
                    except Exception:
                        backup.db_type = ""
                else:
                    backup.db_type = tmp[backup.service_image_id]
            else:
                backup.db_type = ""
            bks.append(backup)
        backups = bks
        LOG.debug('Getted backups %s'%backups)
        return wsgi.Result(backup_views.BackupViews(backups).data(), 200)