Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
Noe Nieto
Shipwright - LDH Developer
Commits
e00557df
Commit
e00557df
authored
Nov 26, 2018
by
Noe Nieto
💬
Browse files
New commands: up, open and which
parent
52b76175
Changes
1
Hide whitespace changes
Inline
Side-by-side
shipyard/shipyard
View file @
e00557df
...
...
@@ -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):
subprocess
.
run
([
'vagrant'
,
'destroy'
],
cwd
=
vagrant_wd
)
@
only_if_box_exist
def
start_vm
(
hostname
):
"""
Starts the vm with the provided hostname
"""
vagrant_wd
=
XDG_CONFIG_HOME
.
joinpath
(
hostname
)
subprocess
.
run
([
'vagrant'
,
'up'
],
cwd
=
vagrant_wd
)
@
only_if_box_exist
def
halt
(
hostname
):
"""
Stops the vm with the provided hostname
"""
vagrant_wd
=
XDG_CONFIG_HOME
.
joinpath
(
hostname
)
subprocess
.
run
([
'vagrant'
,
'halt'
],
cwd
=
vagrant_wd
)
@
only_if_box_exist
def
invoke_shell
(
hostname
):
"""
...
...
@@ -134,18 +152,38 @@ def invoke_shell(hostname):
subprocess
.
run
([
'vagrant'
,
'ssh'
],
cwd
=
vagrant_wd
)
@
only_if_box_exist
def
which
(
hostname
):
"""
Print the directory of a vm by it's hostname
"""
vagrant_wd
=
XDG_CONFIG_HOME
.
joinpath
(
hostname
)
print
(
vagrant_wd
)
@
only_if_box_exist
def
gio_open_vm
(
hostname
):
"""
Open the vm directory in nautilis or any other file manager
"""
vagrant_wd
=
XDG_CONFIG_HOME
.
joinpath
(
hostname
)
subprocess
.
run
([
'gio'
,
'open'
,
vagrant_wd
])
if
__name__
==
'__main__'
:
parser
=
argparse
.
ArgumentParser
(
prog
=
'shipyard'
,
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'
:
print_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'
:
destroy_box
(
args
.
hostname
)
elif
args
.
command
==
'up'
:
start_vm
(
args
.
hostname
)
elif
args
.
command
==
'ssh'
:
invoke_shell
(
args
.
hostname
)
elif
args
.
command
==
'which'
:
which
(
args
.
hostname
)
elif
args
.
command
==
'open'
:
gio_open_vm
(
args
.
hostname
)
elif
args
.
command
==
'playbook'
:
run_playbook
(
args
.
hostname
,
args
.
playbook
)
else
:
parser
.
print_help
()
exit
(
100
)
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment