Created
August 13, 2009 20:30
-
-
Save jeremyd/167435 to your computer and use it in GitHub Desktop.
rackspace api to launch servers with personalities
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 | |
# | |
# this will eventually be a cmd line script: | |
# inputs - | |
# 1) authentication, 2) packages list, 3) chef recipe url, 4) node attributes as .. yaml? | |
# | |
require 'rubygems' | |
require 'right_rackspace' | |
require 'yaml' | |
rackspace = Rightscale::Rackspace::Interface::new( YOUR_USER, YOUR_PASS, :auth_endpoint => 'https://auth.api.rackspacecloud.com/v1.0', :verbose_errors => true ) | |
images = rackspace.list_images | |
ubuntu = images["images"].select {|i| i["name"] =~ /intrepid/} | |
ubu_img_id = ubuntu.first["id"] | |
flavors = rackspace.list_flavors | |
smallest = flavors["flavors"].select {|f| f["name"] =~ /256 slice/} | |
small_fla_id = smallest.first["id"] | |
replacementRCtwo = <<RCTWO | |
#!/bin/bash | |
# run level 2 init script for chef bootstrap -- ubuntu | |
DEBIAN_FRONTEND=noninteractive | |
apt-get update | |
apt-get install -y ruby rdoc ri libopenssl-ruby ruby1.8-dev build-essential rubygems | |
gem sources -a http://gems.opscode.com/ | |
gem install chef | |
gem sources -a http://gems.github.com | |
exit 0 | |
RCTWO | |
replacementRCs = <<RCS | |
cat > /etc/init.d/#{INIT_FILENAME} <<EOF | |
#{replacementRCtwo} | |
EOF | |
chmod +x /etc/init.d/#{INIT_FILENAME} | |
ln -s /etc/init.d/#{INIT_FILENAME} /etc/rc2.d/S98#{INIT_FILENAME} | |
RCS | |
response = rackspace.create_server(:name => "ussenterprise", | |
:image_id => ubu_img_id, | |
:flavor_id => small_fla_id, | |
:personalities => { '/etc/rcS.d/S98bootstrap.sh' => replacementRCs } | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment