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
5b298e33
Commit
5b298e33
authored
Nov 23, 2018
by
Noe Nieto
💬
Browse files
Implement ssh command
parent
c0b57c33
Changes
1
Hide whitespace changes
Inline
Side-by-side
shipyard/shipyard
View file @
5b298e33
...
...
@@ -26,6 +26,18 @@ end
"""
def
only_if_box_exist
(
func
):
def
wrapper
(
*
args
,
**
kwargs
):
hostname
=
args
[
0
]
dot_shipyard
=
Path
(
os
.
environ
[
'HOME'
],
'.shipyard'
)
vagrant_wd
=
dot_shipyard
.
joinpath
(
hostname
)
if
vagrant_wd
.
exists
():
func
(
*
args
,
**
kwargs
)
else
:
print
(
"Shipyard error: no vm managed by me has the hostname '{}'"
.
format
(
hostname
))
exit
(
1
)
return
wrapper
def
print_status
():
"""
...
...
@@ -71,26 +83,35 @@ def create_box(hostname, ram, cpus):
subprocess
.
run
([
'vagrant'
,
'provision'
],
cwd
=
vagrant_wd
)
@
only_if_box_exist
def
destroy_box
(
hostname
):
"""
Destroy a box, or all
"""
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
(
"Shipyard error: no vm managed by me has the hostname '{}'"
.
format
(
hostname
))
exit
(
0
)
subprocess
.
run
([
'vagrant'
,
'destroy'
],
cwd
=
vagrant_wd
)
shutil
.
rmtree
(
vagrant_wd
)
@
only_if_box_exist
def
run_playbook
(
hostname
,
playbook
):
"""
run a playbook against one of the boxes
"""
dot_shipyard
=
Path
(
os
.
environ
[
'HOME'
],
'.shipyard'
)
vagrant_wd
=
dot_shipyard
.
joinpath
(
hostname
)
subprocess
.
run
([
'vagrant'
,
'destroy'
],
cwd
=
vagrant_wd
)
def
run_playbook
(
name
,
playbook
):
@
only_if_box_exist
def
invoke_shell
(
hostname
):
"""
run a playbook against one of the boxes
"""
print
(
'Running playbook {} for box {}'
.
format
(
playbook
,
name
))
dot_shipyard
=
Path
(
os
.
environ
[
'HOME'
],
'.shipyard'
)
vagrant_wd
=
dot_shipyard
.
joinpath
(
hostname
)
subprocess
.
run
([
'vagrant'
,
'ssh'
],
cwd
=
vagrant_wd
)
if
__name__
==
'__main__'
:
...
...
@@ -115,9 +136,9 @@ if __name__ == '__main__':
elif
args
.
command
==
'destroy'
:
destroy_box
(
args
.
hostname
)
elif
args
.
command
==
'ssh'
:
invoke_shell
()
invoke_shell
(
args
.
hostname
)
elif
args
.
command
==
'playbook'
:
run_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