summaryrefslogtreecommitdiff
path: root/ec2init/CloudConfig.py
diff options
context:
space:
mode:
Diffstat (limited to 'ec2init/CloudConfig.py')
-rw-r--r--ec2init/CloudConfig.py46
1 files changed, 9 insertions, 37 deletions
diff --git a/ec2init/CloudConfig.py b/ec2init/CloudConfig.py
index a6393df9..2b628edb 100644
--- a/ec2init/CloudConfig.py
+++ b/ec2init/CloudConfig.py
@@ -19,6 +19,7 @@
import yaml
import re
import ec2init
+import ec2init.util as util
import subprocess
import os
@@ -28,29 +29,19 @@ class CloudConfig():
cfgfile = None
handlers = { }
cfg = None
- old_conffile = '/etc/ec2-init/ec2-config.cfg'
def __init__(self,cfgfile):
- self.cfg = self.get_config_obj(cfgfile)
self.cloud = ec2init.EC2Init()
+ self.cfg = self.get_config_obj(cfgfile)
self.cloud.get_data_source()
self.add_handler('apt-update-upgrade', self.h_apt_update_upgrade)
self.add_handler('config-ssh')
def get_config_obj(self,cfgfile):
- str=""
- # support reading the old ConfigObj format file and turning it
- # into a yaml string
- try:
- f = file(self.old_conffile)
- str+=file.read().replace('=',': ')
- f.close()
- except:
- pass
-
- f = file(cfgfile)
- cfg=yaml.load(str + f.read())
+ f=file(cfgfile)
+ cfg=yaml.load(f.read())
f.close()
+ util.mergedict(cfg,self.cloud.read_cfg)
return(cfg)
def convert_old_config(self):
@@ -134,10 +125,9 @@ class CloudConfig():
self.cloud.sem_and_run(name, freq, handler, [ name, args ])
def h_apt_update_upgrade(self,name,args):
- update = get_cfg_option_bool(self.cfg, 'apt_update', False)
- upgrade = get_cfg_option_bool(self.cfg, 'apt_upgrade', False)
+ update = util.get_cfg_option_bool(self.cfg, 'apt_update', False)
+ upgrade = util.get_cfg_option_bool(self.cfg, 'apt_upgrade', False)
- print "update = %s , upgrade = %s\n" % (update,upgrade)
if update or upgrade:
#retcode = subprocess.call(list)
subprocess.Popen(['apt-get', 'update']).communicate()
@@ -150,7 +140,6 @@ class CloudConfig():
return(True)
def h_config_ssh(self,name,args):
- print "Warning, not doing anything for config %s" % name
if False:
# if there are keys in cloud-config, use them
# TODO: need to get keys from cloud-config if present
@@ -164,8 +153,8 @@ class CloudConfig():
subprocess.call(('sh', '-c', clean_and_gen))
try:
- user = get_cfg_option_str(self.cfg,'user')
- disable_root = get_cfg_option_bool(self.cfg, "disable_root", True)
+ user = util.get_cfg_option_str(self.cfg,'user')
+ disable_root = util.get_cfg_option_bool(self.cfg, "disable_root", True)
keys = self.cloud.get_public_ssh_keys()
apply_credentials(keys,user,disable_root)
except:
@@ -185,23 +174,6 @@ class CloudConfig():
print "Warning, not doing anything for config %s" % name
-def get_cfg_option_bool(yobj, key, default=False):
- if not yobj.has_key(key): return default
- val = yobj[key]
- if yobj[key] in [ True, '1', 'on', 'yes', 'true']:
- return True
- return False
-
-def get_cfg_option_str(yobj, key, default=None):
- if not yobj.has_key(key): return default
- return yobj[key]
-
-def read_conf(fname):
- stream = file(fname)
- conf = yaml.load(stream)
- stream.close()
- return conf
-
def apply_credentials(keys, user, disable_root):
if user:
setup_user_keys(keys, user, '')