Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
ISC Open Source Projects
Kea
Commits
a47c2eae
Commit
a47c2eae
authored
Aug 08, 2012
by
Jelte Jansen
Browse files
[2172] rearrange freebsd/osx hierarchy
parent
371d3158
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/lib/python/isc/sysinfo/sysinfo.py
View file @
a47c2eae
...
...
@@ -349,9 +349,9 @@ class SysInfoOpenBSD(SysInfoBSD):
except
(
subprocess
.
CalledProcessError
,
OSError
):
self
.
_net_routing_table
=
'Warning: "route -n show" command failed.
\n
'
class
SysInfoFreeBSD
(
SysInfoBSD
):
"""
FreeBSD
implementation of the SysInfo
class.
See the SysInfo class documentation for more information.
class
SysInfoFreeBSD
OSX
(
SysInfoBSD
):
"""
Shared code for the FreeBSD and OS X
implementation
s
of the SysInfo
class.
See the SysInfo class documentation for more information.
"""
def
__init__
(
self
):
super
().
__init__
()
...
...
@@ -360,12 +360,6 @@ class SysInfoFreeBSD(SysInfoBSD):
self
.
_mem_cached
=
-
1
self
.
_mem_buffers
=
-
1
try
:
s
=
subprocess
.
check_output
([
'sysctl'
,
'-n'
,
'kern.smp.active'
])
self
.
_platform_is_smp
=
int
(
s
.
decode
(
'utf-8'
).
strip
())
>
0
except
(
subprocess
.
CalledProcessError
,
OSError
):
pass
try
:
s
=
subprocess
.
check_output
([
'sysctl'
,
'-n'
,
'kern.boottime'
])
t
=
s
.
decode
(
'utf-8'
).
strip
()
...
...
@@ -389,6 +383,25 @@ class SysInfoFreeBSD(SysInfoBSD):
except
(
subprocess
.
CalledProcessError
,
OSError
):
pass
try
:
s
=
subprocess
.
check_output
([
'netstat'
,
'-nr'
])
self
.
_net_routing_table
=
s
.
decode
(
'utf-8'
)
except
(
subprocess
.
CalledProcessError
,
OSError
):
self
.
_net_connections
=
'Warning: "netstat -nr" command failed.
\n
'
class
SysInfoFreeBSD
(
SysInfoFreeBSDOSX
):
"""FreeBSD implementation of the SysInfo class.
See the SysInfo class documentation for more information.
"""
def
__init__
(
self
):
super
().
__init
()
try
:
s
=
subprocess
.
check_output
([
'sysctl'
,
'-n'
,
'kern.smp.active'
])
self
.
_platform_is_smp
=
int
(
s
.
decode
(
'utf-8'
).
strip
())
>
0
except
(
subprocess
.
CalledProcessError
,
OSError
):
pass
try
:
s
=
subprocess
.
check_output
([
'vmstat'
,
'-H'
])
lines
=
s
.
decode
(
'utf-8'
).
split
(
'
\n
'
)
...
...
@@ -408,49 +421,22 @@ class SysInfoFreeBSD(SysInfoBSD):
except
(
subprocess
.
CalledProcessError
,
OSError
):
pass
try
:
s
=
subprocess
.
check_output
([
'netstat'
,
'-nr'
])
self
.
_net_routing_table
=
s
.
decode
(
'utf-8'
)
except
(
subprocess
.
CalledProcessError
,
OSError
):
self
.
_net_connections
=
'Warning: "netstat -nr" command failed.
\n
'
class
SysInfoOSX
(
SysInfoBSD
):
class
SysInfoOSX
(
SysInfoFreeBSDOSX
):
"""OS X (Darwin) implementation of the SysInfo class.
See the SysInfo class documentation for more information.
"""
def
__init__
(
self
):
super
().
__init__
()
# Don't know how to gather these
self
.
_mem_cached
=
-
1
self
.
_mem_buffers
=
-
1
try
:
s
=
subprocess
.
check_output
([
'sysctl'
,
'-n'
,
'kern.smp.active'
])
self
.
_platform_is_smp
=
int
(
s
.
decode
(
'utf-8'
).
strip
())
>
0
except
(
subprocess
.
CalledProcessError
,
OSError
):
pass
try
:
s
=
subprocess
.
check_output
([
'sysctl'
,
'-n'
,
'kern.boottime'
])
t
=
s
.
decode
(
'utf-8'
).
strip
()
r
=
re
.
match
(
'^\{\s+sec\s+\=\s+(\d+),.*'
,
t
)
if
r
:
sec
=
time
.
time
()
-
int
(
r
.
group
(
1
))
self
.
_uptime
=
int
(
round
(
sec
))
except
(
subprocess
.
CalledProcessError
,
OSError
):
pass
# note; this call overrides the value already set when hw.physmem
# was read. However, on OSX, physmem is not necessarily the correct
# value. But since it does not fail and does work on most BSD's, it's
# left in the base class and overwritten here
try
:
s
=
subprocess
.
check_output
([
'sysctl'
,
'-n'
,
'vm.loadavg'
])
l
=
s
.
decode
(
'utf-8'
).
strip
()
r
=
re
.
match
(
'^\{(.*)\}$'
,
l
)
if
r
:
la
=
r
.
group
(
1
).
strip
().
split
(
' '
)
else
:
la
=
l
.
split
(
' '
)
if
len
(
la
)
>=
3
:
self
.
_loadavg
=
[
float
(
la
[
0
]),
float
(
la
[
1
]),
float
(
la
[
2
])]
s
=
subprocess
.
check_output
([
'sysctl'
,
'-n'
,
'hw.memsize'
])
self
.
_mem_total
=
int
(
s
.
decode
(
'utf-8'
).
strip
())
except
(
subprocess
.
CalledProcessError
,
OSError
):
pass
...
...
@@ -459,7 +445,7 @@ class SysInfoOSX(SysInfoBSD):
lines
=
s
.
decode
(
'utf-8'
).
split
(
'
\n
'
)
# store all values in a dict
values
=
{}
page_size
=
4096
page_size
=
None
page_size_re
=
re
.
compile
(
'page size of [0-9]+ bytes'
)
for
line
in
lines
:
page_size_m
=
page_size_re
.
match
(
line
)
...
...
@@ -468,7 +454,10 @@ class SysInfoOSX(SysInfoBSD):
else
:
key
,
_
,
value
=
line
.
partition
(
':'
)
values
[
key
]
=
value
.
strip
()[:
-
1
]
self
.
_mem_free
=
int
(
values
[
'Pages free'
])
*
page_size
# Only calculate memory if page size is known
if
page_size
is
not
None
:
self
.
_mem_free
=
int
(
values
[
'Pages free'
])
*
page_size
+
int
(
values
[
'Pages speculative'
])
*
page_size
except
(
subprocess
.
CalledProcessError
,
OSError
):
pass
...
...
@@ -482,13 +471,6 @@ class SysInfoOSX(SysInfoBSD):
except
(
subprocess
.
CalledProcessError
,
OSError
):
pass
try
:
s
=
subprocess
.
check_output
([
'netstat'
,
'-nr'
])
self
.
_net_routing_table
=
s
.
decode
(
'utf-8'
)
except
(
subprocess
.
CalledProcessError
,
OSError
):
self
.
_net_connections
=
'Warning: "netstat -nr" command failed.
\n
'
class
SysInfoTestcase
(
SysInfo
):
def
__init__
(
self
):
...
...
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