コード例 #1
0
def tenant_delete(tenant_name):
    flag = False
    uuid = None
    try:
        tenant_id = getTenantID(tenant_name)
        tenant_uuid = getTenantOSID(tenant_name)
        userRole = getUserRoleInTenant(tenant_id)
        # print userRole
        id_list = ''
        for i in range(len(userRole)):
            id_list = id_list + str(userRole[i][0]) + ','
            # print 'enter remove_tenant_user_role'
            keystone.remove_tenant_user_role(
                tenant_uuid, str(getUserIDInOSByID(userRole[i][1])),
                str(getRoleIDInOSByID(userRole[i][2])))
        # print 'enter tenant_delete'
        keystone.tenant_delete(tenant_uuid)
    except:
        logging.getLogger('operate').log(
            30,
            'DAOZO tenant delete %s %s %s failed.' % (tenant_name, id, uuid))
        flag = False
    else:
        try:
            cursor = get_cursor()
            sql1 = '''update t_turMap set delete_at = '%s' where t_turMap.id in (%s) ''' % (
                time.strftime('%Y-%m-%d %X', time.localtime()), id_list[:-1])
            # print sql1
            sql2 = '''update t_tenant set delete_at = '%s' where t_tenant.id=%s ''' % (
                time.strftime('%Y-%m-%d %X', time.localtime()), tenant_id)
            # print sql2
            cursor.execute(sql1)
            cursor.execute(sql2)
        except:
            logging.getLogger('operate').log(
                30, 'DAOZO tenant delete %s %s %s failed.' %
                (tenant_name, id, uuid))
            flag = False
        else:
            logging.getLogger('operate').log(
                20, 'DAOZO tenant delete %s %s %s successful.' %
                (tenant_name, id, uuid))
            flag = True
        finally:
            pass
    finally:
        pass
    return flag
コード例 #2
0
def tenant_create2(owner_loginName, tenant_name, tenant_desc):
    cursor = get_cursor()
    uuid = ''
    flag = False
    try:
        tenant = keystone.tenant_create(tenant_name, tenant_desc)
        uuid = keystone.get_baseID(tenant)
        res = keystone.add_tenant_user_role(
            uuid, str(getUserIDInOS(owner_loginName)),
            str(getRoleIDInOS('owner')))
    except:
        logging.getLogger('operate').log(
            30, 'tenant create %s %s %s keystone failed.' %
            (owner_loginName, tenant_name, tenant_desc))
        keystone.remove_tenant_user_role(uuid,
                                         str(getUserIDInOS(owner_loginName)),
                                         str(getRoleIDInOS('owner')))
        keystone.tenant_delete(uuid)
    else:
        try:
            sql = '''insert into t_tenant values (null,'%s','%s','%s',%d,'%s',null) ''' % (
                uuid, tenant_name, tenant_desc, getUserID(owner_loginName),
                time.strftime('%Y-%m-%d %X', time.localtime()))
            cursor.execute(sql)
            sql2 = '''insert into t_turMap values (null,%d,%d,%d,'%s','%s',null) ''' % (
                getTenantID(tenant_name), getUserID(owner_loginName),
                getRoleID('owner'), tenant_desc,
                time.strftime('%Y-%m-%d %X', time.localtime()))
            cursor.execute(sql2)
        except:
            logging.getLogger('operate').log(
                30, 'tenant create %s %s %s sql failed.' %
                (owner_loginName, tenant_name, tenant_desc))
            flag = False
            # transcation.rollback()
        else:
            logging.getLogger('operate').log(
                20, 'tenant create %s %s %s successed.' %
                (owner_loginName, tenant_name, tenant_desc))
            flag = True
            # transcation.commit()
        finally:
            pass
    finally:
        pass
    return flag
コード例 #3
0
ファイル: daozo.py プロジェクト: honj51/dataservice2
def tenant_delete(tenant_name):
    flag = False
    uuid = None
    try:
        tenant_id = getTenantID(tenant_name)
        tenant_uuid = getTenantOSID(tenant_name)
        userRole = getUserRoleInTenant(tenant_id)
        # print userRole
        id_list = ''
        for i in range(len(userRole)):
            id_list = id_list + str(userRole[i][0]) + ','
            # print 'enter remove_tenant_user_role'
            keystone.remove_tenant_user_role(tenant_uuid, str(getUserIDInOSByID(userRole[i][1])),
                str(getRoleIDInOSByID(userRole[i][2])))
        # print 'enter tenant_delete'
        keystone.tenant_delete(tenant_uuid)
    except:
        logging.getLogger('operate').log(30, 'DAOZO tenant delete %s %s %s failed.' % (
            tenant_name, id, uuid))
        flag = False
    else:
        try:
            cursor = get_cursor()
            sql1 = '''update t_turMap set delete_at = '%s' where t_turMap.id in (%s) ''' % (
                time.strftime('%Y-%m-%d %X', time.localtime()), id_list[:-1])
            # print sql1
            sql2 = '''update t_tenant set delete_at = '%s' where t_tenant.id=%s ''' % (
                time.strftime('%Y-%m-%d %X', time.localtime()), tenant_id)
            # print sql2
            cursor.execute(sql1)
            cursor.execute(sql2)
        except:
            logging.getLogger('operate').log(30, 'DAOZO tenant delete %s %s %s failed.' % (
                tenant_name, id, uuid))
            flag = False
        else:
            logging.getLogger('operate').log(20, 'DAOZO tenant delete %s %s %s successful.' % (
                tenant_name, id, uuid))
            flag = True
        finally:
            pass
    finally:
        pass
    return flag
コード例 #4
0
ファイル: daozo.py プロジェクト: honj51/dataservice2
def tenant_create2(owner_loginName, tenant_name, tenant_desc):
   cursor = get_cursor()
   uuid = ''
   flag = False
   try:
       tenant = keystone.tenant_create(tenant_name, tenant_desc)
       uuid = keystone.get_baseID(tenant)
       res = keystone.add_tenant_user_role(uuid, str(getUserIDInOS(owner_loginName)), str(getRoleIDInOS('owner')))
   except:
       logging.getLogger('operate').log(30, 'tenant create %s %s %s keystone failed.' % (owner_loginName, tenant_name, tenant_desc))
       keystone.remove_tenant_user_role(uuid, str(getUserIDInOS(owner_loginName)), str(getRoleIDInOS('owner')))
       keystone.tenant_delete(uuid)
   else:
       try:
           sql = '''insert into t_tenant values (null,'%s','%s','%s',%d,'%s',null) ''' % (
                   uuid, tenant_name, tenant_desc, getUserID(owner_loginName),
                   time.strftime('%Y-%m-%d %X', time.localtime()))
           cursor.execute(sql)
           sql2 = '''insert into t_turMap values (null,%d,%d,%d,'%s','%s',null) ''' % (
                   getTenantID(tenant_name), getUserID(owner_loginName), getRoleID('owner'),
                   tenant_desc, time.strftime('%Y-%m-%d %X', time.localtime()))
           cursor.execute(sql2)
       except:
           logging.getLogger('operate').log(30, 'tenant create %s %s %s sql failed.' % (
                   owner_loginName, tenant_name, tenant_desc))
           flag = False
           # transcation.rollback()
       else:
           logging.getLogger('operate').log(20, 'tenant create %s %s %s successed.' % (
                   owner_loginName, tenant_name, tenant_desc))
           flag = True
           # transcation.commit()
       finally:
           pass
   finally:
       pass
   return flag
コード例 #5
0
def tenant_del_user(tenant, user, role):
    # print tenant
    # print base.getTenantIDByName(tenant)
    # print base.getTenantOSIDByName(tenant)
    # print user
    # print base.getUserIDByName(user)
    # print base.getUserOSIDByName(user)
    # print role
    # print base.getRoleOSIDByID(role)
    flag = False
    try:
        res = keystone.remove_tenant_user_role(
            str(base.getTenantOSIDByName(tenant)),
            str(base.getUserOSIDByName(user)),
            str(base.getRoleOSIDByName(role)))
    except:
        print 'keystone tenant del user failed.'
    else:
        flag = True
        print 'keystone tenant del user successful.'
        try:
            cursor = base.get_cursor()
            sql = '''UPDATE t_turMap set delete_at='%s'
                where tenant=%d 
                and user=%d 
                and role=%d 
                and delete_at is NULL ''' % (time.strftime(
                '%Y-%m-%d %X',
                time.localtime()), int(base.getTenantIDByName(tenant)),
                                             int(base.getUserIDByName(user)),
                                             int(base.getRoleIDByName(role)))
            print sql
            cursor.execute(sql)
        except:
            print 'sql tenant del user failed.'
            flag = False
        else:
            print 'sql tenant del user successful.'
            flag = True
    finally:
        return flag
コード例 #6
0
ファイル: daozo.py プロジェクト: honj51/dataservice2
def tenant_del_user(tenant, user, role):
    # print tenant
    # print base.getTenantIDByName(tenant)
    # print base.getTenantOSIDByName(tenant)
    # print user
    # print base.getUserIDByName(user)
    # print base.getUserOSIDByName(user)
    # print role
    # print base.getRoleOSIDByID(role)
    flag = False
    try:
        res = keystone.remove_tenant_user_role(str(base.getTenantOSIDByName(tenant)),
            str(base.getUserOSIDByName(user)), str(base.getRoleOSIDByName(role)))
    except:
        print 'keystone tenant del user failed.'
    else:
        flag = True
        print 'keystone tenant del user successful.'
        try:
            cursor = base.get_cursor()
            sql = '''UPDATE t_turMap set delete_at='%s'
                where tenant=%d 
                and user=%d 
                and role=%d 
                and delete_at is NULL ''' % (time.strftime('%Y-%m-%d %X', time.localtime()),
                    int(base.getTenantIDByName(tenant)), int(base.getUserIDByName(user)), int(base.getRoleIDByName(role)))
            print sql
            cursor.execute(sql)
        except:
            print 'sql tenant del user failed.'
            flag = False
        else:
            print 'sql tenant del user successful.'
            flag = True
    finally:
        return flag