Exemplo n.º 1
0
 def __init_app(self, service_base_info, new_service_id, new_servie_alias, user, region, tenant):
     service_base_info.pop("ID")
     ts = TenantServiceInfo(**service_base_info)
     ts.service_id = new_service_id
     ts.service_alias = new_servie_alias
     ts.service_region = region
     ts.creater = user.user_id
     ts.tenant_id = tenant.tenant_id
     ts.create_status = "creating"
     ts.save()
     return ts
Exemplo n.º 2
0
    def _template_to_component(self, tenant_id, template):
        component = TenantServiceInfo()
        component.tenant_id = tenant_id
        component.service_id = make_uuid()
        component.service_cname = template.get("service_cname", "default-name")
        component.service_alias = "gr" + component.service_id[-6:]
        component.creater = self.user.pk
        component.image = template.get("share_image", template["image"])
        component.cmd = template.get("cmd", "")
        component.service_region = self.region_name
        component.service_key = template.get("service_key")
        component.desc = "install from market app"
        component.category = "app_publish"
        component.version = template.get("version")
        component.create_time = datetime.now().strftime('%Y-%m-%d %H:%M:%S')
        component.deploy_version = template.get("deploy_version")
        component.service_type = "application"
        component.service_source = AppConstants.MARKET
        component.create_status = "complete"
        component.tenant_service_group_id = self.original_app.upgrade_group_id
        component.build_upgrade = self.is_deploy

        # component type
        extend_method = template["extend_method"]
        if extend_method:
            if extend_method == "state":
                component.extend_method = ComponentType.state_multiple.value
            elif extend_method == "stateless":
                component.extend_method = ComponentType.stateless_multiple.value
            else:
                component.extend_method = extend_method

        component.min_node = template.get("extend_method_map", {}).get("min_node")
        min_memory = template.get("extend_method_map", {}).get("init_memory")
        if min_memory is not None:
            component.min_memory = min_memory
        elif template.get("extend_method_map", {}).get("min_memory"):
            component.min_memory = template.get("extend_method_map", {}).get("min_memory")
        else:
            component.min_memory = 512

        container_cpu = template.get("extend_method_map", {}).get("container_cpu")
        if container_cpu is not None:
            component.min_cpu = template["extend_method_map"]["container_cpu"]
        else:
            component.min_cpu = 0
        component.total_memory = component.min_node * component.min_memory

        return component
Exemplo n.º 3
0
 def __init_app(self, service_base_info, new_service_id, new_servie_alias, user, region, tenant):
     service_base_info.pop("ID")
     ts = TenantServiceInfo(**service_base_info)
     ts.service_id = new_service_id
     ts.service_alias = new_servie_alias
     ts.service_region = region
     ts.creater = user.user_id
     ts.tenant_id = tenant.tenant_id
     ts.create_status = "creating"
     # compatible component type
     if ts.extend_method == "state":
         ts.extend_method = "state_multiple"
     if ts.extend_method == "stateless":
         ts.extend_method = "stateless_multiple"
     ts.save()
     return ts
 def __init_app(self, service_base_info, new_service_id, new_servie_alias,
                user, region, tenant):
     service_base_info.pop("ID")
     ts = TenantServiceInfo(**service_base_info)
     if service_base_info["service_source"] == "third_party":
         new_service_id = make_uuid(tenant.tenant_id)
         new_servie_alias = app_service.create_service_alias(new_service_id)
     ts.service_id = new_service_id
     ts.service_alias = new_servie_alias
     ts.service_region = region
     ts.creater = user.user_id
     ts.tenant_id = tenant.tenant_id
     ts.create_status = "creating"
     ts.service_cname = ts.service_cname + "-copy"
     # compatible component type
     if ts.extend_method == "state":
         ts.extend_method = "state_multiple"
     if ts.extend_method == "stateless":
         ts.extend_method = "stateless_multiple"
     ts.save()
     return ts
Exemplo n.º 5
0
 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 = service_cname
     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 = ComponentType.stateless_multiple.value
     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 = "checked"
     return tenant_service