mirror of
https://github.com/apache/cloudstack.git
synced 2025-10-26 08:42:29 +01:00
scripts: Fix security_group.py handling of args and unknown commands
Checks the args length, doesn't throw IndexError when no args passed. Also logs to security_group.log when executed with no args or unknown command. Review: https://reviews.apache.org/r/9588 Reviewed-by: Rohit Yadav <bhaisaab@apache.org> Signed-off-by: Rohit Yadav <bhaisaab@apache.org>
This commit is contained in:
parent
43183893bd
commit
0383803188
@ -38,13 +38,13 @@ def can_bridge_firewall(privnic):
|
||||
execute("which iptables")
|
||||
except:
|
||||
print "no iptables on your host machine"
|
||||
exit(1)
|
||||
sys.exit(1)
|
||||
|
||||
try:
|
||||
execute("which ebtables")
|
||||
except:
|
||||
print "no ebtables on your host machine"
|
||||
exit(2)
|
||||
sys.exit(2)
|
||||
|
||||
|
||||
if not os.path.exists('/var/run/cloud'):
|
||||
@ -813,6 +813,9 @@ if __name__ == '__main__':
|
||||
parser.add_option("--hostIp", dest="hostIp")
|
||||
parser.add_option("--hostMacAddr", dest="hostMacAddr")
|
||||
(option, args) = parser.parse_args()
|
||||
if len(args) == 0:
|
||||
logging.debug("No command to execute")
|
||||
sys.exit(1)
|
||||
cmd = args[0]
|
||||
if cmd == "can_bridge_firewall":
|
||||
can_bridge_firewall(args[1])
|
||||
@ -830,3 +833,6 @@ if __name__ == '__main__':
|
||||
cleanup_rules()
|
||||
elif cmd == "post_default_network_rules":
|
||||
post_default_network_rules(option.vmName, option.vmID, option.vmIP, option.vmMAC, option.vif, option.brname, option.dhcpSvr, option.hostIp, option.hostMacAddr)
|
||||
else:
|
||||
logging.debug("Unknown command: " + cmd)
|
||||
sys.exit(1)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user