Commit cfc325cc authored by Noe Nieto's avatar Noe Nieto 💬
Browse files

Command status prints the IPAddress if available

parent 5b298e33
......@@ -7,6 +7,8 @@ import subprocess
import json
import shutil
from pathlib import Path
import ipaddress
vagrant_template = """
Vagrant.configure("2") do |config|
......@@ -39,6 +41,14 @@ def only_if_box_exist(func):
return wrapper
def is_ipaddress(ip_addr):
except ValueError:
return False
return True
def print_status():
Prints the status of all the virtual machines managed by shipyard
......@@ -50,11 +60,25 @@ def print_status():
count = 0
if vgt_db.exists():
print('hostname \t State')
print('hostname \t State\t IP Address')
db = json.loads(
for k, v in db['machines'].items():
if v['vagrantfile_path'] in shpyrd_paths:
print('{name} \t {state}'.format(name=v['name'], state=v['state']))
vagrant_wd = v['vagrantfile_path']
if vagrant_wd in shpyrd_paths:
# get the ip address
cp =
['vagrant','ssh-config'], cwd=vagrant_wd,
stdout=subprocess.PIPE, stderr=subprocess.PIPE,
if cp.returncode != 0:
ip_addr = "<N/A>"
for fld in cp.stdout.split():
if is_ipaddress(str(fld)):
ip_addr = str(fld)
print(f"{v['name']} \t {v['state']}\t {ip_addr}")
print('Total {} machine(s)'.format(count))
......@@ -107,7 +131,7 @@ def run_playbook(hostname, playbook):
def invoke_shell(hostname):
run a playbook against one of the boxes
Open a SSH session to the hostname
dot_shipyard = Path(os.environ['HOME'], '.shipyard')
vagrant_wd = dot_shipyard.joinpath(hostname)
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment