Created
February 19, 2014 19:54
-
-
Save branan/9100258 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/bin/env ruby | |
require 'yaml' | |
# Pull our version information out of the environment | |
PE_VERSION=ENV['pe_version'] | |
PE_FAMILY=ENV['pe_family'] | |
# If our version is the same as our family, we're installing a | |
# released version. Use the archive path. Otherwise, we want to use | |
# the development build path. | |
if PE_VERSION == PE_FAMILY | |
PE_DIR="http://enterprise.delivery.puppetlabs.net/archives/releases/#{PE_FAMILY}/" | |
else | |
PE_DIR="http://enterprise.delivery.puppetlabs.net/#{PE_FAMILY}/ci-ready/" | |
end | |
# This regex determines if we're looking at a OS token or a node | |
# token. If a node token, it captures the platform bittage and the | |
# roles that node should have. | |
NODE_REGEX=/\A(?<bits>\d+)(?<roles>[acdfm]*)\Z/ | |
# Template for a single node. | |
NODE_TEMPLATE = { | |
'roles' => ['agent'], | |
'hypervisor' => 'vcloud', | |
'pe_dir' => PE_DIR, | |
'pe_ver' => PE_VERSION, | |
} | |
# Mapping from character roles to string roles | |
ROLES = { | |
'a' => 'agent', | |
'c' => 'dashboard', | |
'd' => 'database', | |
'f' => 'frictionless', | |
'm' => 'master', | |
} | |
# Mapping from os token / bittage pairs to PE platform and vCenter | |
# template info. This is basically the only per-node information from | |
# the old config files. | |
OSINFO = { | |
'centos4-32' => { | |
'platform' => 'el-4-i386', | |
'template' => 'centos-4-i386' | |
}, | |
'centos4-64' => { | |
'platform' => 'el-4-x86_64', | |
'template' => 'centos-4-x86_64' | |
}, | |
'centos5-32' => { | |
'platform' => 'el-5-i386', | |
'template' => 'centos-5-i386' | |
}, | |
'centos5-64' => { | |
'platform' => 'el-5-x86_64', | |
'template' => 'centos-5-x86_64' | |
}, | |
'centos6-32' => { | |
'platform' => 'el-6-i386', | |
'template' => 'centos-6-i386' | |
}, | |
'centos6-64' => { | |
'platform' => 'el-6-x86_64', | |
'template' => 'centos-6-x86_64' | |
}, | |
'debian6-32' => { | |
'platform' => 'debian-6-i386', | |
'template' => 'debian-6-i386' | |
}, | |
'debian6-64' => { | |
'platform' => 'debian-6-amd64', | |
'template' => 'debian-6-x86_64' | |
}, | |
'debian7-32' => { | |
'platform' => 'debian-7-i386', | |
'template' => 'debian-7-i386' | |
}, | |
'debian7-64' => { | |
'platform' => 'debian-7-amd64', | |
'template' => 'debian-7-x86_64' | |
}, | |
'oracle5-32' => { | |
'platform' => 'el-5-i386', | |
'template' => 'oracle-5-i386' | |
}, | |
'oracle5-64' => { | |
'platform' => 'el-5-x86_64', | |
'template' => 'oracle-5-x86_64' | |
}, | |
'oracle6-32' => { | |
'platform' => 'el-6-i386', | |
'template' => 'oracle-6-i386' | |
}, | |
'oracle6-64' => { | |
'platform' => 'el-6-x86_64', | |
'template' => 'oracle-6-x86_64' | |
}, | |
'redhat4-32' => { | |
'platform' => 'el-4-i386', | |
'template' => 'redhat-4-i386' | |
}, | |
'redhat4-64' => { | |
'platform' => 'el-4-x86_64', | |
'template' => 'redhat-4-x86_64' | |
}, | |
'redhat5-32' => { | |
'platform' => 'el-5-i386', | |
'template' => 'redhat-5-i386' | |
}, | |
'redhat5-64' => { | |
'platform' => 'el-5-x86_64', | |
'template' => 'redhat-5-x86_64' | |
}, | |
'redhat6-32' => { | |
'platform' => 'el-6-i386', | |
'template' => 'redhat-6-i386' | |
}, | |
'redhat6-64' => { | |
'platform' => 'el-6-x86_64', | |
'template' => 'redhat-6-x86_64' | |
}, | |
'scientific5-32' => { | |
'platform' => 'el-5-i386', | |
'template' => 'scientific-5-i386' | |
}, | |
'scientific5-64' => { | |
'platform' => 'el-5-x86_64', | |
'template' => 'scientific-5-x86_64' | |
}, | |
'scientific6-32' => { | |
'platform' => 'el-6-i386', | |
'template' => 'scientific-6-i386' | |
}, | |
'scientific6-64' => { | |
'platform' => 'el-6-x86_64', | |
'template' => 'scientific-6-x86_64' | |
}, | |
'sles11-32' => { | |
'platform' => 'sles-11-i386', | |
'template' => 'sles-11-i386' | |
}, | |
'sles11-64' => { | |
'platform' => 'sles-11-x86_64', | |
'template' => 'sles-11-x86_64' | |
}, | |
'solaris10-64' => { | |
'platform' => 'solaris-10-i386', | |
'template' => 'solaris-10-x86_64' | |
}, | |
'solaris11-64' => { | |
'platform' => 'solaris-11-i386', | |
'template' => 'solaris-11-x86_64' | |
}, | |
'solaris11-64' => { | |
'platform' => 'solaris-11-i386', | |
'template' => 'solaris-11-x86_64' | |
}, | |
'ubuntu1004-32' => { | |
'platform' => 'ubuntu-10.04-i386', | |
'template' => 'ubuntu-1004-i386' | |
}, | |
'ubuntu1004-64' => { | |
'platform' => 'ubuntu-10.04-amd64', | |
'template' => 'ubuntu-1004-x86_64' | |
}, | |
'ubuntu1204-32' => { | |
'platform' => 'ubuntu-12.04-i386', | |
'template' => 'ubuntu-1204-i386' | |
}, | |
'ubuntu1204-64' => { | |
'platform' => 'ubuntu-12.04-amd64', | |
'template' => 'ubuntu-1204-x86_64' | |
}, | |
'windows2003-64' => { | |
'platform' => 'windows-2003-64', | |
'template' => 'win-2003-x86_64' | |
}, | |
'windows2003r2-32' => { | |
'platform' => 'windows-2003r2-32', | |
'template' => 'win-2003r2-i386' | |
}, | |
'windows2003r2-64' => { | |
'platform' => 'windows-2003r2-64', | |
'template' => 'win-2003r2-x86_64', | |
}, | |
'windows2008-64' => { | |
'platform' => 'windows-2008-64', | |
'template' => 'win-2008-x86_64' | |
}, | |
'windows2008r2-64' => { | |
'platform' => 'windows-2008r2-64', | |
'template' => 'win-2008r2-x86_64' | |
}, | |
'windows2012-64' => { | |
'platform' => 'windows-2012-64', | |
'template' => 'win-2012-x86_64' | |
} | |
} | |
# Prepended to all Templates. This uniquely identifies them, because | |
# their names are fairly generic. | |
QA_VCENTER_PATH = 'Delivery/Quality Assurance/Templates/vCloud' | |
# There's no deep copy in ruby by default. I know, right? | |
def deep_copy(object) | |
# I feel so dirty | |
Marshal.load(Marshal.dump(object)) | |
end | |
def fixup_node(cfg) | |
# PE 2.8 doesn't exist for EL 4. We use 2.0 instead. | |
if cfg['platform'] =~ /el-4/ and PE_VERSION =~ /2\.8/ | |
cfg['pe_ver'] = "2.0.3" | |
end | |
end | |
# our configuration hash, in all its glory | |
config = { | |
'HOSTS' => {}, | |
'CONFIG' => { | |
'nfs_server' => 'none', | |
'consoleport' => 443, | |
'datastore' => 'instance0', | |
'folder' => 'Delivery/Quality Assurance/Enterprise/Dynamic', | |
'resourcepool' => 'delivery/Quality Assurance/Enterprise/Dynamic', | |
'pooling_api' => 'http://vcloud.delivery.puppetlabs.net/' | |
} | |
} | |
# node definition state | |
ostype = nil | |
nodeid = 1 | |
# Tokenizing the config definition for great justice | |
tokens = ARGV[0].split('-') | |
tokens.each do |toke| | |
node = NODE_REGEX.match(toke) | |
if node | |
raise "Can't create a node without an OS" unless ostype | |
bits = node['bits'] | |
roles = node['roles'] | |
platform = "#{ostype}-#{bits}" | |
name = "#{platform}-#{nodeid}" | |
cfg = deep_copy(NODE_TEMPLATE) | |
cfg.merge! OSINFO[platform] | |
# parse the roles out and append to the node | |
roles.each_char do |c| | |
cfg['roles'] << ROLES[c] | |
end | |
# Remove any duplicates (such as user-specified agents) | |
cfg['roles'].uniq! | |
# Make the template path fully qualified | |
template = cfg['template'] | |
cfg['template'] = "#{QA_VCENTER_PATH}/#{template}" | |
# Some platforms have special requirements. We munge the node | |
# config here if that is necessary. | |
fixup_node cfg | |
config['HOSTS'][name] = cfg | |
# ensure uniqueness when multiple nodes have same platform and | |
# bittage | |
nodeid += 1 | |
else | |
ostype = toke | |
end | |
end | |
puts config.to_yaml |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment