mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
[clodo] Some cleanup before pool request.
This commit is contained in:
parent
618f76e56b
commit
b09efb5448
7 changed files with 67 additions and 45 deletions
|
@ -2,20 +2,19 @@ module Fog
|
|||
module Compute
|
||||
class Clodo
|
||||
class Real
|
||||
# Вход:
|
||||
# name - название VPS
|
||||
# vps_title - название VPS (может использоваться либо этот параметр, либо "name")
|
||||
# vps_type - тип VPS (VirtualServer,ScaleServer)
|
||||
# vps_memory - память (для ScaleServer - нижняя граница) (в MB)
|
||||
# vps_memory_max - верхняя граница памяти для ScaleServer (в MB)
|
||||
# vps_hdd - размер диска (в GB)
|
||||
# vps_admin - тип поддержки (1 - обычная, 2 - расширенная, 3 - VIP)
|
||||
# vps_os - id ОС
|
||||
# Выход:
|
||||
# id - номер VPS
|
||||
# name - название VPS
|
||||
# imageId - id ОС
|
||||
# adminPass - пароль root
|
||||
# Input:
|
||||
# vps_title - VDS title to display in VDS list
|
||||
# vps_type - VDS type (VirtualServer,ScaleServer)
|
||||
# vps_memory - memory size in megabytes (for ScaleServer - low limit)
|
||||
# vps_memory_max - maximum number of ScaleServer memory megabytes to scale up.
|
||||
# vps_hdd - Virtual HDD size im gigabytes.
|
||||
# vps_admin - support level (1 - usual&free, 2 - extended, 3 - VIP)
|
||||
# vps_os - OS ID to install
|
||||
# Output:
|
||||
# id - VDS ID
|
||||
# name - VDS title
|
||||
# imageId - OS ID
|
||||
# adminPass - root password
|
||||
|
||||
def create_server(image_id, options = {})
|
||||
data = {
|
||||
|
@ -38,6 +37,7 @@ module Fog
|
|||
)
|
||||
|
||||
end
|
||||
|
||||
class Mock
|
||||
def create_server(image_id, options = {})
|
||||
response = Excon::response.new
|
||||
|
@ -46,13 +46,13 @@ module Fog
|
|||
data = {
|
||||
'id' => Fog::Mock.random_numbers(6).to_i,
|
||||
'imageId' => image_id,
|
||||
'name' => options['name'] || "server_#{rand(999)}",
|
||||
'name' => options['name'] || "VPS #{rand(999)}",
|
||||
'adminPass' => '23ryh8udbcbyt'
|
||||
}
|
||||
|
||||
self.data[:last_modified][:servers][data['id']] = Time.now
|
||||
self.data[:servers][data['id']] = data
|
||||
response.body = { 'server' => data.merge({'adminPass' => 'password'}) }
|
||||
response.body = { 'server' => data }
|
||||
response
|
||||
end
|
||||
end
|
||||
|
|
|
@ -23,7 +23,7 @@ module Fog
|
|||
def delete_server(server_id)
|
||||
response = Excon::Response.new
|
||||
if server = list_servers_detail.body['servers'].detect {|_| _['id'] == server_id}
|
||||
if server['status'] == 'BUILD'
|
||||
if server['status'] == 'is_install'
|
||||
response.status = 405
|
||||
raise(Excon::Errors.status_error({:expects => 204}, response))
|
||||
else
|
||||
|
|
|
@ -1,13 +1,20 @@
|
|||
module Fog
|
||||
module Compute
|
||||
class Clodo
|
||||
class Real
|
||||
def get_image_details(image_id)
|
||||
request(:expects => [200,203],
|
||||
:method => 'GET',
|
||||
:path => "images/#{image_id}")
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
module Compute
|
||||
class Clodo
|
||||
class Real
|
||||
def get_image_details(image_id)
|
||||
request(:expects => [200,203],
|
||||
:method => 'GET',
|
||||
:path => "images/#{image_id}")
|
||||
end
|
||||
end
|
||||
class Mock
|
||||
def get_image_details(image_id)
|
||||
response = Excon::Response.new
|
||||
response.status = 404
|
||||
response
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -14,10 +14,10 @@ module Fog
|
|||
# * 'vps_type'<~String> - VirtualServer or ScaleServer
|
||||
def list_images
|
||||
request(
|
||||
:expects => [200, 203],
|
||||
:method => 'GET',
|
||||
:path => 'images'
|
||||
)
|
||||
:expects => [200, 203],
|
||||
:method => 'GET',
|
||||
:path => 'images'
|
||||
)
|
||||
end
|
||||
|
||||
end
|
||||
|
@ -29,9 +29,9 @@ 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 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' }
|
||||
]
|
||||
}
|
||||
response
|
||||
end
|
||||
|
|
|
@ -19,10 +19,10 @@ module Fog
|
|||
|
||||
def list_images_detail
|
||||
request(
|
||||
:expects => [200, 203],
|
||||
:method => 'GET',
|
||||
:path => 'images/detail'
|
||||
)
|
||||
:expects => [200, 203],
|
||||
:method => 'GET',
|
||||
:path => 'images/detail'
|
||||
)
|
||||
end
|
||||
|
||||
end
|
||||
|
@ -33,10 +33,18 @@ module Fog
|
|||
response = Excon::Response.new
|
||||
response.status = 200
|
||||
response.body = {
|
||||
'images' => [
|
||||
{ 'name' => 'Debian 5.0.6 64 bits', 'id' => 1, 'vps_type' => 'VirtualServer', 'status' => 'ACTIVE', 'os_type' => 'debian', 'os_bits' => 64, 'os_hvm' => 0 },
|
||||
{ 'name' => 'CentOS 5.5 32 bits', 'id' => 1, 'vps_type' => 'VirtualServer', 'status' => 'ACTIVE', 'os_type' => 'centos', 'os_bits' => 32, 'os_hvm' => 0 }
|
||||
]
|
||||
'images' => [{ 'os_type' => 'debian', 'os_bits' => 64, 'os_hvm' => 0, '_attr' => {
|
||||
'id' => 1,
|
||||
'name' => 'Debian 5.0.6 64 bits',
|
||||
'status' => 'ACTIVE',
|
||||
'vps_type' => 'VirtualServer'
|
||||
}},
|
||||
{ 'os_type' => 'centos', 'os_bits' => 32, 'os_hvm' => 0, '_attr' => {
|
||||
'name' => 'CentOS 5.5 32 bits',
|
||||
'id' => 1,
|
||||
'vps_type' => 'VirtualServer',
|
||||
'status' => 'ACTIVE',
|
||||
}}]
|
||||
}
|
||||
response
|
||||
end
|
||||
|
|
|
@ -35,9 +35,9 @@ module Fog
|
|||
servers = self.data[:servers].values
|
||||
for server in servers
|
||||
case server['status']
|
||||
when 'BUILD'
|
||||
when 'is_install'
|
||||
if Time.now - self.data[:last_modified][:servers][server['id']] > Fog::Mock.delay * 2
|
||||
server['status'] = 'ACTIVE'
|
||||
server['status'] = 'is_running'
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -10,6 +10,13 @@ module Fog
|
|||
:path => "servers/#{id}/action")
|
||||
end
|
||||
end
|
||||
class Mock
|
||||
def server_action(id, action)
|
||||
response = Excon::Response.new
|
||||
response.status = 204
|
||||
response
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Reference in a new issue