def create_tenant_on_region(self, team_name, region_name): tenant = team_repo.get_team_by_team_name(team_name) if not tenant: return 404, u"需要开通的团队{0}不存在".format(team_name), None region_config = region_repo.get_region_by_region_name(region_name) if not region_config: return 404, u"需要开通的数据中心{0}不存在".format(region_name), None tenant_region = region_repo.get_team_region_by_tenant_and_region(tenant.tenant_id, region_name) if not tenant_region: tenant_region_info = {"tenant_id": tenant.tenant_id, "region_name": region_name, "is_active": False} tenant_region = region_repo.create_tenant_region(**tenant_region_info) if not tenant_region.is_init: res, body = region_api.create_tenant(region_name, tenant.tenant_name, tenant.tenant_id, tenant.enterprise_id) if res["status"] != 200: return res["status"], u"数据中心创建租户失败", None tenant_region.is_active = True tenant_region.is_init = True # TODO 将从数据中心获取的租户信息记录到tenant_region, 当前只是用tenant的数据填充 tenant_region.region_tenant_id = tenant.tenant_id tenant_region.region_tenant_name = tenant.tenant_name tenant_region.region_scope = region_config.scope tenant_region.enterprise_id = tenant.enterprise_id tenant_region.save() else: if (not tenant_region.region_tenant_id) or \ (not tenant_region.region_tenant_name) or \ (not tenant_region.enterprise_id): tenant_region.region_tenant_id = tenant.tenant_id tenant_region.region_tenant_name = tenant.tenant_name tenant_region.region_scope = region_config.scope tenant_region.enterprise_id = tenant.enterprise_id tenant_region.save() group_repo.get_or_create_default_group(tenant.tenant_id, region_name) return 200, u"success", tenant_region
def create_tenant_on_region(self, team_name, region_name): tenant = team_repo.get_team_by_team_name(team_name) if not tenant: return 404, u"需要开通的团队{0}不存在".format(team_name), None region_config = region_repo.get_region_by_region_name(region_name) if not region_config: return 404, u"需要开通的数据中心{0}不存在".format(region_name), None if region_config.scope == "public": logger.debug("open public region {0} ".format(region_name)) is_pass = self.get_enterprise_region_token_from_market( tenant.tenant_id, tenant.enterprise_id, region_name, region_config.url) if not is_pass: return 500, u"数据中心访问token获取异常", None tenant_region = region_repo.get_team_region_by_tenant_and_region( tenant.tenant_id, region_name) if not tenant_region: tenant_region_info = { "tenant_id": tenant.tenant_id, "region_name": region_name, "is_active": False } tenant_region = region_repo.create_tenant_region( **tenant_region_info) if not tenant_region.is_init: res, body = region_api.create_tenant(region_name, tenant.tenant_name, tenant.tenant_id, tenant.enterprise_id) logger.debug("create region tenant : res, {0}, body {1}".format( res, body)) tenant_region.is_active = True tenant_region.is_init = True # TODO 将从数据中心获取的租户信息记录到tenant_region, 当前只是用tenant的数据填充 tenant_region.region_tenant_id = tenant.tenant_id tenant_region.region_tenant_name = tenant.tenant_name tenant_region.region_scope = region_config.scope tenant_region.enterprise_id = tenant.enterprise_id tenant_region.save() else: if (not tenant_region.region_tenant_id) or \ (not tenant_region.region_tenant_name) or \ (not tenant_region.enterprise_id): tenant_region.region_tenant_id = tenant.tenant_id tenant_region.region_tenant_name = tenant.tenant_name tenant_region.region_scope = region_config.scope tenant_region.enterprise_id = tenant.enterprise_id tenant_region.save() group_repo.get_or_create_default_group(tenant.tenant_id, region_name) return 200, u"success", tenant_region
def create_tenant_on_region(self, enterprise_id, team_name, region_name): tenant = team_repo.get_team_by_team_name_and_eid( enterprise_id, team_name) region_config = region_repo.get_enterprise_region_by_region_name( enterprise_id, region_name) if not region_config: raise ServiceHandleException(msg="cluster not found", msg_show="需要开通的集群不存在") tenant_region = region_repo.get_team_region_by_tenant_and_region( tenant.tenant_id, region_name) if not tenant_region: tenant_region_info = { "tenant_id": tenant.tenant_id, "region_name": region_name, "is_active": False } tenant_region = region_repo.create_tenant_region( **tenant_region_info) if not tenant_region.is_init: res, body = region_api.create_tenant(region_name, tenant.tenant_name, tenant.tenant_id, tenant.enterprise_id) if res["status"] != 200 and body[ 'msg'] != 'tenant name {} is exist'.format( tenant.tenant_name): logger.error(res) raise ServiceHandleException(msg="cluster init failure ", msg_show="集群初始化租户失败") tenant_region.is_active = True tenant_region.is_init = True tenant_region.region_tenant_id = tenant.tenant_id tenant_region.region_tenant_name = tenant.tenant_name tenant_region.region_scope = region_config.scope tenant_region.enterprise_id = tenant.enterprise_id tenant_region.save() else: if (not tenant_region.region_tenant_id) or \ (not tenant_region.region_tenant_name) or \ (not tenant_region.enterprise_id): tenant_region.region_tenant_id = tenant.tenant_id tenant_region.region_tenant_name = tenant.tenant_name tenant_region.region_scope = region_config.scope tenant_region.enterprise_id = tenant.enterprise_id tenant_region.save() group_repo.get_or_create_default_group(tenant.tenant_id, region_name) return tenant_region
def create_new_tenant_region(self, tenant, region_name): tenant_region_info = { "tenant_id": tenant.tenant_id, "region_name": region_name } tenant_region = region_repo.create_tenant_region(**tenant_region_info) res, body = region_api.create_tenant(region_name, tenant.tenant_name, tenant.tenant_id, tenant.enterprise_id) logger.debug("create region tenant : res, {0}, body {1}".format( res, body)) tenant_region.is_active = True tenant_region.is_init = True # TODO 将从数据中心获取的租户信息记录到tenant_region, 当前只是用tenant的数据填充 tenant_region.region_tenant_id = tenant.tenant_id tenant_region.region_tenant_name = tenant.tenant_name tenant_region.region_scope = 'public' tenant_region.enterprise_id = tenant.enterprise_id tenant_region.save() return tenant_region