Ejemplo n.º 1
0
Archivo: index.py Proyecto: xxx23/ups
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('')
Ejemplo n.º 2
0
Archivo: virt.py Proyecto: Anbcorp/salt
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]))
Ejemplo n.º 3
0
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)
Ejemplo n.º 4
0
Archivo: virt.py Proyecto: DaveQB/salt
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')
Ejemplo n.º 5
0
 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)))
Ejemplo n.º 6
0
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
Ejemplo n.º 7
0
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
Ejemplo n.º 8
0
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])
Ejemplo n.º 9
0
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
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
 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
Ejemplo n.º 12
0
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
Ejemplo n.º 13
0
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)
Ejemplo n.º 14
0
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
Ejemplo n.º 15
0
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
Ejemplo n.º 16
0
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"
Ejemplo n.º 17
0
 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
 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
 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
Ejemplo n.º 20
0
    def post(self):                                                                                                 
      m_ip=self.get_argument("m_ip") 
      m_port= self.get_argument("m_port") 
      client = salt.client.LocalClient()
      ret = client.cmd(m_ip.encode('utf-8'), 'cmd.run', ['ls -l /data/server/redis/etc/ | awk \'/conf/{print $9}\' | tr "\n" ","'])
      filename=''.join(ret.values()).split(",")[:-1]
      for i in filename: 
	if re.search(m_port.encode('utf-8'),i):
	   file_path='cat /data/server/redis/etc/%s'%i
	   config_file = client.cmd(m_ip.encode('utf-8'), 'cmd.run', [file_path])
	   data= ''.join(config_file.values()).split("\n")
      self.write("%s"%data)
Ejemplo n.º 21
0
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"
Ejemplo n.º 22
0
def key_regen():
    """
    This routine is used to regenerate all keys in an environment. This is
    invasive! ALL KEYS IN THE SALT ENVIRONMENT WILL BE REGENERATED!!

    The key_regen routine sends a command out to minions to revoke the master
    key and remove all minion keys, it then removes all keys from the master
    and prompts the user to restart the master. The minions will all reconnect
    and keys will be placed in pending.

    After the master is restarted and minion keys are in the pending directory
    execute a salt-key -A command to accept the regenerated minion keys.

    The master *must* be restarted within 60 seconds of running this command or
    the minions will think there is something wrong with the keys and abort.

    Only Execute this runner after upgrading minions and master to 0.15.1 or
    higher!

    CLI Example:

    .. code-block:: bash

        salt-run manage.key_regen
    """
    client = salt.client.get_local_client(__opts__["conf_file"])
    try:
        client.cmd("*", "saltutil.regen_keys")
    except SaltClientError as client_error:
        print(client_error)
        return False

    for root, _, files in os.walk(__opts__["pki_dir"]):
        for fn_ in files:
            path = os.path.join(root, fn_)
            try:
                os.remove(path)
            except os.error:
                pass
    msg = (
        "The minion and master keys have been deleted.  Restart the Salt\n"
        "Master within the next 60 seconds!!!\n\n"
        "Wait for the minions to reconnect.  Once the minions reconnect\n"
        "the new keys will appear in pending and will need to be re-\n"
        "accepted by running:\n"
        "    salt-key -A\n\n"
        "Be advised that minions not currently connected to the master\n"
        "will not be able to reconnect and may require manual\n"
        "regeneration via a local call to\n"
        "    salt-call saltutil.regen_keys"
    )
    return msg
Ejemplo n.º 23
0
def restart_samba_services():
    """Restart samba and winbind 

    Returns True on success and False otherwise
    """
    try:
        client = salt.client.LocalClient()
        rc = client.cmd('*', 'service.reload', ['smbd'])
        # print rc
        rc = client.cmd('*', 'service.restart', ['winbind'])
        # print rc
    except Exception, e:
        return False, 'Error restarting SMB services :%s' % str(e)
Ejemplo n.º 24
0
def restart_samba_services():
  try:
    use_salt, err = common.use_salt()
    if err:
      raise Exception(err)
    if use_salt:
      client = salt.client.LocalClient()
      rc = client.cmd('*', 'service.reload', ['smbd'] )
      print rc
      rc = client.cmd('*', 'service.reload', ['winbind'] )
      print rc
      #rc = client.cmd('*', 'service.reload', ['nmbd'] )
      #print rc
    else:
      (ret, rc), err = command.execute_with_rc('service smb reload')
      if err:
        raise Exception(err)
      (ret, rc), err = command.execute_with_rc('service winbind reload')
      if err:
        raise Exception(err)
      if rc != 0:
        err = ''
        tl, er = command.get_output_list(ret)
        if er:
          raise Exception(er)
        if tl:
          err = ','.join(tl)
        tl, er = command.get_error_list(ret)
        if er:
          raise Exception(er)
        if tl:
          err = err + ','.join(tl)
        raise Exception("Return code : %d. Error : %s"%(rc, err))
      (ret, rc), err = command.execute_with_rc('service nmb reload')
      if err:
        raise Exception(err)
      if rc != 0:
        err = ''
        tl, er = command.get_output_list(ret)
        if er:
          raise Exception(er)
        if tl:
          err = ','.join(tl)
        tl, er = command.get_error_list(ret)
        if er:
          raise Exception(er)
        if tl:
          err = err + ','.join(tl)
        raise Exception("Return code : %d. Error : %s"%(rc, err))
  except Exception, e:
    return False, 'Error restarting samba services: %s'%str(e)
Ejemplo n.º 25
0
def semafor_parse(urls, n_instances=None):
    '''
    Parameters
    ----------
    urls: str,
        a list of urls
    n_instances : int, optional(default=None)
        A number of instances to create and provision. If None
        just calls the celery workers and is going to use any
        existent workers
    '''
    import salt.client
    from semafor.minion.worker.tasks import run_semafor

    if n_instances:
        # 1. Create instances
        minion_ips = create_instances(n=n_instances)
        provision_minions(minion_ips)

        # 2 Ping minions
        client = salt.client.LocalClient()
        logger.info('Pinging minions')
        ret = client.cmd(minion_ips, 'test.ping', expr_form='list')
        for i, minion_ip in enumerate(ret):
            logger.info('Ping minion %i[%s]: %s' % (i + 1, minion_ip, ret[minion_ip]))

        # 3 Start celery workers
        logger.info('Starting celery workers on minions')
        cmd = 'sh /home/ubuntu/semafor/app/semafor/minion/start_worker.sh %s' % settings.SALT_MASTER_PUBLIC_ADDRESS
        ret = client.cmd(minion_ips, 'cmd.run', [cmd], expr_form='list', username='******')
        for i, minion_ip in enumerate(ret):
            logger.info('Celery worker minion %i[%s]: %s' % (i + 1, minion_ip, ret[minion_ip]))

    # Call celery workers
    start = 0
    tasks = []
    docs_per_chunk = len(urls) // n_instances
    for i in range(n_instances):
        ends = start + docs_per_chunk if i < n_instances - 1 else len(urls)

        task = run_semafor.delay(urls[start:ends],
                                 settings.READABILITY_TOKEN,
                                 settings.AWS_ACCESS_ID,
                                 settings.AWS_SECRET_KEY,
                                 settings.S3_PATH,
                                 settings.LUIGI_CENTRAL_SCHEDULER)
        tasks.append(task)
        start = ends

    logger.info('Celery worker minion are working, waiting for them :)')
    print tasks
Ejemplo n.º 26
0
def sync_grains(target, instance_id):
    import salt.client
    client = salt.client.LocalClient()

    import boto
    import boto.ec2
    conn = boto.connect_ec2()

    rl = conn.get_all_instances(instance_ids=[instance_id])
    instance = rl[0].instances[0]

    tags = instance.__dict__['tags']
    for key in tags.keys():
        client.cmd(target, 'grains.setval', [key, tags[key]])
Ejemplo n.º 27
0
def salt_client(host,cmd):
	client = salt.client.LocalClient()
	if type(host) == list:
		result = client.cmd(host,"cmd.run",[cmd],expr_form="list")
	else:
		#print '''client.cmd(%s,"cmd.run",[%s])''' % (host,cmd)
		result = client.cmd(host,"cmd.run",[cmd])
	log = ""
	for k,v in result.items():
		log = log + '''
Fllow message from : %s
=======================================================
%s''' % (k,v) + "\n"
	return log
Ejemplo n.º 28
0
def checkout(repo, reset=False):
    '''
    Checkout from a master, for the specified repo
    '''
    grain = __get_conf(repo, 'deployment_repo_grains')
    if not grain:
        return "No grain defined for this repo."
    grain = "deployment_target:" + grain
    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"
Ejemplo n.º 29
0
def run():
    client = salt.client.LocalClient(__opts__['conf_file'])
    runner = salt.runner.RunnerClient(__opts__)
    pillar_dic = comm.get_pillar(__opts__)

    cc_hostname = pillar_dic['iaas_role']['cc']
    ip_port = ""
    iqn = ""
    for key_ip, value in pillar_dic['lun_info']['nodes'].items():
	ip_port = key_ip
        iqn = value["iqn"]

    glance_lun =  pillar_dic['lun_info']['lun_number']['glance_lun']
    glance_mnt_dir = pillar_dic['glance_info']['glance_mnt_dir']

    nova_lun =  pillar_dic['lun_info']['lun_number']['nova_lun']
    nova_mnt_dir = pillar_dic['nova_info']['nova_mnt_dir']

    cinder_lun = pillar_dic['lun_info']['lun_number']['cinder_lun']
    cinder_mnt_dir = pillar_dic['cinder_info']['ocfs2_mounts']

    ocfs2_node = pillar_dic['ocfs2_cluster']['nodes']
    result_list = []

    glance_args_list = [ip_port, iqn, str(glance_lun), glance_mnt_dir, "True"]
    nova_args_list   = [ip_port, iqn, str(nova_lun),   nova_mnt_dir,   "True"]
    cinder_args_list = [ip_port, iqn, str(cinder_lun), cinder_mnt_dir, "True"]

    for index in range(len(ocfs2_node)):
	hostname = ocfs2_node[index]
        mnt_list = []
	if hostname == cc_hostname:
            mnt_list.append(glance_args_list)

        mnt_list.append(nova_args_list)
        mnt_list.append(cinder_args_list)

	if index == 0:
	    for args in mnt_list:
		args_str = " ".join(args)
		result = client.cmd(hostname, "cmd.script", ["salt://ocfs2/script/formart_mount.sh", args_str ])
		result_list.append(result)
	else:
	    for args in mnt_list:
		args[4] = "False"
		args_str = " ".join(args)
                result = client.cmd(hostname, "cmd.script", ["salt://ocfs2/script/formart_mount.sh", args_str ])
		result_list.append(result)
    return result_list
Ejemplo n.º 30
0
def create_local_user(userid, name, pswd):

  error_list = []
  #First check if samba user exists. if so kick out
  ul = get_local_users()
  if ul:
    for ud in ul:
      if ud["userid"] == userid:
        raise Exception("Error creating user. The user \"%s\" already exists. "%userid)

  # Now check if system user exists. If not create..
  create_system_user = False
  try:
    pwd.getpwnam(userid)
  except KeyError:
    create_system_user = True

  if create_system_user:
    #enc_pswd = crypt.crypt(pswd, "28")
    #Set a standard system password - not the one given by the user as the user should not have access to the system
    enc_pswd = crypt.crypt("integralstor_pswd_%s"%userid, "28")
    client = salt.client.LocalClient()
    rc = client.cmd('*', 'user.add', [userid,None,501])
    for hostname, status in rc.items():
      if not status:
        error_list.append("Error creating the userid on GRIDCell %s"%hostname)
    rc = client.cmd('*', 'shadow.set_password', [userid, enc_pswd] )
    for hostname, status in rc.items():
      if not status:
        error_list.append("Error setting the password for userid on GRIDCell %s"%hostname)
    rc = client.cmd('*', 'user.chfullname', [userid, "integralstor_user_%s"%name] )
    for hostname, status in rc.items():
      if not status:
        error_list.append("Error setting the name for userid on GRIDCell %s"%hostname)
    '''
    ret, rc = command.execute_with_rc(r'useradd -p %s -c integralstor_user_%s %s'%(enc_pswd, name, userid))
    if rc != 0:
      raise Exception("Error creating system user. Return code : %d. "%rc)
    '''

  print '/usr/bin/pdbedit  -d 1 -t -a  -u %s -f %s'%(userid, name), "%s\n%s"%(pswd, pswd)
  # Now all set to create samba user
  ret, rc = command.execute_with_conf_and_rc(r'/usr/bin/pdbedit  -d 1 -t -a  -u %s -f %s'%(userid, name), "%s\n%s"%(pswd, pswd))
  if rc != 0:
    #print command.get_error_list(ret)
    raise Exception("Error creating user. Return code : %d. "%rc)
  ul = command.get_output_list(ret)
  #print ul
  return error_list
Ejemplo n.º 31
0
def _clean_files():
    _ = client.cmd(
        tgt="nrp1",
        fun="cmd.run",
        arg=["rm -f -r -d /var/salt-nornir/nrp1/files/*"],
        kwarg={},
        tgt_type="glob",
        timeout=60,
    )
    verify_res = client.cmd(
        tgt="nrp1",
        fun="cmd.run",
        arg=["ls -l /var/salt-nornir/nrp1/files/"],
        kwarg={},
        tgt_type="glob",
        timeout=60,
    )
    if "total 0" not in verify_res["nrp1"]:
        _clean_files()
Ejemplo n.º 32
0
def test_nr_do_call_to_single_step_in_pillar():
    ret = client.cmd(tgt="nrp1",
                     fun="nr.do",
                     arg=["awr"],
                     kwarg={},
                     tgt_type="glob",
                     timeout=60)
    assert ret["nrp1"]["failed"] == False
    assert "awr" in ret["nrp1"]["result"][0]
    assert isinstance(ret["nrp1"]["result"][0]["awr"], dict)
Ejemplo n.º 33
0
 def _get_live_minion_grains(self, minion_ids):
     # Returns a dict of grains fetched directly from the minions
     log.debug('Getting live grains for minions: "%s"', minion_ids)
     client = salt.client.get_local_client(self.opts['conf_file'])
     ret = client.cmd(
                    ','.join(minion_ids),
                     'grains.items',
                     timeout=self.opts['timeout'],
                     tgt_type='list')
     return ret
Ejemplo n.º 34
0
 def _get_live_minion_grains(self, minion_ids):
     # Returns a dict of grains fetched directly from the minions
     log.debug('Getting live grains for minions: "%s"', minion_ids)
     with salt.client.get_local_client(self.opts["conf_file"]) as client:
         return client.cmd(
             ",".join(minion_ids),
             "grains.items",
             timeout=self.opts["timeout"],
             tgt_type="list",
         )
Ejemplo n.º 35
0
def redirect_minion():
    minion = request.form.get('minion')
    conductor_name = request.form.get('conductor')
    ret = client.cmd(minion, 'state.apply', [
        'redirect', "pillar={{'conductor':{}}}".format(
            conductors[conductor_name])
    ])
    print(ret)
    return "Attempting to redirect {} to conductor {}".format(
        minion, conductor_name)
Ejemplo n.º 36
0
def destroy(name, conn=None, call=None):
    '''
    Delete a single VM
    '''
    if call == 'function':
        raise SaltCloudSystemExit(
            'The destroy action must be called with -d, --destroy, '
            '-a or --action.'
        )

    salt.utils.cloud.fire_event(
        'event',
        'destroying instance',
        'salt/cloud/{0}/destroying'.format(name),
        {'name': name},
    )

    if not conn:
        conn = get_conn()   # pylint: disable=E0602

    node = get_node(conn, name)
    profiles = get_configured_provider()['profiles']  # pylint: disable=E0602
    if node is None:
        log.error('Unable to find the VM {0}'.format(name))
    profile = None
    if 'metadata' in node.extra and 'profile' in node.extra['metadata']:
        profile = node.extra['metadata']['profile']
    flush_mine_on_destroy = False
    if profile is not None and profile in profiles:
        if 'flush_mine_on_destroy' in profiles[profile]:
            flush_mine_on_destroy = profiles[profile]['flush_mine_on_destroy']
    if flush_mine_on_destroy:
        log.info('Clearing Salt Mine: {0}'.format(name))
        client = salt.client.LocalClient(__opts__['conf_file'])
        minions = client.cmd(name, 'mine.flush')

    log.info('Clearing Salt Mine: {0}, {1}'.format(name, flush_mine_on_destroy))
    log.info('Destroying VM: {0}'.format(name))
    ret = conn.destroy_node(node)
    if ret:
        log.info('Destroyed VM: {0}'.format(name))
        # Fire destroy action
        event = salt.utils.event.SaltEvent('master', __opts__['sock_dir'])
        salt.utils.cloud.fire_event(
            'event',
            'destroyed instance',
            'salt/cloud/{0}/destroyed'.format(name),
            {'name': name},
        )
        if __opts__['delete_sshkeys'] is True:
            salt.utils.cloud.remove_sshkey(node.public_ips[0])
        return True

    log.error('Failed to Destroy VM: {0}'.format(name))
    return False
Ejemplo n.º 37
0
def versions():
    '''
    Check the version of active minions

    CLI Example:

    .. code-block:: bash

        salt-run manage.versions
    '''
    ret = {}
    client = salt.client.get_local_client(__opts__['conf_file'])
    try:
        minions = client.cmd('*', 'test.version', timeout=__opts__['timeout'])
    except SaltClientError as client_error:
        print(client_error)
        return ret

    labels = {
        -2: 'Minion offline',
        -1: 'Minion requires update',
        0: 'Up to date',
        1: 'Minion newer than master',
        2: 'Master',
    }

    version_status = {}

    master_version = salt.version.__saltstack_version__

    for minion in minions:
        if not minions[minion]:
            minion_version = False
            ver_diff = -2
        else:
            minion_version = salt.version.SaltStackVersion.parse(minions[minion])
            ver_diff = salt.utils.compat.cmp(minion_version, master_version)

        if ver_diff not in version_status:
            version_status[ver_diff] = {}
        if minion_version:
            version_status[ver_diff][minion] = minion_version.string
        else:
            version_status[ver_diff][minion] = minion_version

    # Add version of Master to output
    version_status[2] = master_version.string

    for key in version_status:
        if key == 2:
            ret[labels[key]] = version_status[2]
        else:
            for minion in sorted(version_status[key]):
                ret.setdefault(labels[key], {})[minion] = version_status[key][minion]
    return ret
Ejemplo n.º 38
0
def test_nr_file_diff_last_1_2_and_last_2_3_ceos1():
    _clean_files()
    _generate_files()
    _generate_files()
    _generate_files()

    # check
    ret_1_2 = client.cmd(
        tgt="nrp1",
        fun="nr.file",
        arg=["diff"],
        kwarg={
            "filegroup": ["interfaces", "clock"],
            "last": [1, 2],
            "FB": "ceos1"
        },
        tgt_type="glob",
        timeout=60,
    )
    ret_2_3 = client.cmd(
        tgt="nrp1",
        fun="nr.file",
        arg=["diff"],
        kwarg={
            "filegroup": ["interfaces", "clock"],
            "last": [2, 3],
            "FB": "ceos1"
        },
        tgt_type="glob",
        timeout=60,
    )
    pprint.pprint(ret_1_2)
    pprint.pprint(ret_2_3)

    assert ret_1_2["nrp1"]["ceos1"]["interfaces"] == True
    assert "---" in ret_1_2["nrp1"]["ceos1"]["clock"] and "+++" in ret_1_2[
        "nrp1"]["ceos1"]["clock"]
    assert ret_2_3["nrp1"]["ceos1"]["interfaces"] == True
    assert "---" in ret_2_3["nrp1"]["ceos1"]["clock"] and "+++" in ret_2_3[
        "nrp1"]["ceos1"]["clock"]
    assert ret_1_2["nrp1"]["ceos1"]["clock"] != ret_2_3["nrp1"]["ceos1"][
        "clock"]
Ejemplo n.º 39
0
def populate_hosts_file(client, gridcell_name, mapping_dict):
    """Adds a hostname/IP combination to the hosts file on a specific gridcell.

    client - salt's client handle.
    gridcell_name - the gridcell whose hosts file needs to be populated.
    mapping_dict - The hostname/ip mapping dict to be populated.
    """
    try:
        successful_dict = {}
        failures = False
        for hn, ip in mapping_dict.items():
            if 'integralstor.lan' not in hn:
                r1 = client.cmd(gridcell_name, 'hosts.add_host', [
                                ip, '%s.integralstor.lan' % hn])
            else:
                r1 = client.cmd(gridcell_name, 'hosts.add_host', [ip, hn])
            if not r1:
                failures = True
            else:
                for hn, result in r1.items():
                    if result is not None:
                        if result:
                            successful_dict[hn] = ip
                        else:
                            failures = True
            if failures:
                break

        if failures:
            # If any items successfully added them remove them so re roll back
            # to the original state
            if successful_dict:
                for hn, ip in successful_dict.items():
                    if 'integralstor.lan' not in hn:
                        r1 = client.cmd(gridcell_name, 'hosts.rm_host', [
                                        ip, '%s.integralstor.lan' % hn])
                    else:
                        r1 = client.cmd(
                            gridcell_name, 'hosts.rm_host', [ip, hn])
            raise Exception('Could not populate the hosts file')
    except Exception, e:
        return False, "Error populating the hosts file on GRIDCell %s : %s" % (gridcell_name, str(e))
Ejemplo n.º 40
0
def scale_service(service_name, new_count):
    # Get a docker_swarm manager
    opts = salt.config.master_config('/etc/salt/master')
    runner_client = salt.runner.RunnerClient(opts)
    manager = runner_client.cmd('docker.get_manager', print_event=False)

    # call module to scale the service
    client = salt.client.LocalClient(__opts__['conf_file'])
    return client.cmd(manager,
                      'docker_helper.scale', [service_name, new_count],
                      timeout=1)[manager]
Ejemplo n.º 41
0
def test_nr_nornir_results_queue_dump():
    ret = client.cmd(
        tgt="nrp1",
        fun="nr.nornir",
        arg=["results_queue_dump"],
        kwarg={},
        tgt_type="glob",
        timeout=60,
    )
    pprint.pprint(ret)
    assert ret["nrp1"] == [], "Unexpected return for results_queue_dump"
Ejemplo n.º 42
0
def test_single_stat_call():
    ret = client.cmd(
        tgt="nrp1",
        fun="nr.nornir",
        arg=["stats"],
        kwarg={"stat": "main_process_pid"},
        tgt_type="glob",
        timeout=60,
    )
    assert "nrp1" in ret
    assert len(ret["nrp1"].keys()) == 1
Ejemplo n.º 43
0
def build_configured_users():
    ret = client.cmd('*', 'cmd.run', ['cat /etc/lp-manage-local.conf'])
    for k, v in ret.iteritems():
        labconfig[k] = {
            'id': k,
            'time': time.strftime('%Y-%m-%d %H:%M UTC', time.gmtime())
        }
        if not v.startswith('cat: '):  # ensure file exists
            cfg = get_user_config(v)
            labconfig[k]['configured_groups'] = cfg['lp-groups']
            labconfig[k]['configured_sudoers'] = cfg['sudoers']
Ejemplo n.º 44
0
	def ssh(self):
		s.cmd(tgt=self.ipaddress,fun='test.ping',ignore_host_keys=True,ssh_user=self.user, ssh_passwd=self.passwd,roster='scan')
		s.cmd(tgt=self.ipaddress,fun='cp.get_file',arg=['salt://epel-release-latest-6.noarch.rpm','/tmp/epel-release-latest-6.noarch.rpm'],ssh_user=self.user, ssh_passwd=self.passwd,roster='scan')
		s.cmd(tgt=self.ipaddress,fun='cmd.shell',arg=['rpm -vih /tmp/epel-release-latest-6.noarch.rpm'],ssh_user=self.user, ssh_passwd=self.passwd,roster='scan')
		ret = s.cmd(tgt=self.ipaddress, fun='pkg.install',arg=['salt-minion'],ignore_host_keys=True,ssh_user=self.user, ssh_passwd=self.passwd,roster='scan')
		print ret
		s.cmd(tgt=self.ipaddress,fun='file.sed',arg=['/etc/salt/minion','#master: salt','master: 172.16.88.182'],ssh_user=self.user, ssh_passwd=self.passwd,roster='scan')
		s.cmd(tgt=self.ipaddress,fun='file.sed',arg=['/etc/salt/minion','#id:','id: %s' % self.ipaddress],ssh_user=self.user, ssh_passwd=self.passwd,roster='scan')
		s.cmd(tgt=self.ipaddress,fun='service.start',arg=['salt-minion'],ssh_user=self.user, ssh_passwd=self.passwd,roster='scan')
		ret = client.cmd(self.ipaddress,'test.ping')
		return ret
Ejemplo n.º 45
0
def down():
    '''
    Print a list of all the down or unresponsive salt minions
    '''
    client = salt.client.LocalClient(__opts__['conf_file'])
    key = salt.cli.key.Key(__opts__)
    minions = client.cmd('*', 'test.ping', timeout=1)
    keys = key._keys('acc')

    for minion in sorted(keys - set(minions.keys())):
        print(minion)
Ejemplo n.º 46
0
def _get_pool_results(*args, **kwargs):
    '''
    A helper function which returns a dictionary of minion pools along with
    their matching result sets.
    Useful for developing other "survey style" functions.
    Optionally accepts a "survey_sort=up" or "survey_sort=down" kwargs for
    specifying sort order.
    Because the kwargs namespace of the "salt" and "survey" command are shared,
    the name "survey_sort" was chosen to help avoid option conflicts.
    '''
    # TODO: the option "survey.sort=" would be preferred for namespace
    # separation but the kwargs parser for the salt-run command seems to
    # improperly pass the options containing a "." in them for later modules to
    # process. The "_" is used here instead.

    import hashlib

    tgt = args[0]
    cmd = args[1]
    ret = {}

    sort = kwargs.pop('survey_sort', 'down')
    direction = sort != 'up'

    expr_form = kwargs.pop('expr_form', 'compound')
    if expr_form not in ['compound', 'pcre']:
        expr_form = 'compound'

    kwargs_passthru = dict((k, kwargs[k]) for k in kwargs.iterkeys() if not k.startswith('_'))

    client = salt.client.get_local_client(__opts__['conf_file'])
    try:
        minions = client.cmd(tgt, cmd, args[2:], timeout=__opts__['timeout'], expr_form=expr_form, kwarg=kwargs_passthru)
    except SaltClientError as client_error:
        print(client_error)
        return ret

    # hash minion return values as a string
    for minion in sorted(minions):
        digest = hashlib.sha256(str(minions[minion])).hexdigest()
        if digest not in ret:
            ret[digest] = {}
            ret[digest]['pool'] = []
            ret[digest]['result'] = str(minions[minion])

        ret[digest]['pool'].append(minion)

    sorted_ret = []
    for k in sorted(ret, key=lambda k: len(ret[k]['pool']), reverse=direction):
        # return aggregated results, sorted by size of the hash pool

        sorted_ret.append(ret[k])

    return sorted_ret
Ejemplo n.º 47
0
def get_data(client, from_whom):
    if isinstance(from_whom, str):
        expr_form = 'glob'
    elif isinstance(from_whom, list):
        expr_form = 'list'
    else:
        assert False, "Unknown from_whom type: %r" % from_whom
    return client.cmd(from_whom,
                      "cmd.run", ("cat /home/lantern/access_data.json", ),
                      timeout=20,
                      expr_form=expr_form)
Ejemplo n.º 48
0
    def cpfile(self, filenames):
        self.filenames = filenames
        print self.filenames
        #try:
        if os.path.isfile(file_roots + self.filenames):
            #if os.path.isfile(self.filenames):
            ret = client.cmd(
                self.ipaddress, 'cp.get_file',
                ['salt://%s' % self.filenames,
                 '/tmp/%s' % self.filenames])
            return ret
        if os.path.isdir(file_roots + self.filenames):
            ret = client.cmd(self.ipaddress, 'cp.get_dir',
                             ['salt://%s' % self.filenames, '/tmp/'])
            return ret

        else:
            #finally:
            ret = "it's not a file or dir"
            return ret
Ejemplo n.º 49
0
def up():  # pylint: disable-msg=C0103
    '''
    Print a list of all of the minions that are up
    '''
    client = salt.client.LocalClient(__opts__['conf_file'])
    minions = client.cmd('*', 'test.ping', timeout=__opts__['timeout'])

    for minion in sorted(minions):
        print(minion)

    return sorted(minions)
Ejemplo n.º 50
0
def test_nr_cli_pyats_plugin_render_command():
    ret = client.cmd(
        tgt="nrp1",
        fun="nr.cli",
        arg=["ping {{ host.name }}"],
        kwarg={"plugin": "pyats"},
        tgt_type="glob",
        timeout=60,
    )
    assert "PING ceos1" in ret["nrp1"]["ceos1"]["ping ceos1"] 
    assert "PING ceos2" in ret["nrp1"]["ceos2"]["ping ceos2"]
Ejemplo n.º 51
0
def test_nr_test_suite_non_existing_file():
    ret = client.cmd(
        tgt="nrp1",
        fun="nr.test",
        arg=[],
        kwarg={"suite": "salt://tests/test_suite_not_exists.txt"},
        tgt_type="glob",
        timeout=60,
    )
    assert isinstance(ret["nrp1"], str)
    assert "ERROR" in ret["nrp1"]
Ejemplo n.º 52
0
def test_http_pydantic_model_wrong_method_arg():
    ret = client.cmd(
        tgt="nrp1", 
        fun="nr.http", 
        arg=["gett"], 
        kwarg={"url": "http://10.0.1.4", "FB": "ceos1"}, 
        tgt_type="glob", 
        timeout=60
    )
    pprint.pprint(ret)
    assert "ValidationError" in ret["nrp1"]
Ejemplo n.º 53
0
def test_nr_test_inline_contains_with_render():
    ret = client.cmd(
        tgt="nrp1",
        fun="nr.test",
        arg=["ping {{ host.name }}", "contains", "packet loss"],
        tgt_type="glob",
        timeout=60,
    )
    assert len(ret["nrp1"]) == 2
    for item in ret["nrp1"]:
        assert item["result"] == "PASS"
Ejemplo n.º 54
0
Archivo: virt.py Proyecto: zxstar/salt
def migrate(name, target=""):
    """
    Migrate a VM from one host 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_host = 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_host][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_host(data, origin_host)
    if target not in data:
        __jid_event__.fire_event(
            {"error": "Target host {0} not found".format(origin_data)},
            "progress")
        return ""
    try:
        client.cmd(target, "virt.seed_non_shared_migrate", [disks, True])
        jid = client.cmd_async(origin_host, "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 host {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")
Ejemplo n.º 55
0
def test_nr_nornir_connect_napalm_reconnect_several_good_creds():
    _ = client.cmd(
        tgt="nrp1",
        fun="nr.nornir",
        arg=["disconnect"],
        kwarg={},
        tgt_type="glob",
        timeout=60,
    )
    ret = client.cmd(
        tgt="nrp1",
        fun="nr.nornir",
        arg=["connect", "napalm"],
        kwarg={
            "add_details":
            True,
            "username":
            "******",
            "password":
            "******",
            "reconnect": [
                {
                    "username": "******",
                    "password": "******",
                },
                "local_account",
            ]
        },
        tgt_type="glob",
        timeout=60,
    )
    pprint.pprint(ret)
    # verify result contain message: "Connected with reconnect index '1'"
    assert "Connected" in ret["nrp1"]["ceos1"]['connections:open:napalm'][
        "result"]
    assert "index '0'" in ret["nrp1"]["ceos1"]['connections:open:napalm'][
        "result"]
    assert "Connected" in ret["nrp1"]["ceos2"]['connections:open:napalm'][
        "result"]
    assert "index '0'" in ret["nrp1"]["ceos2"]['connections:open:napalm'][
        "result"]
Ejemplo n.º 56
0
Archivo: virt.py Proyecto: sys-dom/salt
def migrate(name, target=''):
    '''
    Migrate a VM from one host 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_host = 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_host][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_host(data, origin_host)
    if target not in data:
        __jid_event__.fire_event(
            {'error': 'Target host {0} not found'.format(origin_data)},
            'progress')
        return ''
    try:
        client.cmd(target, 'virt.seed_non_shared_migrate', [disks, True])
        jid = client.cmd_async(origin_host, '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 host {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')
Ejemplo n.º 57
0
def test_nr_cli_with_iplkp():
    ret = client.cmd(
        tgt="nrp1",
        fun="nr.cli",
        arg=["show ip int brief"],
        kwarg={"iplkp": "salt://lookup/ip.txt"},
        tgt_type="glob",
        timeout=60,
    )
    # pprint.pprint(ret)
    assert "ceos1:Eth1" in ret["nrp1"]["ceos1"]["show ip int brief"]
    assert "ceos2:Eth1" in ret["nrp1"]["ceos2"]["show ip int brief"]
Ejemplo n.º 58
0
def get_packages(osName, hosts):
    client = salt.client.LocalClient()
    eform = "glob" if '*' in hosts else "list"
    if osName in ('debian', 'ubuntu', 'kali'):
        cmd = "dpkg-query -W -f='${Package} ${Version} ${Architecture}\n'"
    elif osName in ('rhel', 'centos', 'oraclelinux', 'suse', 'fedora',
                    'amazon linux'):
        cmd = "rpm -qa"
    else:
        cmd = None
    return client.cmd(hosts, 'cmd.run', [cmd],
                      expr_form=eform) if cmd else None
Ejemplo n.º 59
0
def test_http_get_call_absolute_url():
    ret = client.cmd(
        tgt="nrp1", 
        fun="nr.http", 
        arg=["get"], 
        kwarg={"url": "http://10.0.1.4", "FB": "ceos1"}, 
        tgt_type="glob", 
        timeout=60
    )
    pprint.pprint(ret)
    assert isinstance(ret["nrp1"]["ceos1"]["get"], str)
    assert len(ret["nrp1"]["ceos1"]["get"]) > 500
Ejemplo n.º 60
0
def up():
    '''
    Print a list of all of the minions that are up
    '''
    __opts__ = salt.config.client_config('/etc/salt/master')
    client = salt.client.LocalClient(__opts__['conf_file'])
    minions = client.cmd('*', 'test.ping', timeout=10)
    if len(minions) > 0:
        ret = True
        for minion in sorted(minions):
            print minion
        return ret