mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
CRUDs + tests for servers.
This commit is contained in:
parent
4fa4c6d79f
commit
2f4ac6433e
4 changed files with 89 additions and 0 deletions
33
lib/fog/serverlove/requests/compute/create_server.rb
Normal file
33
lib/fog/serverlove/requests/compute/create_server.rb
Normal file
|
@ -0,0 +1,33 @@
|
|||
module Fog
|
||||
module Compute
|
||||
class Serverlove
|
||||
class Real
|
||||
|
||||
def create_server(options)
|
||||
return nil if options.empty? || options.nil?
|
||||
request(:method => "post", :path => "/servers/create", :expects => 200, :options => options)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
class Mock
|
||||
|
||||
def create_server(options = {})
|
||||
response = Excon::Response.new
|
||||
response.status = 200
|
||||
|
||||
data = {
|
||||
'name' => options['name'] || 'Test',
|
||||
'cpu' => options['cpu'] || 1000,
|
||||
'persistent' => options['persistent'] || false,
|
||||
'vnc:password' => options['vnc:password'] || 'T35tServER!'
|
||||
}
|
||||
|
||||
response.body = data
|
||||
response
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
13
lib/fog/serverlove/requests/compute/destroy_server.rb
Normal file
13
lib/fog/serverlove/requests/compute/destroy_server.rb
Normal file
|
@ -0,0 +1,13 @@
|
|||
module Fog
|
||||
module Compute
|
||||
class Serverlove
|
||||
class Real
|
||||
|
||||
def destroy_server(server_id)
|
||||
request(:method => "post", :path => "/servers/#{server_id}/destroy", :expects => 204)
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
15
lib/fog/serverlove/requests/compute/update_server.rb
Normal file
15
lib/fog/serverlove/requests/compute/update_server.rb
Normal file
|
@ -0,0 +1,15 @@
|
|||
module Fog
|
||||
module Compute
|
||||
class Serverlove
|
||||
class Real
|
||||
|
||||
def update_server(identifier, options)
|
||||
return nil if identifier.nil? || identifier == ""
|
||||
return nil if options.empty? || options.nil?
|
||||
request(:method => "post", :path => "/servers/#{identifier}/set", :expects => 200, :options => options)
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,10 +1,38 @@
|
|||
Shindo.tests('Fog::Compute[:serverlove] | server requests', ['serverlove']) do
|
||||
|
||||
@server_format = {
|
||||
'server' => String,
|
||||
'name' => String,
|
||||
'user' => String,
|
||||
'status' => String,
|
||||
'started' => String,
|
||||
'cpu' => Integer,
|
||||
'persistent' => Fog::Nullable::String,
|
||||
'vnc:password' => String
|
||||
}
|
||||
|
||||
tests('success') do
|
||||
|
||||
attributes = { 'name' => 'Test', 'cpu' => '1000' }
|
||||
|
||||
tests("#create_server").formats(@server_format) do
|
||||
@server = Fog::Compute[:serverlove].create_server(attributes).body
|
||||
end
|
||||
|
||||
tests("#list_servers").succeeds do
|
||||
Fog::Compute[:serverlove].servers
|
||||
end
|
||||
|
||||
tests("#update_server").returns(true) do
|
||||
@server['name'] = "Diff"
|
||||
Fog::Compute[:serverlove].update_server(@server['server'], { name: @server['name']})
|
||||
Fog::Compute[:serverlove].servers.get(@server['server']).name == "Diff"
|
||||
end
|
||||
|
||||
|
||||
tests("#destroy_server").succeeds do
|
||||
Fog::Compute[:serverlove].destroy_server(@server['server'])
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue