mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
[clodo|compute] Actualize Mocks.
This commit is contained in:
parent
da50ea9fce
commit
1059a90a53
11 changed files with 133 additions and 29 deletions
|
@ -37,26 +37,78 @@ module Fog
|
|||
)
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
class Mock
|
||||
def create_server(image_id, options = {})
|
||||
response = Excon::response.new
|
||||
response.status = 202
|
||||
class Mock
|
||||
def create_server(image_id, options = {})
|
||||
|
||||
data = {
|
||||
'id' => Fog::Mock.random_numbers(6).to_i,
|
||||
'imageId' => image_id,
|
||||
'name' => options['name'] || "VPS #{rand(999)}",
|
||||
'adminPass' => '23ryh8udbcbyt'
|
||||
}
|
||||
raise Excon::Errors::BadRequest.new("Invalid image ID") unless image_id > 0
|
||||
|
||||
self.data[:last_modified][:servers][data['id']] = Time.now
|
||||
self.data[:servers][data['id']] = data
|
||||
response.body = { 'server' => data }
|
||||
response
|
||||
end
|
||||
response = Excon::Response.new
|
||||
response.status = 202
|
||||
|
||||
id = Fog::Mock.random_numbers(6).to_i
|
||||
|
||||
data = {
|
||||
'id' => id,
|
||||
'imageId' => "#{image_id}",
|
||||
'name' => options['name'] || "VPS #{rand(999)}",
|
||||
'adminPass' => '23ryh8udbcbyt'
|
||||
}
|
||||
|
||||
self.data[:last_modified][:servers][id] = Time.now
|
||||
self.data[:servers][id] = {
|
||||
'id' => "#{id}",
|
||||
'imageId' => data['imageId'],
|
||||
'name' => data['name'],
|
||||
'vps_os_title' => "OSTitle",
|
||||
'vps_root_pass' => data['adminPass'],
|
||||
'status' => "is_running",
|
||||
'addresses' => {'public' =>[{
|
||||
'ddosprotect' => false,
|
||||
'primary_ip' => true,
|
||||
'isp' => false,
|
||||
'ip' => '66.6.6.66'
|
||||
},
|
||||
{
|
||||
'ddosprotect' => false,
|
||||
'primary_ip' => false,
|
||||
'isp' => false,
|
||||
'ip' => '13.13.13.13'
|
||||
}]},
|
||||
'vps_createdate' => "#{Time.now}",
|
||||
'vps_hdd_max' => "5",
|
||||
'vps_traff' => nil,
|
||||
'vps_mem_1h_max' => "0",
|
||||
'vps_mem_load' => "0",
|
||||
'vps_user_pass' => "wer45345ht",
|
||||
'vps_vnc_pass' => "bi65tdfyb",
|
||||
'vps_adddate' => "#{Time.now}",
|
||||
'vps_update' => "#{Time.now}",
|
||||
'vps_mem_1h_min' => "0",
|
||||
'vps_mem_1h_avg' => nil,
|
||||
'vps_memory_max' => options['vps_memory_max'] || "512",
|
||||
'vps_os_version' => "6.6.6",
|
||||
'vps_cpu_1h_max' => "0",
|
||||
'vps_hdd_load' => "0",
|
||||
'vps_disk_load' => "0",
|
||||
'vps_os_type' => options['vps_os_type'] || "VirtualServer",
|
||||
'type' => options['vps_os_type'] || "VirtualServer",
|
||||
'vps_memory' => options['vps_memory'] || "512",
|
||||
'vps_cpu_load' => "0",
|
||||
'vps_update_days' => "0",
|
||||
'vps_os_bits' => "64",
|
||||
'vps_vnc' => "6.6.6.6:5900",
|
||||
'vps_cpu_max' => "0",
|
||||
'vps_cpu_1h_min' => "0",
|
||||
'vps_cpu_1h_avg' => nil
|
||||
}
|
||||
|
||||
response.body = { 'server' => data }
|
||||
response
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -33,9 +33,10 @@ module Fog
|
|||
|
||||
def get_server_details(server_id)
|
||||
response = Excon::Response.new
|
||||
if server = list_servers_detail.body['servers'].detect {|_| _['id'] == server_id}
|
||||
if server = list_servers_detail.body['servers'].detect {|_| _['id'] == "#{server_id}"}
|
||||
response.status = [200, 203][rand(1)]
|
||||
response.body = { 'server' => server }
|
||||
response.body['server']['id'] = server['id'].to_i
|
||||
response
|
||||
else
|
||||
raise Fog::Compute::Clodo::NotFound
|
||||
|
|
|
@ -29,8 +29,14 @@ module Fog
|
|||
response.status = 200
|
||||
response.body = {
|
||||
'images' => [
|
||||
{ 'name' => 'Debian 5.0.6 64 bits', 'id' => 1, 'vps_type' => 'VirtualServer', 'status' => 'ACTIVE' },
|
||||
{ 'name' => 'CentOS 5.5 32 bits', 'id' => 3, 'vps_type' => 'VirtualServer', 'status' => 'ACTIVE' }
|
||||
{ 'name' => 'Debian 6 64 bits',
|
||||
'id' => "541",
|
||||
'vps_type' => 'ScaleServer',
|
||||
'status' => 'ACTIVE' },
|
||||
{ 'name' => 'CentOS 5.5 32 bits',
|
||||
'id' => "31",
|
||||
'vps_type' => 'VirtualServer',
|
||||
'status' => 'ACTIVE' }
|
||||
]
|
||||
}
|
||||
response
|
||||
|
|
|
@ -33,15 +33,21 @@ module Fog
|
|||
response = Excon::Response.new
|
||||
response.status = 200
|
||||
response.body = {
|
||||
'images' => [{ 'os_type' => 'debian', 'os_bits' => 64, 'os_hvm' => 0, '_attr' => {
|
||||
'id' => 1,
|
||||
'name' => 'Debian 5.0.6 64 bits',
|
||||
'images' => [{ 'os_type' => 'debian',
|
||||
'os_bits' => "64",
|
||||
'os_hvm' => "0",
|
||||
'_attr' => {
|
||||
'id' => "541",
|
||||
'name' => 'Debian 6 64 bits',
|
||||
'status' => 'ACTIVE',
|
||||
'vps_type' => 'VirtualServer'
|
||||
'vps_type' => 'ScaleServer'
|
||||
}},
|
||||
{ 'os_type' => 'centos', 'os_bits' => 32, 'os_hvm' => 0, '_attr' => {
|
||||
{ 'os_type' => 'centos',
|
||||
'os_bits' => "32",
|
||||
'os_hvm' => "0",
|
||||
'_attr' => {
|
||||
'name' => 'CentOS 5.5 32 bits',
|
||||
'id' => 1,
|
||||
'id' => "31",
|
||||
'vps_type' => 'VirtualServer',
|
||||
'status' => 'ACTIVE',
|
||||
}}]
|
||||
|
|
|
@ -9,8 +9,17 @@ module Fog
|
|||
# * response<~Excon::Response>:
|
||||
# * body<~Hash>:
|
||||
# * 'servers'<~Array>:
|
||||
# * 'id'<~Integer> - Id of server
|
||||
# * 'name<~String> - Name of server
|
||||
# * 'id'<~String> - Id of server
|
||||
# * 'name'<~String> - Name of server
|
||||
# * 'addresses'<~Hash>:
|
||||
# * 'public'<~Array>:
|
||||
# * 'dosprotect'<~Bool> - DDoS protection enabled
|
||||
# * 'primary_ip'<~Bool> - Is a primary IP-address
|
||||
# * 'isp'<~Bool> - ISPManager license enabled
|
||||
# * 'ip'<~String> - IP-address
|
||||
# * 'imageId'<~String> - ID of OS image installed
|
||||
# * 'type'<~String> - Type (ScaleServer or Virtual Server)
|
||||
# * 'status'<~String> - Server's status
|
||||
def list_servers
|
||||
request(
|
||||
:expects => [200, 203],
|
||||
|
@ -28,7 +37,7 @@ module Fog
|
|||
data = list_servers_detail.body['servers']
|
||||
servers = []
|
||||
for server in data
|
||||
servers << server.reject { |key, value| !['id', 'name'].include?(key) }
|
||||
servers << server.reject { |key, value| !['id', 'name', 'addresses', 'imageId', 'type', 'status', 'state'].include?(key) }
|
||||
end
|
||||
response.status = [200, 203][rand(1)]
|
||||
response.body = { 'servers' => servers }
|
||||
|
|
|
@ -15,8 +15,6 @@ module Fog
|
|||
# * 'status'<~String> - Current server status
|
||||
# * 'addresses'<~Hash>:
|
||||
# * 'public'<~Array> - public address strings
|
||||
# * 'private'<~Array> - private address strings
|
||||
# * 'metadata'<~Hash> - metadata
|
||||
def list_servers_detail
|
||||
request(
|
||||
:expects => [200, 203],
|
||||
|
|
|
@ -7,6 +7,13 @@ module Fog
|
|||
server_action(id, body)
|
||||
end
|
||||
end
|
||||
|
||||
class Mock
|
||||
def reboot_server(id, type)
|
||||
body = {'reboot' => {}}
|
||||
server_action(id, body)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -8,6 +8,14 @@ module Fog
|
|||
server_action(id, body)
|
||||
end
|
||||
end
|
||||
|
||||
class Mock
|
||||
def rebuild_server(id, image_id, vps_isp = nil)
|
||||
body = {'rebuild' => {'imageId' => image_id}}
|
||||
body['rebuild']['vps_isp'] = vps_isp if vps_isp
|
||||
server_action(id, body)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -12,6 +12,9 @@ module Fog
|
|||
end
|
||||
class Mock
|
||||
def server_action(id, action)
|
||||
|
||||
raise Excon::Errors::BadRequest.new("Invalid server id #{id}.") unless id > 0
|
||||
|
||||
response = Excon::Response.new
|
||||
response.status = 204
|
||||
response
|
||||
|
|
|
@ -7,6 +7,13 @@ module Fog
|
|||
server_action(id, body)
|
||||
end
|
||||
end
|
||||
|
||||
class Mock
|
||||
def start_server(id)
|
||||
body = {'start' => {}}
|
||||
server_action(id, body)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -7,6 +7,13 @@ module Fog
|
|||
server_action(id, body)
|
||||
end
|
||||
end
|
||||
|
||||
class Mock
|
||||
def stop_server(id)
|
||||
body = {'stop' => {}}
|
||||
server_action(id, body)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue