Example #1
0
 def __init_third_party_app(self, region, end_point):
     """
     初始化创建外置服务的默认数据,未存入数据库
     """
     tenant_service = TenantServiceInfo()
     tenant_service.service_region = region
     tenant_service.service_key = "application"
     tenant_service.desc = "third party service"
     tenant_service.category = "application"
     tenant_service.image = "third_party"
     tenant_service.cmd = ""
     tenant_service.setting = ""
     tenant_service.extend_method = "stateless"
     tenant_service.env = ""
     tenant_service.min_node = len(end_point)
     tenant_service.min_memory = 0
     tenant_service.min_cpu = 0
     tenant_service.version = "81701"
     tenant_service.namespace = "third_party"
     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 = 0
     tenant_service.volume_mount_path = ""
     tenant_service.host_path = ""
     tenant_service.service_source = AppConstants.THIRD_PARTY
     tenant_service.create_status = "creating"
     return tenant_service
Example #2
0
 def __init_source_code_app(self, region):
     """
     初始化源码创建的应用默认数据,未存入数据库
     """
     tenant_service = TenantServiceInfo()
     tenant_service.service_region = region
     tenant_service.service_key = "application"
     tenant_service.desc = "application info"
     tenant_service.category = "application"
     tenant_service.image = "goodrain.me/runner"
     tenant_service.cmd = ""
     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 = 5000
     tenant_service.version = "81701"
     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 = ""
     tenant_service.service_source = AppConstants.SOURCE_CODE
     tenant_service.create_status = "creating"
     return tenant_service
Example #3
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