Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
A
ansible
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
OpenEdx
ansible
Commits
5d05049e
Commit
5d05049e
authored
Aug 08, 2014
by
Michael DeHaan
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #7670 from dagwieers/patch-3
Added cross-platform uptime fact
parents
c56ce4c9
fd6f0cb4
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
25 additions
and
0 deletions
+25
-0
lib/ansible/module_utils/facts.py
+25
-0
No files found.
lib/ansible/module_utils/facts.py
View file @
5d05049e
...
...
@@ -120,6 +120,7 @@ class Facts(object):
self
.
facts
=
{}
self
.
get_platform_facts
()
self
.
get_distribution_facts
()
self
.
get_uptime
()
self
.
get_cmdline
()
self
.
get_public_ssh_host_keys
()
self
.
get_selinux_facts
()
...
...
@@ -133,6 +134,20 @@ class Facts(object):
def
populate
(
self
):
return
self
.
facts
def
get_uptime
(
self
):
uptime_path
=
module
.
get_bin_path
(
'uptime'
)
if
uptime_path
:
rc
,
out
,
err
=
module
.
run_command
(
uptime_path
)
if
rc
==
0
:
raw
=
out
.
replace
(
','
,
''
)
days
=
int
(
raw
.
split
()[
2
])
if
'min'
in
raw
:
hours
=
0
minutes
=
int
(
raw
.
split
()[
4
])
else
:
hours
,
minutes
=
map
(
int
,
raw
.
split
()[
4
]
.
split
(
':'
))
self
.
facts
[
'uptime'
]
=
days
*
24
*
60
*
60
+
hours
*
60
*
60
+
minutes
*
60
# Platform
# platform.system() can be Linux, Darwin, Java, or Windows
def
get_platform_facts
(
self
):
...
...
@@ -543,6 +558,11 @@ class LinuxHardware(Hardware):
pass
return
self
.
facts
def
get_uptime
(
self
):
data
=
get_file_content
(
'/proc/uptime'
)
if
data
:
self
.
facts
[
'uptime'
]
=
float
(
data
.
split
()[
0
])
def
get_memory_facts
(
self
):
if
not
os
.
access
(
"/proc/meminfo"
,
os
.
R_OK
):
return
...
...
@@ -806,6 +826,11 @@ class SunOSHardware(Hardware):
self
.
get_memory_facts
()
return
self
.
facts
def
get_uptime
(
self
):
rc
,
out
,
err
=
module
.
run_command
(
"/usr/bin/kstat -p unix:0:system_misc:snaptime"
)
if
out
:
self
.
facts
[
'uptime'
]
=
float
(
out
.
split
()[
1
])
def
get_cpu_facts
(
self
):
physid
=
0
sockets
=
{}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a 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