Skip to content

Commit 5be4b2e

Browse files
author
Your Name
committed
Migrating scripts to python3
1 parent d0651f1 commit 5be4b2e

File tree

11 files changed

+152
-143
lines changed

11 files changed

+152
-143
lines changed

packaging/centos8/cloud.spec

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -49,14 +49,17 @@ BuildRequires: /usr/bin/mkisofs
4949
BuildRequires: maven => 3.0.0
5050
#BuildRequires: python-setuptools
5151

52+
Autoreq: no
53+
AutoReqProv: no
54+
5255
%description
5356
CloudStack is a highly-scalable elastic, open source,
5457
intelligent IaaS cloud implementation.
5558

5659
%package management
5760
Summary: CloudStack management server UI
5861
Requires: java-11-openjdk
59-
Requires: python
62+
Requires: python2
6063
Requires: python3
6164
Requires: bash
6265
Requires: gawk
@@ -74,23 +77,23 @@ Requires: /sbin/service
7477
Requires: /sbin/chkconfig
7578
Requires: /usr/bin/ssh-keygen
7679
Requires: genisoimage
77-
Requires: mysql-connector-python
80+
#Requires: mysql-connector-python
7881
Requires: ipmitool
7982
Requires: %{name}-common = %{_ver}
8083
Requires: iptables-services
8184
Requires: qemu-img
82-
Requires: python-dns
85+
Requires: python3-dns
8386
Group: System Environment/Libraries
8487
%description management
8588
The CloudStack management server is the central point of coordination,
8689
management, and intelligence in CloudStack.
8790

8891
%package common
8992
Summary: Apache CloudStack common files and scripts
90-
Requires: python
93+
Requires: python2
9194
Requires: python3
92-
Requires: python-argparse
93-
Requires: python-netaddr
95+
#Requires: python-argparse
96+
Requires: python3-netaddr
9497
Group: System Environment/Libraries
9598
%description common
9699
The Apache CloudStack files shared between agent and management server
@@ -110,7 +113,7 @@ Requires: net-tools
110113
Requires: iproute
111114
Requires: ipset
112115
Requires: perl
113-
Requires: libvirt-python
116+
Requires: python3-libvirt
114117
Requires: qemu-img
115118
Requires: qemu-kvm
116119
Provides: cloud-agent
@@ -146,9 +149,11 @@ Apache CloudStack command line interface
146149

147150
%package marvin
148151
Summary: Apache CloudStack Marvin library
149-
Requires: python-pip
152+
Requires: python3-pip
153+
Requires: python2-pip
150154
Requires: gcc
151-
Requires: python-devel
155+
Requires: python3-devel
156+
Requires: python2-devel
152157
Requires: libffi-devel
153158
Requires: openssl-devel
154159
Group: System Environment/Libraries
@@ -599,3 +604,4 @@ pip install --upgrade /usr/share/cloudstack-marvin/Marvin-*.tar.gz
599604

600605
* Fri Oct 5 2012 Hugo Trippaers <hugo@apache.org> 4.1.0
601606
- new style spec file
607+

scripts/network/exdhcp/dhcpd_edithosts.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/usr/bin/python
1+
#!/usr/bin/python3
22
# Licensed to the Apache Software Foundation (ASF) under one
33
# or more contributor license agreements. See the NOTICE file
44
# distributed with this work for additional information
@@ -36,27 +36,27 @@ def lock():
3636
sleep(1)
3737
count = count + 1
3838
if count > sleep_max:
39-
print "Can not get file lock at %s, time expired" % file_lock
39+
print("Can not get file lock at %s, time expired" % file_lock)
4040
return False
4141

4242
try:
4343
f = open(file_lock, "w")
4444
f.close()
4545
return True
46-
except IOError,e:
47-
print "Cannot create file lock at /etc/dhcpd.conf_locked,", e
46+
except IOError as e:
47+
print("Cannot create file lock at /etc/dhcpd.conf_locked,", e)
4848
return False
4949

5050

5151
def unlock():
5252
if exists(file_lock) == False:
53-
print "Cannot find %s when unlocking, race condition happens" % file_lock
53+
print("Cannot find %s when unlocking, race condition happens" % file_lock)
5454
else:
5555
try:
5656
remove(file_lock)
5757
return True
58-
except IOError, e:
59-
print "Cannot remove file lock at %s" % file_lock
58+
except IOError as e:
59+
print("Cannot remove file lock at %s" % file_lock)
6060
return False
6161

6262
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):
6666
cmd = 'sed -i /"fixed-address %s"/d %s' % (ip, conf_path)
6767
ret = os.system(cmd)
6868
if ret != 0:
69-
print "Command %s failed" % cmd
69+
print("Command %s failed" % cmd)
7070
unlock()
7171
return 1
7272

7373
cmd = 'sed -i /"hardware ethernet %s"/d %s' % (mac, conf_path)
7474
ret = os.system(cmd)
7575
if ret != 0:
76-
print "Command %s failed" % cmd
76+
print("Command %s failed" % cmd)
7777
unlock()
7878
return 1
7979

@@ -84,14 +84,14 @@ def insert_host_entry(mac, ip, hostname, dns, gateway, next_server):
8484
cmd = '''echo '%s' >> %s''' % (entry, conf_path)
8585
ret = os.system(cmd)
8686
if ret != 0:
87-
print "Command %s failed" % cmd
87+
print("Command %s failed" % cmd)
8888
unlock()
8989
return 1
9090

9191
cmd = 'service dhcpd restart'
9292
ret = os.system(cmd)
9393
if ret != 0:
94-
print "Command %s failed" % cmd
94+
print("Command %s failed" % cmd)
9595
unlock()
9696
return 1
9797

@@ -102,7 +102,7 @@ def insert_host_entry(mac, ip, hostname, dns, gateway, next_server):
102102

103103
if __name__ == "__main__":
104104
if len(sys.argv) < 7:
105-
print usage
105+
print(usage)
106106
sys.exit(1)
107107

108108
mac = sys.argv[1]
@@ -115,7 +115,7 @@ def insert_host_entry(mac, ip, hostname, dns, gateway, next_server):
115115
if exists(conf_path) == False:
116116
conf_path = "/etc/dhcp/dhcpd.conf"
117117
if exists(conf_path) == False:
118-
print "Cannot find dhcpd.conf"
118+
print("Cannot find dhcpd.conf")
119119
sys.exit(1)
120120

121121
ret = insert_host_entry(mac, ip, hostname, dns, gateway, next_server)

scripts/network/ping/baremetal_user_data.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#!/usr/bin/python3
12
# Licensed to the Apache Software Foundation (ASF) under one
23
# or more contributor license agreements. See the NOTICE file
34
# distributed with this work for additional information

scripts/network/ping/prepare_kickstart_bootfile.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/usr/bin/python
1+
#!/usr/bin/python3
22
# Copyright 2012 Citrix Systems, Inc. Licensed under the
33
# Apache License, Version 2.0 (the "License"); you may not use this
44
# file except in compliance with the License. Citrix Systems, Inc.
@@ -62,14 +62,14 @@ def prepare():
6262
f.write(stuff)
6363
f.close()
6464
return 0
65-
except Exception, e:
66-
print e
65+
except Exception as e:
66+
print(e)
6767
return 1
6868

6969

7070
if __name__ == "__main__":
7171
if len(sys.argv) < 7:
72-
print "Usage: prepare_kickstart_bootfile.py tftp_dir mac kernel initrd ks_file ks_device"
72+
print("Usage: prepare_kickstart_bootfile.py tftp_dir mac kernel initrd ks_file ks_device")
7373
exit(1)
7474

7575
(tftp_dir, mac, kernel, initrd, ks_file, ks_device) = sys.argv[1:]

scripts/network/ping/prepare_kickstart_kernel_initrd.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/usr/bin/python
1+
#!/usr/bin/python3
22
# Licensed to the Apache Software Foundation (ASF) under one
33
# or more contributor license agreements. See the NOTICE file
44
# distributed with this work for additional information
@@ -26,7 +26,7 @@
2626
copy_to = None
2727

2828
def cmd(cmdstr, err=True):
29-
print cmdstr
29+
print(cmdstr)
3030
if os.system(cmdstr) != 0 and err:
3131
raise Exception("Failed to run shell command: %s" % cmdstr)
3232

@@ -36,7 +36,7 @@ def prepare():
3636
k = os.path.join(copy_to, "vmlinuz")
3737
i = os.path.join(copy_to, "initrd.img")
3838
if os.path.exists(k) and os.path.exists(i):
39-
print "Having template(%s) prepared already, skip copying" % copy_to
39+
print("Having template(%s) prepared already, skip copying" % copy_to)
4040
return 0
4141
else:
4242
if not os.path.exists(copy_to):
@@ -61,13 +61,13 @@ def copy_from_nfs(src, dst):
6161

6262
copy_from_nfs(kernel, copy_to)
6363
copy_from_nfs(initrd, copy_to)
64-
except Exception, e:
65-
print e
64+
except Exception as e:
65+
print(e)
6666
return 1
6767

6868
if __name__ == "__main__":
6969
if len(sys.argv) < 4:
70-
print "Usage: prepare_kickstart_kerneal_initrd.py path_to_kernel path_to_initrd path_kernel_initrd_copy_to"
70+
print("Usage: prepare_kickstart_kerneal_initrd.py path_to_kernel path_to_initrd path_kernel_initrd_copy_to")
7171
sys.exit(1)
7272

7373
(kernel, initrd, copy_to) = sys.argv[1:]

scripts/network/ping/prepare_tftp_bootfile.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/usr/bin/python
1+
#!/usr/bin/python3
22
# Licensed to the Apache Software Foundation (ASF) under one
33
# or more contributor license agreements. See the NOTICE file
44
# distributed with this work for additional information
@@ -72,14 +72,14 @@ def prepare(is_restore):
7272
f.write(stuff)
7373
f.close()
7474
return 0
75-
except Exception, e:
76-
print e
75+
except Exception as e:
76+
print(e)
7777
return 1
7878

7979

8080
if __name__ == "__main__":
8181
if len(sys.argv) < 12:
82-
print "Usage: prepare_tftp_bootfile.py tftp_dir mac cifs_server share directory image_to_restor cifs_username cifs_password ip netmask gateway"
82+
print("Usage: prepare_tftp_bootfile.py tftp_dir mac cifs_server share directory image_to_restor cifs_username cifs_password ip netmask gateway")
8383
exit(1)
8484

8585
(cmd, tftp_dir, mac, cifs_server, share, directory, template_dir, cifs_username, cifs_password, ip, netmask, gateway) = sys.argv[1:]
@@ -89,7 +89,7 @@ def prepare(is_restore):
8989
elif cmd == "backup":
9090
ret = prepare(False)
9191
else:
92-
print "Unknown cmd: %s"%cmd
92+
print("Unknown cmd: %s"%cmd)
9393
ret = 1
9494

9595
exit(ret)

scripts/storage/secondary/cloud-install-sys-tmplt.py

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/usr/bin/python
1+
#!/usr/bin/python3
22
# -*- coding: utf-8 -*-
33
# Licensed to the Apache Software Foundation (ASF) under one
44
# or more contributor license agreements. See the NOTICE file
@@ -19,7 +19,7 @@
1919

2020
import argparse
2121
import sys
22-
import urllib
22+
import urllib.request, urllib.parse, urllib.error
2323
import uuid
2424
import subprocess
2525
import os
@@ -90,7 +90,7 @@ def populateOptions(self):
9090
self.databaseuserpassword = ""
9191
if self.args.templatesuffix:
9292
self.templatesuffix = self.args.templatesuffix
93-
print 'Password for DB: %s'%self.databaseuserpassword
93+
print('Password for DB: %s'%self.databaseuserpassword)
9494

9595
def errorAndExit(self, msg):
9696
err = '''\n\nWe apologize for below error:
@@ -117,11 +117,11 @@ def runCmd(self, cmds):
117117

118118
def runMysql(self, query):
119119
try:
120-
print 'Running Query: %s' % query
120+
print('Running Query: %s' % query)
121121
mysqlCmds = ['mysql', '--user=%s'%self.databaseusername, '--host=%s'%self.databasehostname, '--password=%s'%self.databaseuserpassword, '--skip-column-names', '-U', 'cloud', '-e "%s"'%query]
122122
templateId = self.runCmd(mysqlCmds)
123-
print 'TemplateId is : %s' % templateId
124-
except Exception, e:
123+
print('TemplateId is : %s' % templateId)
124+
except Exception as e:
125125
err = '''Encountering an error when executing mysql script\n%s''' % str(e)
126126
self.errorAndExit(err)
127127
return templateId
@@ -137,9 +137,9 @@ def fetchTemplateDetails(self):
137137

138138
def downloadTemplate(self):
139139
self.systemvmtemplatepath = self.templateName + "." + self.fileextension
140-
print 'Downloading template from %s To %s' % (self.systemvmtemplateurl, self.systemvmtemplatepath)
140+
print('Downloading template from %s To %s' % (self.systemvmtemplateurl, self.systemvmtemplatepath))
141141
try:
142-
templateFileDownloadUrl = urllib.urlretrieve(self.systemvmtemplateurl, self.systemvmtemplatepath, reporthook=self.report)
142+
templateFileDownloadUrl = urllib.request.urlretrieve(self.systemvmtemplateurl, self.systemvmtemplatepath, reporthook=self.report)
143143
except Exception:
144144
self.errorAndExit("Failed to download template file from %s" % self.systemvmtemplateurl)
145145

@@ -150,23 +150,23 @@ def report(tmp, blocknr, blocksize, size):
150150
def installTemplate(self):
151151
destDir = self.mountpoint + os.sep + "template" + os.sep + "tmpl" + os.sep + "1" + os.sep + str(self.template)
152152
self.destDir = destDir
153-
print 'The desination Directory is : %s' % destDir
153+
print('The desination Directory is : %s' % destDir)
154154
try:
155155
if self.forcecleanup:
156156
if os.path.exists(destDir):
157157
shutil.rmtree(destDir)
158158
if not os.path.exists(destDir):
159159
os.makedirs(destDir)
160-
except Exception, e:
160+
except Exception as e:
161161
self.errorAndExit('Failed to create directories on the mounted path.. %s' % str (e))
162-
print 'Installing Template to : %s' % destDir
162+
print('Installing Template to : %s' % destDir)
163163
tmpFile = self.templateName + "." + "tmp"
164164
self.uncompressFile(tmpFile)
165-
print 'Moving the decompressed file to destination directory %s... which could take a long time, please wait' % destDir
165+
print('Moving the decompressed file to destination directory %s... which could take a long time, please wait' % destDir)
166166
shutil.move(tmpFile, destDir + os.sep + self.templateName)
167167

168168
def uncompressFile(self, fileName):
169-
print 'Uncompressing the file %s... which could take a long time, please wait' % self.systemvmtemplatepath
169+
print('Uncompressing the file %s... which could take a long time, please wait' % self.systemvmtemplatepath)
170170
if self.fileextension == 'gz':
171171
compressedFile = gzip.GzipFile(self.systemvmtemplatepath, 'rb')
172172
decompressedData = compressedFile.read()
@@ -181,7 +181,7 @@ def uncompressFile(self, fileName):
181181
decompressedFile = file(fileName, 'wb')
182182
decompressedFile.write(decompressedData)
183183
decompressedFile.close()
184-
print ''
184+
print('')
185185
elif self.fileextension == 'zip':
186186
zippedFile = zipfile.ZipFile(self.systemvmtemplatepath, 'r')
187187
zippedFiles = zippedFile.namelist()
@@ -191,7 +191,7 @@ def uncompressFile(self, fileName):
191191
decompressedFile.write(decompressedData)
192192
decompressedFile.close()
193193
zippedFile.close()
194-
print ''
194+
print('')
195195
else:
196196
self.errorAndExit('Not supported file type %s to decompress' % self.fileextension)
197197
self.fileSize = os.path.getsize(fileName)
@@ -226,11 +226,11 @@ def run(self):
226226
self.installTemplate()
227227
self.writeProperties()
228228
finally:
229-
print ''
230-
print ''
231-
print "CloudStack has successfully installed system template"
232-
print ''
229+
print('')
230+
print('')
231+
print("CloudStack has successfully installed system template")
232+
print('')
233233

234234
if __name__ == "__main__":
235235
o = InstallSysTemplate()
236-
o.run()
236+
o.run()

0 commit comments

Comments
 (0)