corrected ling errors on solarisips.py

This commit is contained in:
YanChii 2014-07-18 17:46:39 +02:00
parent d503071223
commit f07e2eadb2

View File

@ -20,17 +20,13 @@ Or you can set the provider in sls for each pkg:
''' '''
# Import python libs
import os
import sys
from pprint import pprint # for install()
# Import salt libs # Import salt libs
import salt.utils import salt.utils
# Define the module's virtual name # Define the module's virtual name
__virtualname__ = 'solarisips' __virtualname__ = 'solarisips'
def __virtual__(): def __virtual__():
''' '''
Set the virtual pkg module if the os is Solaris 11 Set the virtual pkg module if the os is Solaris 11
@ -39,6 +35,7 @@ def __virtual__():
return __virtualname__ return __virtualname__
return False return False
ips_pkg_return_values = { ips_pkg_return_values = {
0: 'Command succeeded.', 0: 'Command succeeded.',
1: 'An error occurred.', 1: 'An error occurred.',
@ -50,28 +47,31 @@ ips_pkg_return_values = {
7: 'The image is currently in use by another process and cannot be modified.' 7: 'The image is currently in use by another process and cannot be modified.'
} }
def _ips_get_pkgname(line): def _ips_get_pkgname(line):
''' '''
Extracts package name from "pkg list -v" output. Extracts package name from "pkg list -v" output.
Input: one line of the command output Input: one line of the command output
Output: pkg name (e.g: "pkg://solaris/x11/library/toolkit/libxt") Output: pkg name (e.g: "pkg://solaris/x11/library/toolkit/libxt")
Example use: Example use:
line = "pkg://solaris/x11/library/toolkit/libxt@1.1.3,5.11-0.175.1.0.0.24.1317:20120904T180030Z i--" line = "pkg://solaris/x11/library/toolkit/libxt@1.1.3,5.11-0.175.1.0.0.24.1317:20120904T180030Z i--"
name = _ips_get_pkgname(line) name = _ips_get_pkgname(line)
''' '''
return line.split()[0].split('@')[0].strip() return line.split()[0].split('@')[0].strip()
def _ips_get_pkgversion(line): def _ips_get_pkgversion(line):
''' '''
Extracts package version from "pkg list -v" output. Extracts package version from "pkg list -v" output.
Input: one line of the command output Input: one line of the command output
Output: package version (e.g: "1.1.3,5.11-0.175.1.0.0.24.1317:20120904T180030Z") Output: package version (e.g: "1.1.3,5.11-0.175.1.0.0.24.1317:20120904T180030Z")
Example use: Example use:
line = "pkg://solaris/x11/library/toolkit/libxt@1.1.3,5.11-0.175.1.0.0.24.1317:20120904T180030Z i--" line = "pkg://solaris/x11/library/toolkit/libxt@1.1.3,5.11-0.175.1.0.0.24.1317:20120904T180030Z i--"
name = _ips_get_pkgversion(line) name = _ips_get_pkgversion(line)
''' '''
return line.split()[0].split('@')[1].strip() return line.split()[0].split('@')[1].strip()
def refresh_db(full=False): def refresh_db(full=False):
''' '''
Updates the remote repos database. You can force the full pkg DB refresh from all publishers regardless the last refresh time. Updates the remote repos database. You can force the full pkg DB refresh from all publishers regardless the last refresh time.
@ -86,10 +86,11 @@ def refresh_db(full=False):
else: else:
return __salt__['cmd.retcode']('/bin/pkg refresh') == 0 return __salt__['cmd.retcode']('/bin/pkg refresh') == 0
def upgrade_available(name): def upgrade_available(name):
''' '''
Check if there is an upgrade available for a certain package Check if there is an upgrade available for a certain package
Accepts full or partial FMRI. Returns all matches found. Accepts full or partial FMRI. Returns all matches found.
CLI Example:: CLI Example::
@ -109,8 +110,8 @@ def upgrade_available(name):
def list_upgrades(refresh=False): def list_upgrades(refresh=False):
''' '''
Lists all packages available for update. Lists all packages available for update.
When run in global zone, it reports only upgradable packages for the global zone. When run in global zone, it reports only upgradable packages for the global zone.
When run in non-global zone, it can report more upgradable packages than "pkg update -vn" because "pkg update" hides packages that require newer version of pkg://solaris/entire (which means that they can be upgraded only from global zone). Simply said: if you see pkg://solaris/entire in the list of upgrades, you should upgrade the global zone to get all possible updates. When run in non-global zone, it can report more upgradable packages than "pkg update -vn" because "pkg update" hides packages that require newer version of pkg://solaris/entire (which means that they can be upgraded only from global zone). Simply said: if you see pkg://solaris/entire in the list of upgrades, you should upgrade the global zone to get all possible updates.
You can force full pkg DB refresh before listing. You can force full pkg DB refresh before listing.
CLI Example:: CLI Example::
@ -121,7 +122,7 @@ def list_upgrades(refresh=False):
if salt.utils.is_true(refresh): if salt.utils.is_true(refresh):
refresh_db(full=True) refresh_db(full=True)
upgrades = {} upgrades = {}
# awk is in core-os package so we can use it without checking # awk is in core-os package so we can use it without checking
lines = __salt__['cmd.run_stdout']( lines = __salt__['cmd.run_stdout'](
"/bin/pkg list -Hu | /bin/awk '{print $1}' | /bin/xargs pkg list -Hnv").splitlines() "/bin/pkg list -Hu | /bin/awk '{print $1}' | /bin/xargs pkg list -Hnv").splitlines()
for line in lines: for line in lines:
@ -200,7 +201,7 @@ def list_pkgs(versions_as_list=False, **kwargs):
def version(*names, **kwargs): def version(*names, **kwargs):
''' '''
Common interface for obtaining the version of installed packages. Common interface for obtaining the version of installed packages.
Accepts full or partial FMRI. If called using pkg_resource, full FMRI is required. Accepts full or partial FMRI. If called using pkg_resource, full FMRI is required.
CLI Example:: CLI Example::
@ -226,7 +227,7 @@ def latest_version(name, **kwargs):
''' '''
The available version of the package in the repository. The available version of the package in the repository.
In case of multiple match, it returns list of all matched packages. In case of multiple match, it returns list of all matched packages.
Accepts full or partial FMRI. Accepts full or partial FMRI.
CLI Example:: CLI Example::
@ -269,6 +270,7 @@ def get_fmri(name, **kwargs):
return ret return ret
def normalize_name(name, **kwargs): def normalize_name(name, **kwargs):
''' '''
Normalizes pkg name to full FMRI before running pkg.install. Normalizes pkg name to full FMRI before running pkg.install.
@ -324,7 +326,7 @@ def search(name, versions_as_list=False, **kwargs):
cmd = '/bin/pkg list -aHv {0}'.format(name) cmd = '/bin/pkg list -aHv {0}'.format(name)
out = __salt__['cmd.run_all'](cmd) out = __salt__['cmd.run_all'](cmd)
if out['retcode'] != 0: if out['retcode'] != 0:
# error = nothing found # error = nothing found
return {} return {}
# no error, processing pkg listing # no error, processing pkg listing
# column 1 is full FMRI name in form pkg://publisher/pkg/name@version # column 1 is full FMRI name in form pkg://publisher/pkg/name@version
@ -337,10 +339,11 @@ def search(name, versions_as_list=False, **kwargs):
__salt__['pkg_resource.stringify'](ret) __salt__['pkg_resource.stringify'](ret)
return ret return ret
def install(name=None, refresh=False, pkgs=None, version=None, test=False, **kwargs): def install(name=None, refresh=False, pkgs=None, version=None, test=False, **kwargs):
''' '''
Install the named package using the IPS pkg command. Install the named package using the IPS pkg command.
Accepts full or partial FMRI. Accepts full or partial FMRI.
Returns a dict containing the new package names and versions:: Returns a dict containing the new package names and versions::
@ -356,9 +359,9 @@ def install(name=None, refresh=False, pkgs=None, version=None, test=False, **kwa
CLI Example:: CLI Example::
salt '*' pkg.install vim salt '*' pkg.install vim
salt '*' pkg.install pkg://solaris/editor/vim salt '*' pkg.install pkg://solaris/editor/vim
salt '*' pkg.install pkg://solaris/editor/vim refresh=True salt '*' pkg.install pkg://solaris/editor/vim refresh=True
''' '''
if not pkgs: if not pkgs:
if is_installed(name): if is_installed(name):
@ -371,7 +374,7 @@ def install(name=None, refresh=False, pkgs=None, version=None, test=False, **kwa
if pkgs: # multiple packages specified if pkgs: # multiple packages specified
for pkg in pkgs: for pkg in pkgs:
if pkg.items()[0][1]: # version specified if pkg.items()[0][1]: # version specified
pkg2inst += '{0}@{1} '.format(pkg.items()[0][0],pkg.items()[0][1]) pkg2inst += '{0}@{1} '.format(pkg.items()[0][0], pkg.items()[0][1])
else: else:
pkg2inst += '{0} '.format(pkg.items()[0][0]) pkg2inst += '{0} '.format(pkg.items()[0][0])
print 'Installing these packages instead of {0}: {1}'.format(name, pkg2inst) print 'Installing these packages instead of {0}: {1}'.format(name, pkg2inst)
@ -401,8 +404,8 @@ def install(name=None, refresh=False, pkgs=None, version=None, test=False, **kwa
changes = salt.utils.compare_dicts(old, new) changes = salt.utils.compare_dicts(old, new)
if ret['retcode'] != 0: # there's something worth looking at if ret['retcode'] != 0: # there's something worth looking at
output = {} # so we're adding some additional info output = {} # so we're adding some additional info
output['changes'] = changes output['changes'] = changes
output['retcode'] = ips_pkg_return_values[ret['retcode']] # translate error code output['retcode'] = ips_pkg_return_values[ret['retcode']] # translate error code
output['message'] = ret['stderr'] + '\n' output['message'] = ret['stderr'] + '\n'
@ -468,8 +471,8 @@ def remove(name=None, pkgs=None, **kwargs):
# Compare the pre and post remove package objects and report the uninstalled pkgs. # Compare the pre and post remove package objects and report the uninstalled pkgs.
changes = salt.utils.compare_dicts(old, new) changes = salt.utils.compare_dicts(old, new)
if ret['retcode'] != 0: # there's something worth looking at if ret['retcode'] != 0: # there's something worth looking at
output = {} # so we're adding some additional info output = {} # so we're adding some additional info
output['changes'] = changes output['changes'] = changes
output['retcode'] = ips_pkg_return_values[ret['retcode']] # translate error code output['retcode'] = ips_pkg_return_values[ret['retcode']] # translate error code
output['message'] = ret['stderr'] + '\n' output['message'] = ret['stderr'] + '\n'
@ -490,4 +493,3 @@ def purge(name, **kwargs):
salt '*' pkg.purge <package name> salt '*' pkg.purge <package name>
''' '''
return remove(name, **kwargs) return remove(name, **kwargs)