MCPcopy Create free account
hub / github.com/MaterializeInc/materialize / print_instances

Function print_instances

misc/python/materialize/scratch.py:155–226  ·  view source on GitHub ↗
(
    ists: list[Instance],
    format: str = "table",
    numbered: bool = False,
    show_launched_by: bool = False,
)

Source from the content-addressed store, hash-verified

153
154
155def print_instances(
156 ists: list[Instance],
157 format: str = "table",
158 numbered: bool = False,
159 show_launched_by: bool = False,
160) -> None:
161 if format == "csv":
162 # CSV is machine-readable: emit the full set of columns, unabridged.
163 field_names = [
164 "Name",
165 "Instance ID",
166 "Public IP Address",
167 "Private IP Address",
168 "Launched By",
169 "Delete After",
170 "State",
171 ]
172 if numbered:
173 field_names = ["#"] + field_names
174 w = csv.writer(sys.stdout)
175 w.writerow(field_names)
176 for idx, i in enumerate(ists, 1):
177 t = tags(i)
178 row = [
179 name(t),
180 i.instance_id,
181 i.public_ip_address,
182 i.private_ip_address,
183 launched_by(t),
184 delete_after(t),
185 i.state["Name"],
186 ]
187 if numbered:
188 row = [idx] + row
189 w.writerow(row)
190 return
191
192 if format != "table":
193 raise RuntimeError("Unknown format passed to print_instances")
194
195 # Table is for humans: a compact subset that fits a default terminal.
196 # Private IP is omitted (mssh connects by instance id, not IP) and the
197 # owner only shown when listing instances beyond your own.
198 headers = ["INSTANCE ID", "NAME", "STATE", "EXPIRES", "PUBLIC IP"]
199 if show_launched_by:
200 headers.append("LAUNCHED BY")
201 if numbered:
202 headers = ["#"] + headers
203 rows = []
204 for idx, i in enumerate(ists, 1):
205 t = tags(i)
206 state = i.state["Name"]
207 # A dead instance has no meaningful expiry; don't show a future time.
208 expires = (
209 "-"
210 if state in ("terminated", "shutting-down")
211 else _format_expires(delete_after(t))
212 )

Callers 7

startFunction · 0.90
runFunction · 0.90
runFunction · 0.90
runFunction · 0.90
runFunction · 0.90
pick_instanceFunction · 0.90
runFunction · 0.90

Calls 9

tagsFunction · 0.85
nameFunction · 0.85
launched_byFunction · 0.85
delete_afterFunction · 0.85
_format_expiresFunction · 0.85
_short_nameFunction · 0.85
render_tableFunction · 0.85
writerMethod · 0.80
appendMethod · 0.45

Tested by

no test coverage detected