Commit 94fa9f5b authored by Noe Nieto's avatar Noe Nieto 💬

Fix typo. Implements requirements for #5

parent 628b4eae
---
- name: Install dependencies
\ No newline at end of file
......@@ -96,5 +96,5 @@
vakue: payments@mycompany.com
- name: woocommerce_currency
command: update
vakue: MXN
value: MXN
queries: []
......@@ -42,13 +42,14 @@ ansible_shim = """
"""
XDG_CONFIG_HOME = Path(os.environ['HOME'],'.config','ldh_developer','shipyard')
XDG_VM_CONFIG_HOME = Path(os.environ['HOME'],'.config','ldh_developer','shipyard')
XDG_PB_CONFIG_HOME = Path(os.environ['HOME'],'.config','ldh_developer','playbooks')
def only_if_box_exist(func):
def wrapper(*args, **kwargs):
hostname = args[0]
vagrant_wd = XDG_CONFIG_HOME.joinpath(hostname)
vagrant_wd = XDG_VM_CONFIG_HOME.joinpath(hostname)
if vagrant_wd.exists():
func(*args, **kwargs)
else:
......@@ -69,7 +70,7 @@ def print_status():
"""
Prints the status of all the virtual machines managed by shipyard
"""
shpyrd_paths = [str(d) for d in XDG_CONFIG_HOME.iterdir() if d.is_dir()]
shpyrd_paths = [str(d) for d in XDG_VM_CONFIG_HOME.iterdir() if d.is_dir()]
vgt_db = Path(
os.environ.get('VAGRANT_HOME', str(Path.home().joinpath('.vagrant.d'))),
'data', 'machine-index', 'index'
......@@ -103,7 +104,7 @@ def create_box(hostname, ram, cpus):
"""
This creates a box using the template
"""
vagrant_wd = XDG_CONFIG_HOME.joinpath(hostname)
vagrant_wd = XDG_VM_CONFIG_HOME.joinpath(hostname)
if vagrant_wd.exists():
print("Shipyard error: There's already a vm with that hostname")
exit(0)
......@@ -128,7 +129,7 @@ def destroy_vm(hostname):
"""
Destroy a box, or all
"""
vagrant_wd = XDG_CONFIG_HOME.joinpath(hostname)
vagrant_wd = XDG_VM_CONFIG_HOME.joinpath(hostname)
subprocess.run(['vagrant','destroy'], cwd=vagrant_wd)
shutil.rmtree(vagrant_wd)
......@@ -138,15 +139,15 @@ def run_playbook(hostname, playbook, retry_file=None):
"""
run an Ansible playbook against this vm
"""
vagrant_wd = XDG_CONFIG_HOME.joinpath(hostname)
vagrant_wd = XDG_VM_CONFIG_HOME.joinpath(hostname)
inventory_file = vagrant_wd.joinpath('.vagrant', 'provisioners', 'ansible', 'inventory', 'vagrant_ansible_inventory')
_args = [
'ansible-playbook', '-u', 'vagrant', '-i', f'{inventory_file}',
f'{Path(playbook).resolve()}'
f'{XDG_PB_CONFIG_HOME.joinpath(playbook).resolve()}'
]
if retry_file:
_args.extend(['--limit', f'@{Path(retry_file).resolve()}'])
_args.extend(['--limit', f'@{XDG_PB_CONFIG_HOME.joinpath(retry_file).resolve()}'])
subprocess.run(_args, cwd=vagrant_wd)
......@@ -156,7 +157,7 @@ def start_vm(hostname):
"""
Starts the vm with the provided hostname
"""
vagrant_wd = XDG_CONFIG_HOME.joinpath(hostname)
vagrant_wd = XDG_VM_CONFIG_HOME.joinpath(hostname)
subprocess.run(['vagrant','up'], cwd=vagrant_wd)
......@@ -165,7 +166,7 @@ def halt_vm(hostname):
"""
Stops the vm with the provided hostname
"""
vagrant_wd = XDG_CONFIG_HOME.joinpath(hostname)
vagrant_wd = XDG_VM_CONFIG_HOME.joinpath(hostname)
subprocess.run(['vagrant','halt'], cwd=vagrant_wd)
......@@ -174,7 +175,7 @@ def invoke_shell(hostname):
"""
Open a SSH session to the hostname
"""
vagrant_wd = XDG_CONFIG_HOME.joinpath(hostname)
vagrant_wd = XDG_VM_CONFIG_HOME.joinpath(hostname)
subprocess.run(['vagrant','ssh'], cwd=vagrant_wd)
......@@ -183,7 +184,7 @@ def which(hostname):
"""
Print the directory of a vm by it's hostname
"""
vagrant_wd = XDG_CONFIG_HOME.joinpath(hostname)
vagrant_wd = XDG_VM_CONFIG_HOME.joinpath(hostname)
print(vagrant_wd)
......@@ -192,7 +193,7 @@ def gio_open_vm(hostname):
"""
Open the vm directory in nautilis or any other file manager
"""
vagrant_wd = XDG_CONFIG_HOME.joinpath(hostname)
vagrant_wd = XDG_VM_CONFIG_HOME.joinpath(hostname)
subprocess.run(['gio','open', vagrant_wd])
COMMANDS = {
......@@ -216,8 +217,8 @@ if __name__ == '__main__':
cmd_parser.add_argument('command', choices=COMMANDS,)
cmd_args = cmd_parser.parse_args(sys.argv[1:2])
# Ensure XDG_CONFIG_HOME exists
XDG_CONFIG_HOME.mkdir(parents=True, exist_ok=True)
# Ensure XDG_VM_CONFIG_HOME exists
XDG_VM_CONFIG_HOME.mkdir(parents=True, exist_ok=True)
if cmd_args.command == 'status':
print_status()
......
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