コード例 #1
0
ファイル: api.py プロジェクト: andrewbogott/novawikiplugins
    def index(self, req):
        """Return a list of existing file shares."""
        filesystems = self.fs_driver.list_fs()

        # Only return filesystems in the db.
        context = req.environ['nova.context']

        if self.has_db_support:
            db_list = sharedfs_db.filesystem_list(context)

            fs_list = []
            for fs in filesystems:
                name = fs.get('name')
                if name in db_list:
                    db_entry = sharedfs_db.filesystem_get(context, name)
                    fs_list.append({'name': fs.get('name'),
                                    'size': fs.get('size'),
                                    'scope': db_entry.get('scope'),
                                    'project': db_entry.get('project_id')})
                    db_list.remove(name)
                else:
                    LOG.warn(_("Found filesystem %s that is not recored "
                             "in the database.  Ignoring.") % name)

            if db_list:
                LOG.warn(_("Possible database integrity issue.  The following "
                         "filesystems are recorded in the database but cannot "
                         "be located: %s") % db_list)
        else:
            fs_list = [{'name': fs.get('name'), 'size': fs.get('size'),
                        'scope': 'unknown', 'project': 'unknown'}
                       for fs in filesystems]

        return _translate_fs_entries_view(fs_list)
コード例 #2
0
    def notify(self, message):
        event_type = message.get('event_type')
        if event_type not in ['compute.instance.delete.start',
                              'compute.instance.create.end']:
            return

        payload = message['payload']

        instance = payload['instance_id']
        tenant = payload['tenant_id']
        user = payload['user_id']
        ctxt = context.RequestContext(user, tenant)

        # Find all global scope filesystems
        #  and all project-scope systems that are
        #  associated with this project.
        fs_list = []
        db_fs_list = sharedfs_db.filesystem_list(ctxt)
        for fs_name in db_fs_list:
            fs = sharedfs_db.filesystem_get(ctxt, fs_name)
            if not fs:
                LOG.debug(_("Database inconsistency:  no record for FS %s") %
                          fs_name)
                continue
            if fs.scope == 'global':
                fs_list.append(fs_name)
            elif fs.scope == 'project' and fs.project_id == tenant:
                fs_list.append(fs_name)

        for fs_name in fs_list:
            if event_type == 'compute.instance.delete.start':
                self.unattach(ctxt, instance, fs_name)
            elif event_type == 'compute.instance.create.end':
                self.attach(ctxt, instance, fs_name)