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

Python client.cmd函数代码示例

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

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



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

示例1: migrate

def migrate(name, target=''):
    '''
    Migrate a vm from one hypervisor to another. This routine will just start
    the migration and display information on how to look up the progress.
    '''
    client = salt.client.get_local_client(__opts__['conf_file'])
    data = query(quiet=True)
    origin_data = _find_vm(name, data, quiet=True)
    try:
        origin_hyper = list(origin_data.keys())[0]
    except IndexError:
        __jid_event__.fire_event({'error': 'Named vm {0} was not found to migrate'.format(name)}, 'progress')
        return ''
    disks = origin_data[origin_hyper][name]['disks']
    if not origin_data:
        __jid_event__.fire_event({'error': 'Named vm {0} was not found to migrate'.format(name)}, 'progress')
        return ''
    if not target:
        target = _determine_hyper(data, origin_hyper)
    if target not in data:
        __jid_event__.fire_event({'error': 'Target hypervisor {0} not found'.format(origin_data)}, 'progress')
        return ''
    try:
        client.cmd(target, 'virt.seed_non_shared_migrate', [disks, True])
        jid = client.cmd_async(origin_hyper,
                               'virt.migrate_non_shared',
                               [name, target])
    except SaltClientError as client_error:
        return 'Virtual machine {0} could not be migrated: {1}'.format(name, client_error)

    msg = ('The migration of virtual machine {0} to hypervisor {1} has begun, '
           'and can be tracked via jid {2}. The ``salt-run virt.query`` '
           'runner can also be used, the target vm will be shown as paused '
           'until the migration is complete.').format(name, target, jid)
    __jid_event__.fire_event({'message': msg}, 'progress')
开发者ID:DaveQB,项目名称:salt,代码行数:35,代码来源:virt.py


示例2: migrate

def migrate(name, target=""):
    """
    Migrate a vm from one hypervisor to another. This routine will just start
    the migration and display information on how to look up the progress.
    """
    client = salt.client.get_local_client(__opts__["conf_file"])
    data = query(quiet=True)
    origin_data = _find_vm(name, data, quiet=True)
    try:
        origin_hyper = origin_data.iterkeys().next()
    except StopIteration:
        print("Named vm {0} was not found to migrate".format(name))
        return ""
    disks = origin_data[origin_hyper][name]["disks"]
    if not origin_data:
        print("Named vm {0} was not found to migrate".format(name))
        return ""
    if not target:
        target = _determine_hyper(data, origin_hyper)
    if target not in data:
        print("Target hypervisor {0} not found".format(origin_data))
        return ""
    client.cmd(target, "virt.seed_non_shared_migrate", [disks, True])
    jid = client.cmd_async(origin_hyper, "virt.migrate_non_shared", [name, target])

    msg = (
        "The migration of virtual machine {0} to hypervisor {1} has begun, "
        "and can be tracked via jid {2}. The ``salt-run virt.query`` "
        "runner can also be used, the target vm will be shown as paused "
        "until the migration is complete."
    ).format(name, target, jid)
    print(msg)
开发者ID:wikimedia,项目名称:operations-debs-salt,代码行数:32,代码来源:virt.py


示例3: main

def main():
    cmd = 'cd /var/www; php /var/www/multiprocess.php '
    for i in range(0, 10):
        for j in range(0, 5):
            result = client.cmd('web-mongo*.hsng.org',
                                'cmd.run',
                                [cmd + str(i + 1)],
                                20 * (i + 1))
            if j != 0:
                sys.stdout.write(',')
            sys.stdout.write(str(_max(result)))
            # print(result)
            sleep(5)
        print('')
    print('')

    for i in range(0, 10):
        for j in range(0, 5):
            result = client.cmd('web-mysql*.hsng.org',
                                'cmd.run',
                                [cmd + str(i + 1)],
                                40 * (i + 1))
            if j != 0:
                sys.stdout.write(',')
            sys.stdout.write(str(_max(result)))
            # print(result)
            sleep(5)
        print('')
开发者ID:xxx23,项目名称:ups,代码行数:28,代码来源:index.py


示例4: migrate

def migrate(name, target=''):
    '''
    Migrate a vm from one hypervisor to another. This routine will just start
    the migration and display information on how to look up the progress
    '''
    client = salt.client.LocalClient(__opts__['conf_file'])
    data = query(quiet=True)
    origin_data = _find_vm(name, data, quiet=True)
    try:
        origin_hyper = origin_data.keys()[0]
    except IndexError:
        print('Named vm {0} was not found to migrate'.format(name))
        return ''
    disks = origin_data[origin_hyper][name]['disks']
    if not origin_data:
        print('Named vm {0} was not found to migrate'.format(name))
        return ''
    if not target:
        target = _determine_hyper(data, origin_hyper)
    if target not in data:
        print('Target hypervisor {0} not found'.format(origin_data))
        return ''
    client.cmd(target, 'virt.seed_non_shared_migrate', [disks, True])
    print(client.cmd_async(origin_hyper,
                           'virt.migrate_non_shared',
                           [name, target]))
开发者ID:Anbcorp,项目名称:salt,代码行数:26,代码来源:virt.py


示例5: info

def info(client, instance):
    """
    Shows whether an instance of LAVA is running or not on its configured hosts.
    """
    cmd = 'status lava-instance LAVA_INSTANCE={0}'.format(instance)
    inst_path = '/srv/lava/instances/{0}'.format(instance)
    worker_file = '{0}/sbin/mount-masterfs'.format(inst_path)

    inf = {}

    ret = client.cmd('*', 'lava.list_instances', [])
    for k, v in ret.iteritems():
        if inst_path in v:
            ret = client.cmd(k, 'cmd.run', [cmd])
            running = UNKNOWN
            if ret[k] == 'status: Unknown instance: %s' % instance:
                running = STOPPED
            elif ret[k] == 'lava-instance (%s) start/running' % instance:
                running = RUNNING

            ret = client.cmd(k, 'file.file_exists', [worker_file])
            master = not ret[k]

            inf[k] = {'running': running, 'master': master}
    return inf
开发者ID:hellbentv,项目名称:salt,代码行数:25,代码来源:lava_salt.py


示例6: post

 def post(self):
   slave_1		=self.get_argument("slave_1")
   config_name_1	=self.get_argument("config_name_1")
   config_conteny_1	=self.get_argument("config_conteny_1")
   slave_2		=self.get_argument("slave_2")
   config_name_2	=self.get_argument("config_name_2")
   config_conteny_2	=self.get_argument("config_conteny_2")
   client = salt.client.LocalClient()
   f_1=open(config_name_1,'a')
   f_1.write(config_conteny_1)
   f_1.close()
   shell_commond_1='/usr/bin/salt-cp -L \'%s\' %s /data/server/redis/etc/ ' %(slave_1,config_name_1)
   shell_commond_2='/usr/bin/salt-cp -L \'%s\' %s /data/server/redis/etc/ ' %(slave_2,config_name_1)
   a_1,b_1 = commands.getstatusoutput(shell_commond_1)
   a_2,b_2 = commands.getstatusoutput(shell_commond_2)
   os.remove(config_name_1)
   if a_1 != 0:
   	self.write(str("%上传失败"%slave_1))
   if a_2 != 0:
   	self.write(str("%上传失败"%slave_2))
   #启动redis服务
   start_server="/data/server/redis/bin/redis-server  /data/server/redis/etc/%s "%config_name_1
   ret_1 = client.cmd(slave_1.encode('utf-8'), 'cmd.run', [start_server])
   ret_2 = client.cmd(slave_2.encode('utf-8'), 'cmd.run', [start_server])
   print ret_1,ret_2
   self.write(str("%s上新的redis实例启动成功\n%s上新的redis实例启动成功"%(ret_1,ret_2)))
开发者ID:xiaoyang2008mmm,项目名称:redis_qianyi,代码行数:26,代码来源:server.py


示例7: os_info

def os_info():
    ret = client.cmd('*', 'grains.items')
    for k, v in ret.iteritems():
        labconfig[k]['grains'] = v

    ret = client.cmd('*', 'disk.usage')
    for k, v in ret.iteritems():
        labconfig[k]['disk'] = v
开发者ID:hellbentv,项目名称:lava-lab,代码行数:8,代码来源:salt-site.py


示例8: git_pull

def git_pull(target, path, rev):
    import salt.client
    client = salt.client.LocalClient()

    # Fetch first
    client.cmd(target, 'git.pull', [path, '--all'])
    # Then checkout
    client.cmd(target, 'git.checkout', [path, rev])
开发者ID:zklapow,项目名称:leonidas,代码行数:8,代码来源:tasks.py


示例9: ready

def ready(**kwargs):
    """
    Wait for minions to respond.  Compare test.ping results to either
    the list of all accepted keys or search criteria of cached pillar
    data.
    """
    settings = { 
                 'timeout': None,
                 'search': None,
                 'sleep': 6
               }
    settings.update(kwargs)

    ret = {}
    #client = salt.client.get_local_client(__opts__['conf_file'])

    end_time = None
    if settings['timeout']:
        end_time = time.time() + settings['timeout']
        log.debug("end time: {}".format(end_time))

    client = salt.client.LocalClient()

    while True:
        try:
            if settings['search']:
                results = client.cmd(settings['search'], 'test.ping', timeout=__opts__['timeout'], expr_form="compound")
            else:
                results = client.cmd('*', 'test.ping', timeout=__opts__['timeout'])
        except SaltClientError as client_error:
            print(client_error)
            return ret

        actual = set(results.keys())

        if settings['search']:
            pillar_util = salt.utils.master.MasterPillarUtil(settings['search'], "compound",
                                                     use_cached_grains=True,
                                                     grains_fallback=False,
                                                     opts=__opts__)

            cached = pillar_util.get_minion_pillar()
            expected = set(cached.keys())
        else:
            key = salt.key.Key(__opts__)
            expected = set(key.list_keys()['minions'])

        if actual == expected:
            log.warn("All minions are ready")
            break
        log.warn("Waiting on {}".format(",".join(list(expected - actual))))
        if end_time:
            if end_time < time.time():
                log.warn("Timeout reached")
                return False
        time.sleep(settings['sleep'])

    return True
开发者ID:swiftgist,项目名称:pillar-prototype,代码行数:58,代码来源:minions.py


示例10: restart_samba_services

def restart_samba_services():
  client = salt.client.LocalClient()
  rc = client.cmd('*', 'service.reload', ['smbd'] )
  print rc
  rc = client.cmd('*', 'service.restart', ['winbind'] )
  print rc
  #rc = client.cmd('*', 'service.restart', ['nmbd'] )
  #print rc
  return
开发者ID:pingnagan,项目名称:integralstor-unicell,代码行数:9,代码来源:samba_settings.py


示例11: upgrade

def upgrade(client, instance, dry_run=True):
    """
    Runs lava-deployment-tool upgrade for a LAVA setup. It first shuts down
    each worker node instance. Then it runs lava-deployment-tool upgrade on
    the master. Lastly, it runs lava-deployment-tool upgradeworker on the
    worker nodes.
    """
    timeout = 300  # 5 minutes
    workers = []
    master = None

    for host, props in info(client, instance).iteritems():
        if props['master']:
            assert not master, 'Detected multiple master instances in LAVA deployment'
            master = host
        else:
            workers.append(host)

    assert master, 'No master instance found in LAVA deployment'

    w_ret = {}
    for h in workers:
        w_ret[h] = {'stop': 'dry-run', 'upgrade': 'dry-run', 'start': 'dry-run'}

    if dry_run:
        m_ret = {master: 'dry-run: upgrade master'}
        return m_ret, w_ret

    # first stop workers. This prevents a DB error if the upgrade changes
    # the schema.
    ret = stop(client, instance, True)
    if ret:
        for host, msg in ret.iteritems():
            w_ret[host]['stop'] = msg

    # now upgrade the master node
    cmd = 'SKIP_ROOT_CHECK=yes {0} upgrade {1}'.format(LDT, instance)
    m_ret = client.cmd(master, 'cmd.run', [cmd], timeout=timeout)

    # now upgrade the workers
    cmd = 'SKIP_ROOT_CHECK=yes {0} upgradeworker {1}'.format(LDT, instance)
    if len(workers):
        ret = client.cmd(workers, 'cmd.run', [cmd], timeout=timeout, expr_form='list')
        for host, msg in ret.iteritems():
            w_ret[host]['upgrade'] = msg

    ret = start(client, instance)
    if ret:
        for host, msg in ret.iteritems():
            if host in w_ret:
                w_ret[host]['start'] = msg

    # last thing: l-d-t ran as root, lets chmod things
    cmd = 'chown -R instance-manager:instance-manager /srv/lava/instances/{0}/code/*'.format(instance)
    client.cmd(workers + [master], 'cmd.run', [cmd], expr_form='list')

    return m_ret, w_ret
开发者ID:hellbentv,项目名称:lava-lab,代码行数:57,代码来源:lava_salt.py


示例12: get_file

 def get_file(self,hn, fname):
     f = client.cmd(hn, 'file.file_exists',[fname])
     t = (f[hn])
     if t is True:
         k = fname.split('/')
         fi = k[-1]
         client.cmd(hn,'file.rename',[fname,'/data/deploy/%s/%s' % (date,fi+'-'+time)])
     c = client.cmd(hn, 'cp.get_file', ['salt:/%s' % fname, fname])
     print c
开发者ID:tianyongkang,项目名称:devops,代码行数:9,代码来源:程序在预发布机器update.py


示例13: ping_all_connected_minions

def ping_all_connected_minions(opts):
    client = salt.client.LocalClient()
    if opts['minion_data_cache']:
        tgt = list(salt.utils.minions.CkMinions(opts).connected_ids())
        form = 'list'
    else:
        tgt = '*'
        form = 'glob'
    client.cmd(tgt, 'test.ping', tgt_type=form)
开发者ID:bryson,项目名称:salt,代码行数:9,代码来源:master.py


示例14: write_highstate_runner_claim

def write_highstate_runner_claim(minion_id):
  '''Write our saltmaster's id into a file on the minion, designating which saltmaster gets to run the
     highstate on it.  First in wins.
     /tmp/highstate_runner'''
  client = salt.client.LocalClient()
  path = "/tmp/highstate_runner"
  hostname = socket.gethostname()
  results = client.cmd(tgt=minion_id, fun='file.touch', arg=[path])   # sync call
  results_by_minion = client.cmd(tgt=minion_id, fun='file.append', arg=[path, hostname])   # sync call
  return
开发者ID:bkruger99,项目名称:saltconf2015,代码行数:10,代码来源:highstate_runner.py


示例15: write_highstate_ran

def write_highstate_ran(minion_id):
  '''Write our saltmaster's id into a file on the minion, designating which saltmaster gets to run the
     highstate on it.  First in wins.
     /tmp/highstate_runner'''
  client = salt.client.LocalClient()
  path = "/etc/salt/highstate_ran_once"
  seconds = time.time()
  results = client.cmd(tgt=minion_id, fun='file.touch', arg=[path])   # sync call
  results_by_minion = client.cmd(tgt=minion_id, fun='file.append', arg=[path, seconds])   # sync call
  return
开发者ID:bkruger99,项目名称:saltconf2015,代码行数:10,代码来源:highstate_runner.py


示例16: checkout

def checkout(repo, reset=False):
    '''
    Checkout from a master, for the specified repo
    '''
    grain = "deployment_target:" + repo
    client = salt.client.LocalClient(__opts__['conf_file'])
    cmd = 'deploy.checkout'
    arg = (repo, reset)
    client.cmd(grain, cmd, expr_form='grain', arg=arg, timeout=1,
               ret='deploy_redis')
    print "Checkout completed"
开发者ID:filippog,项目名称:trebuchet,代码行数:11,代码来源:deploy.py


示例17: call_saltstack

 def call_saltstack(self,data):
     import salt.client
     client = salt.client.LocalClient()
     act = data.get('act')
     hosts = data.get('hosts')
     argv = data.get('argv')
     if len(hosts.split(',')) > 1:
         result = client.cmd(hosts,act,argv,expr_form='list')
     else:
         result = client.cmd(hosts,act,argv)
     return result
开发者ID:ivanbearcat,项目名称:Center_Server,代码行数:11,代码来源:factory.py


示例18: fetch

def fetch(repo):
    '''
    Fetch from a master, for the specified repo
    '''
    grain = "deployment_target:" + repo
    client = salt.client.LocalClient(__opts__['conf_file'])
    cmd = 'deploy.fetch'
    # comma in the tuple is a workaround for a bug in salt
    arg = (repo,)
    client.cmd(grain, cmd, expr_form='grain', arg=arg, timeout=1,
               ret='deploy_redis')
    print "Fetch completed"
开发者ID:filippog,项目名称:trebuchet,代码行数:12,代码来源:deploy.py


示例19: judge_dir

 def judge_dir(self,hn,fname):
     d = client.cmd(hn, 'file.directory_exists',[fname])
     t = (d[hn])
     if t is not True:
         k = fname.split('/')
         del k[-1]
         v = '/'.join(k)
         d = client.cmd(hn,'file.directory_exists', [v])
         i = (d[hn])
         if i is not True:
             mk = client.cmd(hn, 'file.mkdir', [v])
     return 0
开发者ID:tianyongkang,项目名称:devops,代码行数:12,代码来源:程序在预发布机器update.py


示例20: get_dir

 def get_dir(self,hn, fname):
     f = client.cmd(hn, 'file.directory_exists',[fname])
     t = (f[hn])
     if t is True:
         k = fname.split('/')
         fi = k[-1]
         client.cmd(hn,'file.rename',[fname,'/data/deploy/%s/%s' % (date,fi+'-'+time)])
     fn = fname.split('/')
     del fn[-1]
     v = '/'.join(fn)
     c = client.cmd(hn, 'cp.get_dir', ['salt:/%s' % fname, v])
     print c
开发者ID:tianyongkang,项目名称:devops,代码行数:12,代码来源:程序在预发布机器update.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Python client.cmd_iter函数代码示例发布时间:2022-05-27
下一篇:
Python _compat.ElementTree类代码示例发布时间: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