Esempio n. 1
0
    def get_vim(self, context, vim_id=None, region_name=None):
        """Get Vim information for provided VIM id

        Initiate the NFVO plugin, request VIM information for the provided
        VIM id and validate region
        """
        nfvo_plugin = manager.TackerManager.get_service_plugins().get(
            constants.NFVO)

        if not vim_id:
            LOG.debug(_('VIM id not provided. Attempting to find default '
                        'VIM id'))
            vim_name = cfg.CONF.nfvo_vim.default_vim
            if not vim_name:
                raise nfvo.VimDefaultNameNotDefined()
            try:
                vim_info = nfvo_plugin.get_vim_by_name(context, vim_name)
            except Exception:
                    raise nfvo.VimDefaultIdException(
                        vim_name=vim_name)
        else:
            try:
                vim_info = nfvo_plugin.get_vim(context, vim_id)
            except Exception:
                raise nfvo.VimNotFoundException(vim_id=vim_id)
        LOG.debug(_('VIM info found for vim id %s'), vim_id)
        if region_name and not self.region_valid(vim_info['placement_attr']
                                                 ['regions'], region_name):
            raise nfvo.VimRegionNotFoundException(region_name=region_name)

        vim_auth = self._build_vim_auth(vim_info)
        vim_res = {'vim_auth': vim_auth, 'vim_id': vim_info['id'],
                   'vim_name': vim_info.get('name', vim_info['id'])}
        return vim_res
Esempio n. 2
0
    def get_vim(self, context, vim_id=None, region_name=None):
        """Get Vim information for provided VIM id

        Initiate the NFVO plugin, request VIM information for the provided
        VIM id and validate region
        """
        nfvo_plugin = manager.TackerManager.get_service_plugins().get(
            constants.NFVO)

        if not vim_id:
            LOG.debug('VIM id not provided. Attempting to find default '
                      'VIM information')
            try:
                vim_info = nfvo_plugin.get_default_vim(context)
            except Exception as ex:
                LOG.debug('Fail to get default vim due to %s', ex)
                raise nfvo.VimDefaultNotDefined()
        else:
            try:
                vim_info = nfvo_plugin.get_vim(context, vim_id,
                                               mask_password=False)
            except Exception:
                raise nfvo.VimNotFoundException(vim_id=vim_id)
        LOG.debug('VIM info found for vim id %s', vim_id)
        if region_name and not self.region_valid(vim_info['placement_attr']
                                                 ['regions'], region_name):
            raise nfvo.VimRegionNotFoundException(region_name=region_name)

        vim_auth = self._build_vim_auth(context, vim_info)
        vim_res = {'vim_auth': vim_auth, 'vim_id': vim_info['id'],
                   'vim_name': vim_info.get('name', vim_info['id']),
                   'vim_type': vim_info['type']}
        return vim_res
Esempio n. 3
0
    def update_vim(self, context, vim_id, vim):
        self._validate_default_vim(context, vim, vim_id=vim_id)
        with context.session.begin(subtransactions=True):
            vim_cred = vim['auth_cred']
            vim_project = vim['vim_project']
            is_default = vim.get('is_default')
            vim_db = self._get_resource(context, Vim, vim_id)
            try:
                if is_default:
                    vim_db.update({'is_default': is_default})
                vim_auth_db = (self._model_query(context, VimAuth).filter(
                    VimAuth.vim_id == vim_id).with_lockmode('update').one())
            except orm_exc.NoResultFound:
                    raise nfvo.VimNotFoundException(vim_id=vim_id)
            vim_auth_db.update({'auth_cred': vim_cred, 'password':
                               vim_cred.pop('password'), 'vim_project':
                               vim_project})
            vim_db.update({'updated_at': timeutils.utcnow()})
            self._cos_db_plg.create_event(
                context, res_id=vim_db['id'],
                res_type=constants.RES_TYPE_VIM,
                res_state=vim_db['status'],
                evt_type=constants.RES_EVT_UPDATE,
                tstamp=vim_db[constants.RES_EVT_UPDATED_FLD])

        return self.get_vim(context, vim_id)
Esempio n. 4
0
 def _get_resource(self, context, model, id):
     try:
         return self._get_by_id(context, model, id)
     except orm_exc.NoResultFound:
         if issubclass(model, Vim):
             raise nfvo.VimNotFoundException(vim_id=id)
         else:
             raise
Esempio n. 5
0
 def update_vim_status(self, context, vim_id, status):
     with context.session.begin(subtransactions=True):
         try:
             vim_db = (self._model_query(context, Vim).filter(
                 Vim.id == vim_id).with_lockmode('update').one())
         except orm_exc.NoResultFound:
             raise nfvo.VimNotFoundException(vim_id=vim_id)
         vim_db.update({'status': status, 'updated_at': timeutils.utcnow()})
     return self._make_vim_dict(vim_db)
Esempio n. 6
0
    def _decode_vim_auth(self, vim_id, cred):
        """Decode Vim credentials

        Decrypt VIM cred. using Fernet Key
        """
        vim_key = self._find_vim_key(vim_id)
        f = fernet.Fernet(vim_key)
        if not f:
            LOG.warning(_('Unable to decode VIM auth'))
            raise nfvo.VimNotFoundException('Unable to decode VIM auth key')
        return f.decrypt(cred)
Esempio n. 7
0
 def update_vim(self, context, vim_id, vim):
     with context.session.begin(subtransactions=True):
         vim_cred = vim['auth_cred']
         vim_project = vim['vim_project']
         try:
             vim_auth_db = (self._model_query(context, VimAuth).filter(
                 VimAuth.vim_id == vim_id).with_lockmode('update').one())
         except orm_exc.NoResultFound:
             raise nfvo.VimNotFoundException(vim_id=vim_id)
         vim_auth_db.update({
             'auth_cred': vim_cred,
             'password': vim_cred.pop('password'),
             'vim_project': vim_project
         })
     return self.get_vim(context, vim_id)
Esempio n. 8
0
 def update_vim_status(self, context, vim_id, status):
     with context.session.begin(subtransactions=True):
         try:
             vim_db = (self._model_query(context, Vim).filter(
                 Vim.id == vim_id).with_lockmode('update').one())
         except orm_exc.NoResultFound:
             raise nfvo.VimNotFoundException(vim_id=vim_id)
         vim_db.update({'status': status})
         self._cos_db_plg.create_event(context,
                                       res_id=vim_db['id'],
                                       res_type=constants.RES_TYPE_VIM,
                                       res_state=vim_db['status'],
                                       evt_type=constants.RES_EVT_UPDATE,
                                       tstamp=timeutils.utcnow())
     return self._make_vim_dict(vim_db)
Esempio n. 9
0
    def get_vim(self, context, vim_id=None, region_name=None):
        """Get Vim information for provided VIM id

        Initiate the NFVO plugin, request VIM information for the provided
        VIM id and validate region
        """
        nfvo_plugin = manager.TackerManager.get_service_plugins().get(
            constants.NFVO)

        if not vim_id:
            LOG.debug(
                _('VIM id not provided. Attempting to find default '
                  'VIM information'))
            try:
                vim_info = nfvo_plugin.get_default_vim(context)
            except Exception:
                LOG.debug(
                    _('Default vim not set in db.'
                      'Attempting to find default vim from tacker.conf'))
                vim_name = cfg.CONF.nfvo_vim.default_vim
                if not vim_name:
                    raise nfvo.VimDefaultNameNotDefined()
                versionutils.report_deprecated_feature(
                    LOG, 'Configuration of '
                    'default-vim in tacker.conf is deprecated and will be '
                    'removed in Newton cycle')
                vim_info = self._get_default_vim_by_name(
                    context, nfvo_plugin, vim_name)
        else:
            try:
                vim_info = nfvo_plugin.get_vim(context,
                                               vim_id,
                                               mask_password=False)
            except Exception:
                raise nfvo.VimNotFoundException(vim_id=vim_id)
        LOG.debug(_('VIM info found for vim id %s'), vim_id)
        if region_name and not self.region_valid(
                vim_info['placement_attr']['regions'], region_name):
            raise nfvo.VimRegionNotFoundException(region_name=region_name)

        vim_auth = self._build_vim_auth(vim_info)
        vim_res = {
            'vim_auth': vim_auth,
            'vim_id': vim_info['id'],
            'vim_name': vim_info.get('name', vim_info['id']),
            'vim_type': vim_info['type']
        }
        return vim_res
Esempio n. 10
0
    def _decode_vim_auth(self, context, vim_id, auth):
        """Decode Vim credentials

        Decrypt VIM cred, get fernet Key from local_file_system or
        barbican.
        """
        cred = auth['password'].encode('utf-8')
        if auth.get('key_type') == 'barbican_key':
            keystone_conf = CONF.keystone_authtoken
            secret_uuid = auth['secret_uuid']
            keymgr_api = KEYMGR_API(keystone_conf.auth_url)
            secret_obj = keymgr_api.get(context, secret_uuid)
            vim_key = secret_obj.payload
        else:
            vim_key = self._find_vim_key(vim_id)

        f = fernet.Fernet(vim_key)
        if not f:
            LOG.warning('Unable to decode VIM auth')
            raise nfvo.VimNotFoundException('Unable to decode VIM auth key')
        return f.decrypt(cred)
 def update_vim(self, context, vim_id, status):
     t_admin_context = t_context.get_admin_context()
     update_time = timeutils.utcnow()
     with t_admin_context.session.begin(subtransactions=True):
         try:
             query = t_admin_context.session.query(nfvo_db.Vim)
             query.filter(
                 nfvo_db.Vim.id == vim_id).update(
                     {'status': status,
                      'updated_at': update_time})
         except orm_exc.NoResultFound:
             raise nfvo.VimNotFoundException(vim_id=vim_id)
         event_db = common_services_db.Event(
             resource_id=vim_id,
             resource_type=constants.RES_TYPE_VIM,
             resource_state=status,
             event_details="",
             event_type=constants.RES_EVT_MONITOR,
             timestamp=update_time)
         t_admin_context.session.add(event_db)
     return status