summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorScott Moser <smoser@ubuntu.com>2010-01-22 13:59:25 -0500
committerScott Moser <smoser@ubuntu.com>2010-01-22 13:59:25 -0500
commit3c0b9591b5203e60ac3cdda030b6eecbae27e938 (patch)
tree425c24d82396c1f0b5ff82a1084a8601e687f18b
parent9645203e0c320a1623162124aa839f4163527d15 (diff)
downloadvyos-cloud-init-3c0b9591b5203e60ac3cdda030b6eecbae27e938.tar.gz
vyos-cloud-init-3c0b9591b5203e60ac3cdda030b6eecbae27e938.zip
function ec2 metadata service removal. also fix issues with empty cloud-config
-rwxr-xr-xec2-init.py2
-rw-r--r--ec2init/CloudConfig.py9
-rw-r--r--ec2init/__init__.py3
3 files changed, 13 insertions, 1 deletions
diff --git a/ec2-init.py b/ec2-init.py
index 0ca01466..66fd62e2 100755
--- a/ec2-init.py
+++ b/ec2-init.py
@@ -37,7 +37,7 @@ def main():
# set the defaults (like what ec2-set-defaults.py did)
try:
cloud.sem_and_run("set_defaults", "once-per-instance",
- set_defaults,cloud,False)
+ set_defaults,[ cloud ],False)
except:
warn("failed to set defaults\n")
diff --git a/ec2init/CloudConfig.py b/ec2init/CloudConfig.py
index 9c58246f..17a14363 100644
--- a/ec2init/CloudConfig.py
+++ b/ec2init/CloudConfig.py
@@ -23,6 +23,7 @@ import ec2init.util as util
import subprocess
import os
import glob
+import sys
per_instance="once-per-instance"
@@ -37,11 +38,13 @@ class CloudConfig():
self.cloud.get_data_source()
self.add_handler('apt-update-upgrade', self.h_apt_update_upgrade)
self.add_handler('config-ssh')
+ self.add_handler('disable-ec2-metadata')
def get_config_obj(self,cfgfile):
f=file(cfgfile)
cfg=yaml.load(f.read())
f.close()
+ if cfg is None: cfg = { }
return(util.mergedict(cfg,self.cloud.cfg))
def convert_old_config(self):
@@ -143,6 +146,12 @@ class CloudConfig():
return(True)
+ def h_disable_ec2_metadata(self,name,args):
+ if util.get_cfg_option_bool(self.cfg, "disable_ec2_metadata", False):
+ #fwall="iptables -A OUTPUT -p tcp --dport 80 --destination 169.254.169.254 -j REJECT"
+ fwall="route add -host 169.254.169.254 reject"
+ subprocess.call(fwall.split(' '))
+
def h_config_ssh(self,name,args):
# remove the static keys from the pristine image
for f in glob.glob("/etc/ssh/ssh_host_*_key*"):
diff --git a/ec2init/__init__.py b/ec2init/__init__.py
index 9d701619..80203c80 100644
--- a/ec2init/__init__.py
+++ b/ec2init/__init__.py
@@ -73,12 +73,15 @@ class EC2Init:
stream.close()
except:
pass
+
+ if conf is None: conf = { }
# support reading the old ConfigObj format file and merging
# it into the yaml dictionary
try:
from configobj import ConfigObj
oldcfg = ConfigObj(self.old_conffile)
+ if oldcfg is None: oldcfg = { }
conf = util.mergedict(conf,oldcfg)
except:
pass