mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
[new_servers] rename new_servers to compute for consistency
This commit is contained in:
parent
24897e9c1e
commit
5e5946b2ad
17 changed files with 375 additions and 341 deletions
|
@ -1,88 +1,18 @@
|
|||
require 'fog/parser'
|
||||
|
||||
module Fog
|
||||
class NewServers < Fog::Service
|
||||
module NewServers
|
||||
|
||||
requires :new_servers_password
|
||||
requires :new_servers_username
|
||||
extend Fog::Provider
|
||||
|
||||
model_path 'fog/new_servers/models'
|
||||
|
||||
request_path 'fog/new_servers/requests'
|
||||
request :add_server
|
||||
request :cancel_server
|
||||
request :get_server
|
||||
request :list_images
|
||||
request :list_plans
|
||||
request :list_servers
|
||||
request :reboot_server
|
||||
|
||||
class Mock
|
||||
include Collections
|
||||
|
||||
def self.data
|
||||
@data ||= Hash.new do |hash, key|
|
||||
hash[key] = {}
|
||||
end
|
||||
end
|
||||
|
||||
def self.reset_data(keys=data.keys)
|
||||
for key in [*keys]
|
||||
data.delete(key)
|
||||
end
|
||||
end
|
||||
|
||||
def initialize(options={})
|
||||
@new_server_username = options[:new_servers_username]
|
||||
@data = self.class.data[@new_server_username]
|
||||
end
|
||||
service_path 'fog/new_servers'
|
||||
service 'compute'
|
||||
|
||||
def self.new(attributes = {})
|
||||
location = caller.first
|
||||
warning = "[yellow][WARN] Fog::NewServers#new is deprecated, use Fog::NewServers::Compute#new instead[/]"
|
||||
warning << " [light_black](" << location << ")[/] "
|
||||
Formatador.display_line(warning)
|
||||
Fog::NewServers::Compute.new(attributes)
|
||||
end
|
||||
|
||||
class Real
|
||||
include Collections
|
||||
|
||||
def initialize(options={})
|
||||
@new_servers_password = options[:new_servers_password]
|
||||
@new_servers_username = options[:new_servers_username]
|
||||
@host = options[:host] || "noc.newservers.com"
|
||||
@port = options[:port] || 443
|
||||
@scheme = options[:scheme] || 'https'
|
||||
@connection = Fog::Connection.new("#{@scheme}://#{@host}:#{@port}", options[:persistent])
|
||||
end
|
||||
|
||||
def reload
|
||||
@connection.reset
|
||||
end
|
||||
|
||||
def request(params)
|
||||
params[:query] ||= {}
|
||||
params[:query].merge!({
|
||||
:password => @new_servers_password,
|
||||
:username => @new_servers_username
|
||||
})
|
||||
params[:headers] ||= {}
|
||||
case params[:method]
|
||||
when 'DELETE', 'GET', 'HEAD'
|
||||
params[:headers]['Accept'] = 'application/xml'
|
||||
when 'POST', 'PUT'
|
||||
params[:headers]['Content-Type'] = 'application/xml'
|
||||
end
|
||||
|
||||
begin
|
||||
response = @connection.request(params.merge!({:host => @host}))
|
||||
rescue Excon::Errors::Error => error
|
||||
raise case error
|
||||
when Excon::Errors::NotFound
|
||||
Fog::NewServers::NotFound.slurp(error)
|
||||
else
|
||||
error
|
||||
end
|
||||
end
|
||||
|
||||
response
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -9,15 +9,15 @@ module NewServers
|
|||
def [](service)
|
||||
@@connections ||= Hash.new do |hash, key|
|
||||
hash[key] = case key
|
||||
when :new_servers
|
||||
Fog::NewServers.new
|
||||
when :compute
|
||||
Fog::NewServers::Compute.new
|
||||
end
|
||||
end
|
||||
@@connections[service]
|
||||
end
|
||||
|
||||
def services
|
||||
[:new_servers]
|
||||
[:compute]
|
||||
end
|
||||
|
||||
else
|
||||
|
|
90
lib/fog/new_servers/compute.rb
Normal file
90
lib/fog/new_servers/compute.rb
Normal file
|
@ -0,0 +1,90 @@
|
|||
require 'fog/parser'
|
||||
|
||||
module Fog
|
||||
module NewServers
|
||||
class Compute < Fog::Service
|
||||
|
||||
requires :new_servers_password
|
||||
requires :new_servers_username
|
||||
|
||||
model_path 'fog/new_servers/models/compute'
|
||||
|
||||
request_path 'fog/new_servers/requests/compute'
|
||||
request :add_server
|
||||
request :cancel_server
|
||||
request :get_server
|
||||
request :list_images
|
||||
request :list_plans
|
||||
request :list_servers
|
||||
request :reboot_server
|
||||
|
||||
class Mock
|
||||
include Collections
|
||||
|
||||
def self.data
|
||||
@data ||= Hash.new do |hash, key|
|
||||
hash[key] = {}
|
||||
end
|
||||
end
|
||||
|
||||
def self.reset_data(keys=data.keys)
|
||||
for key in [*keys]
|
||||
data.delete(key)
|
||||
end
|
||||
end
|
||||
|
||||
def initialize(options={})
|
||||
@new_server_username = options[:new_servers_username]
|
||||
@data = self.class.data[@new_server_username]
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
class Real
|
||||
include Collections
|
||||
|
||||
def initialize(options={})
|
||||
@new_servers_password = options[:new_servers_password]
|
||||
@new_servers_username = options[:new_servers_username]
|
||||
@host = options[:host] || "noc.newservers.com"
|
||||
@port = options[:port] || 443
|
||||
@scheme = options[:scheme] || 'https'
|
||||
@connection = Fog::Connection.new("#{@scheme}://#{@host}:#{@port}", options[:persistent])
|
||||
end
|
||||
|
||||
def reload
|
||||
@connection.reset
|
||||
end
|
||||
|
||||
def request(params)
|
||||
params[:query] ||= {}
|
||||
params[:query].merge!({
|
||||
:password => @new_servers_password,
|
||||
:username => @new_servers_username
|
||||
})
|
||||
params[:headers] ||= {}
|
||||
case params[:method]
|
||||
when 'DELETE', 'GET', 'HEAD'
|
||||
params[:headers]['Accept'] = 'application/xml'
|
||||
when 'POST', 'PUT'
|
||||
params[:headers]['Content-Type'] = 'application/xml'
|
||||
end
|
||||
|
||||
begin
|
||||
response = @connection.request(params.merge!({:host => @host}))
|
||||
rescue Excon::Errors::Error => error
|
||||
raise case error
|
||||
when Excon::Errors::NotFound
|
||||
Fog::NewServers::NotFound.slurp(error)
|
||||
else
|
||||
error
|
||||
end
|
||||
end
|
||||
|
||||
response
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,39 +0,0 @@
|
|||
module Fog
|
||||
class NewServers
|
||||
class Real
|
||||
|
||||
# Boot a new server
|
||||
#
|
||||
# ==== Parameters
|
||||
# * planId<~String> - The id of the plan to boot the server with
|
||||
# * options<~Hash>: optional extra arguments
|
||||
# * imageId<~String> - Optional image to boot server from
|
||||
# * name<~String> - Name to boot new server with
|
||||
#
|
||||
# ==== Returns
|
||||
# * response<~Excon::Response>:
|
||||
# * body<~Hash>:
|
||||
# * 'server'<~Hash>:
|
||||
# * 'id'<~String> - Id of the image
|
||||
#
|
||||
def add_server(plan_id, options = {})
|
||||
request(
|
||||
:expects => 200,
|
||||
:method => 'GET',
|
||||
:parser => Fog::ToHashDocument.new,
|
||||
:path => 'api/addServer',
|
||||
:query => {'planId' => plan_id}.merge!(options)
|
||||
)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
class Mock
|
||||
|
||||
def add_server(server_id)
|
||||
Fog::Mock.not_implemented
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,36 +0,0 @@
|
|||
module Fog
|
||||
class NewServers
|
||||
class Real
|
||||
|
||||
# Shutdown a running server
|
||||
#
|
||||
# ==== Parameters
|
||||
# * serverId<~String> - The id of the server to shutdown
|
||||
#
|
||||
# ==== Returns
|
||||
# * response<~Excon::Response>:
|
||||
# * body<~Hash>:
|
||||
# * 'server'<~Hash>:
|
||||
# * 'id'<~String> - Id of the image
|
||||
#
|
||||
def cancel_server(server_id)
|
||||
request(
|
||||
:expects => 200,
|
||||
:method => 'GET',
|
||||
:parser => Fog::ToHashDocument.new,
|
||||
:path => 'api/cancelServer',
|
||||
:query => {'serverId' => server_id}
|
||||
)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
class Mock
|
||||
|
||||
def cancel_server(server_id)
|
||||
Fog::Mock.not_implemented
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
41
lib/fog/new_servers/requests/compute/add_server.rb
Normal file
41
lib/fog/new_servers/requests/compute/add_server.rb
Normal file
|
@ -0,0 +1,41 @@
|
|||
module Fog
|
||||
module NewServers
|
||||
class Compute
|
||||
class Real
|
||||
|
||||
# Boot a new server
|
||||
#
|
||||
# ==== Parameters
|
||||
# * planId<~String> - The id of the plan to boot the server with
|
||||
# * options<~Hash>: optional extra arguments
|
||||
# * imageId<~String> - Optional image to boot server from
|
||||
# * name<~String> - Name to boot new server with
|
||||
#
|
||||
# ==== Returns
|
||||
# * response<~Excon::Response>:
|
||||
# * body<~Hash>:
|
||||
# * 'server'<~Hash>:
|
||||
# * 'id'<~String> - Id of the image
|
||||
#
|
||||
def add_server(plan_id, options = {})
|
||||
request(
|
||||
:expects => 200,
|
||||
:method => 'GET',
|
||||
:parser => Fog::ToHashDocument.new,
|
||||
:path => 'api/addServer',
|
||||
:query => {'planId' => plan_id}.merge!(options)
|
||||
)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
class Mock
|
||||
|
||||
def add_server(server_id)
|
||||
Fog::Mock.not_implemented
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
38
lib/fog/new_servers/requests/compute/cancel_server.rb
Normal file
38
lib/fog/new_servers/requests/compute/cancel_server.rb
Normal file
|
@ -0,0 +1,38 @@
|
|||
module Fog
|
||||
module NewServers
|
||||
class Compute
|
||||
class Real
|
||||
|
||||
# Shutdown a running server
|
||||
#
|
||||
# ==== Parameters
|
||||
# * serverId<~String> - The id of the server to shutdown
|
||||
#
|
||||
# ==== Returns
|
||||
# * response<~Excon::Response>:
|
||||
# * body<~Hash>:
|
||||
# * 'server'<~Hash>:
|
||||
# * 'id'<~String> - Id of the image
|
||||
#
|
||||
def cancel_server(server_id)
|
||||
request(
|
||||
:expects => 200,
|
||||
:method => 'GET',
|
||||
:parser => Fog::ToHashDocument.new,
|
||||
:path => 'api/cancelServer',
|
||||
:query => {'serverId' => server_id}
|
||||
)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
class Mock
|
||||
|
||||
def cancel_server(server_id)
|
||||
Fog::Mock.not_implemented
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
44
lib/fog/new_servers/requests/compute/get_server.rb
Normal file
44
lib/fog/new_servers/requests/compute/get_server.rb
Normal file
|
@ -0,0 +1,44 @@
|
|||
module Fog
|
||||
module NewServers
|
||||
class Compute
|
||||
class Real
|
||||
|
||||
# List servers
|
||||
#
|
||||
# ==== Returns
|
||||
# * response<~Excon::Response>:
|
||||
# * server<~Hash>:
|
||||
# * 'id'<~String> - Id of the server
|
||||
# * 'ip'<~Hash>:
|
||||
# * 'address'<~String> - Address of the ip
|
||||
# * 'name'<~String> - Name of the ip
|
||||
# * 'login'<~Hash>:
|
||||
# * 'name'<~String> - Name of the login
|
||||
# * 'password'<~String> - Password of the login
|
||||
# * 'username'<~String> - Username of the login
|
||||
# * 'name'<~String> - Name of the server
|
||||
# * 'notes'<~String> - Notes about the server
|
||||
# * 'state'<~String> - State of the server
|
||||
#
|
||||
def get_server(server_id)
|
||||
request(
|
||||
:expects => 200,
|
||||
:method => 'GET',
|
||||
:parser => Fog::ToHashDocument.new,
|
||||
:path => 'api/getServer',
|
||||
:query => {'serverId' => server_id}
|
||||
)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
class Mock
|
||||
|
||||
def get_server(server_id)
|
||||
Fog::Mock.not_implemented
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
35
lib/fog/new_servers/requests/compute/list_images.rb
Normal file
35
lib/fog/new_servers/requests/compute/list_images.rb
Normal file
|
@ -0,0 +1,35 @@
|
|||
module Fog
|
||||
module NewServers
|
||||
class Compute
|
||||
class Real
|
||||
|
||||
# List images
|
||||
#
|
||||
# ==== Returns
|
||||
# * response<~Excon::Response>:
|
||||
# * body<~Array>:
|
||||
# * 'id'<~String> - Id of the image
|
||||
# * 'name'<~String> - Name of the image
|
||||
# * 'size'<~String> - Size of the image
|
||||
#
|
||||
def list_images
|
||||
request(
|
||||
:expects => 200,
|
||||
:method => 'GET',
|
||||
:parser => Fog::ToHashDocument.new,
|
||||
:path => 'api/listImages'
|
||||
)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
class Mock
|
||||
|
||||
def list_images
|
||||
Fog::Mock.not_implemented
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
38
lib/fog/new_servers/requests/compute/list_plans.rb
Normal file
38
lib/fog/new_servers/requests/compute/list_plans.rb
Normal file
|
@ -0,0 +1,38 @@
|
|||
module Fog
|
||||
module NewServers
|
||||
class Compute
|
||||
class Real
|
||||
|
||||
# List available plans
|
||||
#
|
||||
# ==== Returns
|
||||
# * response<~Excon::Response>:
|
||||
# * body<~Array>:
|
||||
# * 'description'<~String> - Description of the plan
|
||||
# * 'id'<~String> - Id of the plan
|
||||
# * 'name'<~String> - Name of the plan
|
||||
# * 'rate'<~String> - Cost per hour of the plan
|
||||
# * 'os'<~String> - Operating system of the plan
|
||||
# * 'config'<~String> - Configuration of the plan
|
||||
#
|
||||
def list_plans
|
||||
request(
|
||||
:expects => 200,
|
||||
:method => 'GET',
|
||||
:parser => Fog::ToHashDocument.new,
|
||||
:path => 'api/listPlans'
|
||||
)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
class Mock
|
||||
|
||||
def list_plans
|
||||
Fog::Mock.not_implemented
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
44
lib/fog/new_servers/requests/compute/list_servers.rb
Normal file
44
lib/fog/new_servers/requests/compute/list_servers.rb
Normal file
|
@ -0,0 +1,44 @@
|
|||
module Fog
|
||||
module NewServers
|
||||
class Compute
|
||||
class Real
|
||||
|
||||
# List servers
|
||||
#
|
||||
# ==== Returns
|
||||
# * response<~Excon::Response>:
|
||||
# * body<~Array>:
|
||||
# * server<~Hash>:
|
||||
# * 'id'<~String> - Id of the server
|
||||
# * 'ip'<~Hash>:
|
||||
# * 'address'<~String> - Address of the ip
|
||||
# * 'name'<~String> - Name of the ip
|
||||
# * 'login'<~Hash>:
|
||||
# * 'name'<~String> - Name of the login
|
||||
# * 'password'<~String> - Password of the login
|
||||
# * 'username'<~String> - Username of the login
|
||||
# * 'name'<~String> - Name of the server
|
||||
# * 'notes'<~String> - Notes about the server
|
||||
# * 'state'<~String> - State of the server
|
||||
#
|
||||
def list_servers
|
||||
request(
|
||||
:expects => 200,
|
||||
:method => 'GET',
|
||||
:parser => Fog::ToHashDocument.new,
|
||||
:path => 'api/listServers'
|
||||
)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
class Mock
|
||||
|
||||
def list_servers
|
||||
Fog::Mock.not_implemented
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
32
lib/fog/new_servers/requests/compute/reboot_server.rb
Normal file
32
lib/fog/new_servers/requests/compute/reboot_server.rb
Normal file
|
@ -0,0 +1,32 @@
|
|||
module Fog
|
||||
module NewServers
|
||||
class Compute
|
||||
class Real
|
||||
|
||||
# Reboot a running server
|
||||
#
|
||||
# ==== Parameters
|
||||
# * serverId<~String> - The id of the server to reboot
|
||||
#
|
||||
def reboot_server(server_id)
|
||||
request(
|
||||
:expects => 200,
|
||||
:method => 'GET',
|
||||
:parser => Fog::ToHashDocument.new,
|
||||
:path => 'api/rebootServer',
|
||||
:query => {'serverId' => server_id}
|
||||
)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
class Mock
|
||||
|
||||
def reboot_server(server_id)
|
||||
Fog::Mock.not_implemented
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,42 +0,0 @@
|
|||
module Fog
|
||||
class NewServers
|
||||
class Real
|
||||
|
||||
# List servers
|
||||
#
|
||||
# ==== Returns
|
||||
# * response<~Excon::Response>:
|
||||
# * server<~Hash>:
|
||||
# * 'id'<~String> - Id of the server
|
||||
# * 'ip'<~Hash>:
|
||||
# * 'address'<~String> - Address of the ip
|
||||
# * 'name'<~String> - Name of the ip
|
||||
# * 'login'<~Hash>:
|
||||
# * 'name'<~String> - Name of the login
|
||||
# * 'password'<~String> - Password of the login
|
||||
# * 'username'<~String> - Username of the login
|
||||
# * 'name'<~String> - Name of the server
|
||||
# * 'notes'<~String> - Notes about the server
|
||||
# * 'state'<~String> - State of the server
|
||||
#
|
||||
def get_server(server_id)
|
||||
request(
|
||||
:expects => 200,
|
||||
:method => 'GET',
|
||||
:parser => Fog::ToHashDocument.new,
|
||||
:path => 'api/getServer',
|
||||
:query => {'serverId' => server_id}
|
||||
)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
class Mock
|
||||
|
||||
def get_server(server_id)
|
||||
Fog::Mock.not_implemented
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,33 +0,0 @@
|
|||
module Fog
|
||||
class NewServers
|
||||
class Real
|
||||
|
||||
# List images
|
||||
#
|
||||
# ==== Returns
|
||||
# * response<~Excon::Response>:
|
||||
# * body<~Array>:
|
||||
# * 'id'<~String> - Id of the image
|
||||
# * 'name'<~String> - Name of the image
|
||||
# * 'size'<~String> - Size of the image
|
||||
#
|
||||
def list_images
|
||||
request(
|
||||
:expects => 200,
|
||||
:method => 'GET',
|
||||
:parser => Fog::ToHashDocument.new,
|
||||
:path => 'api/listImages'
|
||||
)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
class Mock
|
||||
|
||||
def list_images
|
||||
Fog::Mock.not_implemented
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,36 +0,0 @@
|
|||
module Fog
|
||||
class NewServers
|
||||
class Real
|
||||
|
||||
# List available plans
|
||||
#
|
||||
# ==== Returns
|
||||
# * response<~Excon::Response>:
|
||||
# * body<~Array>:
|
||||
# * 'description'<~String> - Description of the plan
|
||||
# * 'id'<~String> - Id of the plan
|
||||
# * 'name'<~String> - Name of the plan
|
||||
# * 'rate'<~String> - Cost per hour of the plan
|
||||
# * 'os'<~String> - Operating system of the plan
|
||||
# * 'config'<~String> - Configuration of the plan
|
||||
#
|
||||
def list_plans
|
||||
request(
|
||||
:expects => 200,
|
||||
:method => 'GET',
|
||||
:parser => Fog::ToHashDocument.new,
|
||||
:path => 'api/listPlans'
|
||||
)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
class Mock
|
||||
|
||||
def list_plans
|
||||
Fog::Mock.not_implemented
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,42 +0,0 @@
|
|||
module Fog
|
||||
class NewServers
|
||||
class Real
|
||||
|
||||
# List servers
|
||||
#
|
||||
# ==== Returns
|
||||
# * response<~Excon::Response>:
|
||||
# * body<~Array>:
|
||||
# * server<~Hash>:
|
||||
# * 'id'<~String> - Id of the server
|
||||
# * 'ip'<~Hash>:
|
||||
# * 'address'<~String> - Address of the ip
|
||||
# * 'name'<~String> - Name of the ip
|
||||
# * 'login'<~Hash>:
|
||||
# * 'name'<~String> - Name of the login
|
||||
# * 'password'<~String> - Password of the login
|
||||
# * 'username'<~String> - Username of the login
|
||||
# * 'name'<~String> - Name of the server
|
||||
# * 'notes'<~String> - Notes about the server
|
||||
# * 'state'<~String> - State of the server
|
||||
#
|
||||
def list_servers
|
||||
request(
|
||||
:expects => 200,
|
||||
:method => 'GET',
|
||||
:parser => Fog::ToHashDocument.new,
|
||||
:path => 'api/listServers'
|
||||
)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
class Mock
|
||||
|
||||
def list_servers
|
||||
Fog::Mock.not_implemented
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,30 +0,0 @@
|
|||
module Fog
|
||||
class NewServers
|
||||
class Real
|
||||
|
||||
# Reboot a running server
|
||||
#
|
||||
# ==== Parameters
|
||||
# * serverId<~String> - The id of the server to reboot
|
||||
#
|
||||
def reboot_server(server_id)
|
||||
request(
|
||||
:expects => 200,
|
||||
:method => 'GET',
|
||||
:parser => Fog::ToHashDocument.new,
|
||||
:path => 'api/rebootServer',
|
||||
:query => {'serverId' => server_id}
|
||||
)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
class Mock
|
||||
|
||||
def reboot_server(server_id)
|
||||
Fog::Mock.not_implemented
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in a new issue