summaryrefslogtreecommitdiff
path: root/bin
diff options
context:
space:
mode:
authorScott Moser <smoser@ubuntu.com>2014-02-24 17:20:12 -0500
committerScott Moser <smoser@ubuntu.com>2014-02-24 17:20:12 -0500
commitda13f065c9a2be372fea35db62e51086d443f8dc (patch)
tree6984cf3c222cf2d132498b56271b6c97d4344c5d /bin
parent2781fc8289e4aab130125b1a3e69b45a9318f805 (diff)
downloadvyos-cloud-init-da13f065c9a2be372fea35db62e51086d443f8dc.tar.gz
vyos-cloud-init-da13f065c9a2be372fea35db62e51086d443f8dc.zip
fixes from testing, force symlink
Diffstat (limited to 'bin')
-rwxr-xr-xbin/cloud-init48
1 files changed, 26 insertions, 22 deletions
diff --git a/bin/cloud-init b/bin/cloud-init
index dc480901..78f8600d 100755
--- a/bin/cloud-init
+++ b/bin/cloud-init
@@ -419,7 +419,7 @@ def main_single(name, args):
return 0
-def status_wrapper(args, data_d=None, link_d=None):
+def status_wrapper(name, args, data_d=None, link_d=None):
if data_d is None:
data_d = os.path.normpath("/var/lib/cloud/data")
if link_d is None:
@@ -434,13 +434,15 @@ def status_wrapper(args, data_d=None, link_d=None):
(_name, functor) = args.action
- if args.name:
+ if name == "init":
if args.local:
mode = "init-local"
else:
mode = "init"
- elif args.name == "modules":
+ elif name == "modules":
mode = "modules-%s" % args.mode
+ else:
+ raise ValueError("unknown name: %s" % name)
modes = ('init', 'init-local', 'modules-config', 'modules-final')
@@ -457,40 +459,40 @@ def status_wrapper(args, data_d=None, link_d=None):
if status is None:
nullstatus = {
'errors': [],
- 'state': None,
'start': None,
'end': None,
}
status = {'v1': {}}
- for mode in modes:
- status['v1'][mode] = nullstatus.copy()
+ for m in modes:
+ status['v1'][m] = nullstatus.copy()
status['v1']['datasource'] = None
- status['stage'] = mode
v1 = status['v1']
+ v1['stage'] = mode
v1[mode]['start'] = time.time()
util.write_file(status_path, json.dumps(status))
- util.sym_link(os.path.relpath(os.path.status_path, link_d), status_link)
+ util.sym_link(os.path.relpath(status_path, link_d), status_link,
+ force=True)
try:
- ret = functor(args)
+ ret = functor(name, args)
+ if mode in ('init', 'init-local'):
+ (datasource, errors) = ret
+ if datasource is not None:
+ v1['datasource'] = datasource
+ v1[mode]['errors'] = errors
+ else:
+ errors = ret
+ v1[mode]['errors'] = ret
+
except Exception as e:
v1[mode]['errors'] = [str(e)]
v1[mode]['finished'] = time.time()
v1['stage'] = None
- if mode in ('init', 'init-local'):
- (datasource, errors) = ret
- if datasource is not None:
- v1['datasource'] = datasource
- v1[mode]['errors'] = errors
- else:
- errors = ret
- v1[mode]['errors'] = ret
-
util.write_file(status_path, json.dumps(status))
if mode == "modules-final":
@@ -503,8 +505,8 @@ def status_wrapper(args, data_d=None, link_d=None):
finished = {'datasource': v1['datasource'],
'errors': errors}
util.write_file(result_path, json.dumps(finished))
- util.sym_link(os.path.relpath(os.path.result_path, link_d),
- result_link)
+ util.sym_link(os.path.relpath(result_path, link_d), result_link,
+ force=True)
return len(v1[mode]['errors'])
@@ -540,7 +542,7 @@ def main():
default=False)
# This is used so that we can know which action is selected +
# the functor to use to run this subcommand
- parser_init.set_defaults(action=('init', status_wrapper))
+ parser_init.set_defaults(action=('init', main_init))
# These settings are used for the 'config' and 'final' stages
parser_mod = subparsers.add_parser('modules',
@@ -551,7 +553,7 @@ def main():
"to use (default: %(default)s)"),
default='config',
choices=('init', 'config', 'final'))
- parser_mod.set_defaults(action=('modules', status_wrapper))
+ parser_mod.set_defaults(action=('modules', main_modules))
# These settings are used when you want to query information
# stored in the cloud-init data objects/directories/files
@@ -592,6 +594,8 @@ def main():
signal_handler.attach_handlers()
(name, functor) = args.action
+ if name in ("modules", "init"):
+ functor = status_wrapper
return util.log_time(logfunc=LOG.debug, msg="cloud-init mode '%s'" % name,
get_uptime=True, func=functor, args=(name, args))