"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "salt/modules/win_dism.py" between
salt-2019.2.0.tar.gz and salt-2019.2.1.tar.gz

About: SaltStack is a systems management software for data center automation, cloud orchestration, server provisioning, configuration management and more. Community version.

win_dism.py  (salt-2019.2.0):win_dism.py  (salt-2019.2.1)
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
''' '''
Install features/packages for Windows using DISM, which is useful for minions Install features/packages for Windows using DISM, which is useful for minions
not running server versionsĀ of Windows. Some functions are only available on not running server versionsĀ of Windows. Some functions are only available on
Windows 10. Windows 10.
''' '''
from __future__ import absolute_import, unicode_literals, print_function from __future__ import absolute_import, unicode_literals, print_function
# Import Python libs # Import Python libs
import re
import logging import logging
import os
import re
# Import Salt libs # Import Salt libs
import salt.utils.platform import salt.utils.platform
import salt.utils.versions import salt.utils.versions
# Import 3rd party libs # Import 3rd party libs
from salt.ext import six from salt.ext import six
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
__virtualname__ = "dism" __virtualname__ = "dism"
# We always want to use the version of dism that matches the architecture of the
# host machine. On 32bit boxes that will always be System32. On 64bit boxes that
# are running 64bit salt that will always be System32. On 64bit boxes that are
# running 32bit salt the 64bit dism will be found in SysNative
# Sysnative is a virtual folder, a special alias, that can be used to access the
# 64-bit System32 folder from a 32-bit application
try:
# This does not apply to Non-Windows platforms
if not salt.utils.platform.is_windows():
raise OSError
if os.path.exists(os.path.join(os.environ.get('SystemRoot'), 'SysNative')):
bin_path = os.path.join(os.environ.get('SystemRoot'), 'SysNative')
else:
bin_path = os.path.join(os.environ.get('SystemRoot'), 'System32')
bin_dism = os.path.join(bin_path, 'dism.exe')
except OSError:
log.trace('win_dism: Non-Windows system')
bin_dism = 'dism.exe'
def __virtual__(): def __virtual__():
''' '''
Only work on Windows Only work on Windows
''' '''
if not salt.utils.platform.is_windows(): if not salt.utils.platform.is_windows():
return False, "Only available on Windows systems" return False, "Only available on Windows systems"
return __virtualname__ return __virtualname__
def _get_components(type_regex, plural_type, install_value, image=None): def _get_components(type_regex, plural_type, install_value, image=None):
cmd = ['DISM', cmd = [bin_dism,
'/English', '/English',
'/Image:{0}'.format(image) if image else '/Online', '/Image:{0}'.format(image) if image else '/Online',
'/Get-{0}'.format(plural_type)] '/Get-{0}'.format(plural_type)]
out = __salt__['cmd.run'](cmd) out = __salt__['cmd.run'](cmd)
pattern = r'{0} : (.*)\r\n.*State : {1}\r\n'\ pattern = r'{0} : (.*)\r\n.*State : {1}\r\n'\
.format(type_regex, install_value) .format(type_regex, install_value)
capabilities = re.findall(pattern, out, re.MULTILINE) capabilities = re.findall(pattern, out, re.MULTILINE)
capabilities.sort() capabilities.sort()
return capabilities return capabilities
skipping to change at line 82 skipping to change at line 104
.. code-block:: bash .. code-block:: bash
salt '*' dism.add_capability Tools.Graphics.DirectX~~~~0.0.1.0 salt '*' dism.add_capability Tools.Graphics.DirectX~~~~0.0.1.0
''' '''
if salt.utils.versions.version_cmp(__grains__['osversion'], '10') == -1: if salt.utils.versions.version_cmp(__grains__['osversion'], '10') == -1:
raise NotImplementedError( raise NotImplementedError(
'`install_capability` is not available on this version of Windows: ' '`install_capability` is not available on this version of Windows: '
'{0}'.format(__grains__['osversion'])) '{0}'.format(__grains__['osversion']))
cmd = ['DISM', cmd = [bin_dism,
'/Quiet', '/Quiet',
'/Image:{0}'.format(image) if image else '/Online', '/Image:{0}'.format(image) if image else '/Online',
'/Add-Capability', '/Add-Capability',
'/CapabilityName:{0}'.format(capability)] '/CapabilityName:{0}'.format(capability)]
if source: if source:
cmd.append('/Source:{0}'.format(source)) cmd.append('/Source:{0}'.format(source))
if limit_access: if limit_access:
cmd.append('/LimitAccess') cmd.append('/LimitAccess')
if not restart: if not restart:
skipping to change at line 126 skipping to change at line 148
.. code-block:: bash .. code-block:: bash
salt '*' dism.remove_capability Tools.Graphics.DirectX~~~~0.0.1.0 salt '*' dism.remove_capability Tools.Graphics.DirectX~~~~0.0.1.0
''' '''
if salt.utils.versions.version_cmp(__grains__['osversion'], '10') == -1: if salt.utils.versions.version_cmp(__grains__['osversion'], '10') == -1:
raise NotImplementedError( raise NotImplementedError(
'`uninstall_capability` is not available on this version of ' '`uninstall_capability` is not available on this version of '
'Windows: {0}'.format(__grains__['osversion'])) 'Windows: {0}'.format(__grains__['osversion']))
cmd = ['DISM', cmd = [bin_dism,
'/Quiet', '/Quiet',
'/Image:{0}'.format(image) if image else '/Online', '/Image:{0}'.format(image) if image else '/Online',
'/Remove-Capability', '/Remove-Capability',
'/CapabilityName:{0}'.format(capability)] '/CapabilityName:{0}'.format(capability)]
if not restart: if not restart:
cmd.append('/NoRestart') cmd.append('/NoRestart')
return __salt__['cmd.run_all'](cmd) return __salt__['cmd.run_all'](cmd)
skipping to change at line 164 skipping to change at line 186
.. code-block:: bash .. code-block:: bash
salt '*' dism.get_capabilities salt '*' dism.get_capabilities
''' '''
if salt.utils.versions.version_cmp(__grains__['osversion'], '10') == -1: if salt.utils.versions.version_cmp(__grains__['osversion'], '10') == -1:
raise NotImplementedError( raise NotImplementedError(
'`installed_capabilities` is not available on this version of ' '`installed_capabilities` is not available on this version of '
'Windows: {0}'.format(__grains__['osversion'])) 'Windows: {0}'.format(__grains__['osversion']))
cmd = ['DISM', cmd = [bin_dism,
'/English', '/English',
'/Image:{0}'.format(image) if image else '/Online', '/Image:{0}'.format(image) if image else '/Online',
'/Get-Capabilities'] '/Get-Capabilities']
out = __salt__['cmd.run'](cmd) out = __salt__['cmd.run'](cmd)
pattern = r'Capability Identity : (.*)\r\n' pattern = r'Capability Identity : (.*)\r\n'
capabilities = re.findall(pattern, out, re.MULTILINE) capabilities = re.findall(pattern, out, re.MULTILINE)
capabilities.sort() capabilities.sort()
return capabilities return capabilities
skipping to change at line 267 skipping to change at line 289
Returns: Returns:
dict: A dictionary containing the results of the command dict: A dictionary containing the results of the command
CLI Example: CLI Example:
.. code-block:: bash .. code-block:: bash
salt '*' dism.add_feature NetFx3 salt '*' dism.add_feature NetFx3
''' '''
cmd = ['DISM', cmd = [bin_dism,
'/Quiet', '/Quiet',
'/Image:{0}'.format(image) if image else '/Online', '/Image:{0}'.format(image) if image else '/Online',
'/Enable-Feature', '/Enable-Feature',
'/FeatureName:{0}'.format(feature)] '/FeatureName:{0}'.format(feature)]
if package: if package:
cmd.append('/PackageName:{0}'.format(package)) cmd.append('/PackageName:{0}'.format(package))
if source: if source:
cmd.append('/Source:{0}'.format(source)) cmd.append('/Source:{0}'.format(source))
if limit_access: if limit_access:
cmd.append('/LimitAccess') cmd.append('/LimitAccess')
skipping to change at line 307 skipping to change at line 329
Returns: Returns:
dict: A dictionary containing the results of the command dict: A dictionary containing the results of the command
CLI Example: CLI Example:
.. code-block:: bash .. code-block:: bash
salt '*' dism.remove_feature NetFx3 salt '*' dism.remove_feature NetFx3
''' '''
cmd = ['DISM', cmd = [bin_dism,
'/Quiet', '/Quiet',
'/Image:{0}'.format(image) if image else '/Online', '/Image:{0}'.format(image) if image else '/Online',
'/Disable-Feature', '/Disable-Feature',
'/FeatureName:{0}'.format(feature)] '/FeatureName:{0}'.format(feature)]
if remove_payload: if remove_payload:
cmd.append('/Remove') cmd.append('/Remove')
if not restart: if not restart:
cmd.append('/NoRestart') cmd.append('/NoRestart')
skipping to change at line 352 skipping to change at line 374
# Return all features on the system # Return all features on the system
salt '*' dism.get_features salt '*' dism.get_features
# Return all features in package.cab # Return all features in package.cab
salt '*' dism.get_features C:\\packages\\package.cab salt '*' dism.get_features C:\\packages\\package.cab
# Return all features in the calc package # Return all features in the calc package
salt '*' dism.get_features Microsoft.Windows.Calc.Demo~6595b6144ccf1 df~x86~en~1.0.0.0 salt '*' dism.get_features Microsoft.Windows.Calc.Demo~6595b6144ccf1 df~x86~en~1.0.0.0
''' '''
cmd = ['DISM', cmd = [bin_dism,
'/English', '/English',
'/Image:{0}'.format(image) if image else '/Online', '/Image:{0}'.format(image) if image else '/Online',
'/Get-Features'] '/Get-Features']
if package: if package:
if '~' in package: if '~' in package:
cmd.append('/PackageName:{0}'.format(package)) cmd.append('/PackageName:{0}'.format(package))
else: else:
cmd.append('/PackagePath:{0}'.format(package)) cmd.append('/PackagePath:{0}'.format(package))
skipping to change at line 451 skipping to change at line 473
Returns: Returns:
dict: A dictionary containing the results of the command dict: A dictionary containing the results of the command
CLI Example: CLI Example:
.. code-block:: bash .. code-block:: bash
salt '*' dism.add_package C:\\Packages\\package.cab salt '*' dism.add_package C:\\Packages\\package.cab
''' '''
cmd = ['DISM', cmd = [bin_dism,
'/Quiet', '/Quiet',
'/Image:{0}'.format(image) if image else '/Online', '/Image:{0}'.format(image) if image else '/Online',
'/Add-Package', '/Add-Package',
'/PackagePath:{0}'.format(package)] '/PackagePath:{0}'.format(package)]
if ignore_check: if ignore_check:
cmd.append('/IgnoreCheck') cmd.append('/IgnoreCheck')
if prevent_pending: if prevent_pending:
cmd.append('/PreventPending') cmd.append('/PreventPending')
if not restart: if not restart:
skipping to change at line 493 skipping to change at line 515
CLI Example: CLI Example:
.. code-block:: bash .. code-block:: bash
# Remove the Calc Package # Remove the Calc Package
salt '*' dism.remove_package Microsoft.Windows.Calc.Demo~6595b6144ccf1df ~x86~en~1.0.0.0 salt '*' dism.remove_package Microsoft.Windows.Calc.Demo~6595b6144ccf1df ~x86~en~1.0.0.0
# Remove the package.cab (does not remove C:\\packages\\package.cab) # Remove the package.cab (does not remove C:\\packages\\package.cab)
salt '*' dism.remove_package C:\\packages\\package.cab salt '*' dism.remove_package C:\\packages\\package.cab
''' '''
cmd = ['DISM', cmd = [bin_dism,
'/Quiet', '/Quiet',
'/Image:{0}'.format(image) if image else '/Online', '/Image:{0}'.format(image) if image else '/Online',
'/Remove-Package'] '/Remove-Package']
if not restart: if not restart:
cmd.append('/NoRestart') cmd.append('/NoRestart')
if '~' in package: if '~' in package:
cmd.append('/PackageName:{0}'.format(package)) cmd.append('/PackageName:{0}'.format(package))
else: else:
skipping to change at line 550 skipping to change at line 572
Returns: Returns:
dict: A dictionary containing the results of the command dict: A dictionary containing the results of the command
CLI Example: CLI Example:
.. code-block:: bash .. code-block:: bash
salt '*' dism. package_info C:\\packages\\package.cab salt '*' dism. package_info C:\\packages\\package.cab
''' '''
cmd = ['DISM', cmd = [bin_dism,
'/English', '/English',
'/Image:{0}'.format(image) if image else '/Online', '/Image:{0}'.format(image) if image else '/Online',
'/Get-PackageInfo'] '/Get-PackageInfo']
if '~' in package: if '~' in package:
cmd.append('/PackageName:{0}'.format(package)) cmd.append('/PackageName:{0}'.format(package))
else: else:
cmd.append('/PackagePath:{0}'.format(package)) cmd.append('/PackagePath:{0}'.format(package))
out = __salt__['cmd.run_all'](cmd) out = __salt__['cmd.run_all'](cmd)
 End of changes. 13 change blocks. 
11 lines changed or deleted 33 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)