Commit e00557df authored by Noe Nieto's avatar Noe Nieto 💬

New commands: up, open and which

parent 52b76175
......@@ -53,10 +53,10 @@ def print_status():
Prints the status of all the virtual machines managed by shipyard
shpyrd_paths = [str(d) for d in Path(os.environ['HOME'], '.shipyard').iterdir() if d.is_dir()]
shpyrd_paths = [str(d) for d in XDG_CONFIG_HOME.iterdir() if d.is_dir()]
vgt_db = Path(
os.environ.get('VAGRANT_HOME', str(Path.home())),
'.vagrant.d', 'data', 'machine-index', 'index'
os.environ.get('VAGRANT_HOME', str(Path.home().joinpath('.vagrant.d'))),
'data', 'machine-index', 'index'
count = 0
if vgt_db.exists():
......@@ -125,6 +125,24 @@ def run_playbook(hostname, playbook):['vagrant','destroy'], cwd=vagrant_wd)
def start_vm(hostname):
Starts the vm with the provided hostname
vagrant_wd = XDG_CONFIG_HOME.joinpath(hostname)['vagrant','up'], cwd=vagrant_wd)
def halt(hostname):
Stops the vm with the provided hostname
vagrant_wd = XDG_CONFIG_HOME.joinpath(hostname)['vagrant','halt'], cwd=vagrant_wd)
def invoke_shell(hostname):
......@@ -134,18 +152,38 @@ def invoke_shell(hostname):['vagrant','ssh'], cwd=vagrant_wd)
def which(hostname):
Print the directory of a vm by it's hostname
vagrant_wd = XDG_CONFIG_HOME.joinpath(hostname)
def gio_open_vm(hostname):
Open the vm directory in nautilis or any other file manager
vagrant_wd = XDG_CONFIG_HOME.joinpath(hostname)['gio','open', vagrant_wd])
if __name__ == '__main__':
parser = argparse.ArgumentParser(
description='This utility will create a new virtual machine using vagrant without writing a Vagrant file.',
parser.add_argument('command', choices=['status', 'create', 'destroy', 'ssh', 'playbook'])
parser.add_argument('command', choices=['status', 'create', 'up', 'destroy', 'ssh', 'playbook', 'which', 'open'])
parser.add_argument('--hostname', help='This is the hostname for the new box',)
parser.add_argument('--ram', help='Hoy much RAM for this box (default is 512)', default=512)
parser.add_argument('--cpus', help='Hoy many CPUs for this box (default is 1)', default=1)
parser.add_argument('--playbook', help='Path to the yml file', action='count')
args = parser.parse_args()
# Ensure XDG_CONFIG_HOME exists
XDG_CONFIG_HOME.mkdir(parents=True, exist_ok=True)
if args.command == 'status':
elif args.command == 'create':
......@@ -155,16 +193,16 @@ if __name__ == '__main__':
print("Shipyard error: the hostname is required to create a vm")
elif args.command == 'destroy':
elif args.command == 'up':
elif args.command == 'ssh':
elif args.command == 'which':
elif args.command == 'open':
elif args.command == 'playbook':
run_playbook(args.hostname, args.playbook)
Markdown is supported
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