Exemplo n.º 1
0
    def unbind_domain(self, domain_id, service_id):
        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)
        return domain_service.unbind_domian_by_domain(tenant, service,
                                                      domain_id)
Exemplo n.º 2
0
    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 '绑定域名失败'
Exemplo n.º 3
0
    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, '绑定域名失败'
Exemplo n.º 4
0
    def unbind_domain(self, domain_id, service_id):
        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)
        domain = ServiceDomain.objects.get(ID=domain_id)

        data = {
            "service_id": domain.service_id,
            "domain": domain.domain_name,
            "pool_name":
            tenant.tenant_name + "@" + service.service_alias + ".Pool",
            "container_port": domain.container_port,
            "enterprise_id": tenant.enterprise_id
        }
        try:
            region_api.unbindDomain(service.service_region, tenant.tenant_name,
                                    service.service_alias, data)
            domain.delete()
            return True, None
        except region_api.CallApiError as e:
            return False, '解绑失败'