def select_domain(self): gateways = deployer.list_all_gateways() if not gateways: raise StopChatFlow( "There are no available gateways in the farms bound to your pools." ) domains = dict() for gw_dict in gateways.values(): gateway = gw_dict["gateway"] for domain in gateway.managed_domains: domains[domain] = gw_dict self.domain = self.single_choice( "Please choose the domain you wish to use", list(domains.keys()), required=True) self.gateway = domains[self.domain]["gateway"] self.gateway_pool = domains[self.domain]["pool"] self.domain = f"{self.threebot_name}-{self.solution_name}.{self.domain}" self.domain = j.sals.zos.get().gateway.correct_domain(self.domain) self.addresses = [] for ns in self.gateway.dns_nameserver: self.addresses.append(j.sals.nettools.get_host_by_name(ns)) self.secret = f"{j.core.identity.me.tid}:{uuid.uuid4().hex}"
def domain_selection(self): # {"domain": {"gateway": gw, "pool": p}} gateways = deployer.list_all_gateways() if not gateways: raise StopChatFlow( "There are no available gateways in the farms bound to your pools" ) # add managed domains gateway_id_dict = {} pool_id_dict = {} messages = {} for gw_dict in gateways.values(): gateway_id_dict[gw_dict["gateway"].node_id] = gw_dict["gateway"] pool_id_dict[gw_dict["pool"].pool_id] = gw_dict["pool"] for dom in gw_dict["gateway"].managed_domains: location_list = [ gw_dict["gateway"].location.continent, gw_dict["gateway"].location.country, gw_dict["gateway"].location.city, ] location = " - ".join([ info for info in location_list if info and info != "Unknown" ]) if location: location = f" Location: {location}" messages[f"Managed {dom}{location}"] = gw_dict # add delegate domains delegated_domains = solutions.list_delegated_domain_solutions() for dom in delegated_domains: if dom["Pool"] not in pool_id_dict: pool_id_dict[dom["Pool"]] = gateway_id_dict[dom["Gateway"]] gw_dict = { "gateway": gateway_id_dict[dom["Gateway"]], "pool": pool_id_dict[dom["Pool"]] } messages[f"Delegated {dom['Name']}"] = gw_dict domain_ask_list = list(messages.keys()) # add custom_domain domain_ask_list.append("Custom Domain") chosen_domain = self.single_choice( "Please choose the domain you wish to use", domain_ask_list, required=True) if chosen_domain != "Custom Domain": self.domain_gateway = messages[chosen_domain]["gateway"] self.domain_pool = messages[chosen_domain]["pool"] splits = chosen_domain.split() self.domain_type = splits[0] self.domain = splits[1] retry = False while True: domain = self.string_ask( f"Please specify the sub domain name you wish to bind to. will be (subdomain).{self.domain}", retry=retry, required=True, is_identifier=True, ) domain = j.sals.zos.gateway.correct_domain(domain) if "." in domain: retry = True self.md_show( "You can't nest domains. please click next to try again." ) else: if j.tools.dnstool.is_free(domain + "." + self.domain): break else: self.md_show( f"domain {domain + '.' + self.domain} is not available." ) self.domain = domain + "." + self.domain else: self.domain = self.string_ask( "Please specify the domain name you wish to bind to:", required=True) self.domain = j.sals.zos.gateway.correct_domain(self.domain) self.domain_gateway, self.domain_pool = deployer.select_gateway( self) self.domain_type = "Custom Domain" res = """\ Please create a `CNAME` record in your DNS manager for domain: `{{domain}}` pointing to: {% for dns in gateway.dns_nameserver -%} - {{dns}} {% endfor %} """ res = j.tools.jinja2.render_template(template_text=res, gateway=self.domain_gateway, domain=self.domain) self.md_show(dedent(res), md=True) self.name_server = self.domain_gateway.dns_nameserver[0] self.secret = f"{j.core.identity.me.tid}:{uuid.uuid4().hex}"