handle no datasource better cloud-init-cfg
previously, cloud-init-cfg would call CloudConfig with no cloud specified. Then, CloudConfig would get a new cloudinit instance and specify no ds_deps (which means network and local). If no cache was found, it would wait again for the Ec2 metadata service (even if it wasn't supposed to). Now, we get the cloud instance in the main program and attempt to get the data source, but only from [], which will get only cached. Then, if its not found, exit silently.
This commit is contained in:
@@ -60,7 +60,14 @@ def main():
|
|||||||
if os.environ.has_key(cfg_env_name):
|
if os.environ.has_key(cfg_env_name):
|
||||||
cfg_path = os.environ[cfg_env_name]
|
cfg_path = os.environ[cfg_env_name]
|
||||||
|
|
||||||
cc = CC.CloudConfig(cfg_path)
|
cloud = cloudinit.CloudInit(ds_deps=[]) # ds_deps=[], get only cached
|
||||||
|
try:
|
||||||
|
cloud.get_data_source()
|
||||||
|
except cloudinit.DataSourceNotFoundException as e:
|
||||||
|
# there was no datasource found, theres nothing to do
|
||||||
|
sys.exit(0)
|
||||||
|
|
||||||
|
cc = CC.CloudConfig(cfg_path,cloud)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
(outfmt, errfmt) = CC.get_output_cfg(cc.cfg,modename)
|
(outfmt, errfmt) = CC.get_output_cfg(cc.cfg,modename)
|
||||||
|
|||||||
@@ -33,13 +33,13 @@ class CloudConfig():
|
|||||||
cfgfile = None
|
cfgfile = None
|
||||||
cfg = None
|
cfg = None
|
||||||
|
|
||||||
def __init__(self,cfgfile, cloud=None):
|
def __init__(self,cfgfile, cloud=None, ds_deps=[]):
|
||||||
if cloud == None:
|
if cloud == None:
|
||||||
self.cloud = cloudinit.CloudInit()
|
self.cloud = cloudinit.CloudInit(ds_deps)
|
||||||
|
self.cloud.get_data_source()
|
||||||
else:
|
else:
|
||||||
self.cloud = cloud
|
self.cloud = cloud
|
||||||
self.cfg = self.get_config_obj(cfgfile)
|
self.cfg = self.get_config_obj(cfgfile)
|
||||||
self.cloud.get_data_source()
|
|
||||||
|
|
||||||
def get_config_obj(self,cfgfile):
|
def get_config_obj(self,cfgfile):
|
||||||
try:
|
try:
|
||||||
|
|||||||
Reference in New Issue
Block a user