Skip to content

Instantly share code, notes, and snippets.

@krames
Created December 12, 2012 21:15
Show Gist options
  • Save krames/4271724 to your computer and use it in GitHub Desktop.
Save krames/4271724 to your computer and use it in GitHub Desktop.
This is an example of the current functionality of the Rackspace Cloud Server Version 2 API
#!/usr/bin/env ruby
require 'rubygems'
require 'fog'
RACKSPACE_USERNAME = "racker"
RACKSPACE_API_KEY = "23423423"
#create connection
connection = Fog::Compute.new({
:provider => 'Rackspace',
:rackspace_username => RACKSPACE_USERNAME,
:rackspace_api_key => RACKSPACE_API_KEY,
:version => :v2
})
#list flavors
connection.flavors
#list images
connection.images
#create server
server = connection.servers.create(:name => 'fog-server', :flavor_id => 2, :image_id => "3afe97b2-26dc-49c5-a2cc-a2fc8d80c001")
#list servers
connection.servers
#delete server
server.destroy
#update
server.name = "bob"
server.save
#list addresses
server.private_ip_address #returns IPv4 version
server.public_ip_address
server.addresses #returns a hash of all addresses
#change admin password
server.change_admin_password("BigBoy42 ")
#reboot
server.reboot
#resize
server.resize(3)
#once you confirm a resize you cannot revert and vice versa
#confirm resize
server.confirm_resize
#revert resize
server.revert_resize
#list attachements
connection.list_attachments(server.id)
#add attachments
connection.attach_volume(server.id, "0e7a706c-340d-48b3-802d-192850387f93", "/dev/xvdb") #I created the volume in the GUI; not sure where the device came from
#get attachement
connection.get_attachment(server.id, "0e7a706c-340d-48b3-802d-192850387f93")
#delete attachment
connection.delete_attachment(server.id, "0e7a706c-340d-48b3-802d-192850387f93")
#get specific image info
connection.images.get("992ba82c-083b-4eed-9c26-c54473686466")
#get specific flavor info
connection.flavors.get("2")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment