summaryrefslogtreecommitdiff
path: root/cloud-init-run-module.py
diff options
context:
space:
mode:
authorScott Moser <smoser@ubuntu.com>2011-12-20 12:02:39 -0500
committerScott Moser <smoser@ubuntu.com>2011-12-20 12:02:39 -0500
commitb17a271da699230be8dad5d8c0227a5c7c238503 (patch)
treefc0f9419f83f8533cf6d6259b45c195795f4bb94 /cloud-init-run-module.py
parent13015ef25fa7e748e916c99f083e338b28861a18 (diff)
parent57a28850fae6098a32e7c16ab90541fd785684cb (diff)
downloadvyos-cloud-init-b17a271da699230be8dad5d8c0227a5c7c238503.tar.gz
vyos-cloud-init-b17a271da699230be8dad5d8c0227a5c7c238503.zip
add INSTANCE_ID to env of bootcmd, add cloud-init-per
the environment varible INSTANCE_ID is set when invoking boothooks from multi-part input. However, previously that was not the case for things run via bootcmd. This adds cloud-init-per, which makes it easy for user in bootcmd or boothook to do something per 'instance', 'always', or 'once'. The functionality in cloud-init-per mostly duplicated what was in cloud-init-run-module. That supported "modules", but it is unlikely that it was used for anything other than "execute". So, cloud-init-per now replaces cloud-init-run-module and provides legacy support for the 'execute' path.
Diffstat (limited to 'cloud-init-run-module.py')
-rwxr-xr-xcloud-init-run-module.py85
1 files changed, 0 insertions, 85 deletions
diff --git a/cloud-init-run-module.py b/cloud-init-run-module.py
deleted file mode 100755
index 87fee4f7..00000000
--- a/cloud-init-run-module.py
+++ /dev/null
@@ -1,85 +0,0 @@
-#!/usr/bin/python
-# vi: ts=4 expandtab
-#
-# Copyright (C) 2009-2010 Canonical Ltd.
-#
-# Author: Scott Moser <scott.moser@canonical.com>
-#
-# This program is free software: you can redistribute it and/or modify
-# it under the terms of the GNU General Public License version 3, as
-# published by the Free Software Foundation.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program. If not, see <http://www.gnu.org/licenses/>.
-
-import sys
-import cloudinit
-import cloudinit.util as util
-import logging
-
-def Usage(out = sys.stdout):
- out.write("Usage: cloud-init-run-module freq sem-name mod-name [args]\n")
-
-def main():
- util.close_stdin()
-
- # expect to be called with
- # <freq> <semaphore-name> <module-name> args
- if len(sys.argv) < 4:
- Usage(sys.stderr)
- sys.exit(1)
-
- (freq,semname,modname)=sys.argv[1:4]
- run_args=sys.argv[4:]
-
- cloudinit.logging_set_from_cfg_file()
- log = logging.getLogger()
- log.info("cloud-init-run-module %s" % sys.argv[1:])
- cloud = cloudinit.CloudInit()
- try:
- cloud.get_data_source()
- except Exception as e:
- fail("Failed to get instance data\n\t%s" % traceback.format_exc(),log)
-
- if cloud.sem_has_run(semname,freq):
- msg="%s already ran %s" % (semname,freq)
- sys.stderr.write("%s\n" % msg)
- log.debug(msg)
- sys.exit(0)
-
- try:
- mod = __import__('cloudinit.' + modname)
- inst = getattr(mod,modname)
- except:
- fail("Failed to load module cloudinit.%s\n" % modname)
-
- import os
-
- cfg_path = None
- cfg_env_name = cloudinit.cfg_env_name
- if os.environ.has_key(cfg_env_name):
- cfg_path = os.environ[cfg_env_name]
-
- try:
- cloud.sem_and_run(semname, freq, inst.run, [run_args,cfg_path,log], False)
- except Exception as e:
- fail("Execution of %s failed:%s" % (semname,e), log)
-
- sys.exit(0)
-
-def err(msg,log=None):
- if log:
- log.error(msg)
- sys.stderr.write(msg + "\n")
-
-def fail(msg,log=None):
- err(msg,log)
- sys.exit(1)
-
-if __name__ == '__main__':
- main()