class Fog::Compute::Clodo::Real

Public Class Methods

new(options={}) click to toggle source
# File lib/fog/clodo/compute.rb, line 73
def initialize(options={})
  @clodo_api_key = options[:clodo_api_key]
  @clodo_username = options[:clodo_username]
  @clodo_auth_url = options[:clodo_auth_url]
  @clodo_servicenet = options[:clodo_servicenet]
  @clodo_auth_token = options[:clodo_auth_token]
  @clodo_management_url = options[:clodo_management_url]
  @clodo_must_reauthenticate = false
  authenticate
  Excon.ssl_verify_peer = false if options[:clodo_servicenet] == true
  @connection = Fog::XML::Connection.new("#{@scheme}://#{@host}:#{@port}", options[:persistent])
end

Public Instance Methods

add_ip_address(server_id) click to toggle source

Bye new IP-address for specified server

Paramaters

  • server_id<~Integer> - Id of server to bye IP for

Returns

  • response<~Excon::Response>

# File lib/fog/clodo/requests/compute/add_ip_address.rb, line 13
def add_ip_address(server_id)
  request(
          :expects  => [204],
          :method   => 'PUT',
          :path     => "servers/#{server_id}/ips"
          )
end
create_server(image_id, options = {}) click to toggle source

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

# File lib/fog/clodo/requests/compute/create_server.rb, line 19
def create_server(image_id, options = {})
  data = {
    'server' => {
      :vps_os   => image_id,
      :vps_hdd => options[:vps_hdd]?options[:vps_hdd]:5,
      :vps_memory => options[:vps_memory]?options[:vps_memory]:256,
      :vps_memory_max => options[:vps_memory_max]?options[:vps_memory_max]:1024,
      :vps_admin => options[:vps_admin]?options[:vps_admin]:1
    }
  }

  data['server'].merge! options if options

  request(
          :body     => Fog::JSON.encode(data),
          :expects  => [200, 202],
          :method   => 'POST',
          :path     => 'servers'
          )
end
delete_ip_address(server_id, ip) click to toggle source

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>

# File lib/fog/clodo/requests/compute/delete_ip_address.rb, line 14
def delete_ip_address(server_id, ip)
  data = {'ip' => ip}

  request(
          :expects  => [204],
          :method   => 'DELETE',
          :path     => "servers/#{server_id}/ips",
          :body     => Fog::JSON.encode(data)
          )
end
delete_server(server_id) click to toggle source

Delete an existing server

Parameters

  • id<~Integer> - Id of server to delete

# File lib/fog/clodo/requests/compute/delete_server.rb, line 10
def delete_server(server_id)
  request(
    :expects => 204,
    :method => 'DELETE',
    :path   => "servers/#{server_id}"
  )
end
get_image_details(image_id) click to toggle source
# 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) click to toggle source

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

# File lib/fog/clodo/requests/compute/get_server_details.rb, line 21
def get_server_details(server_id)
  request(
    :expects  => [200, 203],
    :method   => 'GET',
    :path     => "servers/#{server_id}"
  )
end
list_images() click to toggle source

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

# File lib/fog/clodo/requests/compute/list_images.rb, line 14
def list_images
  request(
          :expects  => [200, 203],
          :method   => 'GET',
          :path     => 'images'
          )
end
list_images_detail() click to toggle source

List all images

Returns

  • response<~Excon::Response>:

    • body<~Hash>:

      • 'os_type'<~String> - OS distribution

      • 'os_bits'<~Integer> - OS bits

      • 'os_hvm'<~Integer> - HVM flag

      • '_attr'<~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

# File lib/fog/clodo/requests/compute/list_images_detail.rb, line 19
def list_images_detail
  request(
          :expects  => [200, 203],
          :method   => 'GET',
          :path     => 'images/detail'
          )
end
list_servers() click to toggle source

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

# File lib/fog/clodo/requests/compute/list_servers.rb, line 22
def list_servers
  request(
    :expects  => [200, 203],
    :method   => 'GET',
    :path     => 'servers'
  )
end
list_servers_detail() click to toggle source

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

# File lib/fog/clodo/requests/compute/list_servers_detail.rb, line 17
def list_servers_detail
  request(
    :expects  => [200, 203],
    :method   => 'GET',
    :path     => 'servers/detail'
  )
end
move_ip_address(server_id, ip) click to toggle source

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>

# File lib/fog/clodo/requests/compute/move_ip_address.rb, line 14
def move_ip_address(server_id, ip)
  request(
          :expects  => [204],
          :method   => 'GET',
          :path     => "servers/#{server_id}/ips/moveip",
          :body     => Fog::JSON.encode({'ip'=>"#{ip}"})
          )
end
reboot_server(id, type) click to toggle source
# 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) click to toggle source
# 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() click to toggle source
# File lib/fog/clodo/compute.rb, line 86
def reload
  @connection.reset
end
request(params) click to toggle source
# File lib/fog/clodo/compute.rb, line 90
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 = Fog::JSON.decode(response.body)
  end
  response
end
server_action(id, action) click to toggle source
# File lib/fog/clodo/requests/compute/server_action.rb, line 5
def server_action(id, action)
  request(
          :body    => Fog::JSON.encode(action),
          :expects => [204],
          :method  => 'POST',
          :path    => "servers/#{id}/action")
end
start_server(id) click to toggle source
# 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) click to toggle source
# File lib/fog/clodo/requests/compute/stop_server.rb, line 5
def stop_server(id)
  body = {'stop' => {}}
  server_action(id, body)
end

Private Instance Methods

authenticate() click to toggle source
# File lib/fog/clodo/compute.rb, line 125
def authenticate
  if @clodo_must_reauthenticate || @clodo_auth_token.nil?
    options = {
      :clodo_api_key  => @clodo_api_key,
      :clodo_username => @clodo_username,
      :clodo_auth_url => @clodo_auth_url
    }
    credentials = Fog::Clodo.authenticate(options)
    @auth_token = credentials['X-Auth-Token']
    uri = URI.parse(credentials['X-Server-Management-Url'])
  else
    @auth_token = @clodo_auth_token
    uri = URI.parse(@clodo_management_url)
  end
  @host   = @clodo_servicenet == true ? "snet-#{uri.host}" : uri.host
  @path   = uri.path
  @port   = uri.port
  @scheme = uri.scheme
end