MCPcopy Create free account
hub / github.com/Dstack-TEE/dstack / resolve_vmm_url

Function resolve_vmm_url

vmm/src/vmm-cli.py:108–145  ·  view source on GitHub ↗

Resolve the VMM URL to connect to. Priority: 1. Explicit --url flag 2. DSTACK_VMM_URL env var 3. Config file url 4. If exactly one VMM instance is discovered, use that 5. If active instance is set in config, use that 6. Fall back to default Returns the URL string.

(
    instances: List[Dict[str, Any]],
    config: Dict[str, Any],
    explicit_url: Optional[str] = None,
)

Source from the content-addressed store, hash-verified

106
107
108def resolve_vmm_url(
109 instances: List[Dict[str, Any]],
110 config: Dict[str, Any],
111 explicit_url: Optional[str] = None,
112) -> str:
113 """Resolve the VMM URL to connect to.
114
115 Priority:
116 1. Explicit --url flag
117 2. DSTACK_VMM_URL env var
118 3. Config file url
119 4. If exactly one VMM instance is discovered, use that
120 5. If active instance is set in config, use that
121 6. Fall back to default
122
123 Returns the URL string.
124 """
125 # If user explicitly provided --url or env var, honor it
126 env_url = os.environ.get("DSTACK_VMM_URL")
127 if explicit_url and explicit_url != "http://localhost:8080":
128 return explicit_url
129 if env_url:
130 return env_url
131 config_url = config.get("url")
132 if config_url:
133 return config_url
134
135 # Try auto-discovery
136 active_id = config.get("active_vmm")
137 if active_id:
138 for inst in instances:
139 if inst["id"] == active_id or inst["id"].startswith(active_id):
140 return vmm_address_to_url(inst)
141
142 if len(instances) == 1:
143 return vmm_address_to_url(instances[0])
144
145 return "http://localhost:8080"
146
147
148def vmm_address_to_url(instance: Dict[str, Any]) -> str:

Callers 1

mainFunction · 0.85

Calls 2

vmm_address_to_urlFunction · 0.85
getMethod · 0.45

Tested by

no test coverage detected