diff options
author | Scott Moser <smoser@ubuntu.com> | 2011-01-19 19:46:15 +0000 |
---|---|---|
committer | Scott Moser <smoser@ubuntu.com> | 2011-01-19 19:46:15 +0000 |
commit | 7434e3306d2526173c92ab57db30a0812cc47717 (patch) | |
tree | 54f3ad88ecdada0d3f694158b2da135388acf04e | |
parent | 01512fdad97b581cd8ac3da8758e704b060f3d03 (diff) | |
download | vyos-cloud-init-7434e3306d2526173c92ab57db30a0812cc47717.tar.gz vyos-cloud-init-7434e3306d2526173c92ab57db30a0812cc47717.zip |
convert 'cachedir' to 'seeddir', move cloud_config, scripts to instance
- cloud_config and scripts now live in instance directory
- cachedir is now more correctly named 'seeddir'
-rwxr-xr-x | cloud-init-cfg.py | 2 | ||||
-rw-r--r-- | cloudinit/CloudConfig/cc_runcmd.py | 3 | ||||
-rw-r--r-- | cloudinit/DataSourceEc2.py | 6 | ||||
-rw-r--r-- | cloudinit/DataSourceNoCloud.py | 4 | ||||
-rw-r--r-- | cloudinit/__init__.py | 49 |
5 files changed, 32 insertions, 32 deletions
diff --git a/cloud-init-cfg.py b/cloud-init-cfg.py index eb875182..326062a8 100755 --- a/cloud-init-cfg.py +++ b/cloud-init-cfg.py @@ -55,7 +55,7 @@ def main(): log = logging.getLogger() log.info("cloud-init-cfg %s" % sys.argv[1:]) - cfg_path = cloudinit.cloud_config + cfg_path = cloudinit.get_ipath_cur("cloud_config") cfg_env_name = cloudinit.cfg_env_name if os.environ.has_key(cfg_env_name): cfg_path = os.environ[cfg_env_name] diff --git a/cloudinit/CloudConfig/cc_runcmd.py b/cloudinit/CloudConfig/cc_runcmd.py index 969f6394..afa7a441 100644 --- a/cloudinit/CloudConfig/cc_runcmd.py +++ b/cloudinit/CloudConfig/cc_runcmd.py @@ -21,8 +21,7 @@ import cloudinit.util as util def handle(name,cfg,cloud,log,args): if not cfg.has_key("runcmd"): return - outfile="%s/%s/runcmd" % \ - (cloudinit.user_scripts_dir, cloud.get_instance_id()) + outfile="%s/runcmd" % cloud.get_ipath('scripts') content="#!/bin/sh\n" escaped="%s%s%s%s" % ( "'", '\\', "'", "'" ) diff --git a/cloudinit/DataSourceEc2.py b/cloudinit/DataSourceEc2.py index 84826276..fc8fac5a 100644 --- a/cloudinit/DataSourceEc2.py +++ b/cloudinit/DataSourceEc2.py @@ -30,7 +30,7 @@ import errno class DataSourceEc2(DataSource.DataSource): api_ver = '2009-04-04' - cachedir = cloudinit.cachedir + '/ec2' + seeddir = cloudinit.seeddir + '/ec2' def __init__(self): pass @@ -40,10 +40,10 @@ class DataSourceEc2(DataSource.DataSource): def get_data(self): seedret={ } - if util.read_optional_seed(seedret,base=self.cachedir + "/"): + if util.read_optional_seed(seedret,base=self.seeddir+ "/"): self.userdata_raw = seedret['user-data'] self.metadata = seedret['meta-data'] - cloudinit.log.debug("using seeded ec2 data in %s" % self.cachedir) + cloudinit.log.debug("using seeded ec2 data in %s" % self.seeddir) return True try: diff --git a/cloudinit/DataSourceNoCloud.py b/cloudinit/DataSourceNoCloud.py index 78c9c9c8..2f6033a9 100644 --- a/cloudinit/DataSourceNoCloud.py +++ b/cloudinit/DataSourceNoCloud.py @@ -32,7 +32,7 @@ class DataSourceNoCloud(DataSource.DataSource): supported_seed_starts = ( "/" , "file://" ) seed = None cmdline_id = "ds=nocloud" - seeddir = cloudinit.cachedir + '/nocloud' + seeddir = cloudinit.seeddir + '/nocloud' def __init__(self): pass @@ -143,4 +143,4 @@ def parse_cmdline_data(ds_id,fill,cmdline=None): class DataSourceNoCloudNet(DataSourceNoCloud): cmdline_id = "ds=nocloud-net" supported_seed_starts = ( "http://", "https://", "ftp://" ) - seeddir = cloudinit.cachedir + '/nocloud-net' + seeddir = cloudinit.seeddir + '/nocloud-net' diff --git a/cloudinit/__init__.py b/cloudinit/__init__.py index 32b91979..3bee2c0d 100644 --- a/cloudinit/__init__.py +++ b/cloudinit/__init__.py @@ -21,15 +21,8 @@ varlibdir = '/var/lib/cloud' cur_instance_link = varlibdir + "/instance" datadir = '/var/lib/cloud/data' -semdir = '/var/lib/cloud/sem' -cachedir = datadir + '/cache' -userdata_raw = datadir + '/user-data.txt' -userdata = datadir + '/user-data.txt.i' -user_scripts_dir = datadir + "/scripts" -boothooks_dir = datadir + "/boothooks" -cloud_config = datadir + '/cloud-config.txt' -data_source_cache = cachedir + '/obj.pkl' system_config = '/etc/cloud/cloud.cfg' +seeddir = varlibdir + "/seed" cfg_env_name = "CLOUD_CFG" def_log_file = '/var/log/cloud-init.log' @@ -42,6 +35,18 @@ cloud_type: auto """ logger_name = "cloudinit" +pathmap = { + "handlers" : "/handlers", + "scripts" : "/scripts", + "sem" : "/sem", + "boothooks" : "/boothooks", + "userdata_raw" : "/user-data.txt", + "userdata" : "/user-data-raw.txt.i", + "obj_pkl" : "/obj.pkl", + "cloud_config" : "/cloud-config.txt", + None : "", +} + import os from configobj import ConfigObj @@ -109,17 +114,6 @@ class CloudInit: "all": ( "nocloud-net", "ec2" ), "local" : ( "nocloud", ), } - pathmap = { - "handlers" : "/handlers", - "scripts" : "/scripts", - "sem" : "/sem", - "boothooks" : "/boothooks", - "userdata_raw" : "/user-data.txt", - "userdata" : "/user-data-raw.txt.i", - "obj_pkl" : "/obj.pkl", - None : "", - } - cfg = None part_handlers = { } old_conffile = '/etc/ec2-init/ec2-config.cfg' @@ -160,7 +154,7 @@ class CloudInit: # we try to restore from a current link and static path # by using the instance link, if purge_cache was called # the file wont exist - cache = "%s/%s" % (cur_instance_link, self.pathmap['obj_pkl']) + cache = get_ipath_cur('obj_pkl') f=open(cache, "rb") data = cPickle.load(f) self.datasource = data @@ -255,8 +249,9 @@ class CloudInit: self.datasource.get_userdata(), 0600) def initctl_emit(self): + cc_path = get_ipath_cur('cloud_config') subprocess.Popen(['initctl', 'emit', 'cloud-config', - '%s=%s' % (cfg_env_name,cloud_config)]).communicate() + '%s=%s' % (cfg_env_name,cc_path)]).communicate() def sem_getpath(self,name,freq): if freq == 'once-per-instance': @@ -324,12 +319,12 @@ class CloudInit: # (/var/lib/cloud/instances/<instance>/name)<name>) def get_ipath(self, name=None): return("%s/instances/%s%s" - % (varlibdir,self.get_instance_id(), self.pathmap[name])) + % (varlibdir,self.get_instance_id(), pathmap[name])) # get_cpath : get the "clouddir" (/var/lib/cloud/<name>) # for a name in dirmap def get_cpath(self, name=None): - return("%s%s" % (varlibdir, self.pathmap[name])) + return("%s%s" % (varlibdir, pathmap[name])) def consume_userdata(self): self.get_userdata() @@ -406,8 +401,9 @@ class CloudInit: return filename=filename.replace(os.sep,'_') + scriptsdir = get_ipath_cur('scripts') util.write_file("%s/%s/%s" % - (user_scripts_dir,self.get_instance_id(),filename), payload, 0700) + (scriptsdir,self.get_instance_id(),filename), payload, 0700) def handle_upstart_job(self,data,ctype,filename,payload): if ctype == "__end__" or ctype == "__begin__": return @@ -421,6 +417,7 @@ class CloudInit: self.cloud_config_str="" return if ctype == "__end__": + cloud_config = self.get_ipath("cloud_config") util.write_file(cloud_config, self.cloud_config_str, 0600) ## this could merge the cloud config with the system config @@ -509,5 +506,9 @@ def purge_cache(): return(False) return(True) +def get_ipath_cur(name=None): + return("%s/instance/%s" % (varlibdir, pathmap[name])) + + class DataSourceNotFoundException(Exception): pass |