MCPcopy Create free account
hub / github.com/apache/cloudstack / prepare

Method prepare

extensions/MaaS/maas.py:116–157  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

114 return {}
115
116 def prepare(self):
117 machines = self.call_maas("GET", "/machines/")
118 ready = [m for m in machines if m.get("status_name") == "Ready"]
119 if not ready:
120 fail("No Ready machines available")
121
122 sysid = self.data.get("system_id")
123
124 if sysid:
125 match = next((m for m in ready if m["system_id"] == sysid), None)
126 if not match:
127 fail(f"Provided system_id '{sysid}' not found among Ready machines")
128 system = match
129 else:
130 system = ready[0]
131
132 system_id = system["system_id"]
133 mac = system.get("interface_set", [{}])[0].get("mac_address")
134 hostname = system.get("hostname", "")
135
136 if not mac:
137 fail("No MAC address found")
138
139 # Load original JSON so we can update nics
140 with open(self.config_path, "r") as f:
141 json_data = json.load(f)
142
143 if json_data.get("cloudstack.vm.details", {}).get("nics"):
144 json_data["cloudstack.vm.details"]["nics"][0]["mac"] = mac
145
146 console_url = f"http://{self.data['endpoint'].replace('http://','').replace('https://','')}:5240/MAAS/r/machine/{system_id}/summary"
147
148 result = {
149 "nics": json_data["cloudstack.vm.details"]["nics"],
150 "details": {
151 "External:mac_address": mac,
152 "External:maas_system_id": system_id,
153 "External:hostname": hostname,
154 "External:console_url": console_url,
155 },
156 }
157 succeed(result)
158
159 def create(self):
160 sysid = self.data.get("system_id")

Callers

nothing calls this directly

Calls 7

call_maasMethod · 0.95
nextFunction · 0.85
replaceMethod · 0.80
failFunction · 0.70
succeedFunction · 0.70
getMethod · 0.65
loadMethod · 0.45

Tested by

no test coverage detected