Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions MaintenanceReadme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ Guidelines for using HotAccessor are:
(v) Iteration over accessors is generally better than iteration over results, e.g. These print the same thing:

for sr in HotAccessor().sr: # Iterate over HotAccessors
print sr.name_label()
print(sr.name_label())

for value in HotAccessor().sr().values(): # Iterate over the returned dict of all SRs
print value['name_label']
print(value['name_label'])

(vi) List comprehensions also work

Expand Down
5 changes: 3 additions & 2 deletions XSConsole.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.

from __future__ import print_function
import sys, traceback

from XSConsoleConfig import *
Expand All @@ -27,9 +28,9 @@ def main():
if '--shelltimeout' in sys.argv:
# Print a shell timeout value, suitable for TMOUT=`xsconsole --shelltimeout`
if Config.Inst().AllShellsTimeout():
print State.Inst().AuthTimeoutSeconds()
print(State.Inst().AuthTimeoutSeconds())
else:
print
print()
else:
app = App.Inst()
app.Build( ['plugins-base', 'plugins-oem', 'plugins-extras'] )
Expand Down
2 changes: 1 addition & 1 deletion XSConsoleBases.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
def ParamsToAttr():
d = inspect.currentframe().f_back.f_locals
obj = d.pop("self")
for name, value in d.iteritems():
for name, value in d.items():
setattr(obj, name,value)

def FirstValue(*inArgs):
Expand Down
2 changes: 1 addition & 1 deletion XSConsoleCurses.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.

import curses, sys, commands
import curses, sys

from XSConsoleBases import *
from XSConsoleConfig import *
Expand Down
56 changes: 28 additions & 28 deletions XSConsoleData.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

import XenAPI
import datetime
import commands, re, shutil, sys, tempfile, socket, os
import subprocess, re, shutil, sys, tempfile, socket, os
from pprint import pprint
from simpleconfig import SimpleConfigFile

Expand Down Expand Up @@ -98,31 +98,31 @@ def Create(self):
self.ReadTimezones()
self.ReadKeymaps()

(status, output) = commands.getstatusoutput("dmidecode")
(status, output) = subprocess.getstatusoutput("dmidecode")
if status != 0:
# Use test dmidecode file if there's no real output
(status, output) = commands.getstatusoutput("/bin/cat ./dmidecode.txt")
(status, output) = subprocess.getstatusoutput("/bin/cat ./dmidecode.txt")

if status == 0:
self.ScanDmiDecode(output.split("\n"))

(status, output) = commands.getstatusoutput("/sbin/lspci -m")
(status, output) = subprocess.getstatusoutput("/sbin/lspci -m")
if status != 0:
(status, output) = commands.getstatusoutput("/usr/bin/lspci -m")
(status, output) = subprocess.getstatusoutput("/usr/bin/lspci -m")

if status == 0:
self.ScanLspci(output.split("\n"))

if os.path.isfile("/usr/bin/ipmitool"):
(status, output) = commands.getstatusoutput("/usr/bin/ipmitool mc info")
(status, output) = subprocess.getstatusoutput("/usr/bin/ipmitool mc info")
if status == 0:
self.ScanIpmiMcInfo(output.split("\n"))

(status, output) = commands.getstatusoutput("/bin/cat /etc/xensource-inventory")
(status, output) = subprocess.getstatusoutput("/bin/cat /etc/xensource-inventory")
if status == 0:
self.ScanInventory(output.split("\n"))

(status, output) = commands.getstatusoutput("/usr/bin/openssl x509 -in %s/xapi-ssl.pem -fingerprint -noout" % (Config.Inst().XCPConfigDir()))
(status, output) = subprocess.getstatusoutput("/usr/bin/openssl x509 -in %s/xapi-ssl.pem -fingerprint -noout" % (Config.Inst().XCPConfigDir()))
if status == 0:
fp = output.split("=")
if len(fp) >= 2:
Expand Down Expand Up @@ -301,7 +301,7 @@ def update_SR_reference(inPool, retPool, key):
return retPool

self.data['pools'] = {}
for id, pool in pools.iteritems():
for id, pool in pools.items():
self.data['pools'][id] = convertPool(id, pool)

except socket.timeout:
Expand All @@ -317,7 +317,7 @@ def update_SR_reference(inPool, retPool, key):
pbdRefs.append(pbd['opaqueref'])

srMap= self.session.xenapi.SR.get_all_records()
for opaqueRef, values in srMap.iteritems():
for opaqueRef, values in srMap.items():
values['opaqueref'] = opaqueRef
values['islocal'] = False
for pbdRef in values.get('PBDs', []):
Expand Down Expand Up @@ -454,30 +454,30 @@ def LoggingDestinationSet(self, inDestination):
self.session.xenapi.host.syslog_reconfigure(self.host.opaqueref())

def UpdateFromResolveConf(self):
(status, output) = commands.getstatusoutput("/usr/bin/grep -v \"^;\" /etc/resolv.conf")
(status, output) = subprocess.getstatusoutput("/usr/bin/grep -v \"^;\" /etc/resolv.conf")
if status == 0:
self.ScanResolvConf(output.split("\n"))

def UpdateFromSysconfig(self):
(status, output) = commands.getstatusoutput("/bin/cat /etc/sysconfig/network")
(status, output) = subprocess.getstatusoutput("/bin/cat /etc/sysconfig/network")
if status == 0:
self.ScanSysconfigNetwork(output.split("\n"))

def UpdateFromHostname(self):
(status, output) = commands.getstatusoutput("/bin/cat /etc/hostname")
(status, output) = subprocess.getstatusoutput("/bin/cat /etc/hostname")
if status == 0:
self.ScanHostname(output.split("\n"))

def UpdateFromNTPConf(self):
(status, output) = commands.getstatusoutput("/bin/cat /etc/chrony.conf")
(status, output) = subprocess.getstatusoutput("/bin/cat /etc/chrony.conf")
if status == 0:
self.ScanNTPConf(output.split("\n"))

def StringToBool(self, inString):
return inString.lower().startswith('true')

def RootLabel(self):
output = commands.getoutput('/bin/cat /proc/cmdline')
output = subprocess.getoutput('/bin/cat /proc/cmdline')
match = re.search(r'root=\s*LABEL\s*=\s*(\S+)', output)
if match:
retVal = match.group(1)
Expand Down Expand Up @@ -623,7 +623,7 @@ def Match(self, inLine, inRegExp, inKey):
def MultipleMatch(self, inLine, inRegExp, inKey):
match = re.match(inRegExp, inLine)
if match:
if not self.data['dmi'].has_key(inKey):
if inKey not in self.data['dmi']:
self.data['dmi'][inKey] = []
self.data['dmi'][inKey].append(match.group(1))

Expand Down Expand Up @@ -675,7 +675,7 @@ def ScanIpmiMcInfo(self, inLines):
self.data['bmc']['version'] = match.group(1)

def ScanService(self, service):
(status, output) = commands.getstatusoutput("systemctl is-enabled %s" % (service,))
(status, output) = subprocess.getstatusoutput("systemctl is-enabled %s" % (service,))
self.data['chkconfig'][service] = status == 0

def ScanResolvConf(self, inLines):
Expand Down Expand Up @@ -779,7 +779,7 @@ def TimezoneSet(self, inTimezone):
cfg.write('/etc/sysconfig/clock')

def CurrentTimeString(self):
return commands.getoutput('/bin/date -R')
return subprocess.getoutput('/bin/date -R')

def ReadKeymaps(self):
self.data['keyboard'] = {
Expand Down Expand Up @@ -811,7 +811,7 @@ def KeymapSet(self, inKeymap):

keymapParam = ShellUtils.MakeSafeParam(inKeymap)
# Load the keymap now
status, output = commands.getstatusoutput('/bin/loadkeys "'+keymapParam+'"')
status, output = subprocess.getstatusoutput('/bin/loadkeys "'+keymapParam+'"')
if status != 0:
raise Exception(output)

Expand All @@ -827,7 +827,7 @@ def KeymapSet(self, inKeymap):
def KeymapToName(self, inKeymap):
# Derive a name to present to the user
mapName = FirstValue(inKeymap, Lang('<Default>'))
for key, value in self.keyboard.namestomaps({}).iteritems():
for key, value in self.keyboard.namestomaps({}).items():
if value == inKeymap:
mapName = key

Expand Down Expand Up @@ -914,7 +914,7 @@ def ReconfigureManagement(self, inPIF, inMode, inIP, inNetmask, inGateway, in
self.RequireSession()
self.session.xenapi.PIF.reconfigure_ip(inPIF['opaqueref'], inMode, inIP, inNetmask, inGateway, FirstValue(inDNS, ''))
self.session.xenapi.host.management_reconfigure(inPIF['opaqueref'])
status, output = commands.getstatusoutput('%s host-signal-networking-change' % (Config.Inst().XECLIPath()))
status, output = subprocess.getstatusoutput('%s host-signal-networking-change' % (Config.Inst().XECLIPath()))
if status != 0:
raise Exception(output)
finally:
Expand Down Expand Up @@ -1090,32 +1090,32 @@ def StartXAPI(self):
State.Inst().SaveIfRequired()

def EnableService(self, service):
status, output = commands.getstatusoutput("systemctl enable %s" % (service,))
status, output = subprocess.getstatusoutput("systemctl enable %s" % (service,))
if status != 0:
raise Exception(output)

def DisableService(self, service):
status, output = commands.getstatusoutput("systemctl disable %s" % (service,))
status, output = subprocess.getstatusoutput("systemctl disable %s" % (service,))
if status != 0:
raise Exception(output)

def RestartService(self, service):
status, output = commands.getstatusoutput("systemctl restart %s" % (service,))
status, output = subprocess.getstatusoutput("systemctl restart %s" % (service,))
if status != 0:
raise Exception(output)

def StartService(self, service):
status, output = commands.getstatusoutput("systemctl start %s" % (service,))
status, output = subprocess.getstatusoutput("systemctl start %s" % (service,))
if status != 0:
raise Exception(output)

def StopService(self, service):
status, output = commands.getstatusoutput("systemctl stop %s" % (service,))
status, output = subprocess.getstatusoutput("systemctl stop %s" % (service,))
if status != 0:
raise Exception(output)

def NTPStatus(self):
status, output = commands.getstatusoutput("/usr/bin/ntpstat")
status, output = subprocess.getstatusoutput("/usr/bin/ntpstat")
return output

def SetVerboseBoot(self, inVerbose):
Expand All @@ -1124,7 +1124,7 @@ def SetVerboseBoot(self, inVerbose):
else:
name = 'quiet'

status, output = commands.getstatusoutput(
status, output = subprocess.getstatusoutput(
"(export TERM=xterm && /opt/xensource/libexec/set-boot " + name + ")")
if status != 0:
raise Exception(output)
Expand Down
20 changes: 10 additions & 10 deletions XSConsoleDataUtils.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def DeviceList(cls, inWritableOnly):
@classmethod
def SRDeviceList(self):
retVal= []
status, output = commands.getstatusoutput("/opt/xensource/libexec/list_local_disks")
status, output = subprocess.getstatusoutput("/opt/xensource/libexec/list_local_disks")
if status == 0:
regExp = re.compile(r"\s*\(\s*'([^']*)'\s*,\s*'([^']*)'\s*,\s*'([^']*)'\s*,\s*'([^']*)'\s*,\s*'([^']*)'\s*\)")
for line in output.split("\n"):
Expand Down Expand Up @@ -168,18 +168,18 @@ def USBFormat(self, inVDI):
if e.errno != errno.EINTR: # Loop if EINTR
raise

status, output = commands.getstatusoutput('/bin/sync')
status, output = subprocess.getstatusoutput('/bin/sync')

if status != 0:
raise Exception(output)

# Format the new partition with VFAT
status, output = commands.getstatusoutput("/sbin/mkfs.vfat -n 'XenServer Backup' -F 32 '" +partitionName + "' 2>&1")
status, output = subprocess.getstatusoutput("/sbin/mkfs.vfat -n 'XenServer Backup' -F 32 '" +partitionName + "' 2>&1")

if status != 0:
raise Exception(output)

status, output = commands.getstatusoutput('/bin/sync')
status, output = subprocess.getstatusoutput('/bin/sync')

if status != 0:
raise Exception(output)
Expand Down Expand Up @@ -237,7 +237,7 @@ def __init__(self, inVDI, inMode = None):
FileUtils.AssertSafePath(self.mountDev)
self.mountPoint = tempfile.mkdtemp(".xsconsole")

status, output = commands.getstatusoutput("/bin/mount -t auto -o " + self.mode + ' ' +self.mountDev+" "+self.mountPoint + " 2>&1")
status, output = subprocess.getstatusoutput("/bin/mount -t auto -o " + self.mode + ' ' +self.mountDev+" "+self.mountPoint + " 2>&1")
if status != 0:
try:
self.Unmount()
Expand Down Expand Up @@ -276,7 +276,7 @@ def HandleMountFailure(self, inOutput):
raise Exception(inOutput)

realDevice = FileUtils.DeviceFromVDI(self.vdi)
status, output = commands.getstatusoutput("/sbin/fdisk -l '" +realDevice+"'")
status, output = subprocess.getstatusoutput("/sbin/fdisk -l '" +realDevice+"'")
if status != 0:
raise Exception(output)

Expand Down Expand Up @@ -313,7 +313,7 @@ def Scan(self, inRegExp = None, inNumToReturn = None):
def Unmount(self):
status = 0
if self.mountedVBD:
status, output = commands.getstatusoutput("/bin/umount '"+self.mountPoint + "' 2>&1")
status, output = subprocess.getstatusoutput("/bin/umount '"+self.mountPoint + "' 2>&1")
os.rmdir(self.mountPoint)
self.mountedVBD = False
if self.pluggedVBD:
Expand Down Expand Up @@ -360,7 +360,7 @@ def __init__(self, inVDI, inMode = None):
FileUtils.AssertSafePath(self.mountDev)
self.mountPoint = tempfile.mkdtemp(".xsconsole")

status, output = commands.getstatusoutput("/bin/mount -t auto -o " + self.mode + ' ' +self.mountDev+" "+self.mountPoint + " 2>&1")
status, output = subprocess.getstatusoutput("/bin/mount -t auto -o " + self.mode + ' ' +self.mountDev+" "+self.mountPoint + " 2>&1")
if status != 0:
try:
self.Unmount()
Expand Down Expand Up @@ -400,7 +400,7 @@ def HandleMountFailure(self, inStatus, inOutput):
raise Exception(inOutput)

realDevice = FileUtils.DeviceFromVDI(self.vdi)
status, output = commands.getstatusoutput("/sbin/fdisk -l '" +realDevice+"'")
status, output = subprocess.getstatusoutput("/sbin/fdisk -l '" +realDevice+"'")
if status != 0:
raise Exception(output)

Expand Down Expand Up @@ -437,7 +437,7 @@ def Scan(self, inRegExp = None, inNumToReturn = None):
def Unmount(self):
status = 0
if self.mountedVDI:
status, output = commands.getstatusoutput("/bin/umount '"+self.mountPoint + "' 2>&1")
status, output = subprocess.getstatusoutput("/bin/umount '"+self.mountPoint + "' 2>&1")
os.rmdir(self.mountPoint)
self.mountedVDI = False
XSLog('Unmounted '+self.mountPoint)
Expand Down
2 changes: 1 addition & 1 deletion XSConsoleFields.py
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ def InputFieldAdd(self, inTag, inField):

def GetFieldValues(self):
retVal = {}
for key, field in self.inputTags.iteritems():
for key, field in self.inputTags.items():
retVal[key] = field.Content()

return retVal
Expand Down
Loading