Skip to content

Instantly share code, notes, and snippets.

@hedgehog
Created December 29, 2009 08:45
Show Gist options
  • Save hedgehog/265220 to your computer and use it in GitHub Desktop.
Save hedgehog/265220 to your computer and use it in GitHub Desktop.
Hypothetical port of the libcloud example to Ruby
## from libcloud.types import Provider
## from libcloud.providers import get_driver
require 'fog/types'
require 'fog/providers'
## EC2 = get_driver(Provider.EC2)
## Slicehost = get_driver(Provider.SLICEHOST)
## Rackspace = get_driver(Provider.RACKSPACE)
EC2 = Fog::Provider.new(:ec2) # syntax 1
Slicehost = Fog::Provider.new :slicehost # syntax 1
Rackspace = Fog::Provider::Rackspace.new # syntax 2
## drivers = [ EC2('access key id', 'secret key'),
## Slicehost('api key'),
## Rackspace('username', 'api key') ]
drivers = [ EC2.new('access key id', 'secret key'),
Slicehost.new('api key'),
Rackspace.new('username', 'api key') ]
## nodes = [ driver.list_nodes() for driver in drivers ]
nodes = drivers.collect { |drv| drv.list_nodes() }
p nodes
# [ <Node: provider=Amazon, status=RUNNING, name=bob, ip=1.2.3.4.5>,
# <Node: provider=Slicehost, status=REBOOT, name=korine, ip=6.7.8.9.10>,
# ... ]
# grab the node named "test"
## node = filter(lambda x: x.name == 'test', nodes)[0]
node = nodes.find { |nd| nd.name =~ /test/ }
# reboot "test"
## node.reboot()
node.reboot
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment