Skip to content

Commit e522df2

Browse files
committed
iteration of spawn
1 parent 932f08e commit e522df2

1 file changed

Lines changed: 39 additions & 2 deletions

File tree

src/cfengine_cli/up.py

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,10 @@
99
from cf_remote import commands
1010
from cf_remote import utils
1111
from cf_remote import paths
12+
from cf_remote import aramid
1213

1314
import itertools
14-
15+
import time
1516

1617
# Forces pydantic to throw validation error if config contains unknown keys
1718
class NoExtra(BaseModel, extra="forbid"):
@@ -233,6 +234,10 @@ def validate_config(content):
233234
raise UserError("\n".join(msgs))
234235
return state
235236

237+
def three_dots():
238+
for _ in range(3):
239+
print(".", end="", flush=True)
240+
time.sleep(0.3)
236241

237242
def spawn_from_config(state):
238243

@@ -246,12 +251,14 @@ def spawn_from_config(state):
246251
for old, new in itertools.zip_longest(data.keys(), state.keys()):
247252

248253
if old is not None:
249-
if old not in state:
254+
if old[1:] not in state:
250255
destroy.append(old)
256+
print("<<< {}".format(old[1:]))
251257

252258
if new is not None:
253259
if "@{}".format(new) not in data:
254260
spawn.append(new)
261+
print(">>> {}".format(new))
255262

256263
for k in spawn:
257264
config = state[k].config
@@ -297,3 +304,33 @@ def spawn_from_config(state):
297304

298305
for k in destroy:
299306
commands.destroy(k)
307+
308+
data = utils.read_json(paths.CLOUD_STATE_FPATH)
309+
if data is None:
310+
data = {}
311+
312+
if spawn:
313+
print("Waiting for VMs to be accessible", end="")
314+
three_dots()
315+
print()
316+
317+
for k,v in data.items():
318+
319+
if k[1:] not in spawn:
320+
continue
321+
322+
ips = [h_info["public_ips"][0] for h, h_info in v.items() if h != "meta"]
323+
hosts = [aramid.Host(host_name=ip, user="admin") for ip in ips]
324+
325+
while True:
326+
try:
327+
aramid.execute(hosts, "echo", ignore_failed=False, echo=False, echo_cmd=False)
328+
break
329+
except aramid.ExecutionError:
330+
three_dots()
331+
print("\r\033[2K", end="", flush=True)
332+
333+
commands.info(ips)
334+
335+
print("done")
336+

0 commit comments

Comments
 (0)