本文整理汇总了Python中synapse.syncmd.exec_cmd函数的典型用法代码示例。如果您正苦于以下问题:Python exec_cmd函数的具体用法?Python exec_cmd怎么用?Python exec_cmd使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了exec_cmd函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: update
def update(name):
if name:
ret = exec_cmd(
"/usr/bin/apt-get -quy install {0} --force-yes".format(name))
if ret['returncode'] != 0:
raise ResourceException(ret['stderr'])
else:
ret = exec_cmd("/usr/bin/apt-get -qy update")
ret = exec_cmd("/usr/bin/apt-get -qy upgrade --force-yes")
if ret['returncode'] != 0:
raise ResourceException(ret['stderr'])
示例2: user_add
def user_add(name, password, login_group, groups,
homedir, comment, uid, gid, shell):
cmd = ['/usr/sbin/useradd']
if login_group:
cmd += ['-g', login_group]
if len(groups):
cmd += ['-G', ','.join(groups)]
if homedir:
cmd += ['--home', homedir]
if comment:
cmd += ['--comment', comment]
if uid:
cmd += ['--uid', uid]
if gid:
cmd += ['--gid', gid]
if shell:
cmd += ['--shell', shell]
cmd.append(name)
ret = exec_cmd(' '.join(cmd))
# retcode 9 is group already exists. That's what we want.
if ret['returncode'] != 9 and ret['returncode'] != 0:
raise ResourceException(ret['stderr'])
if password:
set_password(name, password)
示例3: user_add
def user_add(name, password, login_group, groups):
cmd = []
cmd.append("/usr/sbin/useradd")
if login_group:
cmd.append("-g")
cmd.append(login_group)
if groups:
groups_no_ws = re.sub(r'\s', '', groups)
try:
group_list = groups_no_ws.split(',')
for group in group_list:
groups.read(group)
cmd.append("-G")
cmd.append(groups_no_ws)
except ResourceException:
raise ResourceException("Group does not exist")
cmd.append(name)
ret = exec_cmd(' '.join(cmd))
if ret['returncode'] != 0:
raise ResourceException(ret['stderr'])
if password:
set_password(name, password)
示例4: user_mod
def user_mod(name, password, login_group, groups, homedir, move_home,
comment, uid, gid, shell):
try:
if password:
set_password(name, password)
cmd = ["/usr/sbin/usermod"]
if login_group:
cmd += ['-g', login_group]
if len(groups):
cmd += ['-G', ','.join(groups)]
if homedir:
cmd += ['--home', homedir]
if homedir and move_home:
cmd += ['--move-home']
if comment:
cmd += ['--comment', comment]
if uid:
cmd += ['--uid', uid]
if gid:
cmd += ['--gid', gid]
if shell:
cmd += ['--shell', shell]
cmd.append(name)
if len(cmd) > 2:
ret = exec_cmd(' '.join(cmd))
if ret['returncode'] != 0:
raise ResourceException(ret['stderr'])
except ResourceException:
raise
示例5: _execute
def _execute(self, name, cmd):
result = exec_cmd(cmd)
if result['returncode'] != 0:
result['name'] = name
msg = OutgoingMessage(collection=self.__resource__, status=result,
msg_type='alert')
self.publish(msg)
示例6: read
def read(self, res_id=None, attributes=None):
sensors = attributes.keys()
status = {}
for sensor in sensors:
if sensor in self.plugins.keys():
status[sensor] = exec_cmd(self.plugins[sensor]['command'])
return status
示例7: update
def update(name):
# We need to check first if the package is installed. yum update of a
# non-existing package has a returncode of 0. We need to raise an exception
# if the package is not installed !
inst = is_installed(name)
ret = exec_cmd("/usr/bin/yum -q -y update %s" % name)
if ret['returncode'] != 0 or not inst:
raise ResourceException(ret['stderr'])
示例8: get_groups
def get_groups(name):
cmd = ["/usr/bin/groups"]
cmd.append(name)
ret = exec_cmd(' '.join(cmd))
if ret['returncode'] != 0:
raise ResourceException(ret['stderr'])
# Return a list of groups
return ret['stdout'].split(':')[1].lstrip().split()
示例9: update
def update(self, res_id=None, attributes=None):
if not res_id:
raise ResourceException('Please provide a command')
#exec_status = self.module.exec_threaded_cmd(res_id)
self.logger.info("Executing: %s" % res_id)
exec_status = exec_cmd(res_id)
self.response = self.set_response(exec_status)
self.logger.info("Done executing '%s'" % res_id)
return self.response
示例10: group_add
def group_add(name, gid):
cmd = ["/usr/sbin/groupadd"]
if gid:
cmd += ['--gid', "%s" % gid]
cmd.append(name)
ret = exec_cmd(' '.join(cmd))
# retcode 9 is group already exists. That's what we want.
if ret['returncode'] != 9 and ret['returncode'] != 0:
raise ResourceException(ret['stderr'])
示例11: update
def update(self, res_id=None, attributes=None):
if not res_id:
raise ResourceException("Please provide a command")
# status = self.module.exec_threaded_cmd(res_id)
self.logger.info("Executing: %s" % res_id)
status = exec_cmd(res_id)
if status["returncode"] != 0:
error = "Status code %s: [%s]" % (status["returncode"], status["stderr"])
raise ResourceException(error)
self.logger.info("Done executing '%s'" % res_id)
return status
示例12: is_enabled
def is_enabled(name):
ret = exec_cmd("/sbin/runlevel")
if ret['returncode'] != 0:
raise ResourceException(ret['stderr'])
match = False
try:
runlevel = ret['stdout'].split()[1]
for filename in os.listdir('/etc/rc%s.d' % runlevel):
if name in filename and filename.startswith('S'):
match = True
except ValueError, err:
raise ResourceException(err)
示例13: user_mod
def user_mod(name,
password=None,
login_group=None,
add_to_groups=None,
remove_from_groups=None,
set_groups=None
):
try:
if password:
set_password(name, password)
cmd = []
cmd.append("/usr/sbin/usermod")
if login_group:
cmd.append("-g")
cmd.append(login_group)
elif add_to_groups:
groups = filter_existing_groups(add_to_groups)
if len(groups):
cmd.append("-G")
cmd.append(','.join(groups))
cmd.append("-a")
elif remove_from_groups:
groups = filter_existing_groups(remove_from_groups)
current_groups = get_groups(name)
if len(groups):
groups_to_set = filter(lambda x: x not in groups,
current_groups)
cmd.append("-G")
cmd.append(','.join(groups_to_set))
elif set_groups:
groups = filter_existing_groups(set_groups)
if len(groups):
cmd.append("-G")
cmd.append(','.join(groups))
cmd.append(name)
if len(cmd) > 2:
ret = exec_cmd(' '.join(cmd))
if ret['returncode'] != 0:
raise ResourceException(ret['stderr'])
except ResourceException:
raise
示例14: group_mod
def group_mod(name, new_name, gid):
cmd = ["/usr/sbin/groupmod"]
if new_name:
cmd += ['--new-name', "%s" % new_name]
if gid:
cmd += ['--gid', "%s" % gid]
cmd.append(name)
ret = exec_cmd(' '.join(cmd))
if ret['returncode'] != 0:
raise ResourceException(ret['stderr'])
示例15: update
def update(self, res_id=None, attributes=None):
if not res_id:
raise ResourceException('Please provide a command')
#exec_status = self.module.exec_threaded_cmd(res_id)
self.logger.info("Executing: %s" % res_id)
exec_status = exec_cmd(res_id)
if exec_status['returncode'] != 0:
error = "Status code %s: [%s]" %(exec_status["returncode"],
exec_status["stderr"])
raise ResourceException(error)
self.response = self.set_response(exec_status)
self.logger.info("Done executing '%s'" % res_id)
return self.response