diff options
author | Scott Moser <smoser@ubuntu.com> | 2010-02-17 19:41:28 -0500 |
---|---|---|
committer | Scott Moser <smoser@ubuntu.com> | 2010-02-17 19:41:28 -0500 |
commit | 87224b5b1fcc04020c0bec678910a111de96c1c2 (patch) | |
tree | e8c5a35f2dbdbabc29555eec069fa30f9c05db63 | |
parent | 878ba5bef0c16ac61f56869c3bf23d3e491b431c (diff) | |
download | vyos-cloud-init-87224b5b1fcc04020c0bec678910a111de96c1c2.tar.gz vyos-cloud-init-87224b5b1fcc04020c0bec678910a111de96c1c2.zip |
add updates-check support using uec-query-builds
-rw-r--r-- | cloudinit/CloudConfig.py | 31 | ||||
-rwxr-xr-x | tools/motd-hook | 35 |
2 files changed, 66 insertions, 0 deletions
diff --git a/cloudinit/CloudConfig.py b/cloudinit/CloudConfig.py index da89001f..674e868e 100644 --- a/cloudinit/CloudConfig.py +++ b/cloudinit/CloudConfig.py @@ -25,8 +25,10 @@ import subprocess import os import glob import sys +import time per_instance="once-per-instance" +cronpre = "/etc/cron.d/cloudinit" class CloudConfig(): cfgfile = None @@ -43,6 +45,7 @@ class CloudConfig(): self.h_disable_ec2_metadata, "always") self.add_handler('config-mounts') self.add_handler('config-puppet') + self.add_handler('config-misc') def get_config_obj(self,cfgfile): f=file(cfgfile) @@ -184,6 +187,9 @@ class CloudConfig(): send_ssh_keys_to_console() + def h_config_misc(self,name,args): + handle_updates_check(self.cfg) + def h_config_puppet(self,name,args): # If there isn't a puppet key in the configuration don't do anything if not self.cfg.has_key('puppet'): return @@ -463,3 +469,28 @@ def generate_sources_list(mirror): util.render_to_file('sources.list', '/etc/apt/sources.list', \ { 'mirror' : mirror, 'codename' : codename }) + +def handle_updates_check(cfg): + if not util.get_cfg_option_bool(cfg, 'updates-check', True): + return + build_info = "/etc/cloud/build.info" + if not os.path.isfile(build_info): + warn("no %s file" % build_info) + + avail="%s/%s" % ( cloudinit.datadir, "available.build" ) + cmd=( "uec-query-builds", "--system-suite", "--config", "%s" % build_info, + "--output", "%s" % avail, "is-update-available" ) + try: + util.subp(cmd) + except: + warn("failed to execute uec-query-build for updates check") + + # add a cron entry for this hour and this minute every day + try: + cron=open("%s-%s" % (cronpre, "updates") ,"w") + cron.write("%s root %s\n" % \ + (time.strftime("%M %H * * * *"),' '.join(cmd))) + cron.close() + except: + warn("failed to enable cron update system check") + diff --git a/tools/motd-hook b/tools/motd-hook new file mode 100755 index 00000000..c6bec62d --- /dev/null +++ b/tools/motd-hook @@ -0,0 +1,35 @@ +#!/bin/sh +# +# 92-ec2-upgrade-available - update-motd script +# +# Copyright (C) 2010 Canonical Ltd. +# +# Authors: Scott Moser <smoser@ubuntu.com> +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, version 3 of the License. +# +# 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/>. + + +# Determining if updates are available is possibly slow. +# a cronjob runs occasioinally and updates a file with information +# on the latest available release (if newer than current) + +BUILD_FILE=/var/lib/cloud/data/available.build + +[ -s "${BUILD_FILE}" ] || exit 0 + +read suite build_name name serial < "${BUILD_FILE}" + +cat <<EOF +A newer build of the Ubuntu ${suite} ${build_name} image is available. +It is named '${name}' and has build serial '${serial}'. +EOF |