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

Implement destroy command

parent bb4f8f4c
......@@ -5,6 +5,7 @@ import argparse
import tempfile
import subprocess
import json
import shutil
from pathlib import Path
vagrant_template = """
......@@ -24,6 +25,8 @@ Vagrant.configure("2") do |config|
end
"""
def print_status():
"""
Prints the status of all the virtual machines managed by shipyard
......@@ -68,14 +71,20 @@ def create_box(hostname, ram, cpus):
subprocess.run(['vagrant','provision'], cwd=vagrant_wd)
def destroy_box(name, all=False):
def destroy_box(hostname):
"""
Destroy a box, or all
"""
if all:
print('Destroy all boxes')
dot_shipyard = Path(os.environ['HOME'], '.shipyard')
vagrant_wd = dot_shipyard.joinpath(hostname)
if vagrant_wd.exists():
# Execute vagrant with the generated vagrantfile
subprocess.run(['vagrant','destroy'], cwd=vagrant_wd)
shutil.rmtree(vagrant_wd)
else:
print('Destroying box {} ...'.format(name))
print("Shipyard error: no vm managed by me has the hostname '{}'".format(hostname))
exit(0)
def run_playbook(name, playbook):
"""
......@@ -104,7 +113,7 @@ if __name__ == '__main__':
else:
print("Shipyard error: the hostname is required to create a vm")
elif args.command == 'destroy':
destroy_box(args)
destroy_box(args.hostname)
elif args.command == 'ssh':
invoke_shell()
elif args.command == '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