本文整理汇总了Python中salt.version.SaltStackVersion类的典型用法代码示例。如果您正苦于以下问题:Python SaltStackVersion类的具体用法?Python SaltStackVersion怎么用?Python SaltStackVersion使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了SaltStackVersion类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_version_comparison
def test_version_comparison(self):
examples = (
('debian/0.11.1+ds-1-3-ga0afcbd', '0.11.1+ds-2'),
('v0.12.0-85-g2880105', 'v0.12.0-19-g767d4f9'),
('v0.17.0rc1-1-g52ebdfd', '0.17.0rc1'),
('v0.17.0', 'v0.17.0rc1')
)
for v1, v2 in examples:
self.assertTrue(SaltStackVersion.parse(v1) > v2)
self.assertTrue(SaltStackVersion.parse(v2) < v1)
示例2: test_version_comparison
def test_version_comparison(self):
examples = (
('debian/0.11.1+ds-1-3-ga0afcbd', '0.11.1+ds-2'),
('v0.12.0-85-g2880105', 'v0.12.0-19-g767d4f9'),
('v0.17.0rc1-1-g52ebdfd', '0.17.0rc1'),
('v0.17.0', 'v0.17.0rc1'),
('Hydrogen', '0.17.0'),
('Helium', 'Hydrogen'),
('v2014.1.4.1-n/a-abcdefgh', 'v2014.1.4.1rc3-n/a-abcdefgh'),
('v2014.1.4.1-1-abcdefgh', 'v2014.1.4.1-n/a-abcdefgh')
)
for higher_version, lower_version in examples:
self.assertTrue(SaltStackVersion.parse(higher_version) > lower_version)
self.assertTrue(SaltStackVersion.parse(lower_version) < higher_version)
示例3: test_version_parsing
def test_version_parsing(self):
strip_initial_non_numbers_regex = re.compile(r'(?:[^\d]+)?(?P<vs>.*)')
expect = (
('v0.12.0-19-g767d4f9', (0, 12, 0, 0, '', 0, 19, 'g767d4f9'), None),
('v0.12.0-85-g2880105', (0, 12, 0, 0, '', 0, 85, 'g2880105'), None),
('debian/0.11.1+ds-1-3-ga0afcbd',
(0, 11, 1, 0, '', 0, 3, 'ga0afcbd'), '0.11.1-3-ga0afcbd'),
('0.12.1', (0, 12, 1, 0, '', 0, 0, None), None),
('0.12.1', (0, 12, 1, 0, '', 0, 0, None), None),
('0.17.0rc1', (0, 17, 0, 0, 'rc', 1, 0, None), None),
('v0.17.0rc1-1-g52ebdfd', (0, 17, 0, 0, 'rc', 1, 1, 'g52ebdfd'), None),
('v2014.1.4.1', (2014, 1, 4, 1, '', 0, 0, None), None),
('v2014.1.4.1rc3-n/a-abcdefgh', (2014, 1, 4, 1, 'rc', 3, -1, 'abcdefgh'), None),
('v3.4.1.1', (3, 4, 1, 1, '', 0, 0, None), None)
)
for vstr, full_info, version in expect:
saltstack_version = SaltStackVersion.parse(vstr)
self.assertEqual(
saltstack_version.full_info, full_info
)
if version is None:
version = strip_initial_non_numbers_regex.search(vstr).group('vs')
self.assertEqual(saltstack_version.string, version)
示例4: _mk_version
def _mk_version(self, name):
'''
Make a version
:return:
'''
return name, SaltStackVersion.from_name(name)
示例5: test_check_dns_deprecation_warning
def test_check_dns_deprecation_warning(self):
helium_version = SaltStackVersion.from_name('Helium')
if salt_version.__version_info__ >= helium_version:
raise AssertionError(
'Failing this test on purpose! Please delete this test case, '
'the \'check_dns\' keyword argument and the deprecation '
'warnings in `salt.config.minion_config` and '
'salt.config.apply_minion_config`'
)
# Let's force the warning to always be thrown
warnings.resetwarnings()
warnings.filterwarnings(
'always', '(.*)check_dns(.*)', DeprecationWarning, 'salt.config'
)
with warnings.catch_warnings(record=True) as w:
sconfig.minion_config(None, None, check_dns=True)
self.assertEqual(
'The functionality behind the \'check_dns\' keyword argument '
'is no longer required, as such, it became unnecessary and is '
'now deprecated. \'check_dns\' will be removed in Salt '
'{0}.'.format(helium_version.formatted_version),
str(w[-1].message)
)
with warnings.catch_warnings(record=True) as w:
sconfig.apply_minion_config(
overrides=None, defaults=None, check_dns=True
)
self.assertEqual(
'The functionality behind the \'check_dns\' keyword argument '
'is no longer required, as such, it became unnecessary and is '
'now deprecated. \'check_dns\' will be removed in Salt '
'{0}.'.format(helium_version.formatted_version),
str(w[-1].message)
)
with warnings.catch_warnings(record=True) as w:
sconfig.minion_config(None, None, check_dns=False)
self.assertEqual(
'The functionality behind the \'check_dns\' keyword argument '
'is no longer required, as such, it became unnecessary and is '
'now deprecated. \'check_dns\' will be removed in Salt '
'{0}.'.format(helium_version.formatted_version),
str(w[-1].message)
)
with warnings.catch_warnings(record=True) as w:
sconfig.apply_minion_config(
overrides=None, defaults=None, check_dns=False
)
self.assertEqual(
'The functionality behind the \'check_dns\' keyword argument '
'is no longer required, as such, it became unnecessary and is '
'now deprecated. \'check_dns\' will be removed in Salt '
'{0}.'.format(helium_version.formatted_version),
str(w[-1].message)
)
示例6: test_salt_with_git_version
def test_salt_with_git_version(self):
if getattr(self, '_call_binary_', None) is None:
self.skipTest('\'_call_binary_\' not defined.')
from salt.utils import which
from salt.version import __version_info__, SaltStackVersion
git = which('git')
if not git:
self.skipTest('The git binary is not available')
# Let's get the output of git describe
process = subprocess.Popen(
[git, 'describe', '--tags', '--match', 'v[0-9]*'],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
close_fds=True,
cwd=CODE_DIR
)
out, err = process.communicate()
if not out:
self.skipTest(
'Failed to get the output of \'git describe\'. '
'Error: {0!r}'.format(
err
)
)
parsed_version = SaltStackVersion.parse(out)
if parsed_version.info < __version_info__:
self.skipTest(
'We\'re likely about to release a new version. This test '
'would fail. Parsed({0!r}) < Expected({1!r})'.format(
parsed_version.info, __version_info__
)
)
elif parsed_version.info != __version_info__:
self.skipTest(
'In order to get the proper salt version with the '
'git hash you need to update salt\'s local git '
'tags. Something like: \'git fetch --tags\' or '
'\'git fetch --tags upstream\' if you followed '
'salt\'s contribute documentation. The version '
'string WILL NOT include the git hash.'
)
out = '\n'.join(self.run_script(self._call_binary_, '--version'))
self.assertIn(parsed_version.string, out)
示例7: test_warn_until_warning_raised
def test_warn_until_warning_raised(self):
# We *always* want *all* warnings thrown on this module
warnings.filterwarnings('always', '', DeprecationWarning, __name__)
def raise_warning(_version_info_=(0, 16, 0)):
warn_until(
(0, 17), 'Deprecation Message!',
_version_info_=_version_info_
)
def raise_named_version_warning(_version_info_=(0, 16, 0)):
warn_until(
'Hydrogen', 'Deprecation Message!',
_version_info_=_version_info_
)
# raise_warning should show warning until version info is >= (0, 17)
with warnings.catch_warnings(record=True) as recorded_warnings:
raise_warning()
self.assertEqual(
'Deprecation Message!', str(recorded_warnings[0].message)
)
# raise_warning should show warning until version info is >= (0, 17)
with warnings.catch_warnings(record=True) as recorded_warnings:
raise_named_version_warning()
self.assertEqual(
'Deprecation Message!', str(recorded_warnings[0].message)
)
# the deprecation warning is not issued because we passed
# _dont_call_warning
with warnings.catch_warnings(record=True) as recorded_warnings:
warn_until(
(0, 17), 'Foo', _dont_call_warnings=True,
_version_info_=(0, 16)
)
self.assertEqual(0, len(recorded_warnings))
# Let's set version info to (0, 17), a RuntimeError should be raised
with self.assertRaisesRegexp(
RuntimeError,
r'The warning triggered on filename \'(.*)warnings_test.py\', '
r'line number ([\d]+), is supposed to be shown until version '
r'\'0.17.0\' is released. Current version is now \'0.17.0\'. '
r'Please remove the warning.'):
raise_warning(_version_info_=(0, 17, 0))
# Let's set version info to (0, 17), a RuntimeError should be raised
with self.assertRaisesRegexp(
RuntimeError,
r'The warning triggered on filename \'(.*)warnings_test.py\', '
r'line number ([\d]+), is supposed to be shown until version '
r'\'Hydrogen((.*))\' is released. Current version is now '
r'\'([\d.]+)\'. Please remove the warning.'):
raise_named_version_warning(_version_info_=(sys.maxint, 16, 0))
# Even though we're calling warn_until, we pass _dont_call_warnings
# because we're only after the RuntimeError
with self.assertRaisesRegexp(
RuntimeError,
r'The warning triggered on filename \'(.*)warnings_test.py\', '
r'line number ([\d]+), is supposed to be shown until version '
r'\'0.17.0\' is released. Current version is now '
r'\'([\d.]+)\'. Please remove the warning.'):
warn_until(
(0, 17), 'Foo', _dont_call_warnings=True
)
with self.assertRaisesRegexp(
RuntimeError,
r'The warning triggered on filename \'(.*)warnings_test.py\', '
r'line number ([\d]+), is supposed to be shown until version '
r'\'Hydrogen((.*))\' is released. Current version is now '
r'\'([\d.]+)\'. Please remove the warning.'):
warn_until(
'Hydrogen', 'Foo', _dont_call_warnings=True,
_version_info_=(sys.maxint, 16, 0)
)
# version on the deprecation message gets properly formatted
with warnings.catch_warnings(record=True) as recorded_warnings:
vrs = SaltStackVersion.from_name('Helium')
warn_until(
'Helium', 'Deprecation Message until {version}!',
_version_info_=(vrs.major - 1, 0)
)
self.assertEqual(
'Deprecation Message until {0}!'.format(vrs.formatted_version),
str(recorded_warnings[0].message)
)
示例8: installed
#.........这里部分代码省略.........
bin_env = env
ret = {'name': name, 'result': None, 'comment': '', 'changes': {}}
if use_wheel:
min_version = '1.4'
cur_version = __salt__['pip.version'](bin_env)
if not salt.utils.compare_versions(ver1=cur_version, oper='>=',
ver2=min_version):
ret['result'] = False
ret['comment'] = ('The \'use_wheel\' option is only supported in '
'pip {0} and newer. The version of pip detected '
'was {1}.').format(min_version, cur_version)
return ret
if no_use_wheel:
min_version = '1.4'
cur_version = __salt__['pip.version'](bin_env)
if not salt.utils.compare_versions(ver1=cur_version, oper='>=',
ver2=min_version):
ret['result'] = False
ret['comment'] = ('The \'no_use_wheel\' option is only supported in '
'pip {0} and newer. The version of pip detected '
'was {1}.').format(min_version, cur_version)
return ret
if repo is not None:
msg = ('The \'repo\' argument to pip.installed is deprecated and will '
'be removed in Salt {version}. Please use \'name\' instead. '
'The current value for name, {0!r} will be replaced by the '
'value of repo, {1!r}'.format(
name,
repo,
version=_SaltStackVersion.from_name('Lithium').formatted_version
))
salt.utils.warn_until('Lithium', msg)
ret.setdefault('warnings', []).append(msg)
name = repo
from_vcs = False
if name and not requirements:
try:
try:
# With pip < 1.2, the __version__ attribute does not exist and
# vcs+URL urls are not properly parsed.
# The next line is meant to trigger an AttributeError and
# handle lower pip versions
logger.debug(
'Installed pip version: {0}'.format(pip.__version__)
)
install_req = pip.req.InstallRequirement.from_line(name)
except AttributeError:
logger.debug('Installed pip version is lower than 1.2')
supported_vcs = ('git', 'svn', 'hg', 'bzr')
if name.startswith(supported_vcs):
for vcs in supported_vcs:
if name.startswith(vcs):
from_vcs = True
install_req = pip.req.InstallRequirement.from_line(
name.split('{0}+'.format(vcs))[-1]
)
break
else:
install_req = pip.req.InstallRequirement.from_line(name)
except ValueError as exc:
示例9: removed
def removed(name,
requirements=None,
bin_env=None,
log=None,
proxy=None,
timeout=None,
user=None,
runas=None,
cwd=None,
use_vt=False):
'''
Make sure that a package is not installed.
name
The name of the package to uninstall
user
The user under which to run pip
bin_env : None
the pip executable or virtualenenv to use
use_vt
Use VT terminal emulation (see ouptut while installing)
'''
ret = {'name': name, 'result': None, 'comment': '', 'changes': {}}
if runas is not None:
# The user is using a deprecated argument, warn!
msg = ('The \'runas\' argument to pip.installed is deprecated, and '
'will be removed in Salt {version}. Please use \'user\' '
'instead.'.format(
version=_SaltStackVersion.from_name('Lithium').formatted_version
))
salt.utils.warn_until('Lithium', msg)
ret.setdefault('warnings', []).append(msg)
# "There can only be one"
if runas is not None and user:
raise CommandExecutionError(
'The \'runas\' and \'user\' arguments are mutually exclusive. '
'Please use \'user\' as \'runas\' is being deprecated.'
)
# Support deprecated 'runas' arg
elif runas is not None and not user:
user = runas
try:
pip_list = __salt__['pip.list'](bin_env=bin_env, user=user, cwd=cwd)
except (CommandExecutionError, CommandNotFoundError) as err:
ret['result'] = False
ret['comment'] = 'Error uninstalling \'{0}\': {1}'.format(name, err)
return ret
if name not in pip_list:
ret['result'] = True
ret['comment'] = 'Package is not installed.'
return ret
if __opts__['test']:
ret['result'] = None
ret['comment'] = 'Package {0} is set to be removed'.format(name)
return ret
if __salt__['pip.uninstall'](pkgs=name,
requirements=requirements,
bin_env=bin_env,
log=log,
proxy=proxy,
timeout=timeout,
user=user,
cwd=cwd,
use_vt=use_vt):
ret['result'] = True
ret['changes'][name] = 'Removed'
ret['comment'] = 'Package was successfully removed.'
else:
ret['result'] = False
ret['comment'] = 'Could not remove package.'
return ret
示例10: installed
#.........这里部分代码省略.........
# Check that the pip binary supports the 'use_wheel' option
if use_wheel:
min_version = '1.4'
cur_version = __salt__['pip.version'](bin_env)
if not salt.utils.compare_versions(ver1=cur_version, oper='>=',
ver2=min_version):
ret['result'] = False
ret['comment'] = ('The \'use_wheel\' option is only supported in '
'pip {0} and newer. The version of pip detected '
'was {1}.').format(min_version, cur_version)
return ret
# Check that the pip binary supports the 'no_use_wheel' option
if no_use_wheel:
min_version = '1.4'
cur_version = __salt__['pip.version'](bin_env)
if not salt.utils.compare_versions(ver1=cur_version, oper='>=',
ver2=min_version):
ret['result'] = False
ret['comment'] = ('The \'no_use_wheel\' option is only supported in '
'pip {0} and newer. The version of pip detected '
'was {1}.').format(min_version, cur_version)
return ret
# Deprecation warning for the repo option
if repo is not None:
msg = ('The \'repo\' argument to pip.installed is deprecated and will '
'be removed in Salt {version}. Please use \'name\' instead. '
'The current value for name, {0!r} will be replaced by the '
'value of repo, {1!r}'.format(
name,
repo,
version=_SaltStackVersion.from_name('Lithium').formatted_version
))
salt.utils.warn_until('Lithium', msg)
ret.setdefault('warnings', []).append(msg)
name = repo
# Get the packages parsed name and version from the pip library.
# This only is done when there is no requirements or editable parameter.
pkgs_details = []
if pkgs and not (requirements or editable):
comments = []
for pkg in iter(pkgs):
out = _check_pkg_version_format(pkg)
if out['result'] is False:
ret['result'] = False
comments.append(out['comment'])
elif out['result'] is True:
pkgs_details.append((out['prefix'], pkg, out['version_spec']))
if ret['result'] is False:
ret['comment'] = '\n'.join(comments)
return ret
# If a requirements file is specified, only install the contents of the
# requirements file. Similarly, using the --editable flag with pip should
# also ignore the "name" and "pkgs" parameters.
target_pkgs = []
already_installed_comments = []
if requirements or editable:
comments = []
# Append comments if this is a dry run.
if __opts__['test']:
ret['result'] = None
示例11: installed
def installed(name,
pip_bin=None,
requirements=None,
env=None,
bin_env=None,
use_wheel=False,
log=None,
proxy=None,
timeout=None,
repo=None,
editable=None,
find_links=None,
index_url=None,
extra_index_url=None,
no_index=False,
mirrors=None,
build=None,
target=None,
download=None,
download_cache=None,
source=None,
upgrade=False,
force_reinstall=False,
ignore_installed=False,
exists_action=None,
no_deps=False,
no_install=False,
no_download=False,
install_options=None,
user=None,
runas=None,
no_chown=False,
cwd=None,
activate=False,
pre_releases=False):
'''
Make sure the package is installed
name
The name of the python package to install
user
The user under which to run pip
pip_bin : None
Deprecated, use bin_env
use_wheel : False
Prefer wheel archives (requires pip>=1.4)
env : None
Deprecated, use bin_env
bin_env : None
the pip executable or virtualenv to use
.. versionchanged:: 0.17.0
``use_wheel`` option added.
.. admonition:: Attention
As of Salt 0.17.0 the pip state **needs** an importable pip module.
This usually means having the system's pip package installed or running
Salt from an active `virtualenv`_.
The reason for this requirement is because ``pip`` already does a
pretty good job parsing it's own requirements. It makes no sense for
Salt to do ``pip`` requirements parsing and validation before passing
them to the ``pip`` library. It's functionality duplication and it's
more error prone.
.. _`virtualenv`: http://www.virtualenv.org
'''
if pip_bin and not bin_env:
bin_env = pip_bin
elif env and not bin_env:
bin_env = env
ret = {'name': name, 'result': None, 'comment': '', 'changes': {}}
if use_wheel:
min_version = '1.4'
cur_version = __salt__['pip.version'](bin_env)
if not salt.utils.compare_versions(ver1=cur_version, oper='>=',
ver2=min_version):
ret['result'] = False
ret['comment'] = ('The \'use_wheel\' option is only supported in '
'pip {0} and newer. The version of pip detected '
'was {1}.').format(min_version, cur_version)
return ret
if repo is not None:
msg = ('The \'repo\' argument to pip.installed is deprecated and will '
'be removed in Salt {version}. Please use \'name\' instead. '
'The current value for name, {0!r} will be replaced by the '
'value of repo, {1!r}'.format(
name,
repo,
version=_SaltStackVersion.from_name(
'Hydrogen').formatted_version
))
salt.utils.warn_until('Hydrogen', msg)
ret.setdefault('warnings', []).append(msg)
name = repo
#.........这里部分代码省略.........
示例12: __get_version
def __get_version(version, version_info):
'''
If we can get a version provided at installation time or from Git, use
that instead, otherwise we carry on.
'''
try:
# Try to import the version information provided at install time
from saltfuse._version import __version__, __version_info__ # pylint: disable=E0611
return __version__, __version_info__
except ImportError:
pass
# This might be a 'python setup.py develop' installation type. Let's
# discover the version information at runtime.
import os
import warnings
import subprocess
if 'SETUP_DIRNAME' in globals():
# This is from the exec() call in Salt Fuse's setup.py
cwd = SETUP_DIRNAME # pylint: disable=E0602
if not os.path.exists(os.path.join(cwd, '.git')):
# This is not a Salt Fuse git checkout!!! Don't even try to parse...
return version, version_info
else:
cwd = os.path.abspath(os.path.dirname(__file__))
if not os.path.exists(os.path.join(os.path.dirname(cwd), '.git')):
# This is not a Salt git checkout!!! Don't even try to parse...
return version, version_info
try:
kwargs = dict(
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
cwd=cwd
)
if not sys.platform.startswith('win'):
# Let's not import `salt.utils` for the above check
kwargs['close_fds'] = True
process = subprocess.Popen(
['git', 'describe', '--tags', '--match', 'v[0-9]*'], **kwargs)
out, err = process.communicate()
out = out.strip()
err = err.strip()
if not out or err:
return version, version_info
parsed_version = SaltStackVersion.parse(out)
if parsed_version.info > version_info:
warnings.warn(
'The parsed version info, `{0}`, is bigger than the one '
'defined in the file, `{1}`. Missing version bump?'.format(
parsed_version.info,
version_info
),
UserWarning,
stacklevel=2
)
return version, version_info
elif parsed_version.info < version_info:
warnings.warn(
'The parsed version info, `{0}`, is lower than the one '
'defined in the file, `{1}`.'
'In order to get the proper salt version with the git hash '
'you need to update salt\'s local git tags. Something like: '
'\'git fetch --tags\' or \'git fetch --tags upstream\' if '
'you followed salt\'s contribute documentation. The version '
'string WILL NOT include the git hash.'.format(
parsed_version.info,
version_info
),
UserWarning,
stacklevel=2
)
return version, version_info
return parsed_version.string, parsed_version.info
except OSError as os_err:
if os_err.errno != 2:
# If the errno is not 2(The system cannot find the file
# specified), raise the exception so it can be catch by the
# developers
raise
return version, version_info
示例13: installed
#.........这里部分代码省略.........
The reason for this requirement is because ``pip`` already does a
pretty good job parsing it's own requirements. It makes no sense for
Salt to do ``pip`` requirements parsing and validation before passing
them to the ``pip`` library. It's functionality duplication and it's
more error prone.
.. _`virtualenv`: http://www.virtualenv.org
"""
if pip_bin and not bin_env:
bin_env = pip_bin
elif env and not bin_env:
bin_env = env
ret = {"name": name, "result": None, "comment": "", "changes": {}, "state_stdout": ""}
if use_wheel:
min_version = "1.4"
cur_version = __salt__["pip.version"](bin_env)
if not salt.utils.compare_versions(ver1=cur_version, oper=">=", ver2=min_version):
ret["result"] = False
ret["comment"] = (
"The 'use_wheel' option is only supported in "
"pip {0} and newer. The version of pip detected "
"was {1}."
).format(min_version, cur_version)
return ret
if repo is not None:
msg = (
"The 'repo' argument to pip.installed is deprecated and will "
"be removed in Salt {version}. Please use 'name' instead. "
"The current value for name, {0!r} will be replaced by the "
"value of repo, {1!r}".format(name, repo, version=_SaltStackVersion.from_name("Hydrogen").formatted_version)
)
salt.utils.warn_until("Hydrogen", msg)
ret.setdefault("warnings", []).append(msg)
name = repo
from_vcs = False
if name and not requirements:
try:
try:
# With pip < 1.2, the __version__ attribute does not exist and
# vcs+URL urls are not properly parsed.
# The next line is meant to trigger an AttributeError and
# handle lower pip versions
logger.debug("Installed pip version: {0}".format(pip.__version__))
install_req = pip.req.InstallRequirement.from_line(name)
except AttributeError:
logger.debug("Installed pip version is lower than 1.2")
supported_vcs = ("git", "svn", "hg", "bzr")
if name.startswith(supported_vcs):
for vcs in supported_vcs:
if name.startswith(vcs):
from_vcs = True
install_req = pip.req.InstallRequirement.from_line(name.split("{0}+".format(vcs))[-1])
break
else:
install_req = pip.req.InstallRequirement.from_line(name)
except ValueError as exc:
ret["result"] = False
if not from_vcs and "=" in name and "==" not in name:
ret["comment"] = (
"Invalid version specification in package {0}. '=' is "
示例14: removed
def removed(name, requirements=None, bin_env=None, log=None, proxy=None, timeout=None, user=None, runas=None, cwd=None):
"""
Make sure that a package is not installed.
name
The name of the package to uninstall
user
The user under which to run pip
bin_env : None
the pip executable or virtualenenv to use
"""
ret = {"name": name, "result": None, "comment": "", "changes": {}, "state_stdout": ""}
if runas is not None:
# The user is using a deprecated argument, warn!
msg = (
"The 'runas' argument to pip.installed is deprecated, and "
"will be removed in Salt {version}. Please use 'user' "
"instead.".format(version=_SaltStackVersion.from_name("Hydrogen").formatted_version)
)
salt.utils.warn_until("Hydrogen", msg)
ret.setdefault("warnings", []).append(msg)
# "There can only be one"
if runas is not None and user:
raise CommandExecutionError(
"The 'runas' and 'user' arguments are mutually exclusive. "
"Please use 'user' as 'runas' is being deprecated."
)
# Support deprecated 'runas' arg
elif runas is not None and not user:
user = runas
try:
pip_list = __salt__["pip.list"](bin_env=bin_env, user=user, cwd=cwd)
except (CommandExecutionError, CommandNotFoundError) as err:
ret["result"] = False
ret["comment"] = "Error uninstalling '{0}': {1}".format(name, err)
return ret
if name not in pip_list:
ret["result"] = True
ret["comment"] = "Package is not installed."
return ret
if __opts__["test"]:
ret["result"] = None
ret["comment"] = "Package {0} is set to be removed".format(name)
return ret
if __salt__["pip.uninstall"](
pkgs=name,
requirements=requirements,
bin_env=bin_env,
log=log,
proxy=proxy,
timeout=timeout,
user=user,
cwd=cwd,
state_ret=ret,
):
ret["result"] = True
ret["changes"][name] = "Removed"
ret["comment"] = "Package was successfully removed."
else:
ret["result"] = False
ret["comment"] = "Could not remove package."
return ret
示例15: import
# Import salt libs
from salt.exceptions import (
#CommandExecutionError,
SaltInvocationError
)
from salt.utils import warn_until
from salt.version import (
__version__,
SaltStackVersion
)
# is there not SaltStackVersion.current() to get
# the version of the salt running this code??
CUR_VER = SaltStackVersion(__version__[0], __version__[1])
BORON = SaltStackVersion.from_name('Boron')
# pylint: disable=import-error
HAS_GLANCE = False
try:
from glanceclient import client
from glanceclient import exc
HAS_GLANCE = True
except ImportError:
pass
# Workaround, as the Glance API v2 requires you to
# already have a keystone session token
HAS_KEYSTONE = False
try:
from keystoneclient.v2_0 import client as kstone