summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorharlowja <harlowja@virtualbox.rhel>2012-07-01 12:14:12 -0700
committerharlowja <harlowja@virtualbox.rhel>2012-07-01 12:14:12 -0700
commit346739701b2de2db2bf2065d946d611d55bc5653 (patch)
treedf2d11b7987ab67e457e126a84a738695d9f8eb7
parent9e1ffb27f4f316638a1fe83678c19f7215a8ef4b (diff)
parentaa9189e89ec101fba8ca36919a7c800f8b28d5c0 (diff)
downloadvyos-cloud-init-346739701b2de2db2bf2065d946d611d55bc5653.tar.gz
vyos-cloud-init-346739701b2de2db2bf2065d946d611d55bc5653.zip
Merge in pending changes.
-rwxr-xr-xbin/cloud-init4
-rw-r--r--cloudinit/config/cc_final_message.py6
-rw-r--r--cloudinit/config/cc_keys_to_console.py6
-rw-r--r--cloudinit/util.py11
4 files changed, 16 insertions, 11 deletions
diff --git a/bin/cloud-init b/bin/cloud-init
index 22901e15..fce4fe8c 100755
--- a/bin/cloud-init
+++ b/bin/cloud-init
@@ -86,9 +86,7 @@ def welcome(action):
'timestamp': util.time_rfc2822(),
'action': action,
}
- welcome_msg = "%s" % (templater.render_string(msg, tpl_params))
- sys.stderr.write("%s\n" % (welcome_msg))
- LOG.debug(welcome_msg)
+ util.multi_log("%s\n" % (templater.render_string(msg, tpl_params)))
def extract_fns(args):
diff --git a/cloudinit/config/cc_final_message.py b/cloudinit/config/cc_final_message.py
index fd59aa1e..711e7b5b 100644
--- a/cloudinit/config/cc_final_message.py
+++ b/cloudinit/config/cc_final_message.py
@@ -18,8 +18,6 @@
# 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
-
from cloudinit import templater
from cloudinit import util
from cloudinit import version
@@ -57,9 +55,7 @@ def handle(_name, cfg, cloud, log, args):
'timestamp': ts,
'version': cver,
}
- # Use stdout, stderr or the logger??
- content = templater.render_string(msg_in, subs)
- sys.stderr.write("%s\n" % (content))
+ util.multi_log("%s\n" % (templater.render_string(msg_in, subs)))
except Exception:
util.logexc(log, "Failed to render final message template")
diff --git a/cloudinit/config/cc_keys_to_console.py b/cloudinit/config/cc_keys_to_console.py
index d4c877f7..da7d5219 100644
--- a/cloudinit/config/cc_keys_to_console.py
+++ b/cloudinit/config/cc_keys_to_console.py
@@ -29,7 +29,7 @@ frequency = PER_INSTANCE
HELPER_TOOL = '/usr/lib/cloud-init/write-ssh-key-fingerprints'
-def handle(name, cfg, cloud, log, _args):
+def handle(name, cfg, _cloud, log, _args):
if not os.path.exists(HELPER_TOOL):
log.warn(("Unable to activate module %s,"
" helper tool not found at %s"), name, HELPER_TOOL)
@@ -46,7 +46,7 @@ def handle(name, cfg, cloud, log, _args):
cmd.append(','.join(fp_blacklist))
cmd.append(','.join(key_blacklist))
(stdout, _stderr) = util.subp(cmd)
- util.write_file(cloud.paths.join(False, '/dev/console'), stdout)
+ util.multi_log("%s\n" % (stdout.strip()), stderr=False)
except:
- log.warn("Writing keys to /dev/console failed!")
+ log.warn("Writing keys to the system console failed!")
raise
diff --git a/cloudinit/util.py b/cloudinit/util.py
index f07d22e7..6b23a0ee 100644
--- a/cloudinit/util.py
+++ b/cloudinit/util.py
@@ -275,6 +275,17 @@ def find_modules(root_dir):
return entries
+def multi_log(text, console=True, stderr=True, log=None):
+ if stderr:
+ sys.stderr.write(text)
+ if console:
+ with open('/dev/console', 'wb') as wfh:
+ wfh.write(text)
+ wfh.flush()
+ if log:
+ log.debug(text)
+
+
def is_ipv4(instr):
""" determine if input string is a ipv4 address. return boolean"""
toks = instr.split('.')