Return the targets from the flat yaml file, checks opts for location but
    defaults to /etc/salt/roster
765744
def targets(tgt, tgt_type='glob', **kwargs):
    '''
    
    '''
    rmatcher = RosterMatcher(tgt, tgt_type)
    return rmatcher.targets()
76745
def get_targets(self):
        
        if not hasattr(self, "_targets"):
            targets = []
            for target_def in self.config.targets or []:
                target = Target(target_def)
                targets.append(target)
            self._targets = targets
        return self._targets
682641
def get_default_yaml_parsers(parser_finder: ParserFinder, conversion_finder: ConversionFinder) -> List[AnyParser]:
    
    return [# yaml for any object
            SingleFileParserFunction(parser_function=read_object_from_yaml,
                                     streaming_mode=True,
                                     supported_exts={'.yaml','.yml'},
                                     supported_types={AnyObject},
                                     ),
            # yaml for collection objects
            SingleFileParserFunction(parser_function=read_collection_from_yaml,
                                     custom_name='read_collection_from_yaml',
                                     streaming_mode=True,
                                     supported_exts={'.yaml','.yml'},
                                     supported_types={Tuple, Dict, List, Set},
                                     function_args={'conversion_finder': conversion_finder}
                                     )
    ]
909537
def _handle_salt_host_resource(resource):
    '''
    
    '''
    ret = {}
    attrs = resource.get('primary', {}).get('attributes', {})
    ret[MINION_ID] = attrs.get(MINION_ID)
    valid_attrs = set(attrs.keys()).intersection(TF_ROSTER_ATTRS.keys())
    for attr in valid_attrs:
        ret[attr] = _cast_output_to_type(attrs.get(attr), TF_ROSTER_ATTRS.get(attr))
    return ret
641260
def targets_to_stage(self, source_targets, ps):
        """"""

        result = []

        # Traverse the dependencies, if needed.
        if ps.get('install-dependencies') == ['on']:
            source_targets = self.collect_targets(source_targets)

        # Filter the target types, if needed.
        included_types = ps.get('install-type')
        for r in source_targets:
            ty = r.type()
            if ty:
                # Do not stage searched libs.
                if ty != "SEARCHED_LIB":
                    if included_types:
                        if self.include_type(ty, included_types):
                            result.append(r)
                    else:
                        result.append(r)
            elif not included_types:
                # Don't install typeless target if there is an explicit list of
                # allowed types.
                result.append(r)

        return result
1240902
def cargo_target_path(target, *path_components)
      target_base = ENV.fetch('CARGO_TARGET_DIR', File.join(rust_toplevel_dir, 'target'))
      File.join(target_base, target, *path_components)
    end
1263596
def get_projects(osa_repo_dir, commit):
    """"""
    # Check out the correct commit SHA from the repository
    repo = Repo(osa_repo_dir)
    checkout(repo, commit)

    yaml_files = glob.glob(
        '{0}/playbooks/defaults/repo_packages/*.yml'.format(osa_repo_dir)
    )
    yaml_parsed = []
    for yaml_file in yaml_files:
        with open(yaml_file, 'r') as f:
            yaml_parsed.append(yaml.load(f))

    merged_dicts = {k: v for d in yaml_parsed for k, v in d.items()}

    return normalize_yaml(merged_dicts)
740513
def targets(self, module):
        

        if module not in self.module_targets:
            raise BuildError("Could not find module in targets()", module=module)

        return [self.find(x, module) for x in self.module_targets[module]]
554096
def imported_targets(self):
    
    libs = []
    for spec in self.imported_target_specs(payload=self.payload):
      resolved_target = self._build_graph.get_target_from_spec(spec,
                                                               relative_to=self.address.spec_path)
      if not resolved_target:
        raise self.UnresolvedImportError(
          'Could not find target {spec} referenced from {relative_to}'
          .format(spec=spec, relative_to=self.address.spec))
      try:
        libs.append(self.expected_target_constraint.validate_satisfied_by(resolved_target))
      except TypeConstraintError as e:
        raise self.WrongTargetTypeError(
          'Wrong target type {spec} referenced from remote sources target {relative_to}: {err}'
          .format(spec=spec, relative_to=self.address.spec, err=str(e)),
          e)
    return libs
220057
function defaultUngrep(targets) {
    if (targets && targets.length) {
        var ungreps = [], target, len = targets.length;

        for (var i = 0; i < len; i++) {
            target = targets[i];
            target = '(?:^' + path.dirname(target) + sep + '){1}';
            target += '(?:/?.*/?)*' + NM_SEG;
            ungreps.push(new RegExp(escape(target)));
        }
        return ungreps;
    }
    return [new RegExp(escape(NM_SEG))];
}
1303625
def load_yaml(data=None, path=None, name='NT'):
    
    if data and not path:
        return mapper(yaml.load(data), _nt_name=name)
    if path and not data:
        with open(path, 'r') as f:
            data = yaml.load(f)
        return mapper(data, _nt_name=name)
    if data and path:
        raise ValueError('expected one source and received two')
1136790
def run(self, jid=None):
        '''
        
        '''
        if self.opts.get('list_hosts'):
            self._get_roster()
            ret = {}
            for roster_file in self.__parsed_rosters:
                if roster_file.startswith('#'):
                    continue
                ret[roster_file] = {}
                for host_id in self.__parsed_rosters[roster_file]:
                    hostname = self.__parsed_rosters[roster_file][host_id]['host']
                    ret[roster_file][host_id] = hostname
            salt.output.display_output(ret, 'nested', self.opts)
            sys.exit()

        fstr = '{0}.prep_jid'.format(self.opts['master_job_cache'])
        jid = self.returners[fstr](passed_jid=jid or self.opts.get('jid', None))

        # Save the invocation information
        argv = self.opts['argv']

        if self.opts.get('raw_shell', False):
            fun = 'ssh._raw'
            args = argv
        else:
            fun = argv[0] if argv else ''
            args = argv[1:]

        job_load = {
            'jid': jid,
            'tgt_type': self.tgt_type,
            'tgt': self.opts['tgt'],
            'user': self.opts['user'],
            'fun': fun,
            'arg': args,
            }

        # save load to the master job cache
        try:
            if isinstance(jid, bytes):
                jid = jid.decode('utf-8')
            if self.opts['master_job_cache'] == 'local_cache':
                self.returners['{0}.save_load'.format(self.opts['master_job_cache'])](jid, job_load, minions=self.targets.keys())
            else:
                self.returners['{0}.save_load'.format(self.opts['master_job_cache'])](jid, job_load)
        except Exception as exc:
            log.exception(exc)
            log.error(
                'Could not save load with returner %s: %s',
                self.opts['master_job_cache'], exc
            )

        if self.opts.get('verbose'):
            msg = 'Executing job with jid {0}'.format(jid)
            print(msg)
            print('-' * len(msg) + '\n')
            print('')
        sret = {}
        outputter = self.opts.get('output', 'nested')
        final_exit = 0
        for ret in self.handle_ssh():
            host = next(six.iterkeys(ret))
            if isinstance(ret[host], dict):
                host_ret = ret[host].get('retcode', 0)
                if host_ret != 0:
                    final_exit = 1
            else:
                # Error on host
                final_exit = 1

            self.cache_job(jid, host, ret[host], fun)
            ret = self.key_deploy(host, ret)

            if isinstance(ret[host], dict) and (ret[host].get('stderr') or '').startswith('ssh:'):
                ret[host] = ret[host]['stderr']

            if not isinstance(ret[host], dict):
                p_data = {host: ret[host]}
            elif 'return' not in ret[host]:
                p_data = ret
            else:
                outputter = ret[host].get('out', self.opts.get('output', 'nested'))
                p_data = {host: ret[host].get('return', {})}
            if self.opts.get('static'):
                sret.update(p_data)
            else:
                salt.output.display_output(
                        p_data,
                        outputter,
                        self.opts)
            if self.event:
                id_, data = next(six.iteritems(ret))
                if isinstance(data, six.text_type):
                    data = {'return': data}
                if 'id' not in data:
                    data['id'] = id_
                data['jid'] = jid  # make the jid in the payload the same as the jid in the tag
                self.event.fire_event(
                    data,
                    salt.utils.event.tagify(
                        [jid, 'ret', host],
                        'job'))
        if self.opts.get('static'):
            salt.output.display_output(
                    sret,
                    outputter,
                    self.opts)
        if final_exit:
            sys.exit(salt.defaults.exitcodes.EX_AGGREGATE)
1329596
def load(self, target_uris, fields=None, **kwargs):
        
        yaml_dict = self._load_first(
            target_uris, yamlsettings.yamldict.load, **kwargs
        )
        # TODO: Move this into the extension, otherwise every load from
        # a persistant location will refilter fields.
        if fields:
            yaml_dict.limit(fields)

        return yaml_dict
229366
def _get_file_list(load):
    '''
    
    '''
    if 'env' in load:
        # "env" is not supported; Use "saltenv".
        load.pop('env')

    if 'saltenv' not in load or load['saltenv'] not in envs():
        return []
    ret = set()
    for repo in init():
        repo['repo'].open()
        ref = _get_ref(repo, load['saltenv'])
        if ref:
            manifest = repo['repo'].manifest(rev=ref[1])
            for tup in manifest:
                relpath = os.path.relpath(tup[4], repo['root'])
                # Don't add files outside the hgfs_root
                if not relpath.startswith('../'):
                    ret.add(os.path.join(repo['mountpoint'], relpath))
        repo['repo'].close()
    return sorted(ret)
534284
def targets(tgt, tgt_type='glob', **kwargs):  # pylint: disable=W0613
    '''
    
    '''
    minions = salt.utils.minions.CkMinions(__opts__)
    _res = minions.check_minions(tgt, tgt_type)
    minions = _res['minions']

    ret = {}
    if not minions:
        return ret
    # log.debug(minions)

    cache = salt.cache.Cache(__opts__)

    roster_order = __opts__.get('roster_order', {
        'host': ('ipv6-private', 'ipv6-global', 'ipv4-private', 'ipv4-public')
    })

    ret = {}
    for minion_id in minions:
        try:
            minion = _load_minion(minion_id, cache)
        except LookupError:
            continue

        minion_res = copy.deepcopy(__opts__.get('roster_defaults', {}))
        for param, order in roster_order.items():
            if not isinstance(order, (list, tuple)):
                order = [order]
            for key in order:
                kres = _minion_lookup(minion_id, key, minion)
                if kres:
                    minion_res[param] = kres
                    break

        if 'host' in minion_res:
            ret[minion_id] = minion_res
        else:
            log.warning('Could not determine host information for minion %s', minion_id)

    log.debug('Roster lookup result: %s', ret)

    return ret
1235099
def _find_install_targets(name=None,
                          version=None,
                          pkgs=None,
                          sources=None,
                          skip_suggestions=False,
                          pkg_verify=False,
                          normalize=True,
                          ignore_epoch=False,
                          reinstall=False,
                          refresh=False,
                          **kwargs):
    '''
    
    '''
    was_refreshed = False

    if all((pkgs, sources)):
        return {'name': name,
                'changes': {},
                'result': False,
                'comment': 'Only one of "pkgs" and "sources" is permitted.'}

    # dict for packages that fail pkg.verify and their altered files
    altered_files = {}
    # Get the ignore_types list if any from the pkg_verify argument
    if isinstance(pkg_verify, list) \
            and any(x.get('ignore_types') is not None
                    for x in pkg_verify
                    if isinstance(x, _OrderedDict)
                    and 'ignore_types' in x):
        ignore_types = next(x.get('ignore_types')
                            for x in pkg_verify
                            if 'ignore_types' in x)
    else:
        ignore_types = []

    # Get the verify_options list if any from the pkg_verify argument
    if isinstance(pkg_verify, list) \
            and any(x.get('verify_options') is not None
                    for x in pkg_verify
                    if isinstance(x, _OrderedDict)
                    and 'verify_options' in x):
        verify_options = next(x.get('verify_options')
                            for x in pkg_verify
                            if 'verify_options' in x)
    else:
        verify_options = []

    if __grains__['os'] == 'FreeBSD':
        kwargs['with_origin'] = True

    if salt.utils.platform.is_windows():
        # Windows requires a refresh to establish a pkg db if refresh=True, so
        # add it to the kwargs.
        kwargs['refresh'] = refresh

    resolve_capabilities = kwargs.get('resolve_capabilities', False) and 'pkg.list_provides' in __salt__
    try:
        cur_pkgs = __salt__['pkg.list_pkgs'](versions_as_list=True, **kwargs)
        cur_prov = resolve_capabilities and __salt__['pkg.list_provides'](**kwargs) or dict()
    except CommandExecutionError as exc:
        return {'name': name,
                'changes': {},
                'result': False,
                'comment': exc.strerror}

    if salt.utils.platform.is_windows() and kwargs.pop('refresh', False):
        # We already refreshed when we called pkg.list_pkgs
        was_refreshed = True
        refresh = False

    if any((pkgs, sources)):
        if pkgs:
            desired = _repack_pkgs(pkgs, normalize=normalize)
        elif sources:
            desired = __salt__['pkg_resource.pack_sources'](
                sources,
                normalize=normalize,
            )

        if not desired:
            # Badly-formatted SLS
            return {'name': name,
                    'changes': {},
                    'result': False,
                    'comment': 'Invalidly formatted \'{0}\' parameter. See '
                               'minion log.'.format('pkgs' if pkgs
                                                    else 'sources')}

        to_unpurge = _find_unpurge_targets(desired, **kwargs)
    else:
        if salt.utils.platform.is_windows():
            pkginfo = _get_package_info(name, saltenv=kwargs['saltenv'])
            if not pkginfo:
                return {'name': name,
                        'changes': {},
                        'result': False,
                        'comment': 'Package {0} not found in the '
                                   'repository.'.format(name)}
            if version is None:
                version = _get_latest_pkg_version(pkginfo)

        if normalize:
            _normalize_name = \
                __salt__.get('pkg.normalize_name', lambda pkgname: pkgname)
            desired = {_normalize_name(name): version}
        else:
            desired = {name: version}

        to_unpurge = _find_unpurge_targets(desired, **kwargs)

        # FreeBSD pkg supports `openjdk` and `java/openjdk7` package names
        origin = bool(re.search('/', name))

        if __grains__['os'] == 'FreeBSD' and origin:
            cver = [k for k, v in six.iteritems(cur_pkgs)
                    if v['origin'] == name]
        else:
            cver = cur_pkgs.get(name, [])

        if name not in to_unpurge:
            if version and version in cver \
                    and not reinstall \
                    and not pkg_verify:
                # The package is installed and is the correct version
                return {'name': name,
                        'changes': {},
                        'result': True,
                        'comment': 'Version {0} of package \'{1}\' is already '
                                   'installed'.format(version, name)}

            # if cver is not an empty string, the package is already installed
            elif cver and version is None \
                    and not reinstall \
                    and not pkg_verify:
                # The package is installed
                return {'name': name,
                        'changes': {},
                        'result': True,
                        'comment': 'Package {0} is already '
                                   'installed'.format(name)}

    version_spec = False
    if not sources:
        # Check for alternate package names if strict processing is not
        # enforced. Takes extra time. Disable for improved performance
        if not skip_suggestions:
            # Perform platform-specific pre-flight checks
            not_installed = dict([
                (name, version)
                for name, version in desired.items()
                if not (name in cur_pkgs and (version is None or _fulfills_version_string(cur_pkgs[name], version)))
            ])
            if not_installed:
                try:
                    problems = _preflight_check(not_installed, **kwargs)
                except CommandExecutionError:
                    pass
                else:
                    comments = []
                    if problems.get('no_suggest'):
                        comments.append(
                            'The following package(s) were not found, and no '
                            'possible matches were found in the package db: '
                            '{0}'.format(
                                ', '.join(sorted(problems['no_suggest']))
                            )
                        )
                    if problems.get('suggest'):
                        for pkgname, suggestions in \
                                six.iteritems(problems['suggest']):
                            comments.append(
                                'Package \'{0}\' not found (possible matches: '
                                '{1})'.format(pkgname, ', '.join(suggestions))
                            )
                    if comments:
                        if len(comments) > 1:
                            comments.append('')
                        return {'name': name,
                                'changes': {},
                                'result': False,
                                'comment': '. '.join(comments).rstrip()}

    # Resolve the latest package version for any packages with "latest" in the
    # package version
    wants_latest = [] \
        if sources \
        else [x for x, y in six.iteritems(desired) if y == 'latest']
    if wants_latest:
        resolved_latest = __salt__['pkg.latest_version'](*wants_latest,
                                                         refresh=refresh,
                                                         **kwargs)
        if len(wants_latest) == 1:
            resolved_latest = {wants_latest[0]: resolved_latest}
        if refresh:
            was_refreshed = True
            refresh = False

        # pkg.latest_version returns an empty string when the package is
        # up-to-date. So check the currently-installed packages. If found, the
        # resolved latest version will be the currently installed one from
        # cur_pkgs. If not found, then the package doesn't exist and the
        # resolved latest version will be None.
        for key in resolved_latest:
            if not resolved_latest[key]:
                if key in cur_pkgs:
                    resolved_latest[key] = cur_pkgs[key][-1]
                else:
                    resolved_latest[key] = None
        # Update the desired versions with the ones we resolved
        desired.update(resolved_latest)

    # Find out which packages will be targeted in the call to pkg.install
    targets = {}
    to_reinstall = {}
    problems = []
    warnings = []
    failed_verify = False
    for package_name, version_string in six.iteritems(desired):
        cver = cur_pkgs.get(package_name, [])
        if resolve_capabilities and not cver and package_name in cur_prov:
            cver = cur_pkgs.get(cur_prov.get(package_name)[0], [])

        # Package not yet installed, so add to targets
        if not cver:
            targets[package_name] = version_string
            continue
        if sources:
            if reinstall:
                to_reinstall[package_name] = version_string
                continue
            elif 'lowpkg.bin_pkg_info' not in __salt__:
                continue
            # Metadata parser is available, cache the file and derive the
            # package's name and version
            err = 'Unable to cache {0}: {1}'
            try:
                cached_path = __salt__['cp.cache_file'](version_string, saltenv=kwargs['saltenv'])
            except CommandExecutionError as exc:
                problems.append(err.format(version_string, exc))
                continue
            if not cached_path:
                problems.append(err.format(version_string, 'file not found'))
                continue
            elif not os.path.exists(cached_path):
                problems.append('{0} does not exist on minion'.format(version_string))
                continue
            source_info = __salt__['lowpkg.bin_pkg_info'](cached_path)
            if source_info is None:
                warnings.append('Failed to parse metadata for {0}'.format(version_string))
                continue
            else:
                verstr = source_info['version']
        else:
            verstr = version_string
            if reinstall:
                to_reinstall[package_name] = version_string
                continue
            if not __salt__['pkg_resource.check_extra_requirements'](package_name, version_string):
                targets[package_name] = version_string
                continue
            # No version specified and pkg is installed
            elif __salt__['pkg_resource.version_clean'](version_string) is None:
                if (not reinstall) and pkg_verify:
                    try:
                        verify_result = __salt__['pkg.verify'](
                            package_name,
                            ignore_types=ignore_types,
                            verify_options=verify_options,
                            **kwargs
                        )
                    except (CommandExecutionError, SaltInvocationError) as exc:
                        failed_verify = exc.strerror
                        continue
                    if verify_result:
                        to_reinstall[package_name] = version_string
                        altered_files[package_name] = verify_result
                continue
        version_fulfilled = False
        allow_updates = bool(not sources and kwargs.get('allow_updates'))
        try:
            version_fulfilled = _fulfills_version_string(cver, verstr, ignore_epoch=ignore_epoch, allow_updates=allow_updates)
        except CommandExecutionError as exc:
            problems.append(exc.strerror)
            continue

        # Compare desired version against installed version.
        version_spec = True
        if not version_fulfilled:
            if reinstall:
                to_reinstall[package_name] = version_string
            else:
                version_conditions = _parse_version_string(version_string)
                if pkg_verify and any(oper == '==' for oper, version in version_conditions):
                    try:
                        verify_result = __salt__['pkg.verify'](
                            package_name,
                            ignore_types=ignore_types,
                            verify_options=verify_options,
                            **kwargs
                        )
                    except (CommandExecutionError, SaltInvocationError) as exc:
                        failed_verify = exc.strerror
                        continue
                    if verify_result:
                        to_reinstall[package_name] = version_string
                        altered_files[package_name] = verify_result
                else:
                    log.debug(
                        'Current version (%s) did not match desired version '
                        'specification (%s), adding to installation targets',
                        cver, version_string
                    )
                    targets[package_name] = version_string

    if failed_verify:
        problems.append(failed_verify)

    if problems:
        return {'name': name,
                'changes': {},
                'result': False,
                'comment': ' '.join(problems)}

    if not any((targets, to_unpurge, to_reinstall)):
        # All specified packages are installed
        msg = 'All specified packages are already installed{0}'
        msg = msg.format(
            ' and are at the desired version' if version_spec and not sources
            else ''
        )
        ret = {'name': name,
               'changes': {},
               'result': True,
               'comment': msg}
        if warnings:
            ret.setdefault('warnings', []).extend(warnings)
        return ret

    return (desired, targets, to_unpurge, to_reinstall, altered_files,
            warnings, was_refreshed)
585806
def _check_yaml_and_paths(ymlfilepath, yamldefs):
        
        relpath = os.path.relpath(ymlfilepath)
        if '/' not in relpath:
            relpath = './%s' % relpath
        pathroot = os.path.abspath(os.path.dirname(ymlfilepath))

        for imagename, defn in iteritems(yamldefs):
            if imagename == '_SOURCES_':
                yamldefs['_SOURCES_'] = [os.path.relpath(_get_abspath(pathroot, p))
                                         for p in yamldefs['_SOURCES_']]
                continue
            elif imagename in SPECIAL_FIELDS:
                continue

            for key in ('build_directory', 'FROM_DOCKERFILE', 'ignorefile'):
                if key in defn:
                    defn[key] = _get_abspath(pathroot, defn[key])

            if 'copy_from' in defn:
                if not isinstance(defn['copy_from'], dict):
                    raise errors.ParsingFailure((
                            'Syntax error in file "%s": \n' +
                            'The "copy_from" field in image definition "%s" is not \n' 
                            'a key:value list.') % (ymlfilepath, imagename))
                for otherimg, value in defn.get('copy_from', {}).items():
                    if not isinstance(value, dict):
                        raise errors.ParsingFailure((
                            'Syntax error in field:\n'
                            '     %s . copy_from . %s\nin file "%s". \n'
                            'All entries must be of the form "sourcepath: destpath"')%
                                 (imagename, otherimg, ymlfilepath))

            # save the file path for logging
            defn['_sourcefile'] = relpath

            if 'ignore' in defn and 'ignorefile' in defn:
                raise errors.MultipleIgnoreError(
                        'Image "%s" has both "ignore" AND "ignorefile" fields.' % imagename +
                        ' At most ONE of these should be defined')

            if 'secret_files' in defn and not defn.get('squash', True):
                raise errors.ParsingFailure(
                        "Step '%s' defines secret_files, so 'squash' cannot be set to 'false'"
                        % imagename)

            if defn.get('secret_files', None) and defn.get('copy_from', False):
                raise errors.ParsingFailure(
                        '`secret_files` currently is not implmemented to handle `copy_from`'
                        ' (step %s)' % imagename)

            for key in defn:
                if key not in RECOGNIZED_KEYS:
                    raise errors.UnrecognizedKeyError(
                            'Field "%s" in image "%s" in file "%s" not recognized' %
                            (key, imagename, relpath))