From c6b33abbfb97da1358c3daff2a50595bb8da0f59 Mon Sep 17 00:00:00 2001 From: Scott Moser Date: Thu, 27 Oct 2011 21:38:28 -0400 Subject: Replace static dict mapping version to packages with a method (LP: #848932) Previously, there was a 'ruby_packages' dictionary that mapped the ruby version (1.8, 1.9, 1.9.1) to a list of packages that would need to be installed to get a functional gems. This replaces that with a method that is more likely to support future versions without requiring updates to cloud-init. It is not identical output as before. The changes are: * do not include 'ruby' in the case of 1.8, but rather 'ruby1.8' This is because the default could change, and 'ruby' would depend on a different default version. * do not explicitly list 'libruby-' as that is a dependenency of 'ruby' * End result is for any 'version' != 1.8, you'll get the following installed ruby ruby-dev LP: #848932 --- cloudinit/CloudConfig/cc_chef.py | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) (limited to 'cloudinit') diff --git a/cloudinit/CloudConfig/cc_chef.py b/cloudinit/CloudConfig/cc_chef.py index 807c3717..14960a3c 100644 --- a/cloudinit/CloudConfig/cc_chef.py +++ b/cloudinit/CloudConfig/cc_chef.py @@ -24,9 +24,7 @@ import ConfigParser import cloudinit.CloudConfig as cc import cloudinit.util as util -ruby_packages = {'1.8': ('ruby', 'rubygems', 'ruby-dev', 'libopenssl-ruby'), - '1.9.1': ('ruby1.9.1', 'ruby1.9.1-dev', 'libruby1.9.1'), - '1.9': ('ruby1.9', 'ruby1.9-dev', 'libruby1.9') } +ruby_version_default = "1.8" def handle(name,cfg,cloud,log,args): # If there isn't a chef key in the configuration don't do anything @@ -72,7 +70,8 @@ def handle(name,cfg,cloud,log,args): if install_type == "gems": # this will install and run the chef-client from gems chef_version = util.get_cfg_option_str(chef_cfg, 'version', None) - ruby_version = util.get_cfg_option_str(chef_cfg, 'ruby_version', '1.8') + ruby_version = util.get_cfg_option_str(chef_cfg, 'ruby_version', + ruby_version_default) install_chef_from_gems(ruby_version, chef_version) # and finally, run chef-client log.debug('running chef-client') @@ -81,8 +80,15 @@ def handle(name,cfg,cloud,log,args): # this will install and run the chef-client from packages cc.install_packages(('chef',)) +def get_ruby_packages(version): + # return a list of packages needed to install ruby at version + pkgs = [ 'ruby%s' % version, 'ruby%s-dev' % version ] + if version == "1.8": + pkgs.extend(('libopenssl-ruby1.8', 'rubygems1.8')) + return(pkgs) + def install_chef_from_gems(ruby_version, chef_version = None): - cc.install_packages(ruby_packages[ruby_version]) + cc.install_packages(get_ruby_packages(ruby_version)) if not os.path.exists('/usr/bin/gem'): os.symlink('/usr/bin/gem%s' % ruby_version, '/usr/bin/gem') if not os.path.exists('/usr/bin/ruby'): -- cgit v1.2.3