mirror of https://github.com/apache/cloudstack.git
Convert scripts to python 3
This commit is contained in:
parent
8e3bbe2d56
commit
782f28b365
|
|
@ -36,27 +36,27 @@ def lock():
|
|||
sleep(1)
|
||||
count = count + 1
|
||||
if count > sleep_max:
|
||||
print "Can not get file lock at %s, time expired" % file_lock
|
||||
print("Can not get file lock at %s, time expired" % file_lock)
|
||||
return False
|
||||
|
||||
try:
|
||||
f = open(file_lock, "w")
|
||||
f.close()
|
||||
return True
|
||||
except IOError,e:
|
||||
print "Cannot create file lock at /etc/dhcpd.conf_locked,", e
|
||||
except IOError as e:
|
||||
print("Cannot create file lock at /etc/dhcpd.conf_locked,", e)
|
||||
return False
|
||||
|
||||
|
||||
def unlock():
|
||||
if exists(file_lock) == False:
|
||||
print "Cannot find %s when unlocking, race condition happens" % file_lock
|
||||
print("Cannot find %s when unlocking, race condition happens" % file_lock)
|
||||
else:
|
||||
try:
|
||||
remove(file_lock)
|
||||
return True
|
||||
except IOError, e:
|
||||
print "Cannot remove file lock at %s" % file_lock
|
||||
except IOError as e:
|
||||
print("Cannot remove file lock at %s" % file_lock)
|
||||
return False
|
||||
|
||||
def insert_host_entry(mac, ip, hostname, dns, gateway, next_server):
|
||||
|
|
@ -66,14 +66,14 @@ def insert_host_entry(mac, ip, hostname, dns, gateway, next_server):
|
|||
cmd = 'sed -i /"fixed-address %s"/d %s' % (ip, conf_path)
|
||||
ret = os.system(cmd)
|
||||
if ret != 0:
|
||||
print "Command %s failed" % cmd
|
||||
print("Command %s failed" % cmd)
|
||||
unlock()
|
||||
return 1
|
||||
|
||||
cmd = 'sed -i /"hardware ethernet %s"/d %s' % (mac, conf_path)
|
||||
ret = os.system(cmd)
|
||||
if ret != 0:
|
||||
print "Command %s failed" % cmd
|
||||
print("Command %s failed" % cmd)
|
||||
unlock()
|
||||
return 1
|
||||
|
||||
|
|
@ -84,14 +84,14 @@ def insert_host_entry(mac, ip, hostname, dns, gateway, next_server):
|
|||
cmd = '''echo '%s' >> %s''' % (entry, conf_path)
|
||||
ret = os.system(cmd)
|
||||
if ret != 0:
|
||||
print "Command %s failed" % cmd
|
||||
print("Command %s failed" % cmd)
|
||||
unlock()
|
||||
return 1
|
||||
|
||||
cmd = 'service dhcpd restart'
|
||||
ret = os.system(cmd)
|
||||
if ret != 0:
|
||||
print "Command %s failed" % cmd
|
||||
print("Command %s failed" % cmd)
|
||||
unlock()
|
||||
return 1
|
||||
|
||||
|
|
@ -102,7 +102,7 @@ def insert_host_entry(mac, ip, hostname, dns, gateway, next_server):
|
|||
|
||||
if __name__ == "__main__":
|
||||
if len(sys.argv) < 7:
|
||||
print usage
|
||||
print(usage)
|
||||
sys.exit(1)
|
||||
|
||||
mac = sys.argv[1]
|
||||
|
|
@ -115,7 +115,7 @@ if __name__ == "__main__":
|
|||
if exists(conf_path) == False:
|
||||
conf_path = "/etc/dhcp/dhcpd.conf"
|
||||
if exists(conf_path) == False:
|
||||
print "Cannot find dhcpd.conf"
|
||||
print("Cannot find dhcpd.conf")
|
||||
sys.exit(1)
|
||||
|
||||
ret = insert_host_entry(mac, ip, hostname, dns, gateway, next_server)
|
||||
|
|
|
|||
|
|
@ -62,14 +62,14 @@ def prepare():
|
|||
f.write(stuff)
|
||||
f.close()
|
||||
return 0
|
||||
except Exception, e:
|
||||
print e
|
||||
except Exception as e:
|
||||
print(e)
|
||||
return 1
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
if len(sys.argv) < 7:
|
||||
print "Usage: prepare_kickstart_bootfile.py tftp_dir mac kernel initrd ks_file ks_device"
|
||||
print("Usage: prepare_kickstart_bootfile.py tftp_dir mac kernel initrd ks_file ks_device")
|
||||
exit(1)
|
||||
|
||||
(tftp_dir, mac, kernel, initrd, ks_file, ks_device) = sys.argv[1:]
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@ initrd = None
|
|||
copy_to = None
|
||||
|
||||
def cmd(cmdstr, err=True):
|
||||
print cmdstr
|
||||
print(cmdstr)
|
||||
if os.system(cmdstr) != 0 and err:
|
||||
raise Exception("Failed to run shell command: %s" % cmdstr)
|
||||
|
||||
|
|
@ -36,7 +36,7 @@ def prepare():
|
|||
k = os.path.join(copy_to, "vmlinuz")
|
||||
i = os.path.join(copy_to, "initrd.img")
|
||||
if os.path.exists(k) and os.path.exists(i):
|
||||
print "Having template(%s) prepared already, skip copying" % copy_to
|
||||
print("Having template(%s) prepared already, skip copying" % copy_to)
|
||||
return 0
|
||||
else:
|
||||
if not os.path.exists(copy_to):
|
||||
|
|
@ -61,14 +61,14 @@ def prepare():
|
|||
|
||||
copy_from_nfs(kernel, copy_to)
|
||||
copy_from_nfs(initrd, copy_to)
|
||||
except Exception, e:
|
||||
print e
|
||||
except Exception as e:
|
||||
print(e)
|
||||
return 1
|
||||
|
||||
if __name__ == "__main__":
|
||||
if len(sys.argv) < 4:
|
||||
print "Usage: prepare_kickstart_kerneal_initrd.py path_to_kernel path_to_initrd path_kernel_initrd_copy_to"
|
||||
sys.exit(1)
|
||||
print("Usage: prepare_kickstart_kerneal_initrd.py path_to_kernel path_to_initrd path_kernel_initrd_copy_to")
|
||||
sys.exit(1)
|
||||
|
||||
(kernel, initrd, copy_to) = sys.argv[1:]
|
||||
sys.exit(prepare())
|
||||
|
|
|
|||
|
|
@ -72,14 +72,14 @@ def prepare(is_restore):
|
|||
f.write(stuff)
|
||||
f.close()
|
||||
return 0
|
||||
except Exception, e:
|
||||
print e
|
||||
except Exception as e:
|
||||
print(e)
|
||||
return 1
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
if len(sys.argv) < 12:
|
||||
print "Usage: prepare_tftp_bootfile.py tftp_dir mac cifs_server share directory image_to_restor cifs_username cifs_password ip netmask gateway"
|
||||
print("Usage: prepare_tftp_bootfile.py tftp_dir mac cifs_server share directory image_to_restor cifs_username cifs_password ip netmask gateway")
|
||||
exit(1)
|
||||
|
||||
(cmd, tftp_dir, mac, cifs_server, share, directory, template_dir, cifs_username, cifs_password, ip, netmask, gateway) = sys.argv[1:]
|
||||
|
|
@ -89,7 +89,7 @@ if __name__ == "__main__":
|
|||
elif cmd == "backup":
|
||||
ret = prepare(False)
|
||||
else:
|
||||
print "Unknown cmd: %s"%cmd
|
||||
print("Unknown cmd: %s"%cmd)
|
||||
ret = 1
|
||||
|
||||
exit(ret)
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@
|
|||
|
||||
import argparse
|
||||
import sys
|
||||
import urllib
|
||||
import urllib.request, urllib.parse, urllib.error
|
||||
import uuid
|
||||
import subprocess
|
||||
import os
|
||||
|
|
@ -90,7 +90,7 @@ class InstallSysTemplate(object):
|
|||
self.databaseuserpassword = ""
|
||||
if self.args.templatesuffix:
|
||||
self.templatesuffix = self.args.templatesuffix
|
||||
print 'Password for DB: %s'%self.databaseuserpassword
|
||||
print('Password for DB: %s'%self.databaseuserpassword)
|
||||
|
||||
def errorAndExit(self, msg):
|
||||
err = '''\n\nWe apologize for below error:
|
||||
|
|
@ -117,11 +117,11 @@ for full help
|
|||
|
||||
def runMysql(self, query):
|
||||
try:
|
||||
print 'Running Query: %s' % query
|
||||
print('Running Query: %s' % query)
|
||||
mysqlCmds = ['mysql', '--user=%s'%self.databaseusername, '--host=%s'%self.databasehostname, '--password=%s'%self.databaseuserpassword, '--skip-column-names', '-U', 'cloud', '-e "%s"'%query]
|
||||
templateId = self.runCmd(mysqlCmds)
|
||||
print 'TemplateId is : %s' % templateId
|
||||
except Exception, e:
|
||||
print('TemplateId is : %s' % templateId)
|
||||
except Exception as e:
|
||||
err = '''Encountering an error when executing mysql script\n%s''' % str(e)
|
||||
self.errorAndExit(err)
|
||||
return templateId
|
||||
|
|
@ -137,9 +137,9 @@ for full help
|
|||
|
||||
def downloadTemplate(self):
|
||||
self.systemvmtemplatepath = self.templateName + "." + self.fileextension
|
||||
print 'Downloading template from %s To %s' % (self.systemvmtemplateurl, self.systemvmtemplatepath)
|
||||
print('Downloading template from %s To %s' % (self.systemvmtemplateurl, self.systemvmtemplatepath))
|
||||
try:
|
||||
templateFileDownloadUrl = urllib.urlretrieve(self.systemvmtemplateurl, self.systemvmtemplatepath, reporthook=self.report)
|
||||
templateFileDownloadUrl = urllib.request.urlretrieve(self.systemvmtemplateurl, self.systemvmtemplatepath, reporthook=self.report)
|
||||
except Exception:
|
||||
self.errorAndExit("Failed to download template file from %s" % self.systemvmtemplateurl)
|
||||
|
||||
|
|
@ -150,23 +150,23 @@ for full help
|
|||
def installTemplate(self):
|
||||
destDir = self.mountpoint + os.sep + "template" + os.sep + "tmpl" + os.sep + "1" + os.sep + str(self.template)
|
||||
self.destDir = destDir
|
||||
print 'The desination Directory is : %s' % destDir
|
||||
print('The desination Directory is : %s' % destDir)
|
||||
try:
|
||||
if self.forcecleanup:
|
||||
if os.path.exists(destDir):
|
||||
shutil.rmtree(destDir)
|
||||
if not os.path.exists(destDir):
|
||||
os.makedirs(destDir)
|
||||
except Exception, e:
|
||||
except Exception as e:
|
||||
self.errorAndExit('Failed to create directories on the mounted path.. %s' % str (e))
|
||||
print 'Installing Template to : %s' % destDir
|
||||
print('Installing Template to : %s' % destDir)
|
||||
tmpFile = self.templateName + "." + "tmp"
|
||||
self.uncompressFile(tmpFile)
|
||||
print 'Moving the decompressed file to destination directory %s... which could take a long time, please wait' % destDir
|
||||
print('Moving the decompressed file to destination directory %s... which could take a long time, please wait' % destDir)
|
||||
shutil.move(tmpFile, destDir + os.sep + self.templateName)
|
||||
|
||||
def uncompressFile(self, fileName):
|
||||
print 'Uncompressing the file %s... which could take a long time, please wait' % self.systemvmtemplatepath
|
||||
print('Uncompressing the file %s... which could take a long time, please wait' % self.systemvmtemplatepath)
|
||||
if self.fileextension == 'gz':
|
||||
compressedFile = gzip.GzipFile(self.systemvmtemplatepath, 'rb')
|
||||
decompressedData = compressedFile.read()
|
||||
|
|
@ -181,7 +181,7 @@ for full help
|
|||
decompressedFile = file(fileName, 'wb')
|
||||
decompressedFile.write(decompressedData)
|
||||
decompressedFile.close()
|
||||
print ''
|
||||
print('')
|
||||
elif self.fileextension == 'zip':
|
||||
zippedFile = zipfile.ZipFile(self.systemvmtemplatepath, 'r')
|
||||
zippedFiles = zippedFile.namelist()
|
||||
|
|
@ -191,7 +191,7 @@ for full help
|
|||
decompressedFile.write(decompressedData)
|
||||
decompressedFile.close()
|
||||
zippedFile.close()
|
||||
print ''
|
||||
print('')
|
||||
else:
|
||||
self.errorAndExit('Not supported file type %s to decompress' % self.fileextension)
|
||||
self.fileSize = os.path.getsize(fileName)
|
||||
|
|
@ -226,10 +226,10 @@ for full help
|
|||
self.installTemplate()
|
||||
self.writeProperties()
|
||||
finally:
|
||||
print ''
|
||||
print ''
|
||||
print "CloudStack has successfully installed system template"
|
||||
print ''
|
||||
print('')
|
||||
print('')
|
||||
print("CloudStack has successfully installed system template")
|
||||
print('')
|
||||
|
||||
if __name__ == "__main__":
|
||||
o = InstallSysTemplate()
|
||||
|
|
|
|||
|
|
@ -80,7 +80,7 @@ ipmitool = Command("ipmitool")
|
|||
|
||||
def check_tool():
|
||||
if exists(TOOl_PATH) == False:
|
||||
print "Can not find ipmitool"
|
||||
print("Can not find ipmitool")
|
||||
return False
|
||||
|
||||
def ping(args):
|
||||
|
|
@ -89,15 +89,15 @@ def ping(args):
|
|||
password = args.get("password")
|
||||
|
||||
if hostname == None:
|
||||
print "No hostname"
|
||||
print("No hostname")
|
||||
return 1
|
||||
|
||||
o = ipmitool("-H", hostname, "-U", usrname, "-P", password, "chassis", "power", "status")
|
||||
if o.ret:
|
||||
print o.stderr
|
||||
print(o.stderr)
|
||||
return 1
|
||||
else:
|
||||
print o.stdout
|
||||
print(o.stdout)
|
||||
return 0
|
||||
|
||||
def boot_dev(args):
|
||||
|
|
@ -107,16 +107,16 @@ def boot_dev(args):
|
|||
dev = args.get("dev")
|
||||
|
||||
if hostname == None:
|
||||
print "No hostname"
|
||||
print("No hostname")
|
||||
return 1
|
||||
|
||||
if dev == None:
|
||||
print "No boot device specified"
|
||||
print("No boot device specified")
|
||||
return 1
|
||||
|
||||
o = ipmitool("-H", hostname, "-U", usrname, "-P", password, "chassis", "bootdev", dev)
|
||||
if o.ret:
|
||||
print o.stderr
|
||||
print(o.stderr)
|
||||
return 1
|
||||
else:
|
||||
return 0
|
||||
|
|
@ -127,12 +127,12 @@ def reboot(args):
|
|||
password = args.get("password")
|
||||
|
||||
if hostname == None:
|
||||
print "No hostname"
|
||||
print("No hostname")
|
||||
return 1
|
||||
|
||||
o = ipmitool("-H", hostname, "-U", usrname, "-P", password, "chassis", "power", "status")
|
||||
if o.ret:
|
||||
print o.stderr
|
||||
print(o.stderr)
|
||||
return 1
|
||||
|
||||
|
||||
|
|
@ -142,7 +142,7 @@ def reboot(args):
|
|||
o = ipmitool("-H", hostname, "-U", usrname, "-P", password, "chassis", "power", "reset")
|
||||
|
||||
if o.ret:
|
||||
print o.stderr
|
||||
print(o.stderr)
|
||||
return 1
|
||||
else:
|
||||
return 0
|
||||
|
|
@ -154,12 +154,12 @@ def power(args):
|
|||
action = args.get("action")
|
||||
|
||||
if hostname == None:
|
||||
print "No hostname"
|
||||
print("No hostname")
|
||||
return 1
|
||||
|
||||
o = ipmitool("-H", hostname, "-U", usrname, "-P", password, "chassis", "power", action)
|
||||
if o.ret:
|
||||
print o.stderr
|
||||
print(o.stderr)
|
||||
return 1
|
||||
else:
|
||||
return 0
|
||||
|
|
@ -170,7 +170,7 @@ def boot_or_reboot(args):
|
|||
password = args.get("password")
|
||||
o = ipmitool("-H", hostname, "-U", usrname, "-P", password, "chassis", "power", "status")
|
||||
if o.ret:
|
||||
print o.stderr
|
||||
print(o.stderr)
|
||||
return 1
|
||||
|
||||
if "is on" in o.stdout:
|
||||
|
|
@ -179,7 +179,7 @@ def boot_or_reboot(args):
|
|||
args["action"] = "on"
|
||||
return power(args)
|
||||
else:
|
||||
print "unknown power status:" + o.stdout
|
||||
print("unknown power status:" + o.stdout)
|
||||
return 1
|
||||
|
||||
|
||||
|
|
@ -189,14 +189,14 @@ def dispatch(args):
|
|||
params = args[2:]
|
||||
func_params = {}
|
||||
|
||||
if call_table.has_key(cmd) == False:
|
||||
print "No function %s" % cmd
|
||||
if (cmd in call_table) == False:
|
||||
print("No function %s" % cmd)
|
||||
return 1
|
||||
|
||||
for p in params:
|
||||
pairs = p.split("=")
|
||||
if len(pairs) != 2:
|
||||
print "Invalid parameter %s" % p
|
||||
print("Invalid parameter %s" % p)
|
||||
return 1
|
||||
func_params[pairs[0]] = pairs[1]
|
||||
|
||||
|
|
@ -207,6 +207,6 @@ if __name__ == "__main__":
|
|||
if check_tool() == False:
|
||||
sys.exit(1)
|
||||
if len(sys.argv) < 2:
|
||||
print "Not enough arguments, at least one"
|
||||
print("Not enough arguments, at least one")
|
||||
sys.exit(1)
|
||||
sys.exit(dispatch(sys.argv))
|
||||
|
|
|
|||
|
|
@ -26,5 +26,5 @@ def randomMAC():
|
|||
random.randint(0x00, 0x7f),
|
||||
random.randint(0x00, 0xff),
|
||||
random.randint(0x00, 0xff) ]
|
||||
return ':'.join(map(lambda x: "%02x" % x, mac))
|
||||
print randomMAC()
|
||||
return ':'.join(["%02x" % x for x in mac])
|
||||
print(randomMAC())
|
||||
|
|
|
|||
|
|
@ -31,7 +31,7 @@ import logging
|
|||
import logging.handlers
|
||||
|
||||
from xen.util.xmlrpcclient import ServerProxy
|
||||
from xmlrpclib import Error
|
||||
from xmlrpc.client import Error
|
||||
from xen.xend import XendClient
|
||||
from agent.api.base import Agent
|
||||
from agent.lib.settings import get_api_version
|
||||
|
|
@ -134,7 +134,7 @@ def domrSftp(host, localfile, remotefile, timeout=10, username=domrRoot, port=do
|
|||
# rf.close()
|
||||
sftp.close()
|
||||
ssh.close()
|
||||
except Exception, e:
|
||||
except Exception as e:
|
||||
raise e
|
||||
return True
|
||||
|
||||
|
|
@ -145,7 +145,7 @@ def domrScp(host, localfile, remotefile, timeout=10, username=domrRoot, port=dom
|
|||
rc = subprocess.call(cmd, shell=False)
|
||||
if rc == 0:
|
||||
return True
|
||||
except Exception, e:
|
||||
except Exception as e:
|
||||
raise e
|
||||
return False
|
||||
|
||||
|
|
@ -236,7 +236,7 @@ def _replaceInFile(file, orig, set, full=False):
|
|||
if re.search(orig, line):
|
||||
line = line.replace(orig, set)
|
||||
replaced = True
|
||||
print line
|
||||
print(line)
|
||||
return replaced
|
||||
|
||||
def _ovsIni(setting, change):
|
||||
|
|
@ -278,7 +278,7 @@ def ovsControlInterface(dev, cidr):
|
|||
if re.search("%s" % (cidr), line) and not re.search("%s" % (dev), line):
|
||||
command = ['ip', 'route', 'del', cidr]
|
||||
subprocess.call(command, shell=False)
|
||||
print "removed: %s" % (line)
|
||||
print("removed: %s" % (line))
|
||||
elif re.search("%s" % (cidr), line) and re.search("%s" % (dev), line):
|
||||
controlRoute = True
|
||||
|
||||
|
|
@ -354,7 +354,7 @@ def dom0CheckStorageHealth(path, script, guid, timeout):
|
|||
# return True
|
||||
|
||||
# create a dir if we need it
|
||||
def ovsMkdirs(dir, mode=0700):
|
||||
def ovsMkdirs(dir, mode=0o700):
|
||||
if not os.path.exists(dir):
|
||||
return os.makedirs(dir, mode)
|
||||
return True
|
||||
|
|
@ -369,15 +369,15 @@ def ovsUploadFile(path, filename, content):
|
|||
file = "%s/%s" % (path, filename)
|
||||
try:
|
||||
ovsMkdirs(os.path.expanduser(path))
|
||||
except Error, v:
|
||||
print "path was already there %s" % path
|
||||
except Error as v:
|
||||
print("path was already there %s" % path)
|
||||
|
||||
try:
|
||||
text_file = open("%s" % file, "w")
|
||||
text_file.write("%s" % content)
|
||||
text_file.close()
|
||||
except Error, v:
|
||||
print "something went wrong creating %s: %s" % (file, v)
|
||||
except Error as v:
|
||||
print("something went wrong creating %s: %s" % (file, v))
|
||||
return False
|
||||
return True
|
||||
|
||||
|
|
@ -390,8 +390,8 @@ def ovsDomrUploadFile(domr, path, file, content):
|
|||
# domrSftp(domr, temp.name, remotefile)
|
||||
domrScp(domr, temp.name, remotefile)
|
||||
temp.close
|
||||
except Exception, e:
|
||||
print "problem uploading file %s/%s to %s, %s" % (path, file, domr, e)
|
||||
except Exception as e:
|
||||
print("problem uploading file %s/%s to %s, %s" % (path, file, domr, e))
|
||||
raise e
|
||||
return True
|
||||
|
||||
|
|
@ -417,13 +417,13 @@ def getVncPort(domain):
|
|||
dom = server.xend.domain(domain, 1)
|
||||
devices = [child for child in sxp.children(dom)
|
||||
if len(child) > 0 and child[0] == "device"]
|
||||
vfbs_sxp = map(lambda x: x[1], [device for device in devices
|
||||
if device[1][0] == "vfb"])[0]
|
||||
vfbs_sxp = [x[1] for x in [device for device in devices
|
||||
if device[1][0] == "vfb"]][0]
|
||||
loc = [child for child in vfbs_sxp
|
||||
if child[0] == "location"][0][1]
|
||||
listner, port = loc.split(":")
|
||||
else:
|
||||
print "no valid domain: %s" % domain
|
||||
print("no valid domain: %s" % domain)
|
||||
return port
|
||||
|
||||
def get_child_by_name(exp, childname, default=None):
|
||||
|
|
@ -450,10 +450,10 @@ def ovsDomUStats(domain):
|
|||
devids = [dev[0] for dev in devs]
|
||||
for dev in devids:
|
||||
sys_path = "/sys/devices/%s-%s-%s/statistics" % ("vbd", domid, dev)
|
||||
_rd_bytes += long(open("%s/rd_sect" % sys_path).readline().strip())
|
||||
_wr_bytes += long(open("%s/wr_sect" % sys_path).readline().strip())
|
||||
_rd_ops += long(open("%s/rd_req" % sys_path).readline().strip())
|
||||
_wr_ops += long(open("%s/wr_req" % sys_path).readline().strip())
|
||||
_rd_bytes += int(open("%s/rd_sect" % sys_path).readline().strip())
|
||||
_wr_bytes += int(open("%s/wr_sect" % sys_path).readline().strip())
|
||||
_rd_ops += int(open("%s/rd_req" % sys_path).readline().strip())
|
||||
_wr_ops += int(open("%s/wr_req" % sys_path).readline().strip())
|
||||
|
||||
# vifs
|
||||
devs = server.xend.domain.getDeviceSxprs(domain, 'vif')
|
||||
|
|
@ -461,8 +461,8 @@ def ovsDomUStats(domain):
|
|||
for dev in devids:
|
||||
vif = "vif%s.%s" % (domid, dev)
|
||||
sys_path = "/sys/devices/%s-%s-%s/net/%s/statistics" % ("vif", domid, dev, vif)
|
||||
_tx_bytes += long(open("%s/tx_bytes" % sys_path).readline().strip())
|
||||
_rx_bytes += long(open("%s/rx_bytes" % sys_path).readline().strip())
|
||||
_tx_bytes += int(open("%s/tx_bytes" % sys_path).readline().strip())
|
||||
_rx_bytes += int(open("%s/rx_bytes" % sys_path).readline().strip())
|
||||
|
||||
epoch = time.time()
|
||||
stats['rd_bytes'] = "%s" % (_rd_bytes * 512)
|
||||
|
|
@ -513,7 +513,7 @@ if __name__ == '__main__':
|
|||
opts, args = getopt.getopt(sys.argv[1:], "eosp::",
|
||||
[ 'port=', 'ssl=', 'exec=', 'opts='])
|
||||
except getopt.GetoptError:
|
||||
print "Available Options: --port=<number>, --ssl=<true|false>, --exec=<method>, --opts=<arg1,arg2..>"
|
||||
print("Available Options: --port=<number>, --ssl=<true|false>, --exec=<method>, --opts=<arg1,arg2..>")
|
||||
sys.exit()
|
||||
|
||||
for o, a in opts:
|
||||
|
|
@ -528,12 +528,12 @@ if __name__ == '__main__':
|
|||
|
||||
if exec_sub != "":
|
||||
func = "%s(%s)" % (exec_sub, exec_opts)
|
||||
print "exec: %s" % (func)
|
||||
print("exec: %s" % (func))
|
||||
if exec_opts:
|
||||
opts = exec_opts.split(',')
|
||||
else:
|
||||
opts = ""
|
||||
print locals()[exec_sub](*opts)
|
||||
print(locals()[exec_sub](*opts))
|
||||
sys.exit()
|
||||
|
||||
# check if we're in the modules already
|
||||
|
|
@ -553,24 +553,24 @@ if __name__ == '__main__':
|
|||
if re.search("MODULES", line):
|
||||
n = cs.getName()
|
||||
line = "%s\n\t%s.%s," % (line, n.lower(), n)
|
||||
print line
|
||||
print "Api inserted, %s in %s" % (cs.getName(), api)
|
||||
print(line)
|
||||
print("Api inserted, %s in %s" % (cs.getName(), api))
|
||||
else:
|
||||
print "Api missing, %s" % (api)
|
||||
print("Api missing, %s" % (api))
|
||||
else:
|
||||
print "Api present, %s in %s" % (cs.getName(), api)
|
||||
print("Api present, %s in %s" % (cs.getName(), api))
|
||||
|
||||
# either way check our version and install if checksum differs
|
||||
modfile = "%s/%s.py" % (modpath, cs.getName().lower())
|
||||
me = os.path.abspath(__file__)
|
||||
if os.path.isfile(modfile):
|
||||
if hashlib.md5(open(me).read()).hexdigest() != hashlib.md5(open(modfile).read()).hexdigest():
|
||||
print "Module copy, %s" % (modfile)
|
||||
print("Module copy, %s" % (modfile))
|
||||
copyfile(me, modfile)
|
||||
else:
|
||||
print "Module correct, %s" % (modfile)
|
||||
print("Module correct, %s" % (modfile))
|
||||
else:
|
||||
print "Module copy, %s" % (modfile)
|
||||
print("Module copy, %s" % (modfile))
|
||||
copyfile(me, modfile)
|
||||
|
||||
# setup ssl and port
|
||||
|
|
|
|||
|
|
@ -72,9 +72,9 @@ class Check(object):
|
|||
def nfsoutput(self):
|
||||
command="mount -v -t nfs"
|
||||
p=subprocess.Popen(command, shell=True, stdout=subprocess.PIPE)
|
||||
lines=map(lambda line: line.split()[2], p.stdout.readlines())
|
||||
lines=[line.split()[2] for line in p.stdout.readlines()]
|
||||
test=re.compile("^%s" % (primary))
|
||||
lines=filter(test.search, lines)
|
||||
lines=list(filter(test.search, lines))
|
||||
return lines
|
||||
|
||||
"""
|
||||
|
|
@ -128,7 +128,7 @@ def figureOutPrimary():
|
|||
return "/var/run/sr-mount"
|
||||
if "Oracle VM server" in line:
|
||||
return "/OVS/Repositories/"
|
||||
print "Unknown hypervisor, consider adding it, exiting"
|
||||
print("Unknown hypervisor, consider adding it, exiting")
|
||||
sys.exit(42)
|
||||
|
||||
""" The logger is here """
|
||||
|
|
@ -165,11 +165,11 @@ if __name__ == '__main__':
|
|||
opts, args = getopt.getopt(sys.argv[1:], "h:y:i:s",
|
||||
[ 'host', 'timeout', 'interval', 'state'])
|
||||
except getopt.GetoptError:
|
||||
print """Usage:
|
||||
print("""Usage:
|
||||
host: host guid.
|
||||
timeout: timeout to fail on
|
||||
interval: time between checks
|
||||
state: check the state"""
|
||||
state: check the state""")
|
||||
sys.exit()
|
||||
for o, a in opts:
|
||||
if o in ('host'):
|
||||
|
|
@ -187,14 +187,14 @@ if __name__ == '__main__':
|
|||
opts, args = getopt.getopt(sys.argv[1:], "g:p:f:c:t:i:s",
|
||||
[ 'guid=', 'primary=','failcmd=','cmd=','timeout=','interval', 'state'])
|
||||
except getopt.GetoptError:
|
||||
print """Usage:
|
||||
print("""Usage:
|
||||
--guid|-g: guid of the host to check
|
||||
--primary|-p: match for primary storage to monitor.
|
||||
--failcmd|-f: executed on timeout.
|
||||
--cmd|-c: command to execute next to hb file(s) on primary.
|
||||
--timeout|-t: excute failcmd after timeout(s) is hit.
|
||||
--interval|-i: run the checks every %ss>
|
||||
--state|-s check state"""
|
||||
--state|-s check state""")
|
||||
sys.exit()
|
||||
|
||||
for o, a in opts:
|
||||
|
|
@ -226,10 +226,10 @@ if __name__ == '__main__':
|
|||
if pid > 0:
|
||||
# exit first parent
|
||||
if me == "heartbeat":
|
||||
print "> DONE <"
|
||||
print("> DONE <")
|
||||
sys.exit(0)
|
||||
except OSError, e:
|
||||
print >>sys.stderr, "fork #1 failed: %d (%s)" % (e.errno, e.strerror)
|
||||
except OSError as e:
|
||||
print("fork #1 failed: %d (%s)" % (e.errno, e.strerror), file=sys.stderr)
|
||||
sys.exit(1)
|
||||
|
||||
checker=Check(cmd=cmd,
|
||||
|
|
@ -247,7 +247,7 @@ if __name__ == '__main__':
|
|||
logger.debug("cmd time: %s" % (runtime))
|
||||
if checkstate:
|
||||
for fs in checker.results:
|
||||
print "%s: %s" % (fs, checker.results[fs])
|
||||
print("%s: %s" % (fs, checker.results[fs]))
|
||||
if checker.ok == False:
|
||||
sys.exit(1)
|
||||
else:
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@
|
|||
|
||||
# Common function for Cloudstack's XenAPI plugins
|
||||
|
||||
import ConfigParser
|
||||
import configparser
|
||||
import logging
|
||||
import os
|
||||
import subprocess
|
||||
|
|
@ -73,7 +73,7 @@ def setup_logging(log_file=None):
|
|||
log_date_format = DEFAULT_LOG_DATE_FORMAT
|
||||
# try to read plugin configuration file
|
||||
if os.path.exists(PLUGIN_CONFIG_PATH):
|
||||
config = ConfigParser.ConfigParser()
|
||||
config = configparser.ConfigParser()
|
||||
config.read(PLUGIN_CONFIG_PATH)
|
||||
try:
|
||||
options = config.options('LOGGING')
|
||||
|
|
@ -91,7 +91,7 @@ def setup_logging(log_file=None):
|
|||
# configuration file contained invalid attributes
|
||||
# ignore them
|
||||
pass
|
||||
except ConfigParser.NoSectionError:
|
||||
except configparser.NoSectionError:
|
||||
# Missing 'Logging' section in configuration file
|
||||
pass
|
||||
|
||||
|
|
@ -138,7 +138,7 @@ def _is_process_run(pidFile, name):
|
|||
fpid = open(pidFile, "r")
|
||||
pid = fpid.readline()
|
||||
fpid.close()
|
||||
except IOError, e:
|
||||
except IOError as e:
|
||||
return -1
|
||||
|
||||
pid = pid[:-1]
|
||||
|
|
@ -335,11 +335,11 @@ class jsonLoader(object):
|
|||
|
||||
def __repr__(self):
|
||||
return '{%s}' % str(', '.join('%s : %s' % (k, repr(v)) for (k, v)
|
||||
in self.__dict__.iteritems()))
|
||||
in self.__dict__.items()))
|
||||
|
||||
def __str__(self):
|
||||
return '{%s}' % str(', '.join('%s : %s' % (k, repr(v)) for (k, v)
|
||||
in self.__dict__.iteritems()))
|
||||
in self.__dict__.items()))
|
||||
def get_acl(vpcconfig, required_acl_id):
|
||||
acls = vpcconfig.acls
|
||||
for acl in acls:
|
||||
|
|
@ -409,7 +409,7 @@ def create_tunnel(bridge, remote_ip, gre_key, src_host, dst_host, network_uuid):
|
|||
key_validation = do_cmd(verify_interface_key)
|
||||
ip_validation = do_cmd(verify_interface_ip)
|
||||
|
||||
if not gre_key in key_validation or not remote_ip in ip_validation:
|
||||
if gre_key not in key_validation or remote_ip not in ip_validation:
|
||||
logging.debug("WARNING: Unexpected output while verifying " +
|
||||
"interface %s on bridge %s" % (name, bridge))
|
||||
return "FAILURE:VERIFY_INTERFACE_FAILED"
|
||||
|
|
@ -581,7 +581,7 @@ def configure_vpc_bridge_for_network_topology(bridge, this_host_id, json_config,
|
|||
|
||||
return "SUCCESS: successfully configured bridge as per the VPC topology update with sequence no: %s"%sequence_no
|
||||
|
||||
except Exception,e:
|
||||
except Exception as e:
|
||||
error_message = "An unexpected error occurred while configuring bridge " + bridge + \
|
||||
" as per latest VPC topology update with sequence no: %s" %sequence_no
|
||||
logging.debug(error_message + " due to " + str(e))
|
||||
|
|
@ -757,7 +757,7 @@ def configure_vpc_bridge_for_routing_policies(bridge, json_config, sequence_no):
|
|||
return "SUCCESS: successfully configured bridge as per the latest routing policies update with " \
|
||||
"sequence no: %s"%sequence_no
|
||||
|
||||
except Exception,e:
|
||||
except Exception as e:
|
||||
error_message = "An unexpected error occurred while configuring bridge " + bridge + \
|
||||
" as per latest VPC's routing policy update with sequence number %s." %sequence_no
|
||||
logging.debug(error_message + " due to " + str(e))
|
||||
|
|
@ -797,7 +797,7 @@ def update_flooding_rules_on_port_plug_unplug(bridge, interface, command, if_net
|
|||
|
||||
if port.startswith('vif'):
|
||||
network_id = get_network_id_for_vif(port)
|
||||
if network_id not in all_tiers.keys():
|
||||
if network_id not in list(all_tiers.keys()):
|
||||
all_tiers[network_id] = tier_ports()
|
||||
tier_ports_info = all_tiers[network_id]
|
||||
tier_ports_info.tier_vif_ofports.append(if_ofport)
|
||||
|
|
@ -806,14 +806,14 @@ def update_flooding_rules_on_port_plug_unplug(bridge, interface, command, if_net
|
|||
|
||||
if port.startswith('t'):
|
||||
network_id = get_network_id_for_tunnel_port(port)[1:-1]
|
||||
if network_id not in all_tiers.keys():
|
||||
if network_id not in list(all_tiers.keys()):
|
||||
all_tiers[network_id] = tier_ports()
|
||||
tier_ports_info = all_tiers[network_id]
|
||||
tier_ports_info.tier_tunnelif_ofports.append(if_ofport)
|
||||
tier_ports_info.tier_all_ofports.append(if_ofport)
|
||||
all_tiers[network_id] = tier_ports_info
|
||||
|
||||
for network_id, tier_ports_info in all_tiers.items():
|
||||
for network_id, tier_ports_info in list(all_tiers.items()):
|
||||
if len(tier_ports_info.tier_all_ofports) == 1 :
|
||||
continue
|
||||
|
||||
|
|
@ -850,7 +850,7 @@ def update_flooding_rules_on_port_plug_unplug(bridge, interface, command, if_net
|
|||
|
||||
logging.debug("successfully configured bridge %s as per the latest flooding rules " %bridge)
|
||||
|
||||
except Exception,e:
|
||||
except Exception as e:
|
||||
if os.path.isfile(ofspec_filename):
|
||||
os.remove(ofspec_filename)
|
||||
error_message = "An unexpected error occurred while updating the flooding rules for the bridge " + \
|
||||
|
|
|
|||
|
|
@ -31,7 +31,7 @@ def getHost():
|
|||
host = session.xenapi.host
|
||||
hosts = session.xenapi.host.get_by_name_label(hostname)
|
||||
if len(hosts) != 1:
|
||||
print "can't find host:" + hostname
|
||||
print("can't find host:" + hostname)
|
||||
sys.exit(1)
|
||||
localhost = hosts[0]
|
||||
return [host, localhost]
|
||||
|
|
@ -44,7 +44,7 @@ def callPlugin(pluginName, func, params):
|
|||
|
||||
def main():
|
||||
if len(sys.argv) < 3:
|
||||
print "args: pluginName funcName params"
|
||||
print("args: pluginName funcName params")
|
||||
sys.exit(1)
|
||||
|
||||
pluginName = sys.argv[1]
|
||||
|
|
@ -52,15 +52,15 @@ def main():
|
|||
|
||||
paramList = sys.argv[3:]
|
||||
if (len(paramList) % 2) != 0:
|
||||
print "params must be name/value pair"
|
||||
print("params must be name/value pair")
|
||||
sys.exit(2)
|
||||
params = {}
|
||||
pos = 0;
|
||||
for i in range(len(paramList) / 2):
|
||||
params[str(paramList[pos])] = str(paramList[pos+1])
|
||||
pos = pos + 2
|
||||
print "call: " + pluginName + " " + funcName + ", with params: " + str(params)
|
||||
print "return: " + callPlugin(pluginName, funcName, params)
|
||||
print("call: " + pluginName + " " + funcName + ", with params: " + str(params))
|
||||
print("return: " + callPlugin(pluginName, funcName, params))
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
|
|
|||
|
|
@ -137,8 +137,8 @@ def main(command, vif_raw):
|
|||
|
||||
if __name__ == "__main__":
|
||||
if len(sys.argv) != 3:
|
||||
print "usage: %s [online|offline] vif-domid-idx" % \
|
||||
os.path.basename(sys.argv[0])
|
||||
print("usage: %s [online|offline] vif-domid-idx" % \
|
||||
os.path.basename(sys.argv[0]))
|
||||
sys.exit(1)
|
||||
else:
|
||||
command, vif_raw = sys.argv[1:3]
|
||||
|
|
|
|||
|
|
@ -66,19 +66,19 @@ class NFSSR(FileSR.FileSR):
|
|||
self.ops_exclusive = FileSR.OPS_EXCLUSIVE
|
||||
self.lock = Lock(vhdutil.LOCK_TYPE_SR, self.uuid)
|
||||
self.sr_vditype = SR.DEFAULT_TAP
|
||||
if not self.dconf.has_key('server'):
|
||||
if 'server' not in self.dconf:
|
||||
raise xs_errors.XenError('ConfigServerMissing')
|
||||
self.remoteserver = self.dconf['server']
|
||||
self.path = os.path.join(SR.MOUNT_BASE, sr_uuid)
|
||||
|
||||
# Test for the optional 'nfsoptions' dconf attribute
|
||||
self.transport = DEFAULT_TRANSPORT
|
||||
if self.dconf.has_key('useUDP') and self.dconf['useUDP'] == 'true':
|
||||
if 'useUDP' in self.dconf and self.dconf['useUDP'] == 'true':
|
||||
self.transport = "udp"
|
||||
|
||||
|
||||
def validate_remotepath(self, scan):
|
||||
if not self.dconf.has_key('serverpath'):
|
||||
if 'serverpath' not in self.dconf:
|
||||
if scan:
|
||||
try:
|
||||
self.scan_exports(self.dconf['server'])
|
||||
|
|
@ -92,7 +92,7 @@ class NFSSR(FileSR.FileSR):
|
|||
def check_server(self):
|
||||
try:
|
||||
nfs.check_server_tcp(self.remoteserver)
|
||||
except nfs.NfsException, exc:
|
||||
except nfs.NfsException as exc:
|
||||
raise xs_errors.XenError('NFSVersion',
|
||||
opterr=exc.errstr)
|
||||
|
||||
|
|
@ -100,7 +100,7 @@ class NFSSR(FileSR.FileSR):
|
|||
def mount(self, mountpoint, remotepath):
|
||||
try:
|
||||
nfs.soft_mount(mountpoint, self.remoteserver, remotepath, self.transport)
|
||||
except nfs.NfsException, exc:
|
||||
except nfs.NfsException as exc:
|
||||
raise xs_errors.XenError('NFSMount', opterr=exc.errstr)
|
||||
|
||||
|
||||
|
|
@ -151,7 +151,7 @@ class NFSSR(FileSR.FileSR):
|
|||
|
||||
try:
|
||||
nfs.unmount(self.path, True)
|
||||
except nfs.NfsException, exc:
|
||||
except nfs.NfsException as exc:
|
||||
raise xs_errors.XenError('NFSUnMount', opterr=exc.errstr)
|
||||
|
||||
return super(NFSSR, self).detach(sr_uuid)
|
||||
|
|
@ -168,7 +168,7 @@ class NFSSR(FileSR.FileSR):
|
|||
self.remotepath = self.dconf['serverpath']
|
||||
try:
|
||||
self.mount_remotepath(sr_uuid)
|
||||
except Exception, exn:
|
||||
except Exception as exn:
|
||||
try:
|
||||
os.rmdir(self.path)
|
||||
except:
|
||||
|
|
@ -193,7 +193,7 @@ class NFSSR(FileSR.FileSR):
|
|||
if util.ioretry(lambda: util.pathexists(newpath)):
|
||||
util.ioretry(lambda: os.rmdir(newpath))
|
||||
self.detach(sr_uuid)
|
||||
except util.CommandException, inst:
|
||||
except util.CommandException as inst:
|
||||
self.detach(sr_uuid)
|
||||
if inst.code != errno.ENOENT:
|
||||
raise xs_errors.XenError('NFSDelete')
|
||||
|
|
@ -210,7 +210,7 @@ class NFSSR(FileSR.FileSR):
|
|||
def scan_exports(self, target):
|
||||
util.SMlog("scanning2 (target=%s)" % target)
|
||||
dom = nfs.scan_exports(target)
|
||||
print >>sys.stderr,dom.toprettyxml()
|
||||
print(dom.toprettyxml(), file=sys.stderr)
|
||||
|
||||
class NFSFileVDI(FileSR.FileVDI):
|
||||
def attach(self, sr_uuid, vdi_uuid):
|
||||
|
|
|
|||
|
|
@ -66,19 +66,19 @@ class NFSSR(FileSR.FileSR):
|
|||
self.ops_exclusive = FileSR.OPS_EXCLUSIVE
|
||||
self.lock = Lock(vhdutil.LOCK_TYPE_SR, self.uuid)
|
||||
self.sr_vditype = SR.DEFAULT_TAP
|
||||
if not self.dconf.has_key('server'):
|
||||
if 'server' not in self.dconf:
|
||||
raise xs_errors.XenError('ConfigServerMissing')
|
||||
self.remoteserver = self.dconf['server']
|
||||
self.path = os.path.join(SR.MOUNT_BASE, sr_uuid)
|
||||
|
||||
# Test for the optional 'nfsoptions' dconf attribute
|
||||
self.transport = DEFAULT_TRANSPORT
|
||||
if self.dconf.has_key('useUDP') and self.dconf['useUDP'] == 'true':
|
||||
if 'useUDP' in self.dconf and self.dconf['useUDP'] == 'true':
|
||||
self.transport = "udp"
|
||||
|
||||
|
||||
def validate_remotepath(self, scan):
|
||||
if not self.dconf.has_key('serverpath'):
|
||||
if 'serverpath' not in self.dconf:
|
||||
if scan:
|
||||
try:
|
||||
self.scan_exports(self.dconf['server'])
|
||||
|
|
@ -92,7 +92,7 @@ class NFSSR(FileSR.FileSR):
|
|||
def check_server(self):
|
||||
try:
|
||||
nfs.check_server_tcp(self.remoteserver)
|
||||
except nfs.NfsException, exc:
|
||||
except nfs.NfsException as exc:
|
||||
raise xs_errors.XenError('NFSVersion',
|
||||
opterr=exc.errstr)
|
||||
|
||||
|
|
@ -100,7 +100,7 @@ class NFSSR(FileSR.FileSR):
|
|||
def mount(self, mountpoint, remotepath):
|
||||
try:
|
||||
nfs.soft_mount(mountpoint, self.remoteserver, remotepath, self.transport)
|
||||
except nfs.NfsException, exc:
|
||||
except nfs.NfsException as exc:
|
||||
raise xs_errors.XenError('NFSMount', opterr=exc.errstr)
|
||||
|
||||
|
||||
|
|
@ -150,7 +150,7 @@ class NFSSR(FileSR.FileSR):
|
|||
|
||||
try:
|
||||
nfs.unmount(self.path, True)
|
||||
except nfs.NfsException, exc:
|
||||
except nfs.NfsException as exc:
|
||||
raise xs_errors.XenError('NFSUnMount', opterr=exc.errstr)
|
||||
|
||||
return super(NFSSR, self).detach(sr_uuid)
|
||||
|
|
@ -167,7 +167,7 @@ class NFSSR(FileSR.FileSR):
|
|||
self.remotepath = self.dconf['serverpath']
|
||||
try:
|
||||
self.mount_remotepath(sr_uuid)
|
||||
except Exception, exn:
|
||||
except Exception as exn:
|
||||
try:
|
||||
os.rmdir(self.path)
|
||||
except:
|
||||
|
|
@ -192,7 +192,7 @@ class NFSSR(FileSR.FileSR):
|
|||
if util.ioretry(lambda: util.pathexists(newpath)):
|
||||
util.ioretry(lambda: os.rmdir(newpath))
|
||||
self.detach(sr_uuid)
|
||||
except util.CommandException, inst:
|
||||
except util.CommandException as inst:
|
||||
self.detach(sr_uuid)
|
||||
if inst.code != errno.ENOENT:
|
||||
raise xs_errors.XenError('NFSDelete')
|
||||
|
|
@ -209,7 +209,7 @@ class NFSSR(FileSR.FileSR):
|
|||
def scan_exports(self, target):
|
||||
util.SMlog("scanning2 (target=%s)" % target)
|
||||
dom = nfs.scan_exports(target)
|
||||
print >>sys.stderr,dom.toprettyxml()
|
||||
print(dom.toprettyxml(), file=sys.stderr)
|
||||
|
||||
class NFSFileVDI(FileSR.FileVDI):
|
||||
def attach(self, sr_uuid, vdi_uuid):
|
||||
|
|
|
|||
|
|
@ -47,7 +47,7 @@ def log(s):
|
|||
if get_log_destination() == 'syslog':
|
||||
syslog.syslog(s)
|
||||
else:
|
||||
print >>sys.stderr, s
|
||||
print(s, file=sys.stderr)
|
||||
|
||||
# Exceptions.
|
||||
|
||||
|
|
@ -244,8 +244,8 @@ def _strlist_from_xml(n, ltag, itag):
|
|||
def _otherconfig_to_xml(xml, parent, val, attrs):
|
||||
otherconfig = xml.createElement("other_config")
|
||||
parent.appendChild(otherconfig)
|
||||
for n,v in val.items():
|
||||
if not n in attrs:
|
||||
for n,v in list(val.items()):
|
||||
if n not in attrs:
|
||||
raise Error("Unknown other-config attribute: %s" % n)
|
||||
_str_to_xml(xml, otherconfig, n, v)
|
||||
def _otherconfig_from_xml(n, attrs):
|
||||
|
|
@ -270,10 +270,10 @@ _VLAN_XML_TAG = "vlan"
|
|||
_BOND_XML_TAG = "bond"
|
||||
_NETWORK_XML_TAG = "network"
|
||||
|
||||
_ETHTOOL_OTHERCONFIG_ATTRS = ['ethtool-%s' % x for x in 'autoneg', 'speed', 'duplex', 'rx', 'tx', 'sg', 'tso', 'ufo', 'gso' ]
|
||||
_ETHTOOL_OTHERCONFIG_ATTRS = ['ethtool-%s' % x for x in ('autoneg', 'speed', 'duplex', 'rx', 'tx', 'sg', 'tso', 'ufo', 'gso') ]
|
||||
|
||||
_PIF_OTHERCONFIG_ATTRS = [ 'domain', 'peerdns', 'defaultroute', 'mtu', 'static-routes' ] + \
|
||||
[ 'bond-%s' % x for x in 'mode', 'miimon', 'downdelay', 'updelay', 'use_carrier' ] + \
|
||||
[ 'bond-%s' % x for x in ('mode', 'miimon', 'downdelay', 'updelay', 'use_carrier') ] + \
|
||||
_ETHTOOL_OTHERCONFIG_ATTRS
|
||||
|
||||
_PIF_ATTRS = { 'uuid': (_str_to_xml,_str_from_xml),
|
||||
|
|
@ -358,11 +358,11 @@ class DatabaseCache(object):
|
|||
return dict(defs)
|
||||
|
||||
def __pif_on_host(self,pif):
|
||||
return self.__pifs.has_key(pif)
|
||||
return pif in self.__pifs
|
||||
|
||||
def __get_pif_records_from_xapi(self, session, host):
|
||||
self.__pifs = {}
|
||||
for (p,rec) in session.xenapi.PIF.get_all_records().items():
|
||||
for (p,rec) in list(session.xenapi.PIF.get_all_records().items()):
|
||||
if rec['host'] != host:
|
||||
continue
|
||||
self.__pifs[p] = {}
|
||||
|
|
@ -370,12 +370,12 @@ class DatabaseCache(object):
|
|||
self.__pifs[p][f] = rec[f]
|
||||
self.__pifs[p]['other_config'] = {}
|
||||
for f in _PIF_OTHERCONFIG_ATTRS:
|
||||
if not rec['other_config'].has_key(f): continue
|
||||
if f not in rec['other_config']: continue
|
||||
self.__pifs[p]['other_config'][f] = rec['other_config'][f]
|
||||
|
||||
def __get_vlan_records_from_xapi(self, session):
|
||||
self.__vlans = {}
|
||||
for (v,rec) in session.xenapi.VLAN.get_all_records().items():
|
||||
for (v,rec) in list(session.xenapi.VLAN.get_all_records().items()):
|
||||
if not self.__pif_on_host(rec['untagged_PIF']):
|
||||
continue
|
||||
self.__vlans[v] = {}
|
||||
|
|
@ -384,7 +384,7 @@ class DatabaseCache(object):
|
|||
|
||||
def __get_bond_records_from_xapi(self, session):
|
||||
self.__bonds = {}
|
||||
for (b,rec) in session.xenapi.Bond.get_all_records().items():
|
||||
for (b,rec) in list(session.xenapi.Bond.get_all_records().items()):
|
||||
if not self.__pif_on_host(rec['master']):
|
||||
continue
|
||||
self.__bonds[b] = {}
|
||||
|
|
@ -393,7 +393,7 @@ class DatabaseCache(object):
|
|||
|
||||
def __get_network_records_from_xapi(self, session):
|
||||
self.__networks = {}
|
||||
for (n,rec) in session.xenapi.network.get_all_records().items():
|
||||
for (n,rec) in list(session.xenapi.network.get_all_records().items()):
|
||||
self.__networks[n] = {}
|
||||
for f in _NETWORK_ATTRS:
|
||||
if f == "PIFs":
|
||||
|
|
@ -407,7 +407,7 @@ class DatabaseCache(object):
|
|||
self.__networks[n][f] = rec[f]
|
||||
self.__networks[n]['other_config'] = {}
|
||||
for f in _NETWORK_OTHERCONFIG_ATTRS:
|
||||
if not rec['other_config'].has_key(f): continue
|
||||
if f not in rec['other_config']: continue
|
||||
self.__networks[n]['other_config'][f] = rec['other_config'][f]
|
||||
|
||||
def __to_xml(self, xml, parent, key, ref, rec, attrs):
|
||||
|
|
@ -417,8 +417,8 @@ class DatabaseCache(object):
|
|||
if ref:
|
||||
e.setAttribute('ref', ref)
|
||||
|
||||
for n,v in rec.items():
|
||||
if attrs.has_key(n):
|
||||
for n,v in list(rec.items()):
|
||||
if n in attrs:
|
||||
h,_ = attrs[n]
|
||||
h(xml, e, n, v)
|
||||
else:
|
||||
|
|
@ -449,7 +449,7 @@ class DatabaseCache(object):
|
|||
try:
|
||||
|
||||
inventory = self.__read_xensource_inventory()
|
||||
assert(inventory.has_key('INSTALLATION_UUID'))
|
||||
assert('INSTALLATION_UUID' in inventory)
|
||||
log("host uuid is %s" % inventory['INSTALLATION_UUID'])
|
||||
|
||||
host = session.xenapi.host.get_by_uuid(inventory['INSTALLATION_UUID'])
|
||||
|
|
@ -499,13 +499,13 @@ class DatabaseCache(object):
|
|||
|
||||
xml = getDOMImplementation().createDocument(
|
||||
None, "xenserver-network-configuration", None)
|
||||
for (ref,rec) in self.__pifs.items():
|
||||
for (ref,rec) in list(self.__pifs.items()):
|
||||
self.__to_xml(xml, xml.documentElement, _PIF_XML_TAG, ref, rec, _PIF_ATTRS)
|
||||
for (ref,rec) in self.__bonds.items():
|
||||
for (ref,rec) in list(self.__bonds.items()):
|
||||
self.__to_xml(xml, xml.documentElement, _BOND_XML_TAG, ref, rec, _BOND_ATTRS)
|
||||
for (ref,rec) in self.__vlans.items():
|
||||
for (ref,rec) in list(self.__vlans.items()):
|
||||
self.__to_xml(xml, xml.documentElement, _VLAN_XML_TAG, ref, rec, _VLAN_ATTRS)
|
||||
for (ref,rec) in self.__networks.items():
|
||||
for (ref,rec) in list(self.__networks.items()):
|
||||
self.__to_xml(xml, xml.documentElement, _NETWORK_XML_TAG, ref, rec,
|
||||
_NETWORK_ATTRS)
|
||||
|
||||
|
|
@ -514,9 +514,7 @@ class DatabaseCache(object):
|
|||
f.close()
|
||||
|
||||
def get_pif_by_uuid(self, uuid):
|
||||
pifs = map(lambda (ref,rec): ref,
|
||||
filter(lambda (ref,rec): uuid == rec['uuid'],
|
||||
self.__pifs.items()))
|
||||
pifs = [ref_rec3[0] for ref_rec3 in [ref_rec for ref_rec in list(self.__pifs.items()) if uuid == ref_rec[1]['uuid']]]
|
||||
if len(pifs) == 0:
|
||||
raise Error("Unknown PIF \"%s\"" % uuid)
|
||||
elif len(pifs) > 1:
|
||||
|
|
@ -525,14 +523,10 @@ class DatabaseCache(object):
|
|||
return pifs[0]
|
||||
|
||||
def get_pifs_by_device(self, device):
|
||||
return map(lambda (ref,rec): ref,
|
||||
filter(lambda (ref,rec): rec['device'] == device,
|
||||
self.__pifs.items()))
|
||||
return [ref_rec4[0] for ref_rec4 in [ref_rec1 for ref_rec1 in list(self.__pifs.items()) if ref_rec1[1]['device'] == device]]
|
||||
|
||||
def get_pif_by_bridge(self, bridge):
|
||||
networks = map(lambda (ref,rec): ref,
|
||||
filter(lambda (ref,rec): rec['bridge'] == bridge,
|
||||
self.__networks.items()))
|
||||
networks = [ref_rec5[0] for ref_rec5 in [ref_rec2 for ref_rec2 in list(self.__networks.items()) if ref_rec2[1]['bridge'] == bridge]]
|
||||
if len(networks) == 0:
|
||||
raise Error("No matching network \"%s\"" % bridge)
|
||||
|
||||
|
|
@ -549,13 +543,13 @@ class DatabaseCache(object):
|
|||
return answer
|
||||
|
||||
def get_pif_record(self, pif):
|
||||
if self.__pifs.has_key(pif):
|
||||
if pif in self.__pifs:
|
||||
return self.__pifs[pif]
|
||||
raise Error("Unknown PIF \"%s\"" % pif)
|
||||
def get_all_pifs(self):
|
||||
return self.__pifs
|
||||
def pif_exists(self, pif):
|
||||
return self.__pifs.has_key(pif)
|
||||
return pif in self.__pifs
|
||||
|
||||
def get_management_pif(self):
|
||||
""" Returns the management pif on host
|
||||
|
|
@ -567,18 +561,18 @@ class DatabaseCache(object):
|
|||
return None
|
||||
|
||||
def get_network_record(self, network):
|
||||
if self.__networks.has_key(network):
|
||||
if network in self.__networks:
|
||||
return self.__networks[network]
|
||||
raise Error("Unknown network \"%s\"" % network)
|
||||
|
||||
def get_bond_record(self, bond):
|
||||
if self.__bonds.has_key(bond):
|
||||
if bond in self.__bonds:
|
||||
return self.__bonds[bond]
|
||||
else:
|
||||
return None
|
||||
|
||||
def get_vlan_record(self, vlan):
|
||||
if self.__vlans.has_key(vlan):
|
||||
if vlan in self.__vlans:
|
||||
return self.__vlans[vlan]
|
||||
else:
|
||||
return None
|
||||
|
|
@ -589,19 +583,19 @@ class DatabaseCache(object):
|
|||
|
||||
def ethtool_settings(oc):
|
||||
settings = []
|
||||
if oc.has_key('ethtool-speed'):
|
||||
if 'ethtool-speed' in oc:
|
||||
val = oc['ethtool-speed']
|
||||
if val in ["10", "100", "1000"]:
|
||||
settings += ['speed', val]
|
||||
else:
|
||||
log("Invalid value for ethtool-speed = %s. Must be 10|100|1000." % val)
|
||||
if oc.has_key('ethtool-duplex'):
|
||||
if 'ethtool-duplex' in oc:
|
||||
val = oc['ethtool-duplex']
|
||||
if val in ["10", "100", "1000"]:
|
||||
settings += ['duplex', 'val']
|
||||
else:
|
||||
log("Invalid value for ethtool-duplex = %s. Must be half|full." % val)
|
||||
if oc.has_key('ethtool-autoneg'):
|
||||
if 'ethtool-autoneg' in oc:
|
||||
val = oc['ethtool-autoneg']
|
||||
if val in ["true", "on"]:
|
||||
settings += ['autoneg', 'on']
|
||||
|
|
@ -611,7 +605,7 @@ def ethtool_settings(oc):
|
|||
log("Invalid value for ethtool-autoneg = %s. Must be on|true|off|false." % val)
|
||||
offload = []
|
||||
for opt in ("rx", "tx", "sg", "tso", "ufo", "gso"):
|
||||
if oc.has_key("ethtool-" + opt):
|
||||
if "ethtool-" + opt in oc:
|
||||
val = oc["ethtool-" + opt]
|
||||
if val in ["true", "on"]:
|
||||
offload += [opt, 'on']
|
||||
|
|
@ -631,12 +625,12 @@ def mtu_setting(nw, type, oc):
|
|||
mtu = None
|
||||
|
||||
nwrec = db().get_network_record(nw)
|
||||
if nwrec.has_key('MTU'):
|
||||
if 'MTU' in nwrec:
|
||||
mtu = nwrec['MTU']
|
||||
else:
|
||||
mtu = "1500"
|
||||
|
||||
if oc.has_key('mtu'):
|
||||
if 'mtu' in oc:
|
||||
log("Override Network.MTU setting on bridge %s from %s.MTU is %s" % \
|
||||
(nwrec['bridge'], type, mtu))
|
||||
mtu = oc['mtu']
|
||||
|
|
@ -645,7 +639,7 @@ def mtu_setting(nw, type, oc):
|
|||
try:
|
||||
int(mtu) # Check that the value is an integer
|
||||
return mtu
|
||||
except ValueError, x:
|
||||
except ValueError as x:
|
||||
log("Invalid value for mtu = %s" % mtu)
|
||||
|
||||
return None
|
||||
|
|
@ -854,7 +848,7 @@ def DatapathFactory(pif):
|
|||
network_conf = open(root_prefix() + "/etc/xensource/network.conf", 'r')
|
||||
network_backend = network_conf.readline().strip()
|
||||
network_conf.close()
|
||||
except Exception, e:
|
||||
except Exception as e:
|
||||
raise Error("failed to determine network backend:" + e)
|
||||
|
||||
if network_backend == "bridge":
|
||||
|
|
|
|||
|
|
@ -65,19 +65,19 @@ class NFSSR(FileSR.FileSR):
|
|||
def load(self, sr_uuid):
|
||||
self.lock = Lock(vhdutil.LOCK_TYPE_SR, self.uuid)
|
||||
self.sr_vditype = SR.DEFAULT_TAP
|
||||
if not self.dconf.has_key('server'):
|
||||
if 'server' not in self.dconf:
|
||||
raise xs_errors.XenError('ConfigServerMissing')
|
||||
self.remoteserver = self.dconf['server']
|
||||
self.path = os.path.join(SR.MOUNT_BASE, sr_uuid)
|
||||
|
||||
# Test for the optional 'nfsoptions' dconf attribute
|
||||
self.transport = DEFAULT_TRANSPORT
|
||||
if self.dconf.has_key('useUDP') and self.dconf['useUDP'] == 'true':
|
||||
if 'useUDP' in self.dconf and self.dconf['useUDP'] == 'true':
|
||||
self.transport = "udp"
|
||||
|
||||
|
||||
def validate_remotepath(self, scan):
|
||||
if not self.dconf.has_key('serverpath'):
|
||||
if 'serverpath' not in self.dconf:
|
||||
if scan:
|
||||
try:
|
||||
self.scan_exports(self.dconf['server'])
|
||||
|
|
@ -91,7 +91,7 @@ class NFSSR(FileSR.FileSR):
|
|||
def check_server(self):
|
||||
try:
|
||||
nfs.check_server_tcp(self.remoteserver)
|
||||
except nfs.NfsException, exc:
|
||||
except nfs.NfsException as exc:
|
||||
raise xs_errors.XenError('NFSVersion',
|
||||
opterr=exc.errstr)
|
||||
|
||||
|
|
@ -99,7 +99,7 @@ class NFSSR(FileSR.FileSR):
|
|||
def mount(self, mountpoint, remotepath):
|
||||
try:
|
||||
nfs.soft_mount(mountpoint, self.remoteserver, remotepath, self.transport)
|
||||
except nfs.NfsException, exc:
|
||||
except nfs.NfsException as exc:
|
||||
raise xs_errors.XenError('NFSMount', opterr=exc.errstr)
|
||||
|
||||
|
||||
|
|
@ -153,7 +153,7 @@ class NFSSR(FileSR.FileSR):
|
|||
|
||||
try:
|
||||
nfs.unmount(self.path, True)
|
||||
except nfs.NfsException, exc:
|
||||
except nfs.NfsException as exc:
|
||||
raise xs_errors.XenError('NFSUnMount', opterr=exc.errstr)
|
||||
|
||||
return super(NFSSR, self).detach(sr_uuid)
|
||||
|
|
@ -171,7 +171,7 @@ class NFSSR(FileSR.FileSR):
|
|||
self.remotepath = self.dconf['serverpath']
|
||||
try:
|
||||
self.mount_remotepath(sr_uuid)
|
||||
except Exception, exn:
|
||||
except Exception as exn:
|
||||
try:
|
||||
os.rmdir(self.path)
|
||||
except:
|
||||
|
|
@ -197,7 +197,7 @@ class NFSSR(FileSR.FileSR):
|
|||
if util.ioretry(lambda: util.pathexists(newpath)):
|
||||
util.ioretry(lambda: os.rmdir(newpath))
|
||||
self.detach(sr_uuid)
|
||||
except util.CommandException, inst:
|
||||
except util.CommandException as inst:
|
||||
self.detach(sr_uuid)
|
||||
if inst.code != errno.ENOENT:
|
||||
raise xs_errors.XenError('NFSDelete')
|
||||
|
|
@ -214,7 +214,7 @@ class NFSSR(FileSR.FileSR):
|
|||
def scan_exports(self, target):
|
||||
util.SMlog("scanning2 (target=%s)" % target)
|
||||
dom = nfs.scan_exports(target)
|
||||
print >>sys.stderr,dom.toprettyxml()
|
||||
print(dom.toprettyxml(), file=sys.stderr)
|
||||
|
||||
class NFSFileVDI(FileSR.FileVDI):
|
||||
def attach(self, sr_uuid, vdi_uuid):
|
||||
|
|
|
|||
|
|
@ -67,19 +67,19 @@ class NFSSR(FileSR.FileSR):
|
|||
self.ops_exclusive = FileSR.OPS_EXCLUSIVE
|
||||
self.lock = Lock(vhdutil.LOCK_TYPE_SR, self.uuid)
|
||||
self.sr_vditype = SR.DEFAULT_TAP
|
||||
if not self.dconf.has_key('server'):
|
||||
if 'server' not in self.dconf:
|
||||
raise xs_errors.XenError('ConfigServerMissing')
|
||||
self.remoteserver = self.dconf['server']
|
||||
self.path = os.path.join(SR.MOUNT_BASE, sr_uuid)
|
||||
|
||||
# Test for the optional 'nfsoptions' dconf attribute
|
||||
self.transport = DEFAULT_TRANSPORT
|
||||
if self.dconf.has_key('useUDP') and self.dconf['useUDP'] == 'true':
|
||||
if 'useUDP' in self.dconf and self.dconf['useUDP'] == 'true':
|
||||
self.transport = "udp"
|
||||
|
||||
|
||||
def validate_remotepath(self, scan):
|
||||
if not self.dconf.has_key('serverpath'):
|
||||
if 'serverpath' not in self.dconf:
|
||||
if scan:
|
||||
try:
|
||||
self.scan_exports(self.dconf['server'])
|
||||
|
|
@ -93,7 +93,7 @@ class NFSSR(FileSR.FileSR):
|
|||
def check_server(self):
|
||||
try:
|
||||
nfs.check_server_tcp(self.remoteserver)
|
||||
except nfs.NfsException, exc:
|
||||
except nfs.NfsException as exc:
|
||||
raise xs_errors.XenError('NFSVersion',
|
||||
opterr=exc.errstr)
|
||||
|
||||
|
|
@ -101,7 +101,7 @@ class NFSSR(FileSR.FileSR):
|
|||
def mount(self, mountpoint, remotepath):
|
||||
try:
|
||||
nfs.soft_mount(mountpoint, self.remoteserver, remotepath, self.transport)
|
||||
except nfs.NfsException, exc:
|
||||
except nfs.NfsException as exc:
|
||||
raise xs_errors.XenError('NFSMount', opterr=exc.errstr)
|
||||
|
||||
|
||||
|
|
@ -151,7 +151,7 @@ class NFSSR(FileSR.FileSR):
|
|||
|
||||
try:
|
||||
nfs.unmount(self.path, True)
|
||||
except nfs.NfsException, exc:
|
||||
except nfs.NfsException as exc:
|
||||
raise xs_errors.XenError('NFSUnMount', opterr=exc.errstr)
|
||||
|
||||
return super(NFSSR, self).detach(sr_uuid)
|
||||
|
|
@ -168,7 +168,7 @@ class NFSSR(FileSR.FileSR):
|
|||
self.remotepath = self.dconf['serverpath']
|
||||
try:
|
||||
self.mount_remotepath(sr_uuid)
|
||||
except Exception, exn:
|
||||
except Exception as exn:
|
||||
try:
|
||||
os.rmdir(self.path)
|
||||
except:
|
||||
|
|
@ -193,7 +193,7 @@ class NFSSR(FileSR.FileSR):
|
|||
if util.ioretry(lambda: util.pathexists(newpath)):
|
||||
util.ioretry(lambda: os.rmdir(newpath))
|
||||
self.detach(sr_uuid)
|
||||
except util.CommandException, inst:
|
||||
except util.CommandException as inst:
|
||||
self.detach(sr_uuid)
|
||||
if inst.code != errno.ENOENT:
|
||||
raise xs_errors.XenError('NFSDelete')
|
||||
|
|
@ -210,7 +210,7 @@ class NFSSR(FileSR.FileSR):
|
|||
def scan_exports(self, target):
|
||||
util.SMlog("scanning2 (target=%s)" % target)
|
||||
dom = nfs.scan_exports(target)
|
||||
print >>sys.stderr,dom.toprettyxml()
|
||||
print(dom.toprettyxml(), file=sys.stderr)
|
||||
|
||||
class NFSFileVDI(FileSR.FileVDI):
|
||||
def attach(self, sr_uuid, vdi_uuid):
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ import SR, VDI, SRCommand, FileSR, util
|
|||
import errno
|
||||
import os, re, sys
|
||||
import xml.dom.minidom
|
||||
import xmlrpclib
|
||||
import xmlrpc.client
|
||||
import xs_errors
|
||||
import nfs
|
||||
import vhdutil
|
||||
|
|
@ -72,19 +72,19 @@ class NFSSR(FileSR.FileSR):
|
|||
self.lock = Lock(vhdutil.LOCK_TYPE_SR, self.uuid)
|
||||
self.sr_vditype = SR.DEFAULT_TAP
|
||||
self.driver_config = DRIVER_CONFIG
|
||||
if not self.dconf.has_key('server'):
|
||||
if 'server' not in self.dconf:
|
||||
raise xs_errors.XenError('ConfigServerMissing')
|
||||
self.remoteserver = self.dconf['server']
|
||||
self.path = os.path.join(SR.MOUNT_BASE, sr_uuid)
|
||||
|
||||
# Test for the optional 'nfsoptions' dconf attribute
|
||||
self.transport = DEFAULT_TRANSPORT
|
||||
if self.dconf.has_key('useUDP') and self.dconf['useUDP'] == 'true':
|
||||
if 'useUDP' in self.dconf and self.dconf['useUDP'] == 'true':
|
||||
self.transport = "udp"
|
||||
|
||||
|
||||
def validate_remotepath(self, scan):
|
||||
if not self.dconf.has_key('serverpath'):
|
||||
if 'serverpath' not in self.dconf:
|
||||
if scan:
|
||||
try:
|
||||
self.scan_exports(self.dconf['server'])
|
||||
|
|
@ -98,7 +98,7 @@ class NFSSR(FileSR.FileSR):
|
|||
def check_server(self):
|
||||
try:
|
||||
nfs.check_server_tcp(self.remoteserver)
|
||||
except nfs.NfsException, exc:
|
||||
except nfs.NfsException as exc:
|
||||
raise xs_errors.XenError('NFSVersion',
|
||||
opterr=exc.errstr)
|
||||
|
||||
|
|
@ -106,7 +106,7 @@ class NFSSR(FileSR.FileSR):
|
|||
def mount(self, mountpoint, remotepath):
|
||||
try:
|
||||
nfs.soft_mount(mountpoint, self.remoteserver, remotepath, self.transport)
|
||||
except nfs.NfsException, exc:
|
||||
except nfs.NfsException as exc:
|
||||
raise xs_errors.XenError('NFSMount', opterr=exc.errstr)
|
||||
|
||||
|
||||
|
|
@ -157,7 +157,7 @@ class NFSSR(FileSR.FileSR):
|
|||
|
||||
try:
|
||||
nfs.unmount(self.path, True)
|
||||
except nfs.NfsException, exc:
|
||||
except nfs.NfsException as exc:
|
||||
raise xs_errors.XenError('NFSUnMount', opterr=exc.errstr)
|
||||
|
||||
return super(NFSSR, self).detach(sr_uuid)
|
||||
|
|
@ -174,7 +174,7 @@ class NFSSR(FileSR.FileSR):
|
|||
self.remotepath = self.dconf['serverpath']
|
||||
try:
|
||||
self.mount_remotepath(sr_uuid)
|
||||
except Exception, exn:
|
||||
except Exception as exn:
|
||||
try:
|
||||
os.rmdir(self.path)
|
||||
except:
|
||||
|
|
@ -199,7 +199,7 @@ class NFSSR(FileSR.FileSR):
|
|||
if util.ioretry(lambda: util.pathexists(newpath)):
|
||||
util.ioretry(lambda: os.rmdir(newpath))
|
||||
self.detach(sr_uuid)
|
||||
except util.CommandException, inst:
|
||||
except util.CommandException as inst:
|
||||
self.detach(sr_uuid)
|
||||
if inst.code != errno.ENOENT:
|
||||
raise xs_errors.XenError('NFSDelete')
|
||||
|
|
@ -216,11 +216,11 @@ class NFSSR(FileSR.FileSR):
|
|||
def scan_exports(self, target):
|
||||
util.SMlog("scanning2 (target=%s)" % target)
|
||||
dom = nfs.scan_exports(target)
|
||||
print >>sys.stderr,dom.toprettyxml()
|
||||
print(dom.toprettyxml(), file=sys.stderr)
|
||||
|
||||
class NFSFileVDI(FileSR.FileVDI):
|
||||
def attach(self, sr_uuid, vdi_uuid):
|
||||
if self.sr.srcmd.params.has_key("vdi_ref"):
|
||||
if "vdi_ref" in self.sr.srcmd.params:
|
||||
try:
|
||||
vdi_ref = self.sr.srcmd.params['vdi_ref']
|
||||
self.session.xenapi.VDI.remove_from_xenstore_data(vdi_ref, \
|
||||
|
|
@ -246,8 +246,8 @@ class NFSFileVDI(FileSR.FileVDI):
|
|||
resp['command'] = 'vdi_attach_from_config'
|
||||
# Return the 'config' encoded within a normal XMLRPC response so that
|
||||
# we can use the regular response/error parsing code.
|
||||
config = xmlrpclib.dumps(tuple([resp]), "vdi_attach_from_config")
|
||||
return xmlrpclib.dumps((config,), "", True)
|
||||
config = xmlrpc.client.dumps(tuple([resp]), "vdi_attach_from_config")
|
||||
return xmlrpc.client.dumps((config,), "", True)
|
||||
|
||||
def attach_from_config(self, sr_uuid, vdi_uuid):
|
||||
"""Used for HA State-file only. Will not just attach the VDI but
|
||||
|
|
|
|||
|
|
@ -116,7 +116,7 @@ def copy_priv_key(newKey):
|
|||
return 0
|
||||
print ("Copying new private key file as it is not matching with old file")
|
||||
shutil.copyfile(newKey, currDir + pathSep + "id_rsa.cloud")
|
||||
os.chmod(currDir + pathSep + "id_rsa.cloud", 0644)
|
||||
os.chmod(currDir + pathSep + "id_rsa.cloud", 0o644)
|
||||
return 0
|
||||
|
||||
if len(sys.argv) != 4:
|
||||
|
|
|
|||
Loading…
Reference in New Issue