Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
S
settingsd
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
etersoft
settingsd
Commits
10183645
Commit
10183645
authored
Feb 10, 2011
by
Devaev Maxim
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
New function execProcess() with input support
parent
8f2b56b5
Show whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
85 additions
and
83 deletions
+85
-83
fmod_common_info.py
plugins/functions/fmod_common_info.py
+4
-4
fmod_date_time.py
plugins/functions/fmod_date_time.py
+4
-4
fmod_disks_smart.py
plugins/functions/fmod_disks_smart.py
+6
-6
fmod_local_groups.py
plugins/functions/fmod_local_groups.py
+15
-9
fmod_local_users.py
plugins/functions/fmod_local_users.py
+19
-18
fmod_machine.py
plugins/functions/fmod_machine.py
+11
-18
fmod_nss_roles.py
plugins/functions/fmod_nss_roles.py
+7
-4
fmod_ntp_config.py
plugins/functions/fmod_ntp_config.py
+1
-2
fmod_system_services.py
plugins/functions/fmod_system_services.py
+12
-12
process.py
settingsd/tools/process.py
+6
-6
No files found.
plugins/functions/fmod_common_info.py
View file @
10183645
...
...
@@ -95,12 +95,12 @@ class CommonInfo(service.FunctionObject) :
### Private ###
def
lsbOption
(
self
,
option
)
:
proc_args
=
"
%
s
%
s"
%
(
config
.
value
(
SERVICE_NAME
,
"lsb_release_bin"
),
option
)
return
":"
.
join
(
tools
.
process
.
execProcess
(
proc_args
)[
0
]
.
split
(
":"
)[
1
:])
.
strip
()
proc_args
_list
=
[
config
.
value
(
SERVICE_NAME
,
"lsb_release_bin"
),
option
]
return
":"
.
join
(
tools
.
process
.
execProcess
(
proc_args
_list
)[
0
]
.
split
(
":"
)[
1
:])
.
strip
()
def
unameOption
(
self
,
option
)
:
proc_args
=
"
%
s
%
s"
%
(
config
.
value
(
SERVICE_NAME
,
"uname_bin"
),
option
)
return
tools
.
process
.
execProcess
(
proc_args
)[
0
]
.
strip
()
proc_args
_list
=
[
config
.
value
(
SERVICE_NAME
,
"uname_bin"
),
option
]
return
tools
.
process
.
execProcess
(
proc_args
_list
)[
0
]
.
strip
()
##### Public classes #####
...
...
plugins/functions/fmod_date_time.py
View file @
10183645
...
...
@@ -37,9 +37,9 @@ class DateTime(service.FunctionObject) :
@service.functionMethod
(
SYSTEM_CLOCK_METHODS_NAMESPACE
,
in_signature
=
"iiiiii"
,
out_signature
=
"i"
)
def
setUtcTime
(
self
,
month
,
monthday
,
hour
,
minute
,
year
,
second
)
:
proc_args
=
"
%
s -u
%02
d
%02
d
%02
d
%02
d
%04
d.
%02
d"
%
(
config
.
value
(
SERVICE_NAME
,
"date_bin"
),
month
,
monthday
,
hour
,
minute
,
year
,
second
)
return
tools
.
process
.
execProcess
(
proc_args
,
False
)[
2
]
proc_args
_list
=
[
config
.
value
(
SERVICE_NAME
,
"date_bin"
),
"-u"
,
"
%02
d
%02
d
%02
d
%02
d
%04
d.
%02
d"
%
(
month
,
monthday
,
hour
,
minute
,
year
,
second
)
]
return
tools
.
process
.
execProcess
(
proc_args
_list
,
fatal_flag
=
False
)[
2
]
@service.functionMethod
(
SYSTEM_CLOCK_METHODS_NAMESPACE
,
out_signature
=
"iiiiii"
)
def
utcTime
(
self
)
:
...
...
@@ -102,7 +102,7 @@ class DateTime(service.FunctionObject) :
@service.functionMethod
(
HARDWARE_CLOCK_METHODS_NAMESPACE
,
out_signature
=
"i"
)
def
syncWithSystem
(
self
)
:
return
tools
.
process
.
execProcess
(
"
%
s --systohc"
%
(
config
.
value
(
SERVICE_NAME
,
"hwclock_bin"
)),
False
)[
0
]
return
tools
.
process
.
execProcess
(
[
config
.
value
(
SERVICE_NAME
,
"hwclock_bin"
),
"--systohc"
],
fatal_flag
=
False
)[
0
]
##### Public classes #####
...
...
plugins/functions/fmod_disks_smart.py
View file @
10183645
...
...
@@ -38,11 +38,11 @@ class Disk(service.FunctionObject) :
@service.functionMethod
(
SMART_METHODS_NAMESPACE
,
out_signature
=
"a(isiiiissss)"
)
def
attributes
(
self
)
:
proc_args
=
"
%
s -A
%
s"
%
(
config
.
value
(
SERVICE_NAME
,
"smartctl_bin"
),
self
.
__device_file_path
)
proc_args
_list
=
[
config
.
value
(
SERVICE_NAME
,
"smartctl_bin"
),
"-A"
,
self
.
__device_file_path
]
attrs_list
=
[]
attrs_found_flag
=
False
for
attrs_list_item
in
tools
.
process
.
execProcess
(
proc_args
)[
0
]
.
split
(
"
\n
"
)
:
for
attrs_list_item
in
tools
.
process
.
execProcess
(
proc_args
_list
)[
0
]
.
split
(
"
\n
"
)
:
attrs_list_item
=
attrs_list_item
.
strip
()
if
attrs_found_flag
:
...
...
@@ -65,11 +65,11 @@ class Disk(service.FunctionObject) :
@service.functionMethod
(
SMART_METHODS_NAMESPACE
,
out_signature
=
"b"
)
def
health
(
self
)
:
proc_args
=
"
%
s -H
%
s"
%
(
config
.
value
(
SERVICE_NAME
,
"smartctl_bin"
),
self
.
__device_file_path
)
proc_args
_list
=
[
config
.
value
(
SERVICE_NAME
,
"smartctl_bin"
),
"-H"
,
self
.
__device_file_path
]
disk_health_flag
=
False
health_found_flag
=
False
for
health_list_item
in
tools
.
process
.
execProcess
(
proc_args
)[
0
]
.
split
(
"
\n
"
)
:
for
health_list_item
in
tools
.
process
.
execProcess
(
proc_args
_list
)[
0
]
.
split
(
"
\n
"
)
:
health_list_item
=
health_list_item
.
strip
()
if
health_found_flag
:
...
...
@@ -142,8 +142,8 @@ class Service(service.Service) :
### Private ###
def
smartAvailable
(
self
,
device_file_path
)
:
proc_args
=
"
%
s
%
s"
%
(
config
.
value
(
SERVICE_NAME
,
"smartctl_bin"
),
device_file_path
)
return
not
bool
(
tools
.
process
.
execProcess
(
proc_args
,
False
)[
2
])
proc_args
_list
=
[
config
.
value
(
SERVICE_NAME
,
"smartctl_bin"
),
device_file_path
]
return
not
bool
(
tools
.
process
.
execProcess
(
proc_args
_list
,
fatal_flag
=
False
)[
2
])
###
...
...
plugins/functions/fmod_local_groups.py
View file @
10183645
...
...
@@ -54,8 +54,8 @@ class LocalGroup(service.FunctionObject) :
logger
.
verbose
(
"{mod}: Request to change gid for local group
\"
%
s
\"
, new gid=
%
d"
%
(
self
.
__group_name
,
gid
))
return
tools
.
process
.
execProcess
(
"
%
s -g
%
d
%
s"
%
(
config
.
value
(
SERVICE_NAME
,
"groupmod_bin"
),
gid
,
self
.
__group_name
),
False
)[
2
]
proc_args_list
=
[
config
.
value
(
SERVICE_NAME
,
"groupmod_bin"
),
"-g"
,
str
(
gid
),
self
.
__group_name
]
return
tools
.
process
.
execProcess
(
proc_args_list
,
fatal_flag
=
False
)[
2
]
@service.functionMethod
(
LOCAL_GROUP_METHODS_NAMESPACE
,
out_signature
=
"i"
)
def
gid
(
self
)
:
...
...
@@ -68,8 +68,9 @@ class LocalGroup(service.FunctionObject) :
user_name
=
validators
.
os
.
validUserName
(
user_name
)
logger
.
verbose
(
"{mod}: Request to add user
\"
%
s
\"
to local group
\"
%
s
\"
"
%
(
user_name
,
self
.
__group_name
))
return
tools
.
process
.
execProcess
(
"
%
s -a -G
%
s
%
s"
%
(
config
.
value
(
SERVICE_NAME
,
"usermod_bin"
),
self
.
__group_name
,
user_name
),
False
)[
2
]
proc_args_list
=
[
config
.
value
(
SERVICE_NAME
,
"usermod_bin"
),
"-a"
,
"-G"
,
self
.
__group_name
,
user_name
]
return
tools
.
process
.
execProcess
(
proc_args_list
,
fatal_flag
=
False
)[
2
]
@service.functionMethod
(
LOCAL_GROUP_METHODS_NAMESPACE
,
in_signature
=
"s"
,
out_signature
=
"i"
)
def
removeUser
(
self
,
user_name
)
:
...
...
@@ -77,10 +78,12 @@ class LocalGroup(service.FunctionObject) :
users_list
=
grp
.
getgrnam
(
self
.
__group_name
)
.
gr_mem
users_list
.
remove
(
self
.
__group_name
)
users
=
","
.
join
(
users_list
)
logger
.
verbose
(
"{mod}: Request to remove user
\"
%
s
\"
from local group
\"
%
s
\"
"
%
(
user_name
,
self
.
__group_name
))
return
tools
.
process
.
execProcess
(
"
%
s -G
%
s
%
s"
%
(
config
.
value
(
SERVICE_NAME
,
"usermod_bin"
),
","
.
join
(
users_list
),
user_name
),
False
)[
2
]
proc_args_list
=
[
config
.
value
(
SERVICE_NAME
,
"usermod_bin"
),
"-G"
,
users
,
user_name
]
return
tools
.
process
.
execProcess
(
proc_args_list
,
fatal_flag
=
False
)[
2
]
@service.functionMethod
(
LOCAL_GROUP_METHODS_NAMESPACE
,
out_signature
=
"as"
)
def
users
(
self
)
:
...
...
@@ -94,18 +97,21 @@ class LocalGroups(service.FunctionObject) :
@service.functionMethod
(
LOCAL_GROUPS_METHODS_NAMESPACE
,
in_signature
=
"si"
,
out_signature
=
"i"
)
def
addGroup
(
self
,
group_name
,
gid
)
:
group_name
=
validators
.
os
.
validGroupName
(
group_name
)
(
gid_arg
,
gid_str
)
=
(
(
"-g
%
d"
%
(
gid
),
str
(
gid
))
if
gid
>=
0
else
(
""
,
"auto"
)
)
(
gid_arg
s_list
,
gid_str
)
=
(
([
"-g"
,
str
(
gid
)],
str
(
gid
))
if
gid
>=
0
else
([]
,
"auto"
)
)
logger
.
verbose
(
"{mod}: Request to add local group
\"
%
s
\"
with gid=
%
s"
%
(
group_name
,
gid_str
))
return
tools
.
process
.
execProcess
(
"
%
s
%
s
%
s"
%
(
config
.
value
(
SERVICE_NAME
,
"groupadd_bin"
),
gid_arg
,
group_name
))
proc_args_list
=
[
config
.
value
(
SERVICE_NAME
,
"groupadd_bin"
)]
+
gid_args_list
+
[
group_name
]
return
tools
.
process
.
execProcess
(
proc_args_list
,
fatal_flag
=
False
)[
2
]
@service.functionMethod
(
LOCAL_GROUPS_METHODS_NAMESPACE
,
in_signature
=
"s"
,
out_signature
=
"i"
)
def
removeGroup
(
self
,
group_name
)
:
group_name
=
validators
.
os
.
validGroupName
(
group_name
)
logger
.
verbose
(
"{mod}: Request to remove local group
\"
%
s
\"
"
%
(
group_name
))
return
tools
.
process
.
execProcess
(
"
%
s
%
s"
%
(
config
.
value
(
SERVICE_NAME
,
"groupdel_bin"
),
group_name
),
False
)[
2
]
proc_args_list
=
[
config
.
value
(
SERVICE_NAME
,
"groupdel_bin"
),
group_name
]
return
tools
.
process
.
execProcess
(
proc_args_list
,
fatal_flag
=
False
)[
2
]
###
...
...
plugins/functions/fmod_local_users.py
View file @
10183645
...
...
@@ -55,8 +55,8 @@ class LocalUser(service.FunctionObject) :
logger
.
verbose
(
"{mod}: Request to change uid for local user
\"
%
s
\"
, new uid=
%
d"
%
(
self
.
__user_name
,
uid
))
return
tools
.
process
.
execProcess
(
"
%
s -u
%
d
%
s"
%
(
config
.
value
(
SERVICE_NAME
,
"usermod_bin"
),
uid
,
self
.
__user_name
),
False
)[
2
]
proc_args_list
=
[
config
.
value
(
SERVICE_NAME
,
"usermod_bin"
),
"-u"
,
str
(
uid
),
self
.
__user_name
]
return
tools
.
process
.
execProcess
(
proc_args_list
,
fatal_flag
=
False
)[
2
]
@service.functionMethod
(
LOCAL_USER_METHODS_NAMESPACE
,
out_signature
=
"i"
)
def
uid
(
self
)
:
...
...
@@ -71,8 +71,8 @@ class LocalUser(service.FunctionObject) :
logger
.
verbose
(
"{mod}: Request to change gid for local user
\"
%
s
\"
, new gid=
%
d"
%
(
self
.
__user_name
,
gid
))
return
tools
.
process
.
execProcess
(
"
%
s -g
%
d
%
s"
%
(
config
.
value
(
SERVICE_NAME
,
"usermod_bin"
),
gid
,
self
.
__user_name
),
False
)[
2
]
proc_args_list
=
[
config
.
value
(
SERVICE_NAME
,
"usermod_bin"
),
"-g"
,
str
(
gid
),
self
.
__user_name
]
return
tools
.
process
.
execProcess
(
proc_args_list
,
fatal_flag
=
False
)[
2
]
@service.functionMethod
(
LOCAL_USER_METHODS_NAMESPACE
,
out_signature
=
"i"
)
def
gid
(
self
)
:
...
...
@@ -87,8 +87,8 @@ class LocalUser(service.FunctionObject) :
logger
.
verbose
(
"{mod}: Request to change home for local user
\"
%
s
\"
, new home=
\"
%
s
\"
"
%
(
self
.
__user_name
,
path
))
return
tools
.
process
.
execProcess
(
"
%
s -d
\'
%
s
\'
%
s"
%
(
config
.
value
(
SERVICE_NAME
,
"usermod_bin"
),
path
,
self
.
__user_name
),
False
)[
2
]
proc_args_list
=
[
config
.
value
(
SERVICE_NAME
,
"usermod_bin"
),
"-d"
,
path
,
self
.
__user_name
]
return
tools
.
process
.
execProcess
(
proc_args_list
,
fatal_flag
=
False
)[
2
]
@service.functionMethod
(
LOCAL_USER_METHODS_NAMESPACE
,
out_signature
=
"s"
)
def
homePath
(
self
)
:
...
...
@@ -101,8 +101,8 @@ class LocalUser(service.FunctionObject) :
logger
.
verbose
(
"{mod}: Request to change shell for local user
\"
%
s
\"
, new shell=
\"
%
s
\"
"
%
(
self
.
__user_name
,
path
))
return
tools
.
process
.
execProcess
(
"
%
s -s
\'
%
s
\'
%
s"
%
(
config
.
value
(
SERVICE_NAME
,
"usermod_bin"
),
path
,
self
.
__user_name
),
False
)[
2
]
proc_args_list
=
[
config
.
value
(
SERVICE_NAME
,
"usermod_bin"
),
"-s"
,
path
,
self
.
__user_name
]
return
tools
.
process
.
execProcess
(
proc_args_list
,
fatal_flag
=
False
)[
2
]
@service.functionMethod
(
LOCAL_USER_METHODS_NAMESPACE
,
out_signature
=
"s"
)
def
shell
(
self
)
:
...
...
@@ -117,8 +117,8 @@ class LocalUser(service.FunctionObject) :
logger
.
verbose
(
"{mod}: Request to change comment for local user
\"
%
s
\"
, new comment=
\"
%
s
\"
"
%
(
self
.
__user_name
,
text
))
return
tools
.
process
.
execProcess
(
"
%
s -c
\'
%
s
\'
%
s"
%
(
config
.
value
(
SERVICE_NAME
,
"usermod_bin"
),
text
,
self
.
__user_name
),
False
)[
2
]
proc_args_list
=
[
config
.
value
(
SERVICE_NAME
,
"usermod_bin"
),
"-c"
,
text
,
self
.
__user_name
]
return
tools
.
process
.
execProcess
(
proc_args_list
,
fatal_flag
=
False
)[
2
]
@service.functionMethod
(
LOCAL_USER_METHODS_NAMESPACE
,
out_signature
=
"s"
)
def
comment
(
self
)
:
...
...
@@ -132,8 +132,8 @@ class LocalUser(service.FunctionObject) :
logger
.
verbose
(
"{mod}: Request to
%
s local user
\"
%
s
\"
"
%
(
lock_str
))
return
tools
.
process
.
execProcess
(
"
%
s
%
s
%
s"
%
(
config
.
value
(
SERVICE_NAME
,
"usermod_bin"
),
lock_arg
,
self
.
__user_name
),
False
)[
2
]
proc_args_list
=
[
config
.
value
(
SERVICE_NAME
,
"usermod_bin"
),
lock_arg
,
self
.
__user_name
]
return
tools
.
process
.
execProcess
(
proc_args_list
,
fatal_flag
=
False
)[
2
]
@service.functionMethod
(
LOCAL_USER_METHODS_NAMESPACE
,
out_signature
=
"b"
)
def
isLocked
(
self
)
:
...
...
@@ -151,13 +151,13 @@ class LocalUsers(service.FunctionObject) :
@service.functionMethod
(
LOCAL_USERS_METHODS_NAMESPACE
,
in_signature
=
"sii"
,
out_signature
=
"i"
)
def
addUser
(
self
,
user_name
,
uid
,
gid
)
:
user_name
=
validators
.
os
.
validUserName
(
user_name
)
(
uid_arg
,
uid_str
)
=
(
(
"-u
%
d"
%
(
uid
),
str
(
uid
))
if
uid
>=
0
else
(
""
,
"auto"
)
)
(
gid_arg
,
gid_str
)
=
(
(
"-g
%
d"
%
(
gid
),
str
(
gid
))
if
gid
>=
0
else
(
""
,
"auto"
)
)
(
uid_arg
s_list
,
uid_str
)
=
(
([
"-u"
,
str
(
uid
)],
str
(
uid
))
if
uid
>=
0
else
([]
,
"auto"
)
)
(
gid_arg
s_list
,
gid_str
)
=
(
([
"-g"
,
str
(
gid
)],
str
(
gid
))
if
gid
>=
0
else
([]
,
"auto"
)
)
logger
.
verbose
(
"{mod}: Request to add local user
\"
%
s
\"
with uid=
%
s and gid=
%
s"
%
(
user_name
,
uid_str
,
gid_str
))
return
tools
.
process
.
execProcess
(
"
%
s
%
s
%
s
%
s"
%
(
config
.
value
(
SERVICE_NAME
,
"useradd_bin"
),
uid_arg
,
gid_arg
,
user_name
))
proc_args_list
=
[
config
.
value
(
SERVICE_NAME
,
"useradd_bin"
)]
+
uid_args_list
+
gid_args_list
+
[
user_name
]
return
tools
.
process
.
execProcess
(
proc_args_list
,
fatal_flag
=
False
)[
2
]
@service.functionMethod
(
LOCAL_USERS_METHODS_NAMESPACE
,
in_signature
=
"sb"
,
out_signature
=
"i"
)
def
removeUser
(
self
,
user_name
,
remove_data_flag
)
:
...
...
@@ -165,8 +165,9 @@ class LocalUsers(service.FunctionObject) :
(
remove_data_arg
,
remove_data_str
)
=
(
(
"-r"
,
" and its data"
)
if
remove_data_flag
else
(
""
,
""
)
)
logger
.
verbose
(
"{mod}: Request to remove local user
\"
%
s
\"
%
s"
%
(
user_name
,
remove_data_str
))
return
tools
.
process
.
execProcess
(
"
%
s
%
s
%
s"
%
(
config
.
value
(
SERVICE_NAME
,
"userdel_bin"
),
remove_data_arg
,
user_name
),
False
)[
2
]
proc_args_list
=
[
config
.
value
(
SERVICE_NAME
,
"userdel_bin"
),
remove_data_arg
,
user_name
]
return
tools
.
process
.
execProcess
(
proc_args_list
,
fatal_flag
=
False
)[
2
]
###
...
...
plugins/functions/fmod_machine.py
View file @
10183645
...
...
@@ -19,9 +19,6 @@ SERVICE_NAME = "machine"
POWER_METHODS_NAMESPACE
=
"power"
RUNLEVELS_METHODS_NAMESPACE
=
"runlevels"
RUNLEVELS
=
"0123456"
##### Private classes #####
class
Machine
(
service
.
FunctionObject
)
:
...
...
@@ -29,33 +26,31 @@ class Machine(service.FunctionObject) :
@service.functionMethod
(
POWER_METHODS_NAMESPACE
,
out_signature
=
"i"
)
def
shutdown
(
self
)
:
return
tools
.
process
.
execProcess
(
"
%
s -h now"
%
(
config
.
value
(
SERVICE_NAME
,
"shutdown_bin"
)),
False
)[
2
]
return
tools
.
process
.
execProcess
(
[
config
.
value
(
SERVICE_NAME
,
"shutdown_bin"
),
"-h"
,
"now"
],
fatal_flag
=
False
)[
2
]
@service.functionMethod
(
POWER_METHODS_NAMESPACE
,
out_signature
=
"i"
)
def
reboot
(
self
)
:
return
tools
.
process
.
execProcess
(
"
%
s -r now"
%
(
config
.
value
(
SERVICE_NAME
,
"shutdown_bin"
)),
False
)[
2
]
return
tools
.
process
.
execProcess
(
[
config
.
value
(
SERVICE_NAME
,
"shutdown_bin"
),
"-r"
,
"now"
],
fatal_flag
=
False
)[
2
]
@service.functionMethod
(
POWER_METHODS_NAMESPACE
,
out_signature
=
"i"
)
def
suspend
(
self
)
:
return
tools
.
process
.
execProcess
(
config
.
value
(
SERVICE_NAME
,
"pm_suspend_bin"
),
False
)[
2
]
return
tools
.
process
.
execProcess
(
config
.
value
(
SERVICE_NAME
,
"pm_suspend_bin"
),
fatal_flag
=
False
)[
2
]
@service.functionMethod
(
POWER_METHODS_NAMESPACE
,
out_signature
=
"i"
)
def
hibernate
(
self
)
:
return
tools
.
process
.
execProcess
(
config
.
value
(
SERVICE_NAME
,
"pm_hibernate_bin"
),
False
)[
2
]
return
tools
.
process
.
execProcess
(
config
.
value
(
SERVICE_NAME
,
"pm_hibernate_bin"
),
fatal_flag
=
False
)[
2
]
###
@service.functionMethod
(
RUNLEVELS_METHODS_NAMESPACE
,
in_signature
=
"i"
,
out_signature
=
"i"
)
def
switchTo
(
self
,
level
)
:
proc_args
=
"
%
s
%
s"
%
(
config
.
value
(
SERVICE_NAME
,
"telinit_bin"
),
validators
.
common
.
validRange
(
str
(
level
),
RUNLEVELS
))
return
tools
.
process
.
execProcess
(
proc_args
,
False
)[
2
]
proc_args
_list
=
[
config
.
value
(
SERVICE_NAME
,
"telinit_bin"
),
validators
.
common
.
validRange
(
str
(
level
),
"0123456"
)]
return
tools
.
process
.
execProcess
(
proc_args
_list
,
fatal_flag
=
False
)[
2
]
@service.functionMethod
(
RUNLEVELS_METHODS_NAMESPACE
,
out_signature
=
"i"
)
def
currentLevel
(
self
)
:
proc_args
=
config
.
value
(
SERVICE_NAME
,
"runlevel_bin"
)
level_pairs_list
=
tools
.
process
.
execProcess
(
proc_args
)[
0
]
.
strip
()
.
split
(
" "
)
if
len
(
level_pairs_list
)
!=
2
or
not
level_pairs_list
[
1
]
in
RUNLEVELS
:
level_pairs_list
=
tools
.
process
.
execProcess
(
config
.
value
(
SERVICE_NAME
,
"runlevel_bin"
))[
0
]
.
strip
()
.
split
(
" "
)
if
len
(
level_pairs_list
)
!=
2
or
not
level_pairs_list
[
1
]
in
"0123456"
:
raise
tools
.
process
.
SubprocessFailure
(
"Error while execute
\"
%
s
\"\n
Stdout:
%
s
\n
Stderr:
%
s
\n
Return code:
%
d"
%
(
proc_args
,
proc_stdout
.
strip
(),
proc_stderr
.
strip
(),
proc_returncode
))
...
...
@@ -63,14 +58,12 @@ class Machine(service.FunctionObject) :
@service.functionMethod
(
RUNLEVELS_METHODS_NAMESPACE
,
out_signature
=
"i"
)
def
previousLevel
(
self
)
:
proc_args
=
config
.
value
(
SERVICE_NAME
,
"runlevel_bin"
)
level_pairs_list
=
tools
.
process
.
execProcess
(
proc_args
)[
0
]
.
strip
()
.
split
(
" "
)
if
len
(
level_pairs_list
)
!=
2
or
not
level_pairs_list
[
1
]
in
RUNLEVELS
+
"N"
:
level_pairs_list
=
tools
.
process
.
execProcess
(
config
.
value
(
SERVICE_NAME
,
"runlevel_bin"
))[
0
]
.
strip
()
.
split
(
" "
)
if
len
(
level_pairs_list
)
!=
2
or
not
level_pairs_list
[
1
]
in
"0123456N"
:
raise
tools
.
process
.
SubprocessFailure
(
"Error while execute
\"
%
s
\"\n
Stdout:
%
s
\n
Stderr:
%
s
\n
Return code:
%
d"
%
(
proc_args
,
proc_stdout
.
strip
(),
proc_stderr
.
strip
(),
proc_returncode
))
return
(
int
(
level_pairs_list
[
0
])
if
level_pairs_list
[
0
]
in
RUNLEVELS
else
-
1
)
return
(
int
(
level_pairs_list
[
0
])
if
level_pairs_list
[
0
]
in
"0123456"
else
-
1
)
##### Public classes #####
...
...
plugins/functions/fmod_nss_roles.py
View file @
10183645
...
...
@@ -128,8 +128,9 @@ class NssRole(service.FunctionObject) :
user_name
=
validators
.
os
.
validUserName
(
user_name
)
logger
.
verbose
(
"{mod}: Request to add user
\"
%
s
\"
to NSS role
\"
%
s
\"
"
%
(
user_name
,
self
.
__role_name
))
return
tools
.
process
.
execProcess
(
"
%
s -a -G
%
s
%
s"
%
(
config
.
value
(
SERVICE_NAME
,
"usermod_bin"
),
self
.
__role_name
,
user_name
),
False
)[
2
]
proc_args_list
=
[
config
.
value
(
SERVICE_NAME
,
"usermod_bin"
),
"-a"
,
"-G"
,
self
.
__role_name
,
user_name
]
return
tools
.
process
.
execProcess
(
proc_args_list
,
fatal_flag
=
False
)[
2
]
@service.functionMethod
(
NSS_ROLE_METHODS_NAMESPACE
,
in_signature
=
"s"
,
out_signature
=
"i"
)
def
removeUser
(
self
,
user_name
)
:
...
...
@@ -137,10 +138,12 @@ class NssRole(service.FunctionObject) :
users_list
=
grp
.
getgrnam
(
self
.
__role_name
)
.
gr_mem
users_list
.
remove
(
self
.
__role_name
)
users
=
","
.
join
(
users_list
)
logger
.
verbose
(
"{mod}: Request to remove user
\"
%
s
\"
from NSS role
\"
%
s
\"
"
%
(
user_name
,
self
.
__role_name
))
return
tools
.
process
.
execProcess
(
"
%
s -G
%
s
%
s"
%
(
config
.
value
(
SERVICE_NAME
,
"usermod_bin"
),
","
.
join
(
users_list
),
user_name
),
False
)[
2
]
proc_args_list
=
[
config
.
value
(
SERVICE_NAME
,
"usermod_bin"
),
"-G"
,
users
,
user_name
]
return
tools
.
process
.
execProcess
(
proc_args_list
,
fatal_flag
=
False
)[
2
]
@service.functionMethod
(
NSS_ROLE_METHODS_NAMESPACE
,
out_signature
=
"as"
)
def
users
(
self
)
:
...
...
plugins/functions/fmod_ntp_config.py
View file @
10183645
...
...
@@ -46,8 +46,7 @@ class NtpConfig(service.FunctionObject) :
@service.functionMethod
(
NTP_METHODS_NAMESPACE
)
def
request
(
self
)
:
proc_args
=
"
%
s
%
s"
%
(
config
.
value
(
SERVICE_NAME
,
"ntpdate_bin"
),
" "
.
join
(
self
.
servers
()))
tools
.
process
.
execProcess
(
proc_args
)
tools
.
process
.
execProcess
([
config
.
value
(
SERVICE_NAME
,
"ntpdate_bin"
)]
+
self
.
servers
())
##### Public classes #####
...
...
plugins/functions/fmod_system_services.py
View file @
10183645
...
...
@@ -55,8 +55,8 @@ class SystemService(service.FunctionObject) :
@service.functionMethod
(
SYSTEM_SERVICE_METHODS_NAMESPACE
,
out_signature
=
"s"
)
def
levelsMap
(
self
)
:
proc_args
=
"
%
s --list
%
s"
%
(
config
.
value
(
SERVICE_NAME
,
"chkconfig_bin"
),
self
.
__system_service_name
)
(
proc_stdout
,
proc_stderr
,
proc_returncode
)
=
tools
.
process
.
execProcess
(
proc_args
)
proc_args
_list
=
[
config
.
value
(
SERVICE_NAME
,
"chkconfig_bin"
),
"--list"
,
self
.
__system_service_name
]
(
proc_stdout
,
proc_stderr
,
proc_returncode
)
=
tools
.
process
.
execProcess
(
proc_args
_list
)
service_record_list
=
re
.
split
(
r"\s+"
,
proc_stdout
.
split
(
"
\n
"
)[
0
])
levels_list
=
[
"0"
]
*
(
len
(
service_record_list
)
-
1
)
...
...
@@ -81,19 +81,19 @@ class SystemService(service.FunctionObject) :
@service.functionMethod
(
SYSTEM_SERVICE_METHODS_NAMESPACE
,
out_signature
=
"i"
)
def
start
(
self
)
:
logger
.
verbose
(
"{mod}: Request to start service
\"
%
s
\"
"
%
(
self
.
__system_service_name
))
return
tools
.
process
.
execProcess
(
"
%
s start"
%
(
os
.
path
.
join
(
config
.
value
(
SERVICE_NAME
,
"initd_dir"
),
self
.
__system_service_name
)
),
False
)[
2
]
proc_args_list
=
[
os
.
path
.
join
(
config
.
value
(
SERVICE_NAME
,
"initd_dir"
),
self
.
__system_service_name
),
"start"
]
return
tools
.
process
.
execProcess
(
proc_args_list
,
fatal_flag
=
False
)[
2
]
@service.functionMethod
(
SYSTEM_SERVICE_METHODS_NAMESPACE
,
out_signature
=
"i"
)
def
stop
(
self
)
:
logger
.
verbose
(
"{mod}: Request to stop service
\"
%
s
\"
"
%
(
self
.
__system_service_name
))
return
tools
.
process
.
execProcess
(
"
%
s stop"
%
(
os
.
path
.
join
(
config
.
value
(
SERVICE_NAME
,
"initd_dir"
),
self
.
__system_service_name
)
),
False
)[
2
]
proc_args_list
=
[
os
.
path
.
join
(
config
.
value
(
SERVICE_NAME
,
"initd_dir"
),
self
.
__system_service_name
),
"stop"
]
return
tools
.
process
.
execProcess
(
proc_args_list
,
fatal_flag
=
False
)[
2
]
@service.functionMethod
(
SYSTEM_SERVICE_METHODS_NAMESPACE
,
out_signature
=
"i"
)
def
status
(
self
)
:
return
tools
.
process
.
execProcess
(
"
%
s status"
%
(
os
.
path
.
join
(
config
.
value
(
SERVICE_NAME
,
"initd_dir"
),
self
.
__system_service_name
)
),
False
)[
2
]
proc_args_list
=
[
os
.
path
.
join
(
config
.
value
(
SERVICE_NAME
,
"initd_dir"
),
self
.
__system_service_name
),
"status"
]
return
tools
.
process
.
execProcess
(
proc_args_list
,
fatal_flag
=
False
)[
2
]
### Private ###
...
...
@@ -104,10 +104,10 @@ class SystemService(service.FunctionObject) :
logger
.
verbose
(
"Request to
%
s service
\"
%
s
\"
on runlevels
\"
%
s
\"
"
%
(
(
"enable"
if
enabled_flag
else
"disable"
),
self
.
__system_service_name
,
(
levels
if
levels
!=
None
else
"default"
)
))
proc_args
=
"
%
s
%
s
%
s
%
s"
%
(
config
.
value
(
SERVICE_NAME
,
"chkconfig_bin"
),
(
"--level
%
s"
%
(
levels
)
if
levels
!=
None
else
""
),
self
.
__system_service_name
,
(
"on"
if
enabled_flag
else
"off"
)
)
return
tools
.
process
.
execProcess
(
proc_args
,
False
)[
2
]
proc_args
_list
=
(
[
config
.
value
(
SERVICE_NAME
,
"chkconfig_bin"
)]
+
(
[
"--level"
,
str
(
levels
)]
if
levels
!=
None
else
[]
),
self
.
__system_service_name
,
(
[
"on"
]
if
enabled_flag
else
[
"off"
]
)
)
return
tools
.
process
.
execProcess
(
proc_args
_list
,
fatal_flag
=
False
)[
2
]
###
...
...
settingsd/tools/process.py
View file @
10183645
...
...
@@ -11,22 +11,22 @@ class SubprocessFailure(Exception) :
##### Public methods #####
def
execProcess
(
proc_args
,
fatal_flag
=
True
)
:
logger
.
debug
(
"{submod}: Executing child process
\"
%
s
\"
"
%
(
proc_args
))
def
execProcess
(
args_list
,
input
=
None
,
fatal_flag
=
True
)
:
logger
.
debug
(
"{submod}: Executing child process
\"
%
s
\"
"
%
(
str
(
args_list
)
))
proc
=
subprocess
.
Popen
(
proc_args
,
shell
=
True
,
bufsize
=
1024
,
close_fds
=
True
,
proc
=
subprocess
.
Popen
(
args_list
,
shell
=
True
,
bufsize
=
1024
,
close_fds
=
True
,
stdin
=
subprocess
.
PIPE
,
stdout
=
subprocess
.
PIPE
,
stderr
=
subprocess
.
PIPE
,
env
=
{
"LC_ALL"
:
"C"
})
(
proc_stdout
,
proc_stderr
)
=
proc
.
communicate
()
(
proc_stdout
,
proc_stderr
)
=
proc
.
communicate
(
input
)
if
proc
.
returncode
!=
0
:
error_text
=
"Error while execute
\"
%
s
\"\n
Stdout:
%
s
\n
Stderr:
%
s
\n
Return code:
%
d"
%
(
proc_args
,
proc_stdout
.
strip
(),
proc_stderr
.
strip
(),
proc
.
returncode
)
str
(
args_list
)
,
proc_stdout
.
strip
(),
proc_stderr
.
strip
(),
proc
.
returncode
)
if
fatal_flag
:
raise
SubprocessFailure
(
error_text
)
logger
.
error
(
"{submod}: "
+
error_text
)
logger
.
debug
(
"{submod}: Child process
\"
%
s
\"
finished, return_code=
%
d"
%
(
proc_args
,
proc
.
returncode
))
logger
.
debug
(
"{submod}: Child process
\"
%
s
\"
finished, return_code=
%
d"
%
(
str
(
args_list
)
,
proc
.
returncode
))
return
(
proc_stdout
,
proc_stderr
,
proc
.
returncode
)
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