mirror of
https://github.com/valitydev/salt.git
synced 2024-11-07 17:09:03 +00:00
Use list instead of string for cmd
This commit is contained in:
parent
fbdd28f144
commit
7e6382a8b2
@ -29,8 +29,10 @@ def __virtual__():
|
||||
return __virtualname__
|
||||
|
||||
|
||||
def _get_components(type_regex, plural_type, install_value):
|
||||
cmd = 'DISM /Online /Get-{0}'.format(plural_type)
|
||||
def _get_components(type_regex, plural_type, install_value, image=None):
|
||||
cmd = ['DISM',
|
||||
'/Image:{0}'.format(image) if image else '/Online',
|
||||
'/Get-{0}'.format(plural_type)]
|
||||
out = __salt__['cmd.run'](cmd)
|
||||
pattern = r'{0} : (.*)\r\n.*State : {1}\r\n'\
|
||||
.format(type_regex, install_value)
|
||||
@ -39,7 +41,7 @@ def _get_components(type_regex, plural_type, install_value):
|
||||
return capabilities
|
||||
|
||||
|
||||
def add_capability(capability, source=None, limit_access=False):
|
||||
def add_capability(capability, source=None, limit_access=False, image=None):
|
||||
'''
|
||||
Install a capability
|
||||
|
||||
@ -49,6 +51,9 @@ def add_capability(capability, source=None, limit_access=False):
|
||||
is set by group policy and can be Windows Update.
|
||||
limit_access (Optional[bool]): Prevent DISM from contacting Windows
|
||||
Update for the source package
|
||||
image (Optional[str]): The path to the root directory of an offline
|
||||
Windows image. If `None` is passed, the running operating system is
|
||||
targeted. Default is None.
|
||||
|
||||
Raises:
|
||||
NotImplemented Error for all versions of Windows that are not Windows 10
|
||||
@ -68,22 +73,28 @@ def add_capability(capability, source=None, limit_access=False):
|
||||
'`install_capability` is not available on this version of Windows: '
|
||||
'{0}'.format(__grains__['osversion']))
|
||||
|
||||
cmd = 'DISM /Online /Add-Capability /CapabilityName:{0}'.format(capability)
|
||||
cmd = ['DISM',
|
||||
'/Image:{0}'.format(image) if image else '/Online',
|
||||
'/Add-Capability',
|
||||
'/CapabilityName:{0}'.format(capability)]
|
||||
|
||||
if source:
|
||||
cmd += ' /Source:{0}'.format(source)
|
||||
cmd.append('/Source:{0}'.format(source))
|
||||
if limit_access:
|
||||
cmd += ' /LimitAccess'
|
||||
cmd.append('/LimitAccess')
|
||||
|
||||
return __salt__['cmd.run_all'](cmd)
|
||||
|
||||
|
||||
def remove_capability(capability):
|
||||
def remove_capability(capability, image=None):
|
||||
'''
|
||||
Uninstall a capability
|
||||
|
||||
Args:
|
||||
capability(str): The capability to be removed
|
||||
image (Optional[str]): The path to the root directory of an offline
|
||||
Windows image. If `None` is passed, the running operating system is
|
||||
targeted. Default is None.
|
||||
|
||||
Raises:
|
||||
NotImplemented Error for all versions of Windows that are not Windows 10
|
||||
@ -103,16 +114,23 @@ def remove_capability(capability):
|
||||
'`uninstall_capability` is not available on this version of '
|
||||
'Windows: {0}'.format(__grains__['osversion']))
|
||||
|
||||
cmd = 'DISM /Online /Remove-Capability ' \
|
||||
'/CapabilityName:{0}'.format(capability)
|
||||
cmd = ['DISM',
|
||||
'/Image:{0}'.format(image) if image else '/Online',
|
||||
'/Remove-Capability',
|
||||
'/CapabilityName:{0}'.format(capability)]
|
||||
|
||||
return __salt__['cmd.run_all'](cmd)
|
||||
|
||||
|
||||
def get_capabilities():
|
||||
def get_capabilities(image=None):
|
||||
'''
|
||||
List all capabilities on the system
|
||||
|
||||
Args:
|
||||
image (Optional[str]): The path to the root directory of an offline
|
||||
Windows image. If `None` is passed, the running operating system is
|
||||
targeted. Default is None.
|
||||
|
||||
Raises:
|
||||
NotImplemented Error for all versions of Windows that are not Windows 10
|
||||
and later. Server editions of Windows use ServerManager instead.
|
||||
@ -131,7 +149,9 @@ def get_capabilities():
|
||||
'`installed_capabilities` is not available on this version of '
|
||||
'Windows: {0}'.format(__grains__['osversion']))
|
||||
|
||||
cmd = 'DISM /Online /Get-Capabilities'
|
||||
cmd = ['DISM',
|
||||
'/Image:{0}'.format(image) if image else '/Online',
|
||||
'/Get-Capabilities']
|
||||
out = __salt__['cmd.run'](cmd)
|
||||
|
||||
pattern = r'Capability Identity : (.*)'
|
||||
@ -141,10 +161,15 @@ def get_capabilities():
|
||||
return capabilities
|
||||
|
||||
|
||||
def installed_capabilities():
|
||||
def installed_capabilities(image=None):
|
||||
'''
|
||||
List the capabilities installed on the system
|
||||
|
||||
Args:
|
||||
image (Optional[str]): The path to the root directory of an offline
|
||||
Windows image. If `None` is passed, the running operating system is
|
||||
targeted. Default is None.
|
||||
|
||||
Raises:
|
||||
NotImplemented Error for all versions of Windows that are not Windows 10
|
||||
and later. Server editions of Windows use ServerManager instead.
|
||||
@ -165,10 +190,15 @@ def installed_capabilities():
|
||||
return _get_components("Capability Identity", "Capabilities", "Installed")
|
||||
|
||||
|
||||
def available_capabilities():
|
||||
def available_capabilities(image=None):
|
||||
'''
|
||||
List the capabilities available on the system
|
||||
|
||||
Args:
|
||||
image (Optional[str]): The path to the root directory of an offline
|
||||
Windows image. If `None` is passed, the running operating system is
|
||||
targeted. Default is None.
|
||||
|
||||
Raises:
|
||||
NotImplemented Error for all versions of Windows that are not Windows 10
|
||||
and later. Server editions of Windows use ServerManager instead.
|
||||
@ -193,7 +223,8 @@ def add_feature(feature,
|
||||
package=None,
|
||||
source=None,
|
||||
limit_access=False,
|
||||
enable_parent=False,):
|
||||
enable_parent=False,
|
||||
image=None):
|
||||
'''
|
||||
Install a feature using DISM
|
||||
|
||||
@ -208,6 +239,9 @@ def add_feature(feature,
|
||||
Update for the source package
|
||||
enable_parent (Optional[bool]): True will enable all parent features of
|
||||
the specified feature
|
||||
image (Optional[str]): The path to the root directory of an offline
|
||||
Windows image. If `None` is passed, the running operating system is
|
||||
targeted. Default is None.
|
||||
|
||||
Returns:
|
||||
dict: A dictionary containing the results of the command
|
||||
@ -218,20 +252,23 @@ def add_feature(feature,
|
||||
|
||||
salt '*' dism.add_feature NetFx3
|
||||
'''
|
||||
cmd = 'DISM /Online /Enable-Feature /FeatureName:{0}'.format(feature)
|
||||
cmd = ['DISM',
|
||||
'/Image:{0}'.format(image) if image else '/Online',
|
||||
'/Enable-Feature'
|
||||
'/FeatureName:{0}'.format(feature)]
|
||||
if package:
|
||||
cmd += ' /PackageName:{0}'.format(package)
|
||||
cmd.append('/PackageName:{0}'.format(package))
|
||||
if source:
|
||||
cmd += ' /Source:{0}'.format(source)
|
||||
cmd.append('/Source:{0}'.format(source))
|
||||
if limit_access:
|
||||
cmd += ' /LimitAccess'
|
||||
cmd.append('/LimitAccess')
|
||||
if enable_parent:
|
||||
cmd += ' /All'
|
||||
cmd.append('/All')
|
||||
|
||||
return __salt__['cmd.run_all'](cmd)
|
||||
|
||||
|
||||
def remove_feature(feature, remove_payload=False):
|
||||
def remove_feature(feature, remove_payload=False, image=None):
|
||||
'''
|
||||
Disables the feature.
|
||||
|
||||
@ -239,6 +276,9 @@ def remove_feature(feature, remove_payload=False):
|
||||
feature (str): The feature to uninstall
|
||||
remove_payload (Optional[bool]): Remove the feature's payload. Must
|
||||
supply source when enabling in the future.
|
||||
image (Optional[str]): The path to the root directory of an offline
|
||||
Windows image. If `None` is passed, the running operating system is
|
||||
targeted. Default is None.
|
||||
|
||||
Returns:
|
||||
dict: A dictionary containing the results of the command
|
||||
@ -249,15 +289,18 @@ def remove_feature(feature, remove_payload=False):
|
||||
|
||||
salt '*' dism.remove_feature NetFx3
|
||||
'''
|
||||
cmd = 'DISM /Online /Disable-Feature /FeatureName:{0}'.format(feature)
|
||||
cmd = ['DISM',
|
||||
'/Image:{0}'.format(image) if image else '/Online',
|
||||
'/Disable-Feature'
|
||||
'/FeatureName:{0}'.format(feature)]
|
||||
|
||||
if remove_payload:
|
||||
cmd += ' /Remove'
|
||||
cmd.append('/Remove')
|
||||
|
||||
return __salt__['cmd.run_all'](cmd)
|
||||
|
||||
|
||||
def get_features(package=None):
|
||||
def get_features(package=None, image=None):
|
||||
'''
|
||||
List features on the system or in a package
|
||||
|
||||
@ -269,6 +312,9 @@ def get_features(package=None):
|
||||
|
||||
This can also be the name of a package as listed in
|
||||
``dism.installed_packages``
|
||||
image (Optional[str]): The path to the root directory of an offline
|
||||
Windows image. If `None` is passed, the running operating system is
|
||||
targeted. Default is None.
|
||||
|
||||
Returns:
|
||||
list: A list of features
|
||||
@ -286,14 +332,15 @@ def get_features(package=None):
|
||||
# Return all features in the calc package
|
||||
salt '*' dism.get_features Microsoft.Windows.Calc.Demo~6595b6144ccf1df~x86~en~1.0.0.0
|
||||
'''
|
||||
|
||||
cmd = 'DISM /Online /Get-Features'
|
||||
cmd = ['DISM',
|
||||
'/Image:{0}'.format(image) if image else '/Online',
|
||||
'/Get-Features']
|
||||
|
||||
if package:
|
||||
if '~' in package:
|
||||
cmd += ' /PackageName:{0}'.format(package)
|
||||
cmd.append('/PackageName:{0}'.format(package))
|
||||
else:
|
||||
cmd += ' /PackagePath:{0}'.format(package)
|
||||
cmd.append('/PackagePath:{0}'.format(package))
|
||||
|
||||
out = __salt__['cmd.run'](cmd)
|
||||
|
||||
@ -304,10 +351,15 @@ def get_features(package=None):
|
||||
return capabilities
|
||||
|
||||
|
||||
def installed_features():
|
||||
def installed_features(image=None):
|
||||
'''
|
||||
List the features installed on the system
|
||||
|
||||
Args:
|
||||
image (Optional[str]): The path to the root directory of an offline
|
||||
Windows image. If `None` is passed, the running operating system is
|
||||
targeted. Default is None.
|
||||
|
||||
Returns:
|
||||
list: A list of installed features
|
||||
|
||||
@ -320,10 +372,15 @@ def installed_features():
|
||||
return _get_components("Feature Name", "Features", "Enabled")
|
||||
|
||||
|
||||
def available_features():
|
||||
def available_features(image=None):
|
||||
'''
|
||||
List the features available on the system
|
||||
|
||||
Args:
|
||||
image (Optional[str]): The path to the root directory of an offline
|
||||
Windows image. If `None` is passed, the running operating system is
|
||||
targeted. Default is None.
|
||||
|
||||
Returns:
|
||||
list: A list of available features
|
||||
|
||||
@ -336,7 +393,7 @@ def available_features():
|
||||
return _get_components("Feature Name", "Features", "Disabled")
|
||||
|
||||
|
||||
def add_package(package, ignore_check=False, prevent_pending=False):
|
||||
def add_package(package, ignore_check=False, prevent_pending=False, image=None):
|
||||
'''
|
||||
Install a package using DISM
|
||||
|
||||
@ -347,6 +404,9 @@ def add_package(package, ignore_check=False, prevent_pending=False):
|
||||
applicability checks fail
|
||||
prevent_pending (Optional[bool]): Skip the installation of the package
|
||||
if there are pending online actions
|
||||
image (Optional[str]): The path to the root directory of an offline
|
||||
Windows image. If `None` is passed, the running operating system is
|
||||
targeted. Default is None.
|
||||
|
||||
Returns:
|
||||
dict: A dictionary containing the results of the command
|
||||
@ -357,18 +417,20 @@ def add_package(package, ignore_check=False, prevent_pending=False):
|
||||
|
||||
salt '*' dism.add_package C:\\Packages\\package.cab
|
||||
'''
|
||||
cmd = 'DISM /Online /Add-Package ' \
|
||||
'/PackagePath:{0}'.format(package)
|
||||
cmd = ['DISM',
|
||||
'/Image:{0}'.format(image) if image else '/Online',
|
||||
'/Add-Package',
|
||||
'/PackagePath:{0}'.format(package)]
|
||||
|
||||
if ignore_check:
|
||||
cmd += ' /IgnoreCheck'
|
||||
cmd.append('/IgnoreCheck')
|
||||
if prevent_pending:
|
||||
cmd += ' /PreventPending'
|
||||
cmd.append('/PreventPending')
|
||||
|
||||
return __salt__['cmd.run_all'](cmd)
|
||||
|
||||
|
||||
def remove_package(package):
|
||||
def remove_package(package, image=None):
|
||||
'''
|
||||
Uninstall a package
|
||||
|
||||
@ -380,6 +442,10 @@ def remove_package(package):
|
||||
This can also be the name of a package as listed in
|
||||
``dism.installed_packages``
|
||||
|
||||
image (Optional[str]): The path to the root directory of an offline
|
||||
Windows image. If `None` is passed, the running operating system is
|
||||
targeted. Default is None.
|
||||
|
||||
Returns:
|
||||
dict: A dictionary containing the results of the command
|
||||
|
||||
@ -393,20 +459,27 @@ def remove_package(package):
|
||||
# Remove the package.cab (does not remove C:\\packages\\package.cab)
|
||||
salt '*' dism.remove_package C:\\packages\\package.cab
|
||||
'''
|
||||
cmd = 'DISM /Online /Remove-Package'
|
||||
cmd = ['DISM',
|
||||
'/Image:{0}'.format(image) if image else '/Online',
|
||||
'/Remove-Package']
|
||||
|
||||
if '~' in package:
|
||||
cmd += ' /PackageName:{0}'.format(package)
|
||||
cmd.append('/PackageName:{0}'.format(package))
|
||||
else:
|
||||
cmd += ' /PackagePath:{0}'.format(package)
|
||||
cmd.append('/PackagePath:{0}'.format(package))
|
||||
|
||||
return __salt__['cmd.run_all'](cmd)
|
||||
|
||||
|
||||
def installed_packages():
|
||||
def installed_packages(image=None):
|
||||
'''
|
||||
List the packages installed on the system
|
||||
|
||||
Args:
|
||||
image (Optional[str]): The path to the root directory of an offline
|
||||
Windows image. If `None` is passed, the running operating system is
|
||||
targeted. Default is None.
|
||||
|
||||
Returns:
|
||||
list: A list of installed packages
|
||||
|
||||
@ -419,7 +492,7 @@ def installed_packages():
|
||||
return _get_components("Package Identity", "Packages", "Installed")
|
||||
|
||||
|
||||
def package_info(package):
|
||||
def package_info(package, image=None):
|
||||
'''
|
||||
Display information about a package
|
||||
|
||||
@ -428,6 +501,9 @@ def package_info(package):
|
||||
or a folder. Should point to the original source of the package, not
|
||||
to where the file is installed. You cannot use this command to get
|
||||
package information for .msu files
|
||||
image (Optional[str]): The path to the root directory of an offline
|
||||
Windows image. If `None` is passed, the running operating system is
|
||||
targeted. Default is None.
|
||||
|
||||
Returns:
|
||||
dict: A dictionary containing the results of the command
|
||||
@ -438,12 +514,14 @@ def package_info(package):
|
||||
|
||||
salt '*' dism. package_info C:\\packages\\package.cab
|
||||
'''
|
||||
cmd = 'DISM /Online /Get-PackageInfo'
|
||||
cmd = ['DISM',
|
||||
'/Image:{0}'.format(image) if image else '/Online',
|
||||
'/Get-PackageInfo']
|
||||
|
||||
if '~' in package:
|
||||
cmd += ' /PackageName:{0}'.format(package)
|
||||
cmd.append('/PackageName:{0}'.format(package))
|
||||
else:
|
||||
cmd += ' /PackagePath:{0}'.format(package)
|
||||
cmd.append('/PackagePath:{0}'.format(package))
|
||||
|
||||
out = __salt__['cmd.run_all'](cmd)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user