def symlink_list(load): ''' Return a dict of all symlinks based on a given path in the repo ''' gitfs = salt.utils.gitfs.GitFS(__opts__) gitfs.init_remotes(__opts__['gitfs_remotes'], PER_REMOTE_OVERRIDES) return gitfs.symlink_list(load)
def clear_lock(remote=None): ''' Clear update.lk ''' gitfs = salt.utils.gitfs.GitFS(__opts__) gitfs.init_remotes(__opts__['gitfs_remotes'], PER_REMOTE_OVERRIDES) return gitfs.clear_lock(remote=remote)
def serve_file(load, fnd): ''' Return a chunk from a file based on the data received ''' gitfs = salt.utils.gitfs.GitFS(__opts__) gitfs.init_remotes(__opts__['gitfs_remotes'], PER_REMOTE_OVERRIDES) return gitfs.serve_file(load, fnd)
def dir_list(load): ''' Return a list of all directories on the master ''' gitfs = salt.utils.gitfs.GitFS(__opts__) gitfs.init_remotes(__opts__['gitfs_remotes'], PER_REMOTE_OVERRIDES) return gitfs.dir_list(load)
def file_hash(load, fnd): ''' Return a file hash, the hash type is set in the master config file ''' gitfs = salt.utils.gitfs.GitFS(__opts__) gitfs.init_remotes(__opts__['gitfs_remotes'], PER_REMOTE_OVERRIDES) return gitfs.file_hash(load, fnd)
def envs(ignore_cache=False): ''' Return a list of refs that can be used as environments ''' gitfs = salt.utils.gitfs.GitFS(__opts__) gitfs.init_remotes(__opts__['gitfs_remotes'], PER_REMOTE_OVERRIDES) return gitfs.envs(ignore_cache=ignore_cache)
def init(): ''' Initialize remotes. This is only used by the master's pre-flight checks, and is not invoked by GitFS. ''' gitfs = salt.utils.gitfs.GitFS(__opts__) gitfs.init_remotes(__opts__['gitfs_remotes'], PER_REMOTE_OVERRIDES)
def update(): ''' Execute a git fetch on all of the repos ''' gitfs = salt.utils.gitfs.GitFS(__opts__) gitfs.init_remotes(__opts__['gitfs_remotes'], PER_REMOTE_OVERRIDES) gitfs.update()
def file_list(load): ''' Return a list of all files on the file server in a specified environment (specified as a key within the load dict). ''' gitfs = salt.utils.gitfs.GitFS(__opts__) gitfs.init_remotes(__opts__['gitfs_remotes'], PER_REMOTE_OVERRIDES) return gitfs.file_list(load)
def find_file(path, tgt_env='base', **kwargs): # pylint: disable=W0613 ''' Find the first file to match the path and ref, read the file out of git and send the path to the newly cached file ''' gitfs = salt.utils.gitfs.GitFS(__opts__) gitfs.init_remotes(__opts__['gitfs_remotes'], PER_REMOTE_OVERRIDES) return gitfs.find_file(path, tgt_env=tgt_env, **kwargs)
def lock(remote=None): ''' Place an update.lk ``remote`` can either be a dictionary containing repo configuration information, or a pattern. If the latter, then remotes for which the URL matches the pattern will be locked. ''' gitfs = salt.utils.gitfs.GitFS(__opts__) gitfs.init_remotes(__opts__['gitfs_remotes'], PER_REMOTE_OVERRIDES) return gitfs.lock(remote=remote)
def test_per_saltenv_config(self): opts = textwrap.dedent(''' gitfs_saltenv: - baz: # when loaded, the "salt://" prefix will be removed - mountpoint: salt://baz_mountpoint - ref: baz_branch - root: baz_root gitfs_remotes: - file://tmp/repo1: - saltenv: - foo: - ref: foo_branch - root: foo_root - file://tmp/repo2: - mountpoint: repo2 - saltenv: - baz: - mountpoint: abc ''') self.opts.update(yaml.safe_load(opts)) gitfs = salt.utils.gitfs.GitFS(self.opts) gitfs.init_remotes(self.opts['gitfs_remotes'], PER_REMOTE_OVERRIDES, PER_REMOTE_ONLY) # repo1 (branch: foo) # The mountpoint should take the default (from gitfs_mountpoint), while # ref and root should take the per-saltenv params. self.assertEqual(gitfs.remotes[0].mountpoint('foo'), '') self.assertEqual(gitfs.remotes[0].ref('foo'), 'foo_branch') self.assertEqual(gitfs.remotes[0].root('foo'), 'foo_root') # repo1 (branch: bar) # The 'bar' branch does not have a per-saltenv configuration set, so # each of the below values should fall back to global values. self.assertEqual(gitfs.remotes[0].mountpoint('bar'), '') self.assertEqual(gitfs.remotes[0].ref('bar'), 'bar') self.assertEqual(gitfs.remotes[0].root('bar'), 'salt') # repo1 (branch: baz) # The 'baz' branch does not have a per-saltenv configuration set, but # it is defined in the gitfs_saltenv parameter, so the values # from that parameter should be returned. self.assertEqual(gitfs.remotes[0].mountpoint('baz'), 'baz_mountpoint') self.assertEqual(gitfs.remotes[0].ref('baz'), 'baz_branch') self.assertEqual(gitfs.remotes[0].root('baz'), 'baz_root') # repo2 (branch: foo) # The mountpoint should take the per-remote mountpoint value of # 'repo2', while ref and root should fall back to global values. self.assertEqual(gitfs.remotes[1].mountpoint('foo'), 'repo2') self.assertEqual(gitfs.remotes[1].ref('foo'), 'foo') self.assertEqual(gitfs.remotes[1].root('foo'), 'salt') # repo2 (branch: bar) # The 'bar' branch does not have a per-saltenv configuration set, so # the mountpoint should take the per-remote mountpoint value of # 'repo2', while ref and root should fall back to global values. self.assertEqual(gitfs.remotes[1].mountpoint('bar'), 'repo2') self.assertEqual(gitfs.remotes[1].ref('bar'), 'bar') self.assertEqual(gitfs.remotes[1].root('bar'), 'salt') # repo2 (branch: baz) # The 'baz' branch has the mountpoint configured as a per-saltenv # parameter. The other two should take the values defined in # gitfs_saltenv. self.assertEqual(gitfs.remotes[1].mountpoint('baz'), 'abc') self.assertEqual(gitfs.remotes[1].ref('baz'), 'baz_branch') self.assertEqual(gitfs.remotes[1].root('baz'), 'baz_root')