コード例 #1
0
 def new_tenant(self, tenant_name, tenant_description):
     # '''Adds a new tenant to VIM with this name and description, returns the tenant identifier'''
     try:
         client = oca.Client(self.user + ':' + self.passwd, self.url)
         group_list = oca.GroupPool(client)
         user_list = oca.UserPool(client)
         group_list.info()
         user_list.info()
         create_primarygroup = 1
         # create group-tenant
         for group in group_list:
             if str(group.name) == str(tenant_name):
                 create_primarygroup = 0
                 break
         if create_primarygroup == 1:
             oca.Group.allocate(client, tenant_name)
         group_list.info()
         # set to primary_group the tenant_group and oneadmin to secondary_group
         for group in group_list:
             if str(group.name) == str(tenant_name):
                 for user in user_list:
                     if str(user.name) == str(self.user):
                         if user.name == "oneadmin":
                             return str(0)
                         else:
                             self._add_secondarygroup(user.id, group.id)
                             user.chgrp(group.id)
                             return str(group.id)
     except Exception as e:
         self.logger.error("Create new tenant error: " + str(e))
         raise vimconn.vimconnException(e)
コード例 #2
0
 def delete_tenant(self, tenant_id):
     """Delete a tenant from VIM. Returns the old tenant identifier"""
     try:
         client = oca.Client(self.user + ':' + self.passwd, self.url)
         group_list = oca.GroupPool(client)
         user_list = oca.UserPool(client)
         group_list.info()
         user_list.info()
         for group in group_list:
             if str(group.id) == str(tenant_id):
                 for user in user_list:
                     if str(user.name) == str(self.user):
                         self._delete_secondarygroup(user.id, group.id)
                         group.delete(client)
                 return None
         raise vimconn.vimconnNotFoundException("Group {} not found".format(tenant_id))
     except Exception as e:
         self.logger.error("Delete tenant " + str(tenant_id) + " error: " + str(e))
         raise vimconn.vimconnException(e)
コード例 #3
0
ファイル: test_group_pool.py プロジェクト: zwopir/python-oca
 def test_info(self):
     self.client.call = Mock(return_value=self.xml)
     pool = oca.GroupPool(self.client)
     pool.info()
     assert len(pool) == 2