Skip to content

Instantly share code, notes, and snippets.

@antonlindstrom
Created September 18, 2011 11:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save antonlindstrom/1225014 to your computer and use it in GitHub Desktop.
Save antonlindstrom/1225014 to your computer and use it in GitHub Desktop.
Examples of the Glesys API in fog
anton:~ 3> ./bin/fog
Welcome to fog interactive!
:default provides Glesys, VirtualBox and VirtualBox
>> compute = Compute.new(:provider => 'glesys')
>> # The output has been removed, it will show the connection information
>> # Below command will show all servers on the account
>> compute.servers.all
<Fog::Compute::Glesys::Servers
[]
>
>> # The account has no servers yet. Let's create one!
>> compute.servers.create(:hostname => "fog.example.com", :rootpassword => "password")
<Fog::Compute::Glesys::Server
serverid="xm3003147",
hostname="fog.example.com",
datacenter="Falkenberg",
cpucores=1,
memorysize=512,
disksize=10,
transfer=500,
templatename="Debian-6 x64",
managedhosting="no",
platform="Xen",
cost={"amount"=>233.2, "currency"=>"SEK", "timeperiod"=>"month"},
rootpassword="password",
keepip=nil,
state="locked",
iplist=[{"ipaddress"=>"109.74.10.5", "version"=>4, "cost"=>20, "currency"=>"SEK"}],
ipversion=nil,
ip=nil
>
>> # A server was created with the required :hostname and :rootpassword
>> # We can get the information about a server with .get()
>> xm = compute.servers.get("xm3003147")
<Fog::Compute::Glesys::Server
serverid="xm3003147",
hostname="fog.example.com",
datacenter="Falkenberg",
cpucores=1,
memorysize=512,
disksize=10,
transfer={"usage"=>0, "max"=>500, "unit"=>"GB last 30 days"},
templatename="Debian-6 x64",
managedhosting="no",
platform="Xen",
cost={"amount"=>233.2, "currency"=>"SEK", "timeperiod"=>"month"},
rootpassword=nil,
keepip=nil,
state="locked",
iplist=[{"ipaddress"=>"109.74.10.5", "version"=>4, "cost"=>20, "currency"=>"SEK"}],
ipversion=nil,
ip=nil
>
>> # It is also possible to get specific information about the server
>> xm.iplist.first["ipaddress"]
"109.74.10.5"
>> # Or, hostname:
>> xm.hostname
"fog.example.com"
>> # We can also run commands via SSH on the newly created server
>> Fog::SSH.new(xm.iplist.first['ipaddress'], 'root', :password => 'password').run('cat /etc/issue.net').first.stdout
"Debian GNU/Linux 6.0\r\n"
>> # If we are done we should destroy the instance
>> xm.destroy
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment