Class: Fog::Compute::Clodo::Real
- Inherits:
-
Object
- Object
- Fog::Compute::Clodo::Real
- Defined in:
- lib/fog/clodo/compute.rb,
lib/fog/clodo/requests/compute/list_images.rb,
lib/fog/clodo/requests/compute/stop_server.rb,
lib/fog/clodo/requests/compute/list_servers.rb,
lib/fog/clodo/requests/compute/start_server.rb,
lib/fog/clodo/requests/compute/create_server.rb,
lib/fog/clodo/requests/compute/delete_server.rb,
lib/fog/clodo/requests/compute/reboot_server.rb,
lib/fog/clodo/requests/compute/server_action.rb,
lib/fog/clodo/requests/compute/add_ip_address.rb,
lib/fog/clodo/requests/compute/rebuild_server.rb,
lib/fog/clodo/requests/compute/move_ip_address.rb,
lib/fog/clodo/requests/compute/delete_ip_address.rb,
lib/fog/clodo/requests/compute/get_image_details.rb,
lib/fog/clodo/requests/compute/get_server_details.rb,
lib/fog/clodo/requests/compute/list_images_detail.rb,
lib/fog/clodo/requests/compute/list_servers_detail.rb
Instance Method Summary collapse
-
#add_ip_address(server_id) ⇒ Object
Bye new IP-address for specified server ==== Paramaters * server_id<~Integer> - Id of server to bye IP for.
-
#create_server(image_id, options = {}) ⇒ Object
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.
-
#delete_ip_address(server_id, ip) ⇒ Object
Delete IP-address from specified server ==== Paramaters * server_id<~Integer> - Id of server to delete IP from * ip<~String> - IP-address to delete.
-
#delete_server(server_id) ⇒ Object
Delete an existing server.
- #get_image_details(image_id) ⇒ Object
-
#get_server_details(server_id) ⇒ Object
Get details about a server.
-
#initialize(options = {}) ⇒ Real
constructor
A new instance of Real.
-
#list_images ⇒ Object
List all images (IDs and names only).
-
#list_images_detail ⇒ Object
-
‘id’<~Integer> - Id of the image * ‘name’<~String> - Name of the image * ‘status’<~String> - Status of the image * ‘vps_type’<~String> - VirtualServer or ScaleServer.
-
-
#list_servers ⇒ Object
List all servers (IDs and names only).
-
#list_servers_detail ⇒ Object
List all servers details.
-
#move_ip_address(server_id, ip) ⇒ Object
Move IP-address to specified server.
- #reboot_server(id, type) ⇒ Object
- #rebuild_server(id, image_id, vps_isp = nil) ⇒ Object
- #reload ⇒ Object
- #request(params) ⇒ Object
- #server_action(id, action) ⇒ Object
- #start_server(id) ⇒ Object
- #stop_server(id) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Real
Returns a new instance of Real.
76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/fog/clodo/compute.rb', line 76 def initialize(={}) require 'multi_json' @clodo_api_key = [:clodo_api_key] @clodo_username = [:clodo_username] @clodo_auth_url = [:clodo_auth_url] @clodo_servicenet = [:clodo_servicenet] @clodo_auth_token = [:clodo_auth_token] @clodo_management_url = [:clodo_management_url] @clodo_must_reauthenticate = false authenticate Excon.ssl_verify_peer = false if [:clodo_servicenet] == true @connection = Fog::Connection.new("#{@scheme}://#{@host}:#{@port}", [:persistent]) end |
Instance Method Details
#add_ip_address(server_id) ⇒ Object
Bye new IP-address for specified server
Paramaters
-
server_id<~Integer> - Id of server to bye IP for
Returns
-
response<~Excon::Response>
14 15 16 17 18 19 20 |
# File 'lib/fog/clodo/requests/compute/add_ip_address.rb', line 14 def add_ip_address(server_id) request( :expects => [204], :method => 'PUT', :path => "servers/#{server_id}/ips" ) end |
#create_server(image_id, options = {}) ⇒ Object
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
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/fog/clodo/requests/compute/create_server.rb', line 19 def create_server(image_id, = {}) data = { 'server' => { :vps_os => image_id, :vps_hdd => [:vps_hdd]?[:vps_hdd]:5, :vps_memory => [:vps_memory]?[:vps_memory]:256, :vps_memory_max => [:vps_memory_max]?[:vps_memory_max]:1024, :vps_admin => [:vps_admin]?[:vps_admin]:1 } } data['server'].merge! if request( :body => MultiJson.encode(data), :expects => [200, 202], :method => 'POST', :path => 'servers' ) end |
#delete_ip_address(server_id, ip) ⇒ Object
Delete IP-address from specified server
Paramaters
-
server_id<~Integer> - Id of server to delete IP from
-
ip<~String> - IP-address to delete
Returns
-
response<~Excon::Response>
15 16 17 18 19 20 21 22 23 24 |
# File 'lib/fog/clodo/requests/compute/delete_ip_address.rb', line 15 def delete_ip_address(server_id, ip) data = {'ip' => ip} request( :expects => [204], :method => 'DELETE', :path => "servers/#{server_id}/ips", :body => MultiJson.encode(data) ) end |
#delete_server(server_id) ⇒ Object
Delete an existing server
Parameters
-
id<~Integer> - Id of server to delete
11 12 13 14 15 16 17 |
# File 'lib/fog/clodo/requests/compute/delete_server.rb', line 11 def delete_server(server_id) request( :expects => 204, :method => 'DELETE', :path => "servers/#{server_id}" ) end |
#get_image_details(image_id) ⇒ Object
5 6 7 8 9 |
# File 'lib/fog/clodo/requests/compute/get_image_details.rb', line 5 def get_image_details(image_id) request(:expects => [200,203], :method => 'GET', :path => "images/#{image_id}") end |
#get_server_details(server_id) ⇒ Object
Get details about a server
Parameters
-
server_id<~Integer> - Id of server to get details for
Returns
-
response<~Excon::Response>:
-
body<~Hash>:
-
‘server’<~Hash>:
-
‘addresses’<~Hash>:
-
‘public’<~Array> - public address strings
-
‘private’<~Array> - private address strings
-
-
‘id’<~Integer> - Id of server
-
‘imageId’<~Integer> - Id of image used to boot server
-
‘name<~String> - Name of server
-
‘status’<~String> - Current server status
-
-
22 23 24 25 26 27 28 |
# File 'lib/fog/clodo/requests/compute/get_server_details.rb', line 22 def get_server_details(server_id) request( :expects => [200, 203], :method => 'GET', :path => "servers/#{server_id}" ) end |
#list_images ⇒ Object
List all images (IDs and names only)
Returns
-
response<~Excon::Response>:
-
body<~Hash>:
-
‘id’<~Integer> - Id of the image
-
‘name’<~String> - Name of the image
-
‘status’<~String> - Status of the image
-
‘vps_type’<~String> - VirtualServer or ScaleServer
-
-
15 16 17 18 19 20 21 |
# File 'lib/fog/clodo/requests/compute/list_images.rb', line 15 def list_images request( :expects => [200, 203], :method => 'GET', :path => 'images' ) end |
#list_images_detail ⇒ Object
-
‘id’<~Integer> - Id of the image
* 'name'<~String> - Name of the image * 'status'<~String> - Status of the image * 'vps_type'<~String> - VirtualServer or ScaleServer
20 21 22 23 24 25 26 |
# File 'lib/fog/clodo/requests/compute/list_images_detail.rb', line 20 def list_images_detail request( :expects => [200, 203], :method => 'GET', :path => 'images/detail' ) end |
#list_servers ⇒ Object
List all servers (IDs and names only)
Returns
-
response<~Excon::Response>:
-
body<~Hash>:
-
‘servers’<~Array>:
-
‘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
-
-
23 24 25 26 27 28 29 |
# File 'lib/fog/clodo/requests/compute/list_servers.rb', line 23 def list_servers request( :expects => [200, 203], :method => 'GET', :path => 'servers' ) end |
#list_servers_detail ⇒ Object
List all servers details
Returns
-
response<~Excon::Response>:
-
body<~Hash>:
-
‘servers’<~Array>:
-
‘id’<~Integer> - Id of server
-
‘name<~String> - Name of server
-
‘imageId’<~Integer> - Id of image used to boot server
-
‘status’<~String> - Current server status
-
‘addresses’<~Hash>:
-
‘public’<~Array> - public address strings
-
-
-
18 19 20 21 22 23 24 |
# File 'lib/fog/clodo/requests/compute/list_servers_detail.rb', line 18 def list_servers_detail request( :expects => [200, 203], :method => 'GET', :path => 'servers/detail' ) end |
#move_ip_address(server_id, ip) ⇒ Object
Move IP-address to specified server.
Paramaters
-
server_id<~Integer> - Id of server to move IP to
-
ip<~String> - IP-address to move
Returns
-
response<~Excon::Response>
15 16 17 18 19 20 21 22 |
# File 'lib/fog/clodo/requests/compute/move_ip_address.rb', line 15 def move_ip_address(server_id, ip) request( :expects => [204], :method => 'GET', :path => "servers/#{server_id}/ips/moveip", :body => MultiJson.encode({'ip'=>"#{ip}"}) ) end |
#reboot_server(id, type) ⇒ Object
5 6 7 8 |
# File 'lib/fog/clodo/requests/compute/reboot_server.rb', line 5 def reboot_server(id, type) body = {'reboot' => {}} server_action(id, body) end |
#rebuild_server(id, image_id, vps_isp = nil) ⇒ Object
5 6 7 8 9 |
# File 'lib/fog/clodo/requests/compute/rebuild_server.rb', line 5 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 |
#reload ⇒ Object
90 91 92 |
# File 'lib/fog/clodo/compute.rb', line 90 def reload @connection.reset end |
#request(params) ⇒ Object
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 |
# File 'lib/fog/clodo/compute.rb', line 94 def request(params) begin response = @connection.request(params.merge({ :headers => { 'Content-Type' => 'application/json', 'Accept' => 'application/json', 'X-Auth-Token' => @auth_token }.merge!(params[:headers] || {}), :host => @host, :path => "#{@path}/#{params[:path]}" })) rescue Excon::Errors::Unauthorized => error if error.response.body != 'Bad username or password' # token expiration @clodo_must_reauthenticate = true authenticate retry else # bad credentials raise error end rescue Excon::Errors::HTTPStatusError => error raise case error when Excon::Errors::NotFound Fog::Compute::Clodo::NotFound.slurp(error) else error end end unless response.body.empty? response.body = MultiJson.decode(response.body) end response end |
#server_action(id, action) ⇒ Object
5 6 7 8 9 10 11 |
# File 'lib/fog/clodo/requests/compute/server_action.rb', line 5 def server_action(id, action) request( :body => MultiJson.encode(action), :expects => [204], :method => 'POST', :path => "servers/#{id}/action") end |
#start_server(id) ⇒ Object
5 6 7 8 |
# File 'lib/fog/clodo/requests/compute/start_server.rb', line 5 def start_server(id) body = {'start' => {}} server_action(id, body) end |
#stop_server(id) ⇒ Object
5 6 7 8 |
# File 'lib/fog/clodo/requests/compute/stop_server.rb', line 5 def stop_server(id) body = {'stop' => {}} server_action(id, body) end |