Clean up logging and documentation in ec2 interfaces script

(imported from commit e55247931cdeb61563f2348ca09f3d7b9fc85f0c)
This commit is contained in:
Luke Faraone
2013-12-12 16:16:03 -05:00
parent 104c2a06ae
commit 1370c014a5

View File

@@ -1,5 +1,28 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
#
# Copyright © 2013 Zulip, Inc.
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
# Original author: Luke Faraone
'''Configure a host for EC2-VPC dynamically assigned network interfaces
Amazon VPC gives us a good deal of flexibility compared to classic EC2.
@@ -40,12 +63,12 @@ def guess_gateway(device_id):
address[3] = '1'
return '.'.join(address)
log = logging.getLogger('ec2ify')
log = logging.getLogger('configure-cloud-interfaces')
log.setLevel(logging.DEBUG)
log.addHandler(logging.handlers.SysLogHandler(facility=logging.handlers.SysLogHandler.LOG_DAEMON))
log.addHandler(logging.StreamHandler())
log.info("ec2ify starting")
log.info("Starting.")
macs = boto.utils.get_instance_metadata()["network"]["interfaces"]["macs"]
ids = [int(macdata['device-number']) for macdata in macs.values()]
@@ -84,6 +107,7 @@ for device in macs.values():
['/sbin/iptables', '-t', 'mangle', '-A', 'OUTPUT', '-m', 'conntrack', '--ctorigdst',
address_of(device_number), '-j', 'MARK', '--set-mark', str(device_number)])
to_configure.remove(address_of(device_number))
for (count, ip) in enumerate(to_configure):
@@ -99,3 +123,5 @@ for device in macs.values():
# Don't freak out if this doens't work.
subprocess.call(
['/sbin/ip', 'route', 'del', '10.0.0.0/8'])
log.info("Finished.")