def test_list_by_svc_share_uuids(): tenant_id = "6d1c06e1d9e84d57aeb42ea80d49018a" service_id = "560ca84003254737a426d0bd5f513afd" service_cname = "WordPress" group_id = 20 service = TenantServiceInfo() service.tenant_id = tenant_id service.service_id = service_id service.service_cname = service_cname service.save() service_source = ServiceSourceInfo() service_source.team_id = tenant_id service_source.service_id = service_id service_source.service_share_uuid = "2669c2cec6bc7bf5aab29a0ea2703d66" service_source.save() group_relation = ServiceGroupRelation() group_relation.service_id = service_id group_relation.group_id = group_id group_relation.save() from console.repositories.app import service_repo result = service_repo.list_by_svc_share_uuids( group_id, ["2669c2cec6bc7bf5aab29a0ea2703d66"]) service = result[0] assert service.get("service_id") == service_id assert service.get("service_cname") == service_cname
def __init_market_app(self, tenant, region, user, app, tenant_service_group_id, service_origin): """ 初始化应用市场创建的应用默认数据 """ is_slug = bool(app["image"].startswith('goodrain.me/runner') and app["language"] not in ("dockerfile", "docker")) tenant_service = TenantServiceInfo() tenant_service.tenant_id = tenant.tenant_id tenant_service.service_id = make_uuid() tenant_service.service_cname = app_service.generate_service_cname( tenant, app["service_cname"], region) tenant_service.service_alias = "gr" + tenant_service.service_id[-6:] tenant_service.creater = user.pk if is_slug: tenant_service.image = app["image"] else: tenant_service.image = app.get("share_image", app["image"]) tenant_service.cmd = app.get("cmd", "") tenant_service.service_region = region tenant_service.service_key = app["service_key"] tenant_service.desc = "market app " tenant_service.category = "app_publish" tenant_service.setting = "" tenant_service.extend_method = app["extend_method"] tenant_service.env = "," tenant_service.min_node = app["extend_method_map"]["min_node"] tenant_service.min_memory = app["extend_method_map"]["min_memory"] tenant_service.min_cpu = baseService.calculate_service_cpu( region, tenant_service.min_memory) tenant_service.inner_port = 0 tenant_service.version = app["version"] if is_slug: if app.get("service_slug", None): tenant_service.namespace = app["service_slug"]["namespace"] else: if app.get("service_image", None): tenant_service.namespace = app["service_image"]["namespace"] tenant_service.update_version = 1 tenant_service.port_type = "multi_outer" tenant_service.create_time = datetime.now().strftime( '%Y-%m-%d %H:%M:%S') tenant_service.deploy_version = "" tenant_service.git_project_id = 0 tenant_service.service_type = "application" tenant_service.total_memory = tenant_service.min_node * tenant_service.min_memory tenant_service.volume_mount_path = "" tenant_service.host_path = "" tenant_service.code_from = "" tenant_service.language = "" tenant_service.service_source = "market" tenant_service.create_status = "creating" tenant_service.service_origin = service_origin tenant_service.tenant_service_group_id = tenant_service_group_id self.__init_service_source(tenant_service, app) # 存储并返回 tenant_service.save() return tenant_service
def create_service(self, service_id, tenant_id, service_alias, service, creater, region, service_origin='assistant'): """创建console服务""" tenantServiceInfo = {} tenantServiceInfo["service_id"] = service_id tenantServiceInfo["tenant_id"] = tenant_id tenantServiceInfo["service_key"] = service.service_key tenantServiceInfo["service_alias"] = service_alias tenantServiceInfo["service_cname"] = service_alias tenantServiceInfo["service_region"] = region tenantServiceInfo["desc"] = service.desc tenantServiceInfo["category"] = service.category tenantServiceInfo["image"] = service.image tenantServiceInfo["cmd"] = service.cmd tenantServiceInfo["setting"] = service.setting tenantServiceInfo["extend_method"] = service.extend_method tenantServiceInfo["env"] = service.env tenantServiceInfo["min_node"] = service.min_node tenantServiceInfo["min_cpu"] = service.min_cpu tenantServiceInfo["min_memory"] = service.min_memory tenantServiceInfo["inner_port"] = service.inner_port tenantServiceInfo["version"] = service.version tenantServiceInfo["namespace"] = service.namespace tenantServiceInfo["update_version"] = service.update_version volume_path = "" host_path = "" if bool(service.volume_mount_path): volume_path = service.volume_mount_path host_path = "/grdata/tenant/" + tenant_id + "/service/" + service_id tenantServiceInfo["volume_mount_path"] = volume_path tenantServiceInfo["host_path"] = host_path if service.service_key == 'application': tenantServiceInfo["deploy_version"] = "" else: tenantServiceInfo["deploy_version"] = datetime.datetime.now( ).strftime('%Y%m%d%H%M%S') tenantServiceInfo["create_time"] = datetime.datetime.now().strftime( '%Y-%m-%d %H:%M:%S') tenantServiceInfo["git_project_id"] = 0 tenantServiceInfo["service_type"] = service.service_type tenantServiceInfo["creater"] = creater tenantServiceInfo[ "total_memory"] = service.min_node * service.min_memory tenantServiceInfo["service_origin"] = service_origin tenantServiceInfo["port_type"] = "multi_outer" # tenantServiceInfo["port_type"] = "one_outer" newTenantService = TenantServiceInfo(**tenantServiceInfo) newTenantService.save() return newTenantService
def __init_compose_service(self, tenant, user, service_cname, image, region): """ 初始化docker compose创建的应用默认数据 """ tenant_service = TenantServiceInfo() tenant_service.tenant_id = tenant.tenant_id tenant_service.service_id = make_uuid() tenant_service.service_cname = app_service.generate_service_cname( tenant, service_cname, region) tenant_service.service_alias = "gr" + tenant_service.service_id[-6:] tenant_service.creater = user.pk tenant_service.image = image tenant_service.service_region = region tenant_service.service_key = "0000" tenant_service.desc = "docker compose application" tenant_service.category = "app_publish" tenant_service.setting = "" tenant_service.extend_method = "stateless" tenant_service.env = "," tenant_service.min_node = 1 tenant_service.min_memory = 128 tenant_service.min_cpu = baseService.calculate_service_cpu(region, 128) tenant_service.inner_port = 0 tenant_service.version = "latest" tenant_service.namespace = "goodrain" tenant_service.update_version = 1 tenant_service.port_type = "multi_outer" tenant_service.create_time = datetime.datetime.now().strftime( '%Y-%m-%d %H:%M:%S') tenant_service.deploy_version = "" tenant_service.git_project_id = 0 tenant_service.service_type = "application" tenant_service.total_memory = 128 tenant_service.volume_mount_path = "" tenant_service.host_path = "/grdata/tenant/" + tenant.tenant_id + "/service/" + tenant_service.service_id tenant_service.code_from = "image_manual" tenant_service.language = "docker-compose" tenant_service.service_source = AppConstants.DOCKER_COMPOSE tenant_service.create_status = "creating" # 保存并返回 tenant_service.save() return tenant_service
def create_tenant_service(self, **kwargs): tenant_service = TenantServiceInfo(**kwargs) tenant_service.save() return tenant_service