Skip to content

Commit 28b1a2b

Browse files
shwstpprdavidjumani
authored andcommitted
agent specific changes
Signed-off-by: Abhishek Kumar <abhishek.mrt22@gmail.com>
1 parent fc7113e commit 28b1a2b

File tree

8 files changed

+64
-65
lines changed

8 files changed

+64
-65
lines changed

agent/bindir/cloud-guest-tool.in

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/usr/bin/env python
1+
#!/usr/bin/env 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
@@ -78,7 +78,7 @@ class GuestCommand:
7878
info['network'] = 'guest-network-get-interfaces'
7979

8080
result = dict()
81-
for key, cmd in info.items():
81+
for key, cmd in list(info.items()):
8282
result[key] = self.virt.agent_command(self.dom, cmd)
8383

8484
return result, 0
@@ -110,10 +110,10 @@ def main(args):
110110
elif command == 'fstrim':
111111
result, code = guestcmd.fstrim()
112112

113-
print(json.dumps(result))
113+
print((json.dumps(result)))
114114
sys.exit(code)
115115
except libvirt.libvirtError as exc:
116-
print(json.dumps({'error': str(exc)}))
116+
print((json.dumps({'error': str(exc)})))
117117
sys.exit(255)
118118

119119
if __name__ == '__main__':

agent/bindir/cloud-setup-agent.in

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
# 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
@@ -31,56 +31,56 @@ from cloudutils.serviceConfig import configureLibvirtConfig
3131
from optparse import OptionParser
3232

3333
def getUserInputs():
34-
print "Welcome to the CloudStack Agent Setup:"
34+
print("Welcome to the CloudStack Agent Setup:")
3535

3636
cfo = configFileOps("@AGENTSYSCONFDIR@/agent.properties")
3737
oldMgt = cfo.getEntry("host")
3838

39-
mgtSvr = raw_input("Please input the Management Server Hostname/IP-Address:[%s]"%oldMgt)
39+
mgtSvr = input("Please input the Management Server Hostname/IP-Address:[%s]"%oldMgt)
4040
if mgtSvr == "":
4141
mgtSvr = oldMgt
4242
try:
4343
socket.getaddrinfo(mgtSvr, 443)
4444
except:
45-
print "Failed to resolve %s. Please input a valid hostname or IP-Address."%mgtSvr
45+
print("Failed to resolve %s. Please input a valid hostname or IP-Address."%mgtSvr)
4646
exit(1)
4747

4848
oldToken = cfo.getEntry("zone")
49-
zoneToken = raw_input("Please input the Zone Id:[%s]"%oldToken)
49+
zoneToken = input("Please input the Zone Id:[%s]"%oldToken)
5050

5151
if zoneToken == "":
5252
zoneToken = oldToken
5353

5454
oldPod = cfo.getEntry("pod")
55-
podId = raw_input("Please input the Pod Id:[%s]"%oldPod)
55+
podId = input("Please input the Pod Id:[%s]"%oldPod)
5656

5757
if podId == "":
5858
podId = oldToken
5959

6060
oldCluster = cfo.getEntry("cluster")
61-
clusterId = raw_input("Please input the Cluster Id:[%s]"%oldCluster)
61+
clusterId = input("Please input the Cluster Id:[%s]"%oldCluster)
6262
if clusterId == "":
6363
clusterId = oldCluster
6464

6565
oldHypervisor = cfo.getEntry("hypervisor")
6666
if oldHypervisor == "":
6767
oldHypervisor = "kvm"
6868

69-
hypervisor = raw_input("Please input the Hypervisor type kvm/lxc:[%s]"%oldHypervisor)
69+
hypervisor = input("Please input the Hypervisor type kvm/lxc:[%s]"%oldHypervisor)
7070
if hypervisor == "":
7171
hypervisor = oldHypervisor
7272

7373
try:
7474
defaultNic = networkConfig.getDefaultNetwork()
7575
except:
76-
print "Failed to get default route. Please configure your network to have a default route"
76+
print("Failed to get default route. Please configure your network to have a default route")
7777
exit(1)
7878

7979
defNic = defaultNic.name
80-
network = raw_input("Please choose which network used to create VM:[%s]"%defNic)
80+
network = input("Please choose which network used to create VM:[%s]"%defNic)
8181
if network == "":
8282
if defNic == "":
83-
print "You need to specifiy one of Nic or bridge on your system"
83+
print("You need to specifiy one of Nic or bridge on your system")
8484
exit(1)
8585
elif network == "":
8686
network = defNic
@@ -115,7 +115,7 @@ if __name__ == '__main__':
115115

116116
if not options.auto and options.secure:
117117
configureLibvirtConfig(True)
118-
print "Libvirtd with TLS configured"
118+
print("Libvirtd with TLS configured")
119119
sys.exit(0)
120120

121121
if options.auto is None:
@@ -131,10 +131,10 @@ if __name__ == '__main__':
131131
if glbEnv.uuid == "":
132132
glbEnv.uuid = bash("uuidgen").getStdout()
133133
else:
134-
for para, value in options.__dict__.items():
134+
for para, value in list(options.__dict__.items()):
135135
if value is None:
136-
print "Missing operand:%s"%para
137-
print "Try %s --help for more information"%sys.argv[0]
136+
print("Missing operand:%s"%para)
137+
print("Try %s --help for more information"%sys.argv[0])
138138
sys.exit(1)
139139

140140
glbEnv.uuid = options.guid
@@ -149,14 +149,14 @@ if __name__ == '__main__':
149149

150150
glbEnv.secure = options.secure
151151

152-
print "Starting to configure your system:"
152+
print("Starting to configure your system:")
153153
syscfg = sysConfigFactory.getSysConfigFactory(glbEnv)
154154
try:
155155
syscfg.config()
156-
print "CloudStack Agent setup is done!"
157-
except (CloudRuntimeException,CloudInternalException), e:
158-
print e
159-
print "Try to restore your system:"
156+
print("CloudStack Agent setup is done!")
157+
except (CloudRuntimeException,CloudInternalException) as e:
158+
print(e)
159+
print("Try to restore your system:")
160160
try:
161161
syscfg.restore()
162162
except:

agent/bindir/cloudstack-agent-upgrade.in

Lines changed: 8 additions & 8 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
@@ -25,13 +25,13 @@ def isOldStyleBridge(brName):
2525
else:
2626
return False
2727
def upgradeBridgeName(brName, enslavedDev):
28-
print("upgrade bridge: %s, %s"%(brName, enslavedDev))
28+
print(("upgrade bridge: %s, %s"%(brName, enslavedDev)))
2929
vlanId = brName.replace("cloudVirBr", "")
30-
print("find vlan Id: %s"%vlanId)
30+
print(("find vlan Id: %s"%vlanId))
3131
phyDev = enslavedDev.split(".")[0]
32-
print("find physical device %s"%phyDev)
32+
print(("find physical device %s"%phyDev))
3333
newBrName = "br" + phyDev + "-" + vlanId
34-
print("new bridge name %s"%newBrName)
34+
print(("new bridge name %s"%newBrName))
3535
bash("ip link set %s down"%brName)
3636
bash("ip link set %s name %s"%(brName, newBrName))
3737
bash("ip link set %s up" %newBrName)
@@ -49,15 +49,15 @@ def upgradeBridgeName(brName, enslavedDev):
4949
if __name__ == '__main__':
5050
netlib = networkConfig()
5151
bridges = netlib.listNetworks()
52-
bridges = filter(isOldStyleBridge, bridges)
52+
bridges = list(filter(isOldStyleBridge, bridges))
5353
for br in bridges:
5454
enslavedDev = netlib.getEnslavedDev(br, 1)
5555
if enslavedDev is not None:
5656
upgradeBridgeName(br, enslavedDev)
5757

5858
bridges = netlib.listNetworks()
59-
bridges = filter(isOldStyleBridge, bridges)
59+
bridges = list(filter(isOldStyleBridge, bridges))
6060
if len(bridges) > 0:
61-
print("Warning: upgrade is not finished, still some bridges have the old style name:" + str(bridges))
61+
print(("Warning: upgrade is not finished, still some bridges have the old style name:" + str(bridges)))
6262
else:
6363
print("Upgrade succeed")

agent/bindir/libvirtqemuhook.in

Lines changed: 5 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
@@ -32,7 +32,7 @@ logging.basicConfig(filename='/var/log/libvirt/qemu-hook.log',
3232
logger = logging.getLogger('qemu-hook')
3333

3434
customDir = "/etc/libvirt/hooks/custom"
35-
customDirPermissions = 0744
35+
customDirPermissions = 0o744
3636
timeoutSeconds = 10 * 60
3737
validQemuActions = ['prepare', 'start', 'started', 'stopped', 'release', 'migrate', 'restore', 'reconnect', 'attach']
3838

@@ -76,7 +76,7 @@ def handleMigrateBegin():
7676
continue
7777
newBrName = "br" + phyDev + "-" + vlanId
7878
source.setAttribute("bridge", newBrName)
79-
print(domain.toxml())
79+
print((domain.toxml()))
8080
except:
8181
pass
8282

@@ -128,9 +128,8 @@ def terminateProcess(process, scriptName):
128128

129129

130130
def getCustomScriptsFromDirectory():
131-
return sorted(filter(lambda fileName: (fileName is not None) & (fileName != "") & ('_' in fileName) &
132-
(fileName.startswith((action + '_')) | fileName.startswith(('all' + '_'))),
133-
os.listdir(customDir)), key=lambda fileName: substringAfter(fileName, '_'))
131+
return sorted([fileName for fileName in os.listdir(customDir) if (fileName is not None) & (fileName != "") & ('_' in fileName) &
132+
(fileName.startswith((action + '_')) | fileName.startswith(('all' + '_')))], key=lambda fileName: substringAfter(fileName, '_'))
134133

135134

136135
def substringAfter(s, delimiter):

agent/bindir/rolling-maintenance.in

Lines changed: 1 addition & 1 deletion
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

scripts/vm/network/security_group.py

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ def split_ips_by_family(ips):
148148
def destroy_network_rules_for_nic(vm_name, vm_ip, vm_mac, vif, sec_ips):
149149
try:
150150
rules = execute("""iptables-save -t filter | awk '/ %s / { sub(/-A/, "-D", $1) ; print }'""" % vif ).split("\n")
151-
for rule in filter(None, rules):
151+
for rule in [_f for _f in rules if _f]:
152152
try:
153153
execute("iptables " + rule)
154154
except:
@@ -158,7 +158,7 @@ def destroy_network_rules_for_nic(vm_name, vm_ip, vm_mac, vif, sec_ips):
158158

159159
try:
160160
dnats = execute("""iptables-save -t nat | awk '/ %s / { sub(/-A/, "-D", $1) ; print }'""" % vif ).split("\n")
161-
for dnat in filter(None, dnats):
161+
for dnat in [_f for _f in dnats if _f]:
162162
try:
163163
execute("iptables -t nat " + dnat)
164164
except:
@@ -205,14 +205,14 @@ def destroy_network_rules_for_vm(vm_name, vif=None):
205205
destroy_ebtables_rules(vm_name, vif)
206206

207207
chains = [vmchain_default, vmchain, vmchain_egress]
208-
for chain in filter(None, chains):
208+
for chain in [_f for _f in chains if _f]:
209209
try:
210210
execute("iptables -F " + chain)
211211
execute('ip6tables -F ' + chain)
212212
except:
213213
logging.debug("Ignoring failure to flush chain: " + chain)
214214

215-
for chain in filter(None, chains):
215+
for chain in [_f for _f in chains if _f]:
216216
try:
217217
execute("iptables -X " + chain)
218218
execute('ip6tables -X ' + chain)
@@ -229,7 +229,7 @@ def destroy_network_rules_for_vm(vm_name, vif=None):
229229
if vif:
230230
try:
231231
dnats = execute("""iptables -t nat -S | awk '/%s/ { sub(/-A/, "-D", $1) ; print }'""" % vif ).split("\n")
232-
for dnat in filter(None, dnats):
232+
for dnat in [_f for _f in dnats if _f]:
233233
try:
234234
execute("iptables -t nat " + dnat)
235235
except:
@@ -247,14 +247,14 @@ def destroy_ebtables_rules(vm_name, vif):
247247
delcmd = "ebtables -t nat -L PREROUTING | grep " + eb_vm_chain
248248
delcmds = []
249249
try:
250-
delcmds = filter(None, execute(delcmd).split('\n'))
250+
delcmds = [_f for _f in execute(delcmd).split('\n') if _f]
251251
delcmds = ["-D PREROUTING " + x for x in delcmds ]
252252
except:
253253
pass
254254
postcmds = []
255255
try:
256256
postcmd = "ebtables -t nat -L POSTROUTING | grep " + eb_vm_chain
257-
postcmds = filter(None, execute(postcmd).split('\n'))
257+
postcmds = [_f for _f in execute(postcmd).split('\n') if _f]
258258
postcmds = ["-D POSTROUTING " + x for x in postcmds]
259259
except:
260260
pass
@@ -493,7 +493,7 @@ def ebtables_rules_vmip (vmname, vmmac, ips, action):
493493
if action and action.strip() == "-A":
494494
action = "-I"
495495

496-
for ip in filter(None, ips):
496+
for ip in [_f for _f in ips if _f]:
497497
logging.debug("ip = " + ip)
498498
if ip == 0 or ip == "0":
499499
continue
@@ -736,15 +736,15 @@ def delete_rules_for_vm_in_bridge_firewall_chain(vmName):
736736
vmchain = iptables_chain_name(vm_name)
737737

738738
delcmd = """iptables-save | awk '/BF(.*)physdev-is-bridged(.*)%s/ { sub(/-A/, "-D", $1) ; print }'""" % vmchain
739-
delcmds = filter(None, execute(delcmd).split('\n'))
739+
delcmds = [_f for _f in execute(delcmd).split('\n') if _f]
740740
for cmd in delcmds:
741741
try:
742742
execute("iptables " + cmd)
743743
except:
744744
logging.exception("Ignoring failure to delete rules for vm " + vmName)
745745

746746
delcmd = """ip6tables-save | awk '/BF(.*)physdev-is-bridged(.*)%s/ { sub(/-A/, "-D", $1) ; print }'""" % vmchain
747-
delcmds = filter(None, execute(delcmd).split('\n'))
747+
delcmds = [_f for _f in execute(delcmd).split('\n') if _f]
748748
for cmd in delcmds:
749749
try:
750750
execute('ip6tables ' + cmd)
@@ -847,7 +847,7 @@ def network_rules_for_rebooted_vm(vmName):
847847
ipts = []
848848
for cmd in [delcmd, inscmd]:
849849
logging.debug(cmd)
850-
cmds = filter(None, execute(cmd).split('\n'))
850+
cmds = [_f for _f in execute(cmd).split('\n') if _f]
851851
for c in cmds:
852852
ipt = "iptables " + c
853853
ipts.append(ipt)
@@ -882,7 +882,7 @@ def get_rule_logs_for_vms():
882882
except:
883883
logging.exception("Failed to get rule logs, better luck next time!")
884884

885-
print(";".join(result))
885+
print((";".join(result)))
886886

887887

888888
def cleanup_rules_for_dead_vms():
@@ -897,7 +897,7 @@ def cleanup_bridge(bridge):
897897

898898
# Delete iptables/bridge rules
899899
rules = execute("""iptables-save | grep %s | grep '^-A' | sed 's/-A/-D/' """ % bridge_name).split("\n")
900-
for rule in filter(None, rules):
900+
for rule in [_f for _f in rules if _f]:
901901
try:
902902
command = "iptables " + rule
903903
execute(command)
@@ -945,13 +945,13 @@ def cleanup_rules():
945945
cleanup.append(vm_name)
946946

947947
bridge_tables = execute("""grep -E '^ebtable_' /proc/modules | cut -f1 -d' ' | sed s/ebtable_//""").split('\n')
948-
for table in filter(None, bridge_tables):
948+
for table in [_f for _f in bridge_tables if _f]:
949949
chainscmd = """ebtables -t %s -L | awk '/chain:/ { gsub(/(^.*chain: |-(in|out|ips).*)/, ""); print $1}' | sort | uniq""" % table
950950
chains = execute(chainscmd).split('\n')
951951

952952
logging.debug(" ebtables chains in the host: %s ", chains)
953953

954-
for chain in filter(None, chains):
954+
for chain in [_f for _f in chains if _f]:
955955
if 1 in [chain.startswith(c) for c in ['r-', 'i-', 's-', 'v-']]:
956956
vm_name = chain
957957
vmpresent = False
@@ -1421,7 +1421,7 @@ def verify_ipset_for_vm(vm_name, vm_id, vm_ips, vm_ip6):
14211421
found = True
14221422
break
14231423
if not found:
1424-
print("vm ip %s is not found" % vm_ip)
1424+
print(("vm ip %s is not found" % vm_ip))
14251425
return False
14261426

14271427
rules = []
@@ -1435,7 +1435,7 @@ def verify_ipset_for_vm(vm_name, vm_id, vm_ips, vm_ip6):
14351435
found = True
14361436
break
14371437
if not found:
1438-
print("vm ipv6 %s is not found" % vm_ip6)
1438+
print(("vm ipv6 %s is not found" % vm_ip6))
14391439
return False
14401440

14411441
return True
@@ -1574,7 +1574,7 @@ def verify_expected_rules_exist(expected_rules, rules):
15741574
found = True
15751575
break
15761576
if not found:
1577-
print("Rule '%s' is not found" % expected_rule)
1577+
print(("Rule '%s' is not found" % expected_rule))
15781578
return False
15791579
return True
15801580

@@ -1585,7 +1585,7 @@ def verify_expected_rules_in_order(expected_rules, rules):
15851585
if i < len(expected_rules) and rule == expected_rules[i]:
15861586
i += 1
15871587
if i != len(expected_rules):
1588-
print("Cannot find rule '%s'" % expected_rules[i])
1588+
print(("Cannot find rule '%s'" % expected_rules[i]))
15891589
return False
15901590
return True
15911591

0 commit comments

Comments
 (0)