Пример #1
0
 def create_vim(self, context, vim):
     self._validate_default_vim(context, vim)
     vim_cred = vim['auth_cred']
     if not self._does_already_exist(context, vim):
         with context.session.begin(subtransactions=True):
             vim_db = Vim(
                 id=vim.get('id'),
                 type=vim.get('type'),
                 tenant_id=vim.get('tenant_id'),
                 name=vim.get('name'),
                 description=vim.get('description'),
                 placement_attr=vim.get('placement_attr'),
                 is_default=vim.get('is_default'),
                 status=vim.get('status'))
             context.session.add(vim_db)
             vim_auth_db = VimAuth(
                 id=str(uuid.uuid4()),
                 vim_id=vim.get('id'),
                 password=vim_cred.pop('password'),
                 vim_project=vim.get('vim_project'),
                 auth_url=vim.get('auth_url'),
                 auth_cred=vim_cred)
             context.session.add(vim_auth_db)
     else:
             raise nfvo.VimDuplicateUrlException()
     vim_dict = self._make_vim_dict(vim_db)
     self._cos_db_plg.create_event(
         context, res_id=vim_dict['id'],
         res_type=constants.RES_TYPE_VIM,
         res_state=vim_dict['status'],
         evt_type=constants.RES_EVT_CREATE,
         tstamp=vim_dict['created_at'])
     return vim_dict
Пример #2
0
 def create_vim(self, context, vim):
     vim_cred = vim['auth_cred']
     try:
         with context.session.begin(subtransactions=True):
             vim_db = Vim(id=vim.get('id'),
                          type=vim.get('type'),
                          tenant_id=vim.get('tenant_id'),
                          name=vim.get('name'),
                          description=vim.get('description'),
                          placement_attr=vim.get('placement_attr'))
             context.session.add(vim_db)
             vim_auth_db = VimAuth(id=str(uuid.uuid4()),
                                   vim_id=vim.get('id'),
                                   password=vim_cred.pop('password'),
                                   vim_project=vim.get('vim_project'),
                                   auth_url=vim.get('auth_url'),
                                   auth_cred=vim_cred)
             context.session.add(vim_auth_db)
     except exception.DBDuplicateEntry:
         raise nfvo.VimDuplicateUrlException()
     return self._make_vim_dict(vim_db)