summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorScott Moser <smoser@ubuntu.com>2011-02-07 14:43:40 -0500
committerScott Moser <smoser@ubuntu.com>2011-02-07 14:43:40 -0500
commit00ac0cfe971b1891b722455615df2230b0382567 (patch)
treea4c086b4692ae05194702a6563a761d1eff3e0cb
parente2045d8c68d0e7086487f3a02b9512e6f2581009 (diff)
downloadvyos-cloud-init-00ac0cfe971b1891b722455615df2230b0382567.tar.gz
vyos-cloud-init-00ac0cfe971b1891b722455615df2230b0382567.zip
add apt helper routeins to CloudConfig, and use them in apt and puppet
Adding the apt helper routines to CloudConfig. Then, make use of the following from cc_puppet and cc_apt_update_upgrade update_package_sources(): install_packages(pkglist): I'm not really terribly happy with this location for them. Their presence here is really only because of apt-update's use of 'run-once-per-instance'.
-rw-r--r--cloudinit/CloudConfig/__init__.py17
-rw-r--r--cloudinit/CloudConfig/cc_apt_update_upgrade.py27
-rw-r--r--cloudinit/CloudConfig/cc_puppet.py12
3 files changed, 27 insertions, 29 deletions
diff --git a/cloudinit/CloudConfig/__init__.py b/cloudinit/CloudConfig/__init__.py
index c8743ac3..0962c238 100644
--- a/cloudinit/CloudConfig/__init__.py
+++ b/cloudinit/CloudConfig/__init__.py
@@ -231,3 +231,20 @@ def run_per_instance(name, func, args, clear_on_fail=False):
except:
if clear_on_fail: os.unlink(semfile)
raise
+
+# apt_get top level command (install, update...), and args to pass it
+def apt_get(tlc,args=[]):
+ e=os.environ.copy()
+ e['DEBIAN_FRONTEND']='noninteractive'
+ cmd=[ 'apt-get',
+ '--option', 'Dpkg::Options::=--force-confold', '--assume-yes',
+ tlc ]
+ cmd.extend(args)
+ subprocess.check_call(cmd,env=e)
+
+def update_package_sources():
+ run_per_instance("update-sources", apt_get, ("update",))
+
+def install_packages(pkglist):
+ update_package_sources()
+ apt_get("install",pkglist)
diff --git a/cloudinit/CloudConfig/cc_apt_update_upgrade.py b/cloudinit/CloudConfig/cc_apt_update_upgrade.py
index e918e8c8..30ef8d44 100644
--- a/cloudinit/CloudConfig/cc_apt_update_upgrade.py
+++ b/cloudinit/CloudConfig/cc_apt_update_upgrade.py
@@ -20,6 +20,7 @@ import subprocess
import traceback
import os
import glob
+import cloudinit.CloudConfig as cc
def handle(name,cfg,cloud,log,args):
update = util.get_cfg_option_bool(cfg, 'apt_update', False)
@@ -54,29 +55,15 @@ def handle(name,cfg,cloud,log,args):
log.error("Failed to run debconf-set-selections")
log.debug(traceback.format_exc())
- pkglist = []
- if 'packages' in cfg:
- if isinstance(cfg['packages'],list):
- pkglist = cfg['packages']
- else: pkglist.append(cfg['packages'])
-
- if update or upgrade or pkglist:
- #retcode = subprocess.call(list)
- subprocess.Popen(['apt-get', 'update']).communicate()
-
- e=os.environ.copy()
- e['DEBIAN_FRONTEND']='noninteractive'
+ if update:
+ cc.update_package_sources()
if upgrade:
- cmd=[ 'apt-get', '--option', 'Dpkg::Options::=--force-confold',
- 'upgrade', '--assume-yes' ]
-
- subprocess.Popen(cmd, env=e).communicate()
+ cc.apt_get("upgrade")
- if pkglist:
- cmd=['apt-get', 'install', '--assume-yes']
- cmd.extend(pkglist)
- subprocess.Popen(cmd, env=e).communicate()
+ pkglist = util.get_cfg_option_list_or_str(cfg,'packages',[])
+ if len(pkglist):
+ cc.install_packages(pkglist)
return(True)
diff --git a/cloudinit/CloudConfig/cc_puppet.py b/cloudinit/CloudConfig/cc_puppet.py
index 9cfe7a49..b498c5f0 100644
--- a/cloudinit/CloudConfig/cc_puppet.py
+++ b/cloudinit/CloudConfig/cc_puppet.py
@@ -19,21 +19,15 @@ import os
import pwd
import socket
import subprocess
+import cloudinit.CloudConfig as cc
def handle(name,cfg,cloud,log,args):
# If there isn't a puppet key in the configuration don't do anything
if not cfg.has_key('puppet'): return
puppet_cfg = cfg['puppet']
# Start by installing the puppet package ...
- e=os.environ.copy()
- e['DEBIAN_FRONTEND']='noninteractive'
- # Make sure that the apt database is updated since it's not run by
- # default
- # Note: we should have a helper to check if apt-get update
- # has already been run on this instance to speed the boot time.
- subprocess.check_call(['apt-get', 'update'], env=e)
- subprocess.check_call(['apt-get', 'install', '--assume-yes',
- 'puppet'], env=e)
+ cc.install_packages(("puppet",))
+
# ... and then update the puppet configuration
if puppet_cfg.has_key('conf'):
# Add all sections from the conf object to puppet.conf