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
def getTenantCountOfUser(user_name): sql = '''select count(*) from t_turMap where t_turMap.user = %d and t_turMap.delete_at is NULL''' % (base.getUserIDByName(user_name)) cursor = base.get_cursor() cursor.execute(sql) res = cursor.fetchall() return res[0][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
def getTenantCountOfUser(user_name): sql = '''select count(*) from t_turMap where t_turMap.user = %d and t_turMap.delete_at is NULL''' % ( base.getUserIDByName(user_name)) cursor = base.get_cursor() cursor.execute(sql) res = cursor.fetchall() return res[0][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
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