def tearDown(self):
     print("teardown")
     users = oca.UserPool(self.c)
     users.info()
     for user in users:
         if user.name.startswith('inttest_user_'):
             user.delete()
Beispiel #2
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)
Beispiel #3
0
 def _get_user_pool(self):
     try:
         user_pool = oca.UserPool(self.oneadmin_client)
         user_pool.info()
     except ConnectionRefusedError:
         logger.info(
             'Could not connect to host: {host} via protocol {protocol}'.
             format(host=settings.OPENNEBULA_DOMAIN,
                    protocol=settings.OPENNEBULA_PROTOCOL))
         raise
     return user_pool
 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)
Beispiel #5
0
 def test_delete(self):
     vns = oca.UserPool(self.c)
     vns.info()
     for vn in vns:
         if vn.name.startswith('inttest'):
             vn.delete()
Beispiel #6
0
 def test_publish(self):
     vns = oca.UserPool(self.c)
     vns.info()
     for vn in vns:
         if vn.name.startswith('inttest'):
             vn.publish(0, -1)
Beispiel #7
0
 def test_chown(self):
     vns = oca.UserPool(self.c)
     vns.info()
     for vn in vns:
         if vn.name.startswith('inttest'):
             vn.chown(0, -1)
 def test_delete(self):
     users = oca.UserPool(self.c)
     users.info()
     for user in users:
         if user.name.startswith('inttest_user_'):
             user.delete()
 def test_chgrp(self):
     users = oca.UserPool(self.c)
     users.info()
     for user in users:
         if user.name.startswith('inttest_user_'):
             user.chgrp(0)
 def test_change_passwd(self):
     users = oca.UserPool(self.c)
     users.info()
     for user in users:
         if user.name.startswith('inttest_user_'):
             user.change_passwd('new_password')
Beispiel #11
0
 def test_info(self):
     self.client.call = Mock(return_value=self.xml)
     pool = oca.UserPool(self.client)
     pool.info()
     assert len(pool) == 2