Page Menu
Home
ClusterLabs Projects
Search
Configure Global Search
Log In
Files
F2822293
utils.py
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Size
615 B
Referenced Files
None
Subscribers
None
utils.py
View Options
#!/usr/bin/python
import
subprocess
import
re
def
run_cmd
(
cmd
):
p
=
subprocess
.
Popen
(
cmd
,
stdout
=
subprocess
.
PIPE
,
stderr
=
subprocess
.
PIPE
)
(
stdout
,
stderr
)
=
p
.
communicate
()
return
(
stdout
,
stderr
,
p
.
returncode
)
def
get_IP
():
(
stdout
,
stderr
,
returncode
)
=
run_cmd
([
'hostname'
,
'-i'
])
if
returncode
!=
0
:
raise
RuntimeError
,
"Failed to run hostname -i:
\n
"
+
stderr
# in case multiple IP addresses are returned, use only the first
# and also strip '%<device>' part possibly present with IPv6 address
ret
=
re
.
sub
(
r'\s.*'
,
''
,
stdout
)
return
"::1"
if
'%'
in
ret
else
ret
File Metadata
Details
Attached
Mime Type
text/x-script.python
Expires
Sat, Jan 25, 5:26 AM (9 h, 14 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
1239778
Default Alt Text
utils.py (615 B)
Attached To
Mode
rB Booth
Attached
Detach File
Event Timeline
Log In to Comment