def get_service_of_avaliable_port(self, group_id): """ 获取可用http端口的服务 :param group_id: :return: """ group = app_group_svc.get_tenant_service_group_by_pk(group_id, True) data = [] for svc in group.service_list: http_port_svcs = app_group_svc.get_service_http_port( svc.service_id) port = http_port_svcs[0] if http_port_svcs else None if port: domains = ServiceDomain.objects.filter( service_id=port.service_id, protocol='http') ret = { 'service_id': svc.service_id, 'service_key': svc.service_key, 'service_name': svc.service_cname, 'service_version': svc.version, } if not domains: ret.update({'domain': ''}) else: ret.update({ 'domain': { 'domain_id': domains[0].ID, 'domain_url': domains[0].domain_name } }) data.append(ret) return data
def bind_domain(self, service_id, domain_name): if ServiceDomain.objects.filter(domain_name=domain_name).count() > 0: return False, '域名已存在' service = app_svc.get_service_by_id(service_id) if not service: return False, '应不存在' tenant = app_group_svc.get_tenant_by_pk(service.tenant_id) user = app_group_svc.get_user_by_eid(tenant.enterprise_id) ports = app_group_svc.get_service_http_port(service.service_id) if not ports: return False, '未开通对外端口' data = { "uuid": make_uuid(domain_name), "domain_name": domain_name, "service_alias": service.service_alias, "tenant_id": service.tenant_id, "tenant_name": tenant.tenant_name, "service_port": ports[0].container_port, "protocol": "http", "add_time": datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S'), "add_user": user.nick_name if user else "", "enterprise_id": tenant.enterprise_id, "certificate": "", "private_key": "", "certificate_name": "" } try: region_api.bindDomain(service.service_region, tenant.tenant_name, service.service_alias, data) domain = { "service_id": service.service_id, "service_name": service.service_alias, "domain_name": domain_name, "create_time": datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S'), "container_port": ports[0].container_port, "protocol": "http", "certificate_id": 0 } domain_info = ServiceDomain(**domain) domain_info.save() return True, domain_info except Exception as e: return False, e.message.get('body').get('msgcn') or '绑定域名失败'
def bind_domain(self, service_id, domain_name): try: service = app_svc.get_service_by_id(service_id) if not service: return False, '应不存在' tenant = app_group_svc.get_tenant_by_pk(service.tenant_id) user = app_group_svc.get_user_by_eid(tenant.enterprise_id) ports = app_group_svc.get_service_http_port(service.service_id) if not ports: return False, '未开通对外端口' domain = domain_service.bind_siample_http_domain( tenant, user, service, domain_name, ports[0].container_port) if domain: return True, domain return False, None except Exception as e: logger.exception(e) return False, '绑定域名失败'