def get(self, request, *args, **kwargs): """ 查看组件的某个端口的详情 --- parameters: - name: tenantName description: 租户名 required: true type: string paramType: path - name: serviceAlias description: 组件别名 required: true type: string paramType: path - name: port description: 端口号 required: true type: string paramType: path """ container_port = kwargs.get("port", None) if not container_port: return Response(general_message(400, "container_port not specify", u"端口变量名未指定"), status=400) port_info = port_service.get_service_port_by_port(self.service, int(container_port)) variables = port_service.get_port_variables(self.tenant, self.service, port_info) bean = {"port": model_to_dict(port_info)} bean.update(variables) result = general_message(200, "success", "查询成功", bean=bean) return Response(result, status=result["code"])
def get(self, request, *args, **kwargs): """ 获取组件的端口信息 --- parameters: - name: tenantName description: 租户名 required: true type: string paramType: path - name: serviceAlias description: 组件别名 required: true type: string paramType: path """ tenant_service_ports = port_service.get_service_ports(self.service) port_list = [] for port in tenant_service_ports: port_info = port.to_dict() variables = port_service.get_port_variables(self.tenant, self.service, port) port_info["environment"] = variables["environment"] outer_url = "" inner_url = "" if port_info["environment"]: if port.is_inner_service: try: inner_host, inner_port = "127.0.0.1", None for pf in port_info["environment"]: if pf.get("name"): if pf.get("name").endswith("PORT"): inner_port = pf.get("value") inner_url = "{0}:{1}".format(inner_host, inner_port) except Exception as se: logger.exception(se) port_info["inner_url"] = inner_url outer_service = variables.get("outer_service", None) if outer_service: outer_url = "{0}:{1}".format(variables["outer_service"]["domain"], variables["outer_service"]["port"]) port_info["outer_url"] = outer_url port_info["bind_domains"] = [] bind_domains = domain_service.get_port_bind_domains(self.service, port.container_port) if bind_domains: for bind_domain in bind_domains: if not bind_domain.domain_path: bind_domain.domain_path = '/' bind_domain.save() port_info["bind_domains"] = [domain.to_dict() for domain in bind_domains] bind_tcp_domains = domain_service.get_tcp_port_bind_domains(self.service, port.container_port) if bind_tcp_domains: port_info["bind_tcp_domains"] = [domain.to_dict() for domain in bind_tcp_domains] else: port_info["bind_tcp_domains"] = [] port_list.append(port_info) result = general_message(200, "success", "查询成功", list=port_list) return Response(result, status=result["code"])
def get(self, request, *args, **kwargs): """ 获取服务的端口信息 --- parameters: - name: tenantName description: 租户名 required: true type: string paramType: path - name: serviceAlias description: 服务别名 required: true type: string paramType: path """ try: tenant_service_ports = port_service.get_service_ports(self.service) port_list = [] for port in tenant_service_ports: port_info = port.to_dict() variables = port_service.get_port_variables( self.tenant, self.service, port) port_info["environment"] = variables["environment"] outer_url = "" inner_url = "" if port_info["environment"]: if port.is_inner_service: try: inner_url = "{0}:{1}".format( port_info["environment"][0].get("value"), port_info["environment"][1].get("value")) except Exception as se: logger.exception(se) port_info["inner_url"] = inner_url outer_service = variables.get("outer_service", None) if outer_service: outer_url = "{0}:{1}".format( variables["outer_service"]["domain"], variables["outer_service"]["port"]) port_info["outer_url"] = outer_url port_info["bind_domains"] = [] if port.protocol == "http": bind_domains = domain_service.get_port_bind_domains( self.service, port.container_port) port_info["bind_domains"] = [ domain.to_dict() for domain in bind_domains ] port_list.append(port_info) result = general_message(200, "success", "查询成功", list=port_list) except Exception as e: logger.exception(e) result = error_message(e.message) return Response(result, status=result["code"])