Skip to content

Commit

Permalink
Fix nodemgr pushpkg in sol11 zones
Browse files Browse the repository at this point in the history
And apply pylint suggested fixes.
  • Loading branch information
cvaroqui committed Jun 3, 2018
1 parent a361f78 commit 6d97e27
Showing 1 changed file with 62 additions and 54 deletions.
116 changes: 62 additions & 54 deletions lib/rcPkgSunOS.py
@@ -1,104 +1,112 @@
import os
import datetime
from rcUtilities import call, which
from rcUtilities import which, justcall
from rcGlobalEnv import rcEnv
from stat import *
from stat import ST_MTIME

"""
format:
PKGINST: SUNWzoneu
NAME: Solaris Zones (Usr)
CATEGORY: system
ARCH: i386
VERSION: 11.11,REV=2009.04.08.17.26
VENDOR: Sun Microsystems, Inc.
DESC: Solaris Zones Configuration and Administration
HOTLINE: Please contact your local service provider
STATUS: completely installed
def listpkg_ips():
"""
Return a list of ips packages installed.
"""

"""
#
# PKGINST: SUNWzoneu
# NAME: Solaris Zones (Usr)
# CATEGORY: system
# ARCH: i386
# VERSION: 11.11,REV=2009.04.08.17.26
# VENDOR: Sun Microsystems, Inc.
# DESC: Solaris Zones Configuration and Administration
# HOTLINE: Please contact your local service provider
# STATUS: completely installed
#

def listpkg_ips():
if which('uname') is None:
return []
cmd = ['uname', '-p']
(ret, out, err) = call(cmd, errlog=False, cache=True)
out, _, _ = justcall(cmd)
arc = out.split('\n')[0]
if which('pkg') is None:
return []
cmd = ['pkg', 'list', '-H']
(ret, out, err) = call(cmd, errlog=False, cache=True)
out, _, _ = justcall(cmd)
lines = []
for line in out.split('\n'):
l = line.split()
if len(l) != 3:
elems = line.split()
if len(elems) != 3:
continue
x = [rcEnv.nodename, l[0], l[1], arc, "ips", ""]
lines.append(x)
data = [rcEnv.nodename, elems[0], elems[1], arc, "ips", ""]
lines.append(data)
return lines

def listpkg_legacy():
"""
Return a list of legacy packages installed.
"""
if which('pkginfo') is None:
return []
cmd = ['pkginfo', '-l']
(ret, out, err) = call(cmd, errlog=False, cache=True)
out, _, _ = justcall(cmd)
lines = []
for line in out.split('\n'):
l = line.split(':')
if len(l) != 2:
for line in out.splitlines():
elems = line.split(':', 1)
if len(elems) != 2:
continue
l = [x.strip() for x in l]
f = l[0]
if f == "PKGINST":
x = [rcEnv.nodename, l[1], "", "", "pkg", ""]
elif f == "VERSION":
x[2] = l[1]
elif f == "ARCH":
x[3] = l[1]
lines.append(x)
key, val = [elem.strip() for elem in elems]
if key == "PKGINST":
data = [rcEnv.nodename, val, "", "", "pkg", ""]
elif key == "VERSION":
data[2] = val
elif key == "ARCH":
data[3] = val
lines.append(data)

for i, x in enumerate(lines):
for idx, line in enumerate(lines):
# pkg install date
try:
t = os.stat("/var/sadm/pkg/"+x[1])[ST_MTIME]
t = datetime.datetime.fromtimestamp(t).strftime("%Y-%m-%d %H:%M:%S")
except Exception as e:
t = ""
lines[i][5] = t
mtime = os.stat("/var/sadm/pkg/"+line[1])[ST_MTIME]
mtime = datetime.datetime.fromtimestamp(mtime).strftime("%Y-%m-%d %H:%M:%S")
except Exception:
mtime = ""
lines[idx][5] = mtime

return lines

def listpkg():
"""
Return a list of ips and legacy packages installed.
"""
return listpkg_legacy() + listpkg_ips()

def listpatch():
"""
Return a list of patches installed.
Patch: patchnum-rev Obsoletes: num-rev[,patch-rev]... Requires: .... Incompatibles: ... Packages: ...
"""
if which('showrev') is None:
return []
cmd = ['showrev', '-p']
(ret, out, err) = call(cmd, errlog=False, cache=True)
out, _, _ = justcall(cmd)
lines = []
nodename = rcEnv.nodename
for line in out.split('\n'):
l = line.split(' ')
if len(l) > 3:
p = l[1].split('-')
if len(p) != 2:
for line in out.splitlines():
elems = line.split(' ')
if len(elems) > 3:
_elems = elems[1].split('-')
if len(_elems) != 2:
continue
else:
lines.append( [ nodename , p[0], p[1] ] )
lines.append([nodename , _elems[0], _elems[1]])

for i, x in enumerate(lines):
for idx, line in enumerate(lines):
# pkg install date
try:
t = os.stat("/var/sadm/patch/"+x[1])[ST_MTIME]
t = datetime.datetime.fromtimestamp(t).strftime("%Y-%m-%d %H:%M:%S")
except:
t = ""
lines[i].append(t)
mtime = os.stat("/var/sadm/patch/"+line[1])[ST_MTIME]
mtime = datetime.datetime.fromtimestamp(mtime).strftime("%Y-%m-%d %H:%M:%S")
except Exception:
mtime = ""
lines[idx].append(mtime)

return lines

Expand Down

0 comments on commit 6d97e27

Please sign in to comment.