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
cfc325cc
Commit
cfc325cc
authored
Nov 23, 2018
by
Noe Nieto
💬
Browse files
Command status prints the IPAddress if available
parent
5b298e33
Changes
1
Hide whitespace changes
Inline
Side-by-side
shipyard/shipyard
View file @
cfc325cc
...
...
@@ -7,6 +7,8 @@ import subprocess
import
json
import
shutil
from
pathlib
import
Path
import
ipaddress
vagrant_template
=
"""
Vagrant.configure("2") do |config|
...
...
@@ -39,6 +41,14 @@ def only_if_box_exist(func):
return
wrapper
def
is_ipaddress
(
ip_addr
):
try
:
ipaddress
.
ip_address
(
ip_addr
)
except
ValueError
:
return
False
return
True
def
print_status
():
"""
Prints the status of all the virtual machines managed by shipyard
...
...
@@ -50,11 +60,25 @@ def print_status():
)
count
=
0
if
vgt_db
.
exists
():
print
(
'hostname
\t
State'
)
print
(
'hostname
\t
State
\t
IP Address
'
)
db
=
json
.
loads
(
vgt_db
.
open
().
read
())
for
k
,
v
in
db
[
'machines'
].
items
():
if
v
[
'vagrantfile_path'
]
in
shpyrd_paths
:
print
(
'{name}
\t
{state}'
.
format
(
name
=
v
[
'name'
],
state
=
v
[
'state'
]))
vagrant_wd
=
v
[
'vagrantfile_path'
]
if
vagrant_wd
in
shpyrd_paths
:
# get the ip address
cp
=
subprocess
.
run
(
[
'vagrant'
,
'ssh-config'
],
cwd
=
vagrant_wd
,
stdout
=
subprocess
.
PIPE
,
stderr
=
subprocess
.
PIPE
,
universal_newlines
=
True
)
if
cp
.
returncode
!=
0
:
ip_addr
=
"<N/A>"
else
:
for
fld
in
cp
.
stdout
.
split
():
if
is_ipaddress
(
str
(
fld
)):
ip_addr
=
str
(
fld
)
break
print
(
f
"
{
v
[
'name'
]
}
\t
{
v
[
'state'
]
}
\t
{
ip_addr
}
"
)
count
+=
1
print
(
'Total {} machine(s)'
.
format
(
count
))
...
...
@@ -107,7 +131,7 @@ def run_playbook(hostname, playbook):
@
only_if_box_exist
def
invoke_shell
(
hostname
):
"""
ru
n a
playbook against one of the boxes
Ope
n a
SSH session to the hostname
"""
dot_shipyard
=
Path
(
os
.
environ
[
'HOME'
],
'.shipyard'
)
vagrant_wd
=
dot_shipyard
.
joinpath
(
hostname
)
...
...
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