当前位置: 首页>>代码示例>>Python>>正文


Python syncmd.exec_cmd函数代码示例

本文整理汇总了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'])
开发者ID:comodit,项目名称:synapse-agent,代码行数:11,代码来源:apt.py

示例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)
开发者ID:mjvaldez,项目名称:synapse-agent,代码行数:30,代码来源:unix-users.py

示例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)
开发者ID:UshiDesign,项目名称:synapse-agent,代码行数:26,代码来源:win-users.py

示例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
开发者ID:mjvaldez,项目名称:synapse-agent,代码行数:34,代码来源:unix-users.py

示例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)
开发者ID:comodit,项目名称:synapse-agent,代码行数:7,代码来源:nagios.py

示例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
开发者ID:comodit,项目名称:synapse-agent,代码行数:8,代码来源:nagios.py

示例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'])
开发者ID:UshiDesign,项目名称:synapse-agent,代码行数:9,代码来源:yum-pkg.py

示例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()
开发者ID:mjvaldez,项目名称:synapse-agent,代码行数:10,代码来源:unix-users.py

示例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
开发者ID:mjvaldez,项目名称:synapse-agent,代码行数:11,代码来源:executables.py

示例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'])
开发者ID:UshiDesign,项目名称:synapse-agent,代码行数:13,代码来源:unix-groups.py

示例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
开发者ID:comodit,项目名称:synapse-agent,代码行数:13,代码来源:executables.py

示例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)
开发者ID:Smartaleck,项目名称:synapse-agent,代码行数:14,代码来源:services-debian.py

示例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
开发者ID:UshiDesign,项目名称:synapse-agent,代码行数:50,代码来源:win-users.py

示例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'])
开发者ID:UshiDesign,项目名称:synapse-agent,代码行数:15,代码来源:unix-groups.py

示例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
开发者ID:UshiDesign,项目名称:synapse-agent,代码行数:15,代码来源:executables.py


注:本文中的synapse.syncmd.exec_cmd函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。