[glesys|compute] fix for changes in api

This commit is contained in:
Anton Lindström 2012-02-20 20:36:39 +01:00
parent 76e3447c61
commit d7e3ee870a
5 changed files with 218 additions and 155 deletions

View File

@ -96,7 +96,9 @@ module Fog
data.body = MultiJson.decode(data.body) data.body = MultiJson.decode(data.body)
unless data.body['response']['status']['code'] == '200' response_code = data.body['response']['status']['code']
unless response_code.to_i == 200
raise Fog::Compute::Glesys::Error, "#{data.body['response']['status']['text']}" raise Fog::Compute::Glesys::Error, "#{data.body['response']['status']['text']}"
end end
data data

View File

@ -15,11 +15,11 @@ module Fog
attribute :memorysize attribute :memorysize
attribute :disksize attribute :disksize
attribute :transfer attribute :transfer
attribute :template attribute :templatename
attribute :managedhosting attribute :managedhosting
attribute :platform attribute :platform
attribute :cost attribute :cost
attribute :rootpw attribute :rootpassword
attribute :keepip attribute :keepip
attribute :state attribute :state
attribute :iplist attribute :iplist
@ -47,17 +47,17 @@ module Fog
def save def save
raise "Operation not supported" if self.identity raise "Operation not supported" if self.identity
requires :hostname, :rootpw requires :hostname, :rootpassword
options = { options = {
:datacenter => datacenter || "Falkenberg", :datacenter => datacenter || "Falkenberg",
:platform => platform || "Xen", :platform => platform || "Xen",
:hostname => hostname, :hostname => hostname,
:template => template || "Debian-6 x64", :templatename => templatename || "Debian-6 x64",
:disksize => disksize || "10", :disksize => disksize || "10",
:memorysize => memorysize || "512", :memorysize => memorysize || "512",
:cpucores => cpucores || "1", :cpucores => cpucores || "1",
:rootpw => rootpw, :rootpassword => rootpassword,
:transfer => transfer || "500", :transfer => transfer || "500",
} }
data = connection.create(options) data = connection.create(options)

View File

@ -11,53 +11,11 @@ class Glesys
'serverid' => String, 'serverid' => String,
'hostname' => String, 'hostname' => String,
'datacenter' => String, 'datacenter' => String,
'platform' => String, 'platform' => String
}], }],
'status' => { 'status' => {
'code' => String, 'timestamp' => String,
'text' => String 'code' => Integer,
}
}
CREATE = {
'debug' => {
'input' => {
"rootpw" => String,
"disksize" => String,
"memorysize" => String,
"datacenter" => String,
"cpucores" => String,
"transfer" => String,
"template" => String,
"description" => String,
"hostname" => String,
"platform" => String
}
},
'server' => {
'serverid' => String,
'hostname' => String,
'iplist' => [{
'cost' => String,
'version' => String,
'ip' => String
}]
},
'status' => {
'code' => String,
'text' => String
}
}
DESTROY = {
'debug' => {
'input' => {
'serverid' => String,
'keepip' => String,
}
},
'status' => {
'code' => String,
'text' => String 'text' => String
} }
} }
@ -65,7 +23,7 @@ class Glesys
DETAILS = { DETAILS = {
'debug' => { 'debug' => {
'input' => { 'input' => {
'serverid' => String 'serverid' => Fog::Nullable::String
} }
}, },
'server' => { 'server' => {
@ -77,26 +35,56 @@ class Glesys
}, },
'serverid' => String, 'serverid' => String,
'datacenter' => String, 'datacenter' => String,
'memory' => String, 'memorysize' => Integer,
'cpucores' => String, 'cpucores' => Integer,
'transfer' => String, 'transfer' => Integer,
'template' => String, 'templatename' => String,
'iplist' => [{ 'iplist' => [{
'cost' => String, 'cost' => Integer,
'version' => String, 'version' => Fog::Nullable::Integer,
'ip' => String 'ipaddress' => Fog::Nullable::String,
'currency' => String
}], }],
'description' => String, 'description' => String,
'hostname' => String, 'hostname' => String,
'disk' => String, 'disksize' => Integer,
'platform' => String 'platform' => String,
'state' => Fog::Nullable::String
}, },
'status' => { 'status' => {
'code' => String, 'timestamp' => String,
'code' => Integer,
'text' => String 'text' => String
} }
} }
STOP = DETAILS.merge(
'debug' => {
'input' => {
'serverid' => Fog::Nullable::String,
'type' => String
}
}
)
CREATE = DETAILS.merge(
'debug' => {
'input' => {
'serverid' => Fog::Nullable::String,
'hostname' => String,
'rootpassword' => String,
'datacenter' => String,
'platform' => String,
'templatename' => String,
'disksize' => String,
'memorysize' => String,
'cpucores' => String,
'transfer' => String,
'description' => String
}
}
)
STATUS = { STATUS = {
'debug' => { 'debug' => {
'input' => { 'input' => {
@ -104,43 +92,50 @@ class Glesys
} }
}, },
'server' => { 'server' => {
'memory' => String, 'memory' => {
'bandwidth' => { 'usage' => Fog::Nullable::Integer,
'last30days' => Integer, 'max' => Fog::Nullable::Integer,
'today' => Integer, 'unit' => Fog::Nullable::String
'max' => String
}, },
'cpu' => String, 'transfer' => {
'disk' => String, 'usage' => Fog::Nullable::Integer,
'state' => String 'max' => Fog::Nullable::Integer,
'unit' => Fog::Nullable::String
},
'disk' => {
'usage' => Fog::Nullable::Integer,
'max' => Fog::Nullable::Integer,
'unit' => Fog::Nullable::String
},
'state' => String,
'transfer' => {
'usage' => Fog::Nullable::Integer,
'max' => Fog::Nullable::Integer,
'unit' => Fog::Nullable::String
},
'cpu' => [],
'uptime' => {
'current' => Fog::Nullable::Integer,
'unit' => String
}
}, },
'status' => { 'status' => {
'code' => String, 'timestamp' => String,
'code' => Integer,
'text' => String 'text' => String
} }
} }
START = { DESTROY = {
'debug' => {
'input' => {
'serverid' => String
}
},
'status' => {
'code' => String,
'text' => String
}
}
STOP = {
'debug' => { 'debug' => {
'input' => { 'input' => {
'serverid' => String, 'serverid' => String,
'type' => String 'keepip' => String
} }
}, },
'status' => { 'status' => {
'code' => String, 'timestamp' => String,
'code' => Integer,
'text' => String 'text' => String
} }
} }
@ -153,20 +148,26 @@ class Glesys
'input' => [] 'input' => []
}, },
'iplist' => [{ 'iplist' => [{
'price' => { 'cost' => {
'amount' => String, 'amount' => Integer,
'timeperiod' => String, 'timeperiod' => String,
'currency' => String 'currency' => String
}, },
'netmask' => Fog::Nullable::String,
'broadcast' => Fog::Nullable::String,
'gateway' => Fog::Nullable::String,
'nameservers' => [],
'datacenter' => String, 'datacenter' => String,
'serverid' => Fog::Nullable::String, 'serverid' => Fog::Nullable::String,
'platform' => String, 'platform' => String,
'ip' => String, 'ipaddress' => String,
'version' => String, 'ipversion' => Integer,
'PTR' => String, 'ptr' => String,
'reserved' => String
}], }],
'status' => { 'status' => {
'code' => String, 'timestamp' => String,
'code' => Integer,
'text' => String 'text' => String
} }
} }
@ -179,16 +180,17 @@ class Glesys
'platform' => String 'platform' => String
} }
}, },
'iplist' => [], 'iplist' => {
'ipversion' => Integer,
'datacenter' => String,
'platform' => String,
"ipaddresses" => []
},
'status' => { 'status' => {
'code' => String, 'timestamp' => String,
'code' => Integer,
'text' => String 'text' => String
}, },
'ipinfo' => {
'datacenter' => String,
'ipversion' => Integer,
'platform' => String
}
} }
IPLIST_CATCH_RELEASE = { IPLIST_CATCH_RELEASE = {
@ -197,8 +199,28 @@ class Glesys
'ipaddress' => String, 'ipaddress' => String,
} }
}, },
'details' => {
'cost' => {
'amount' => Integer,
'timeperiod' => String,
'currency' => String
},
'ipaddress' => String,
'netmask' => String,
'broadcast' => String,
'gateway' => String,
'nameservers' => [],
'datacenter' => String,
'serverid' => Fog::Nullable::String,
'platform' => String,
'ipaddress' => String,
'ipversion' => Integer,
'ptr' => String,
'reserved' => String
},
'status' => { 'status' => {
'code' => String, 'timestamp' => String,
'code' => Integer,
'text' => String 'text' => String
} }
} }
@ -213,21 +235,22 @@ class Glesys
'templates' => { 'templates' => {
'Xen' => [{ 'Xen' => [{
'name' => String, 'name' => String,
'os' => String, 'operatingsystem' => String,
'min_mem_size' => String, 'minimummemorysize' => Integer,
'min_disk_size' => String, 'minimumdisksize' => Integer,
'platform' => String 'platform' => String
}], }],
'OpenVZ' => [{ 'OpenVZ' => [{
'name' => String, 'name' => String,
'os' => String, 'operatingsystem' => String,
'min_mem_size' => String, 'minimummemorysize' => Integer,
'min_disk_size' => String, 'minimumdisksize' => Integer,
'platform' => String 'platform' => String
}] }]
}, },
'status' => { 'status' => {
'code' => String, 'timestamp' => String,
'code' => Integer,
'text' => String 'text' => String
} }
} }

View File

@ -18,7 +18,7 @@ Shindo.tests('Fog::Compute[:glesys] | ip requests', ['glesys']) do
:platform => "Xen", :platform => "Xen",
:ipversion => 4 :ipversion => 4
) )
@free_ip = ips.body['response']['iplist'].first @free_ip = ips.body['response']['iplist']['ipaddresses'].first
ips.body['response'] ips.body['response']
end end

View File

@ -3,10 +3,14 @@ Shindo.tests('Fog::Compute[:glesys] | server requests', ['glesys']) do
@serverid = nil @serverid = nil
@hostname = "fog-#{Time.now.to_i}" @hostname = "fog-#{Time.now.to_i}"
@create = ":hostname => #@hostname, :rootpw => 'pw#{Time.now.to_i}', "+ @create = ":hostname => #@hostname, :rootpassword => 'pw#{Time.now.to_i}', "+
":datacenter => 'Falkenberg', :platform => 'Xen', :template => 'Debian-6 x64', "+ ":datacenter => 'Falkenberg', :platform => 'Xen', :templatename => 'Debian-6 x64', "+
":disksize => '10', :memorysize => '512', :cpucores => '1', :transfer => '500'" ":disksize => '10', :memorysize => '512', :cpucores => '1', :transfer => '500'"
@create_vz = ":hostname => #@hostname, :rootpassword => 'pw#{Time.now.to_i}', "+
":datacenter => 'Stockholm', :platform => 'OpenVZ', :templatename => 'Debian 6.0 64-bit', "+
":disksize => '10', :memorysize => '256', :cpucores => '2', :transfer => '500'"
tests('success') do tests('success') do
tests("#list_servers()").formats(Glesys::Compute::Formats::Servers::LIST) do tests("#list_servers()").formats(Glesys::Compute::Formats::Servers::LIST) do
@ -18,10 +22,10 @@ Shindo.tests('Fog::Compute[:glesys] | server requests', ['glesys']) do
pending if Fog.mocking? pending if Fog.mocking?
vm = Fog::Compute[:glesys].create( vm = Fog::Compute[:glesys].create(
:hostname => @hostname, :hostname => @hostname,
:rootpw => "pw#{Time.now.to_i}", :rootpassword => "pw#{Time.now.to_i}",
:datacenter => "Falkenberg", :datacenter => "Falkenberg",
:platform => "Xen", :platform => "Xen",
:template => "Debian-6 x64", :templatename => "Debian-6 x64",
:disksize => "10", :disksize => "10",
:memorysize => "512", :memorysize => "512",
:cpucores => "1", :cpucores => "1",
@ -58,7 +62,7 @@ Shindo.tests('Fog::Compute[:glesys] | server requests', ['glesys']) do
s.wait_for { s.state == 'stopped' } s.wait_for { s.state == 'stopped' }
end end
tests("#start(:serverid => #{@serverid})").formats(Glesys::Compute::Formats::Servers::START) do tests("#start(:serverid => #{@serverid})").formats(Glesys::Compute::Formats::Servers::DETAILS) do
pending if Fog.mocking? pending if Fog.mocking?
Fog::Compute[:glesys].start(:serverid => @serverid).body['response'] Fog::Compute[:glesys].start(:serverid => @serverid).body['response']
end end
@ -73,6 +77,40 @@ Shindo.tests('Fog::Compute[:glesys] | server requests', ['glesys']) do
Fog::Compute[:glesys].destroy(:serverid => @serverid).body['response'] Fog::Compute[:glesys].destroy(:serverid => @serverid).body['response']
end end
# Test of OpenVZ
tests("#create(#{@create_vz})").formats(Glesys::Compute::Formats::Servers::CREATE) do
pending if Fog.mocking?
vm = Fog::Compute[:glesys].create(
:hostname => @hostname,
:rootpassword => "pw#{Time.now.to_i}",
:datacenter => "Stockholm",
:platform => "OpenVZ",
:templatename => "Debian 6.0 64-bit",
:disksize => "10",
:memorysize => "256",
:cpucores => "2",
:transfer => "500"
)
@serverid = vm.body['response']['server']['serverid']
vm.body['response']
end
tests("#server_details(#{@serverid})").formats(Glesys::Compute::Formats::Servers::DETAILS) do
pending if Fog.mocking?
Fog::Compute[:glesys].server_details(@serverid).body['response']
end
unless Fog.mocking?
Fog::Compute[:glesys].servers.get(@serverid).wait_for { ready? }
end
tests("#destroy(:serverid => #{@serverid})").formats(Glesys::Compute::Formats::Servers::DESTROY) do
pending if Fog.mocking?
Fog::Compute[:glesys].destroy(:serverid => @serverid).body['response']
end
end end
tests('failure') do tests('failure') do