• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python syncmd.exec_cmd函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中synapse.syncmd.exec_cmd函数的典型用法代码示例。如果您正苦于以下问题:Python exec_cmd函数的具体用法?Python exec_cmd怎么用?Python exec_cmd使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了exec_cmd函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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


示例16: is_installed

def is_installed(name):
    ret = exec_cmd("/usr/bin/dpkg-query -l '{0}'".format(name))
    if ret['returncode'] != 0:
        return False

    # There's no way to use return code of any of the dpkg-query options.
    # Instead we use the "state" column of dpkg-query -l
    # So programmaticaly here:
    # 1. Get stdout
    # 2. Split on new line
    # 3. Get the last but one line (last is blank, in any case?)
    # 4. Get first character (i=installed)
    try:
        return ret['stdout'].split('\n')[-2][0] == 'i'
    except IndexError:
        raise ResourceException(ret['stderr'])
开发者ID:UshiDesign,项目名称:synapse-agent,代码行数:16,代码来源:apt.py


示例17: group_del

def group_del(name):
    ret = exec_cmd("/usr/sbin/groupdel {0}".format(name))
    if ret['returncode'] != 0:
        raise ResourceException(ret['stderr'])
开发者ID:Smartaleck,项目名称:synapse-agent,代码行数:4,代码来源:unix-groups.py


示例18: user_del

def user_del(name):
    ret = exec_cmd("/usr/sbin/userdel {0} -f".format(name))
    if ret['returncode'] != 0:
        raise ResourceException(ret['stderr'])
开发者ID:UshiDesign,项目名称:synapse-agent,代码行数:4,代码来源:win-users.py


示例19: get_installed_packages

def get_installed_packages():
    ret = exec_cmd("/usr/bin/dpkg-query -l")
    return ret['stdout'].split('\n')
开发者ID:comodit,项目名称:synapse-agent,代码行数:3,代码来源:apt.py


示例20: remove

def remove(name):
    ret = exec_cmd("/usr/bin/apt-get -qy remove {0} --force-yes".format(name))
    if ret['returncode'] != 0:
        raise ResourceException(ret['stderr'])
开发者ID:comodit,项目名称:synapse-agent,代码行数:4,代码来源:apt.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python types.RoomID类代码示例发布时间:2022-05-27
下一篇:
Python config.PaginationConfig类代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap