Skip to content
Draft
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
12 changes: 5 additions & 7 deletions debian/cloudstack-common.postinst
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,12 @@

set -e
CLOUDUTILS_DIR="/usr/share/pyshared/"
DIST_DIR=$(python3 -c "from distutils.sysconfig import get_python_lib; print(get_python_lib(1))")
# distutils was removed in Python 3.12 (Ubuntu 24.04); the Debian/Ubuntu-patched
# sysconfig 'deb_system' scheme gives the same /usr/lib/python3/dist-packages path.
DIST_DIR=$(python3 -c "import sysconfig; print(sysconfig.get_path('platlib', 'deb_system'))")

if which pycompile >/dev/null 2>&1; then
pycompile -p cloudstack-common
fi

if which pycompile >/dev/null 2>&1; then
pycompile -p cloudstack-common /usr/share/cloudstack-common
if command -v py3compile >/dev/null 2>&1; then
py3compile -p cloudstack-common
fi

cp $CLOUDUTILS_DIR/cloud_utils.py $DIST_DIR
Expand Down
2 changes: 1 addition & 1 deletion debian/control
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Homepage: http://www.cloudstack.org/

Package: cloudstack-common
Architecture: all
Depends: ${misc:Depends}, ${python3:Depends}, genisoimage, nfs-common, python3-pip, python3-distutils | python3-distutils-extra, python3-netaddr, uuid-runtime
Depends: ${misc:Depends}, ${python3:Depends}, genisoimage, nfs-common, python3-pip, python3-netaddr, uuid-runtime
Conflicts: cloud-scripts, cloud-utils, cloud-system-iso, cloud-console-proxy, cloud-daemonize, cloud-deps, cloud-python, cloud-setup
Description: A common package which contains files which are shared by several CloudStack packages

Expand Down
24 changes: 12 additions & 12 deletions scripts/network/exdhcp/dhcpd_edithosts.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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

Expand All @@ -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

Expand All @@ -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]
Expand All @@ -115,7 +115,7 @@ def insert_host_entry(mac, ip, hostname, dns, gateway, next_server):
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)
Expand Down
6 changes: 3 additions & 3 deletions scripts/network/ping/prepare_kickstart_bootfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:]
Expand Down
12 changes: 6 additions & 6 deletions scripts/network/ping/prepare_kickstart_kernel_initrd.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
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)

Expand All @@ -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):
Expand All @@ -61,14 +61,14 @@ def copy_from_nfs(src, dst):

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_kernel_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())
8 changes: 4 additions & 4 deletions scripts/network/ping/prepare_tftp_bootfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -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_restore 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:]
Expand All @@ -89,7 +89,7 @@ def prepare(is_restore):
elif cmd == "backup":
ret = prepare(False)
else:
print "Unknown cmd: %s"%cmd
print("Unknown cmd: %s"%cmd)
ret = 1

exit(ret)
47 changes: 23 additions & 24 deletions scripts/storage/secondary/cloud-install-sys-tmplt.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/python
#!/usr/bin/python3
# -*- coding: utf-8 -*-
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
Expand All @@ -19,7 +19,7 @@

import argparse
import sys
import urllib
import urllib.request, urllib.parse, urllib.error
import uuid
import subprocess
import os
Expand Down Expand Up @@ -90,7 +90,6 @@ def populateOptions(self):
self.databaseuserpassword = ""
if self.args.templatesuffix:
self.templatesuffix = self.args.templatesuffix
print 'Password for DB: %s'%self.databaseuserpassword

def errorAndExit(self, msg):
err = '''\n\nWe apologize for below error:
Expand All @@ -108,7 +107,7 @@ def errorAndExit(self, msg):
sys.exit(1)

def runCmd(self, cmds):
process = subprocess.Popen(' '.join(cmds), shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
process = subprocess.Popen(' '.join(cmds), shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True)
stdout, stderr = process.communicate()
print(stdout)
if process.returncode != 0:
Expand All @@ -117,11 +116,11 @@ def runCmd(self, cmds):

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)
Comment on lines 118 to +122
except Exception as e:
err = '''Encountering an error when executing mysql script\n%s''' % str(e)
self.errorAndExit(err)
return templateId
Expand All @@ -137,9 +136,9 @@ def fetchTemplateDetails(self):

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)

Expand All @@ -150,54 +149,54 @@ def report(tmp, blocknr, blocksize, size):
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()
compressedFile.close()
decompressedFile = file(fileName, 'wb')
decompressedFile = open(fileName, 'wb')
decompressedFile.write(decompressedData)
decompressedFile.close()
elif self.fileextension == 'bz2':
compressedFile = bz2.BZ2File(self.systemvmtemplatepath)
decompressedData = compressedFile.read()
compressedFile.close()
decompressedFile = file(fileName, 'wb')
decompressedFile = open(fileName, 'wb')
decompressedFile.write(decompressedData)
decompressedFile.close()
print ''
print('')
elif self.fileextension == 'zip':
zippedFile = zipfile.ZipFile(self.systemvmtemplatepath, 'r')
zippedFiles = zippedFile.namelist()
compressedFile = zippedFiles[0]
decompressedData = zippedFile.read(compressedFile)
decompressedFile = file(fileName, 'wb')
decompressedFile = open(fileName, 'wb')
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)

def writeProperties(self):
propertiesFile = file(self.destDir + os.sep + 'template.properties', 'wb')
propertiesFile = open(self.destDir + os.sep + 'template.properties', 'w')
propertiesFile.write('filename=%s\n'%self.templateName)
propertiesFile.write('description=SystemVM Template\n')
propertiesFile.write('checksum=\n')
Expand Down Expand Up @@ -226,10 +225,10 @@ def run(self):
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()
Expand Down
Loading
Loading