Current Articles | RSS Feed
Recently at work I needed to figure out how to bootstrap a server image on Rackspace, preferably using Ubuntu's Cloud-Init package since we already had that working on EC2.I couldn't find a single person who had done this before, so after struggling for a day or two and finally figuring out that it does indeed work (and it turns out to be pretty simple) I thought I would share the knowledge on how to do it.
# get a handle to the fog compute abstractioncompute_adapter = Fog::Compute.new({ provider: "Rackspace", rackspace_api_key: "", rackspace_username: ""}) # generate the ssh key-pairkeys = SSHKey.generate # let's make a multi-part documentscripts = MIME::MultipartMedia::Mixed.new # assuming `files` is an array of File objects corresponding# to real, properly formatted cloud-init script filesfiles.each do |f| do scripts.add_entity(MIME::TextMedia.new(file, "text/plain"))end compute_adapter.servers.bootstrap({ image_id: 39, flavor_id: 1, name: "A Name for the Server", personality: [ { 'path' => '/var/lib/cloud/seed/nocloud-net/user-data', 'contents' => scripts.to_s },{ 'path' => '/var/lib/cloud/seed/nocloud-net/meta-data', 'contents' => ' ' } ], public_key: keys.ssh_public_key, private_key: keys.private_key)
Allowed tags: <a> link, <b> bold, <i> italics