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 /cloudinit | |
parent | 878ba5bef0c16ac61f56869c3bf23d3e491b431c (diff) | |
download | vyos-cloud-init-87224b5b1fcc04020c0bec678910a111de96c1c2.tar.gz vyos-cloud-init-87224b5b1fcc04020c0bec678910a111de96c1c2.zip |
add updates-check support using uec-query-builds
Diffstat (limited to 'cloudinit')
-rw-r--r-- | cloudinit/CloudConfig.py | 31 |
1 files changed, 31 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") + |