示例#1
0
 def get_cli_static_event_returns(self,
                                  jid,
                                  minions,
                                  timeout=None,
                                  tgt='*',
                                  tgt_type='glob',
                                  verbose=False):
     '''
     Get the returns for the command line interface via the event system
     '''
     minions = set(minions)
     if verbose:
         msg = 'Executing job with jid {0}'.format(jid)
         print(msg)
         print('-' * len(msg) + '\n')
     if timeout is None:
         timeout = self.opts['timeout']
     jid_dir = salt.utils.jid_dir(jid, self.opts['cachedir'],
                                  self.opts['hash_type'])
     start = int(time.time())
     found = set()
     ret = {}
     wtag = os.path.join(jid_dir, 'wtag*')
     # Check to see if the jid is real, if not return the empty dict
     if not os.path.isdir(jid_dir):
         return ret
     # Wait for the hosts to check in
     while True:
         raw = self.event.get_event(timeout, jid)
         if not raw is None:
             found.add(raw['id'])
             ret[raw['id']] = {'ret': raw['return']}
             if 'out' in raw:
                 ret[raw['id']]['out'] = raw['out']
             if len(found.intersection(minions)) >= len(minions):
                 # All minions have returned, break out of the loop
                 break
             continue
         # Then event system timeout was reached and nothing was returned
         if len(found.intersection(minions)) >= len(minions):
             # All minions have returned, break out of the loop
             break
         if glob.glob(wtag) and not int(time.time()) > start + timeout + 1:
             # The timeout +1 has not been reached and there is still a
             # write tag for the syndic
             continue
         if int(time.time()) > start + timeout:
             if verbose:
                 if tgt_type == 'glob' or tgt_type == 'pcre':
                     if not len(found) >= len(minions):
                         print('\nThe following minions did not return:')
                         fail = sorted(list(minions.difference(found)))
                         for minion in fail:
                             print(minion)
             break
         time.sleep(0.01)
     return ret
示例#2
0
文件: __init__.py 项目: sijis/salt
 def get_cli_static_event_returns(self, jid, minions, timeout=None, tgt="*", tgt_type="glob", verbose=False):
     """
     Get the returns for the command line interface via the event system
     """
     minions = set(minions)
     if verbose:
         msg = "Executing job with jid {0}".format(jid)
         print(msg)
         print("-" * len(msg) + "\n")
     if timeout is None:
         timeout = self.opts["timeout"]
     jid_dir = salt.utils.jid_dir(jid, self.opts["cachedir"], self.opts["hash_type"])
     start = int(time.time())
     found = set()
     ret = {}
     wtag = os.path.join(jid_dir, "wtag*")
     # Check to see if the jid is real, if not return the empty dict
     if not os.path.isdir(jid_dir):
         return ret
     # Wait for the hosts to check in
     while True:
         raw = self.event.get_event(timeout, jid)
         if raw is not None and "return" in raw:
             if "minions" in raw.get("data", {}):
                 minions.update(raw["data"]["minions"])
                 continue
             found.add(raw["id"])
             ret[raw["id"]] = {"ret": raw["return"]}
             ret[raw["id"]]["success"] = raw.get("success", False)
             if "out" in raw:
                 ret[raw["id"]]["out"] = raw["out"]
             if len(found.intersection(minions)) >= len(minions):
                 # All minions have returned, break out of the loop
                 break
             continue
         # Then event system timeout was reached and nothing was returned
         if len(found.intersection(minions)) >= len(minions):
             # All minions have returned, break out of the loop
             break
         if glob.glob(wtag) and int(time.time()) <= start + timeout + 1:
             # The timeout +1 has not been reached and there is still a
             # write tag for the syndic
             continue
         if int(time.time()) > start + timeout:
             if verbose:
                 if tgt_type in ("glob", "pcre", "list"):
                     if len(found) < len(minions):
                         fail = sorted(list(minions.difference(found)))
                         for minion in fail:
                             ret[minion] = {"out": "no_return", "ret": "Minion did not return"}
             break
         time.sleep(0.01)
     return ret
示例#3
0
    def get_cli_event_returns(self,
                              jid,
                              minions,
                              timeout=None,
                              tgt='*',
                              tgt_type='glob',
                              verbose=False,
                              **kwargs):
        '''
        Get the returns for the command line interface via the event system
        '''
        if not isinstance(minions, set):
            if isinstance(minions, basestring):
                minions = set([minions])
            elif isinstance(minions, (list, tuple)):
                minions = set(list(minions))

        if verbose:
            msg = 'Executing job with jid {0}'.format(jid)
            print(msg)
            print('-' * len(msg) + '\n')
        if timeout is None:
            timeout = self.opts['timeout']
        inc_timeout = timeout
        jid_dir = salt.utils.jid_dir(jid, self.opts['cachedir'],
                                     self.opts['hash_type'])
        start = int(time.time())
        found = set()
        wtag = os.path.join(jid_dir, 'wtag*')
        # Check to see if the jid is real, if not return the empty dict
        if not os.path.isdir(jid_dir):
            yield {}
        # Wait for the hosts to check in
        while True:
            raw = self.event.get_event(timeout, jid)
            if not raw is None:
                if 'syndic' in raw:
                    minions.update(raw['syndic'])
                    continue
                found.add(raw['id'])
                ret = {raw['id']: {'ret': raw['return']}}
                if 'out' in raw:
                    ret[raw['id']]['out'] = raw['out']
                yield ret
                if len(found.intersection(minions)) >= len(minions):
                    # All minions have returned, break out of the loop
                    break
                continue
            # Then event system timeout was reached and nothing was returned
            if len(found.intersection(minions)) >= len(minions):
                # All minions have returned, break out of the loop
                break
            if glob.glob(wtag) and not int(time.time()) > start + timeout + 1:
                # The timeout +1 has not been reached and there is still a
                # write tag for the syndic
                continue
            if int(time.time()) > start + timeout:
                # The timeout has been reached, check the jid to see if the
                # timeout needs to be increased
                jinfo = self.gather_job_info(jid, tgt, tgt_type, **kwargs)
                more_time = False
                for id_ in jinfo:
                    if jinfo[id_]:
                        if verbose:
                            print('Execution is still running on {0}'.format(
                                id_))
                        more_time = True
                if more_time:
                    timeout += inc_timeout
                    continue
                if verbose:
                    if tgt_type == 'glob' or tgt_type == 'pcre':
                        if not len(found) >= len(minions):
                            print('\nThe following minions did not return:')
                            fail = sorted(list(minions.difference(found)))
                            for minion in fail:
                                print(minion)
                break
            time.sleep(0.01)
示例#4
0
 def get_cli_returns(self,
                     jid,
                     minions,
                     timeout=None,
                     tgt='*',
                     tgt_type='glob',
                     verbose=False,
                     **kwargs):
     '''
     This method starts off a watcher looking at the return data for
     a specified jid, it returns all of the information for the jid
     '''
     if verbose:
         msg = 'Executing job with jid {0}'.format(jid)
         print(msg)
         print('-' * len(msg) + '\n')
     if timeout is None:
         timeout = self.opts['timeout']
     fret = {}
     inc_timeout = timeout
     jid_dir = salt.utils.jid_dir(jid, self.opts['cachedir'],
                                  self.opts['hash_type'])
     start = int(time.time())
     found = set()
     wtag = os.path.join(jid_dir, 'wtag*')
     # Check to see if the jid is real, if not return the empty dict
     if not os.path.isdir(jid_dir):
         yield {}
     # Wait for the hosts to check in
     while True:
         for fn_ in os.listdir(jid_dir):
             ret = {}
             if fn_.startswith('.'):
                 continue
             if fn_ not in found:
                 retp = os.path.join(jid_dir, fn_, 'return.p')
                 outp = os.path.join(jid_dir, fn_, 'out.p')
                 if not os.path.isfile(retp):
                     continue
                 while fn_ not in ret:
                     try:
                         check = True
                         ret_data = self.serial.load(
                             salt.utils.fopen(retp, 'r'))
                         if ret_data is None:
                             # Sometimes the ret data is read at the wrong
                             # time and returns None, do a quick re-read
                             if check:
                                 continue
                         ret[fn_] = {'ret': ret_data}
                         if os.path.isfile(outp):
                             ret[fn_]['out'] = self.serial.load(
                                 salt.utils.fopen(outp, 'r'))
                     except Exception:
                         pass
                 found.add(fn_)
                 fret.update(ret)
                 yield ret
         if glob.glob(wtag) and not int(time.time()) > start + timeout + 1:
             # The timeout +1 has not been reached and there is still a
             # write tag for the syndic
             continue
         if len(found.intersection(minions)) >= len(minions):
             # All minions have returned, break out of the loop
             break
         if int(time.time()) > start + timeout:
             # The timeout has been reached, check the jid to see if the
             # timeout needs to be increased
             jinfo = self.gather_job_info(jid, tgt, tgt_type, **kwargs)
             more_time = False
             for id_ in jinfo:
                 if jinfo[id_]:
                     if verbose:
                         print('Execution is still running on {0}'.format(
                             id_))
                     more_time = True
             if more_time:
                 timeout += inc_timeout
                 continue
             if verbose:
                 if tgt_type == 'glob' or tgt_type == 'pcre':
                     if len(found.intersection(minions)) >= len(minions):
                         print('\nThe following minions did not return:')
                         fail = sorted(list(minions.difference(found)))
                         for minion in fail:
                             print(minion)
             break
         time.sleep(0.01)
示例#5
0
文件: __init__.py 项目: jslatts/salt
    def get_cli_event_returns(
            self,
            jid,
            minions,
            timeout=None,
            tgt='*',
            tgt_type='glob',
            verbose=False,
            show_timeout=False,
            **kwargs):
        '''
        Get the returns for the command line interface via the event system
        '''
        if not isinstance(minions, set):
            if isinstance(minions, basestring):
                minions = set([minions])
            elif isinstance(minions, (list, tuple)):
                minions = set(list(minions))

        if verbose:
            msg = 'Executing job with jid {0}'.format(jid)
            print(msg)
            print('-' * len(msg) + '\n')
        if timeout is None:
            timeout = self.opts['timeout']
        inc_timeout = timeout
        jid_dir = salt.utils.jid_dir(jid,
                                     self.opts['cachedir'],
                                     self.opts['hash_type'])
        start = int(time.time())
        found = set()
        wtag = os.path.join(jid_dir, 'wtag*')
        # Check to see if the jid is real, if not return the empty dict
        if not os.path.isdir(jid_dir):
            yield {}
        # Wait for the hosts to check in
        syndic_wait = 0
        while True:
            raw = self.event.get_event(timeout, jid)
            if raw is not None and 'id' in raw:
                if 'minions' in raw.get('data', {}):
                    minions.update(raw['data']['minions'])
                    continue
                if 'syndic' in raw:
                    minions.update(raw['syndic'])
                    continue
                found.add(raw.get('id'))
                ret = {raw['id']: {'ret': raw['return']}}
                if 'out' in raw:
                    ret[raw['id']]['out'] = raw['out']
                yield ret
                if len(found.intersection(minions)) >= len(minions):
                    # All minions have returned, break out of the loop
                    if self.opts['order_masters']:
                        if syndic_wait < self.opts.get('syndic_wait', 1):
                            syndic_wait += 1
                            time.sleep(1)
                            continue
                    break
                continue
            # Then event system timeout was reached and nothing was returned
            if len(found.intersection(minions)) >= len(minions):
                # All minions have returned, break out of the loop
                if self.opts['order_masters']:
                    if syndic_wait < self.opts.get('syndic_wait', 1):
                        syndic_wait += 1
                        time.sleep(1)
                        continue
                break
            if glob.glob(wtag) and int(time.time()) <= start + timeout + 1:
                # The timeout +1 has not been reached and there is still a
                # write tag for the syndic
                continue
            if int(time.time()) > start + timeout:
                # The timeout has been reached, check the jid to see if the
                # timeout needs to be increased
                jinfo = self.gather_job_info(jid, tgt, tgt_type, **kwargs)
                more_time = False
                for id_ in jinfo:
                    if jinfo[id_]:
                        if verbose:
                            print(
                                'Execution is still running on {0}'.format(id_)
                            )
                        more_time = True
                if more_time:
                    timeout += inc_timeout
                    continue
                if verbose or show_timeout:
                    if self.opts.get('minion_data_cache', False) \
                            or tgt_type in ('glob', 'pcre', 'list'):
                        if len(found) < len(minions):
                            fail = sorted(list(minions.difference(found)))
                            for minion in fail:
                                yield({
                                    minion: {
                                        'out': 'no_return',
                                        'ret': 'Minion did not return'
                                    }
                                })
                break
            time.sleep(0.01)
示例#6
0
文件: __init__.py 项目: jslatts/salt
 def get_cli_static_event_returns(
         self,
         jid,
         minions,
         timeout=None,
         tgt='*',
         tgt_type='glob',
         verbose=False):
     '''
     Get the returns for the command line interface via the event system
     '''
     minions = set(minions)
     if verbose:
         msg = 'Executing job with jid {0}'.format(jid)
         print(msg)
         print('-' * len(msg) + '\n')
     if timeout is None:
         timeout = self.opts['timeout']
     jid_dir = salt.utils.jid_dir(jid,
                                  self.opts['cachedir'],
                                  self.opts['hash_type'])
     start = int(time.time())
     found = set()
     ret = {}
     wtag = os.path.join(jid_dir, 'wtag*')
     # Check to see if the jid is real, if not return the empty dict
     if not os.path.isdir(jid_dir):
         return ret
     # Wait for the hosts to check in
     while True:
         raw = self.event.get_event(timeout, jid)
         if raw is not None and 'return' in raw:
             if 'minions' in raw.get('data', {}):
                 minions.update(raw['data']['minions'])
                 continue
             found.add(raw['id'])
             ret[raw['id']] = {'ret': raw['return']}
             ret[raw['id']]['success'] = raw.get('success', False)
             if 'out' in raw:
                 ret[raw['id']]['out'] = raw['out']
             if len(found.intersection(minions)) >= len(minions):
                 # All minions have returned, break out of the loop
                 break
             continue
         # Then event system timeout was reached and nothing was returned
         if len(found.intersection(minions)) >= len(minions):
             # All minions have returned, break out of the loop
             break
         if glob.glob(wtag) and int(time.time()) <= start + timeout + 1:
             # The timeout +1 has not been reached and there is still a
             # write tag for the syndic
             continue
         if int(time.time()) > start + timeout:
             if verbose:
                 if self.opts.get('minion_data_cache', False) \
                         or tgt_type in ('glob', 'pcre', 'list'):
                     if len(found) < len(minions):
                         fail = sorted(list(minions.difference(found)))
                         for minion in fail:
                             ret[minion] = {
                                 'out': 'no_return',
                                 'ret': 'Minion did not return'
                             }
             break
         time.sleep(0.01)
     return ret
示例#7
0
文件: __init__.py 项目: jslatts/salt
 def get_cli_returns(
         self,
         jid,
         minions,
         timeout=None,
         tgt='*',
         tgt_type='glob',
         verbose=False,
         **kwargs):
     '''
     This method starts off a watcher looking at the return data for
     a specified jid, it returns all of the information for the jid
     '''
     if verbose:
         msg = 'Executing job with jid {0}'.format(jid)
         print(msg)
         print('-' * len(msg) + '\n')
     if timeout is None:
         timeout = self.opts['timeout']
     fret = {}
     inc_timeout = timeout
     jid_dir = salt.utils.jid_dir(jid,
                                  self.opts['cachedir'],
                                  self.opts['hash_type'])
     start = int(time.time())
     found = set()
     wtag = os.path.join(jid_dir, 'wtag*')
     # Check to see if the jid is real, if not return the empty dict
     if not os.path.isdir(jid_dir):
         yield {}
     # Wait for the hosts to check in
     while True:
         for fn_ in os.listdir(jid_dir):
             ret = {}
             if fn_.startswith('.'):
                 continue
             if fn_ not in found:
                 retp = os.path.join(jid_dir, fn_, 'return.p')
                 outp = os.path.join(jid_dir, fn_, 'out.p')
                 if not os.path.isfile(retp):
                     continue
                 while fn_ not in ret:
                     try:
                         check = True
                         ret_data = self.serial.load(
                             salt.utils.fopen(retp, 'r')
                         )
                         if ret_data is None:
                             # Sometimes the ret data is read at the wrong
                             # time and returns None, do a quick re-read
                             if check:
                                 continue
                         ret[fn_] = {'ret': ret_data}
                         if os.path.isfile(outp):
                             ret[fn_]['out'] = self.serial.load(
                                 salt.utils.fopen(outp, 'r')
                             )
                     except Exception:
                         pass
                 found.add(fn_)
                 fret.update(ret)
                 yield ret
         if glob.glob(wtag) and int(time.time()) <= start + timeout + 1:
             # The timeout +1 has not been reached and there is still a
             # write tag for the syndic
             continue
         if len(found.intersection(minions)) >= len(minions):
             # All minions have returned, break out of the loop
             break
         if int(time.time()) > start + timeout:
             # The timeout has been reached, check the jid to see if the
             # timeout needs to be increased
             jinfo = self.gather_job_info(jid, tgt, tgt_type, **kwargs)
             more_time = False
             for id_ in jinfo:
                 if jinfo[id_]:
                     if verbose:
                         print(
                             'Execution is still running on {0}'.format(id_)
                         )
                     more_time = True
             if more_time:
                 timeout += inc_timeout
                 continue
             if verbose:
                 if self.opts.get('minion_data_cache', False) \
                         or tgt_type in ('glob', 'pcre', 'list'):
                     if len(found.intersection(minions)) >= len(minions):
                         fail = sorted(list(minions.difference(found)))
                         for minion in fail:
                             yield({
                                 minion: {
                                     'out': 'no_return',
                                     'ret': 'Minion did not return'
                                 }
                             })
             break
         time.sleep(0.01)
示例#8
0
文件: __init__.py 项目: sijis/salt
    def get_cli_event_returns(self, jid, minions, timeout=None, tgt="*", tgt_type="glob", verbose=False, **kwargs):
        """
        Get the returns for the command line interface via the event system
        """
        if not isinstance(minions, set):
            if isinstance(minions, basestring):
                minions = set([minions])
            elif isinstance(minions, (list, tuple)):
                minions = set(list(minions))

        if verbose:
            msg = "Executing job with jid {0}".format(jid)
            print(msg)
            print("-" * len(msg) + "\n")
        if timeout is None:
            timeout = self.opts["timeout"]
        inc_timeout = timeout
        jid_dir = salt.utils.jid_dir(jid, self.opts["cachedir"], self.opts["hash_type"])
        start = int(time.time())
        found = set()
        wtag = os.path.join(jid_dir, "wtag*")
        # Check to see if the jid is real, if not return the empty dict
        if not os.path.isdir(jid_dir):
            yield {}
        # Wait for the hosts to check in
        syndic_wait = 0
        while True:
            raw = self.event.get_event(timeout, jid)
            if raw is not None and "id" in raw:
                if "minions" in raw.get("data", {}):
                    minions.update(raw["data"]["minions"])
                    continue
                if "syndic" in raw:
                    minions.update(raw["syndic"])
                    continue
                found.add(raw.get("id"))
                ret = {raw["id"]: {"ret": raw["return"]}}
                if "out" in raw:
                    ret[raw["id"]]["out"] = raw["out"]
                yield ret
                if len(found.intersection(minions)) >= len(minions):
                    # All minions have returned, break out of the loop
                    if self.opts["order_masters"]:
                        if syndic_wait < self.opts.get("syndic_wait", 1):
                            syndic_wait += 1
                            time.sleep(1)
                            continue
                    break
                continue
            # Then event system timeout was reached and nothing was returned
            if len(found.intersection(minions)) >= len(minions):
                # All minions have returned, break out of the loop
                if self.opts["order_masters"]:
                    if syndic_wait < self.opts.get("syndic_wait", 1):
                        syndic_wait += 1
                        time.sleep(1)
                        continue
                break
            if glob.glob(wtag) and int(time.time()) <= start + timeout + 1:
                # The timeout +1 has not been reached and there is still a
                # write tag for the syndic
                continue
            if int(time.time()) > start + timeout:
                # The timeout has been reached, check the jid to see if the
                # timeout needs to be increased
                jinfo = self.gather_job_info(jid, tgt, tgt_type, **kwargs)
                more_time = False
                for id_ in jinfo:
                    if jinfo[id_]:
                        if verbose:
                            print("Execution is still running on {0}".format(id_))
                        more_time = True
                if more_time:
                    timeout += inc_timeout
                    continue
                if verbose:
                    if tgt_type in ("glob", "pcre", "list"):
                        if len(found) < len(minions):
                            fail = sorted(list(minions.difference(found)))
                            for minion in fail:
                                yield ({minion: {"out": "no_return", "ret": "Minion did not return"}})
                break
            time.sleep(0.01)
示例#9
0
文件: __init__.py 项目: sijis/salt
 def get_cli_returns(self, jid, minions, timeout=None, tgt="*", tgt_type="glob", verbose=False, **kwargs):
     """
     This method starts off a watcher looking at the return data for
     a specified jid, it returns all of the information for the jid
     """
     if verbose:
         msg = "Executing job with jid {0}".format(jid)
         print(msg)
         print("-" * len(msg) + "\n")
     if timeout is None:
         timeout = self.opts["timeout"]
     fret = {}
     inc_timeout = timeout
     jid_dir = salt.utils.jid_dir(jid, self.opts["cachedir"], self.opts["hash_type"])
     start = int(time.time())
     found = set()
     wtag = os.path.join(jid_dir, "wtag*")
     # Check to see if the jid is real, if not return the empty dict
     if not os.path.isdir(jid_dir):
         yield {}
     # Wait for the hosts to check in
     while True:
         for fn_ in os.listdir(jid_dir):
             ret = {}
             if fn_.startswith("."):
                 continue
             if fn_ not in found:
                 retp = os.path.join(jid_dir, fn_, "return.p")
                 outp = os.path.join(jid_dir, fn_, "out.p")
                 if not os.path.isfile(retp):
                     continue
                 while fn_ not in ret:
                     try:
                         check = True
                         ret_data = self.serial.load(salt.utils.fopen(retp, "r"))
                         if ret_data is None:
                             # Sometimes the ret data is read at the wrong
                             # time and returns None, do a quick re-read
                             if check:
                                 continue
                         ret[fn_] = {"ret": ret_data}
                         if os.path.isfile(outp):
                             ret[fn_]["out"] = self.serial.load(salt.utils.fopen(outp, "r"))
                     except Exception:
                         pass
                 found.add(fn_)
                 fret.update(ret)
                 yield ret
         if glob.glob(wtag) and int(time.time()) <= start + timeout + 1:
             # The timeout +1 has not been reached and there is still a
             # write tag for the syndic
             continue
         if len(found.intersection(minions)) >= len(minions):
             # All minions have returned, break out of the loop
             break
         if int(time.time()) > start + timeout:
             # The timeout has been reached, check the jid to see if the
             # timeout needs to be increased
             jinfo = self.gather_job_info(jid, tgt, tgt_type, **kwargs)
             more_time = False
             for id_ in jinfo:
                 if jinfo[id_]:
                     if verbose:
                         print("Execution is still running on {0}".format(id_))
                     more_time = True
             if more_time:
                 timeout += inc_timeout
                 continue
             if verbose:
                 if tgt_type in ("glob", "pcre", "list"):
                     if len(found.intersection(minions)) >= len(minions):
                         fail = sorted(list(minions.difference(found)))
                         for minion in fail:
                             yield ({minion: {"out": "no_return", "ret": "Minion did not return"}})
             break
         time.sleep(0.01)