def get_base_url(self): env = EnvironmentDetector() detected_envs = env.detect() in_cloud_env = is_cloud_env(detected_envs) # First handle known cloud environments nbvm_file_path = "/mnt/azmnt/.nbvm" if not (os.path.exists(nbvm_file_path) and os.path.isfile(nbvm_file_path)): if not in_cloud_env: return "http://{0}:{1}".format( self.ip, self.port) # all non-specified cloud environments are not handled self.env = "cloud" return None self.env = "cloud" # regex to find items of the form key=value where value will be part of a url # the keys of interest to us are "instance" and domainsuffix" envre = re.compile(r'''^([^\s=]+)=(?:[\s"']*)(.+?)(?:[\s"']*)$''') result = {} with open(nbvm_file_path) as nbvm_variables: for line in nbvm_variables: match = envre.match(line) if match is not None: result[match.group(1)] = match.group(2) if "instance" not in result or "domainsuffix" not in result: return None self.env = "azure" instance_name = result["instance"] domain_suffix = result["domainsuffix"] return "https://{}-{}.{}".format(instance_name, self.port, domain_suffix)
def get_base_url(self): env = EnvironmentDetector() detected_envs = env.detect() in_cloud_env = is_cloud_env(detected_envs) result = _get_nbvm() # First handle known cloud environments if result is None: # special case azure, since the azure sdk can set this env setting on local runs if not in_cloud_env or self.env in VM_ENVS: return "http://{0}:{1}".format(self.ip, self.port) # all non-specified, non-credentialed cloud environments are not handled if not self.with_credentials: self.env = 'cloud' return None instance_name = result["instance"] domain_suffix = result["domainsuffix"] return "https://{}-{}.{}".format(instance_name, self.port, domain_suffix)