Пример #1
0
def check_endpoints(endpoints):
    if not endpoints:
        return ["parameter error"], False
    for endpoint in endpoints:
        # TODO: ipv6
        errs = []
        if "https://" in endpoint:
            endpoint = endpoint.partition("https://")[2]
        if "http://" in endpoint:
            endpoint = endpoint.partition("http://")[2]
        if ":" in endpoint:
            endpoint = endpoint.rpartition(":")[0]
        errs = validate_endpoint_address(endpoint)
        if errs:
            if len(endpoints) > 1:
                logger.error(
                    "endpoint: {}; do not support multi domain endpoint".
                    format(endpoint))
                return ["do not support multi domain endpoint"], True
            else:
                return [], True
            logger.error("endpoint: {}; invalid endpoint address: {}".format(
                endpoint, json.dumps(errs)))
            return errs, False
    return [], False
Пример #2
0
def check_endpoints(endpoints):
    if not endpoints:
        return ["parameter error"], False
    total_errs = []
    is_domain = False
    for endpoint in endpoints:
        # TODO: ipv6
        if "https://" in endpoint:
            endpoint = endpoint.partition("https://")[2]
        if "http://" in endpoint:
            endpoint = endpoint.partition("http://")[2]
        if ":" in endpoint:
            endpoint = endpoint.rpartition(":")[0]
        errs, domain_ip = validate_endpoint_address(endpoint)
        if domain_ip:
            is_domain = True
        total_errs.extend(errs)
    if len(endpoints) > 1 and is_domain:
        logger.error(
            "endpoint: {}; do not support multi domain endpoint".format(
                endpoint))
        return ["do not support multi domain endpoint"], is_domain
    elif len(endpoints) == 1 and is_domain:
        return [], is_domain
    else:
        return total_errs, False
Пример #3
0
 def check_domain_thirdpart(self, tenant, service):
     try:
         res, body = region_api.get_third_party_service_pods(
             service.service_region, tenant.tenant_name,
             service.service_alias)
         if res.status != 200:
             return "regin error", "数据中心查询失败", 412
         endpoint_list = body["list"]
         for endpoint in endpoint_list:
             address = endpoint.address
             if "https://" in address:
                 address = address.partition("https://")[2]
             if "http://" in address:
                 address = address.partition("http://")[2]
             if ":" in address:
                 address = address.rpartition(":")[0]
             from console.utils.validation import validate_endpoint_address
             errs = validate_endpoint_address(address)
             if len(errs) > 0:
                 return "do not allow operate outer port for domain endpoints", "不允许开启域名服务实例对外端口", 400
         return "", "", 200
     except Exception as e:
         logger.exception(e)
         from www.utils.return_message import error_message
         result = error_message(e.message)
         return result, "检查第三方域名服务错误", 500
Пример #4
0
 def check_endpoints(endpoints):
     if not endpoints:
         return ["parameter error"]
     for endpoint in endpoints:
         # TODO: ipv6
         address = endpoint.rpartition(":")[0]
         errs = validate_endpoint_address(address)
         if errs:
             return errs
Пример #5
0
def check_endpoints(endpoints):
    if not endpoints:
        return ["parameter error"]
    for endpoint in endpoints:
        # TODO: ipv6
        address = endpoint
        if ":" in endpoint:
            address = endpoint.rpartition(":")[0]
        errs = validate_endpoint_address(address)
        if errs:
            logger.error("endpoint: {}; invalid endpoint address: {}".format(
                endpoint, json.dumps(errs)))
            return errs
Пример #6
0
    def create_third_party_service(self, tenant, service, user_name):
        data = self.__init_third_party_data(tenant, service, user_name)
        # 端口
        ports = port_repo.get_service_ports(tenant.tenant_id,
                                            service.service_id)
        ports_info = ports.values('container_port', 'mapping_port', 'protocol',
                                  'port_alias', 'is_inner_service',
                                  'is_outer_service')

        for port_info in ports_info:
            port_info["is_inner_service"] = False
            port_info["is_outer_service"] = False

        if ports_info:
            data["ports_info"] = list(ports_info)

        # endpoints
        endpoints = service_endpoints_repo.get_service_endpoints_by_service_id(
            service.service_id)
        if endpoints.endpoints_type == "static":
            eps = json.loads(endpoints.endpoints_info)
            for address in eps:
                if "https://" in address:
                    address = address.partition("https://")[2]
                if "http://" in address:
                    address = address.partition("http://")[2]
                if ":" in address:
                    address = address.rpartition(":")[0]
                errs = validate_endpoint_address(address)
                if errs:
                    if len(eps) > 1:
                        raise ErrDoNotSupportMultiDomain(
                            "do not support multi domain address")
        endpoints_dict = dict()
        if endpoints:
            endpoints_dict[endpoints.endpoints_type] = endpoints.endpoints_info
            data["endpoints"] = endpoints_dict
        data["kind"] = service.service_source

        # 数据中心创建
        logger.debug('-----------data-----------_>{0}'.format(data))
        region_api.create_service(service.service_region, tenant.tenant_name,
                                  data)
        # 将组件创建状态变更为创建完成
        service.create_status = "complete"
        self.__handle_service_ports(tenant, service, ports)
        service.save()
        return service