Exemplo n.º 1
0
def tenant_add_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.add_tenant_user_role(
            str(base.getTenantOSIDByName(tenant)),
            str(base.getUserOSIDByName(user)), str(base.getRoleOSIDByID(role)))
    except:
        print 'keystone tenant add user failed.'
    else:
        flag = True
        print 'keystone tenant add user successful.'
        try:
            cursor = base.get_cursor()
            sql = '''INSERT into t_turMap VALUES (NULL,%d,%d,%d,NULL,'%s',NULL)''' % (
                int(base.getTenantIDByName(tenant)),
                int(base.getUserIDByName(user)), int(role),
                time.strftime('%Y-%m-%d %X', time.localtime()))
            print sql
            cursor.execute(sql)
        except:
            print 'sql tenant add user failed.'
            flag = False
        else:
            print 'sql tenant add user successful.'
            flag = True
    finally:
        return flag
Exemplo n.º 2
0
def tenant_add_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.add_tenant_user_role(str(base.getTenantOSIDByName(tenant)),
            str(base.getUserOSIDByName(user)), str(base.getRoleOSIDByID(role)))
    except:
        print 'keystone tenant add user failed.'
    else:
        flag = True
        print 'keystone tenant add user successful.'
        try:
            cursor = base.get_cursor()
            sql = '''INSERT into t_turMap VALUES (NULL,%d,%d,%d,NULL,'%s',NULL)''' % (
                    int(base.getTenantIDByName(tenant)), int(base.getUserIDByName(user)), int(role),
                    time.strftime('%Y-%m-%d %X', time.localtime()))
            print sql
            cursor.execute(sql)
        except:
            print 'sql tenant add user failed.'
            flag = False
        else:
            print 'sql tenant add user successful.'
            flag = True
    finally:
        return flag
Exemplo n.º 3
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
Exemplo n.º 4
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