Class: Fog::Compute::Glesys::Real

Inherits:
Object
  • Object
show all
Defined in:
lib/rackspace-fog/glesys/compute.rb,
lib/rackspace-fog/glesys/requests/compute/stop.rb,
lib/rackspace-fog/glesys/requests/compute/start.rb,
lib/rackspace-fog/glesys/requests/compute/create.rb,
lib/rackspace-fog/glesys/requests/compute/ip_add.rb,
lib/rackspace-fog/glesys/requests/compute/reboot.rb,
lib/rackspace-fog/glesys/requests/compute/destroy.rb,
lib/rackspace-fog/glesys/requests/compute/ip_take.rb,
lib/rackspace-fog/glesys/requests/compute/ip_remove.rb,
lib/rackspace-fog/glesys/requests/compute/ip_details.rb,
lib/rackspace-fog/glesys/requests/compute/ip_release.rb,
lib/rackspace-fog/glesys/requests/compute/ip_list_own.rb,
lib/rackspace-fog/glesys/requests/compute/ip_list_free.rb,
lib/rackspace-fog/glesys/requests/compute/list_servers.rb,
lib/rackspace-fog/glesys/requests/compute/server_status.rb,
lib/rackspace-fog/glesys/requests/compute/template_list.rb,
lib/rackspace-fog/glesys/requests/compute/server_details.rb

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Real

Returns a new instance of Real.



68
69
70
71
72
73
74
75
76
77
# File 'lib/rackspace-fog/glesys/compute.rb', line 68

def initialize(options)
  require 'base64'

  @api_url            = options[:glesys_api_url] || Fog.credentials[:glesys_api_url] || API_URL
  @glesys_username    = options[:glesys_username] || Fog.credentials[:glesys_api_key]
  @glesys_api_key     = options[:glesys_api_key] || Fog.credentials[:glesys_api_key]
  @connection_options = options[:connection_options] || {}
  @persistent         = options[:persistent] || false
  @connection = Fog::Connection.new(@api_url, @persistent, @connection_options)
end

Instance Method Details

#create(options = {}) ⇒ Object



6
7
8
# File 'lib/rackspace-fog/glesys/requests/compute/create.rb', line 6

def create(options = {})
  request('server/create/',options)
end

#destroy(options) ⇒ Object



6
7
8
9
10
11
12
13
# File 'lib/rackspace-fog/glesys/requests/compute/destroy.rb', line 6

def destroy(options)

  if options[:keepip].nil?
    options[:keepip] = 0
  end

  request("/server/destroy", options)
end

#ip_add(params) ⇒ Object



6
7
8
# File 'lib/rackspace-fog/glesys/requests/compute/ip_add.rb', line 6

def ip_add(params)
  request("/ip/add", params)
end

#ip_list_free(options = {}) ⇒ Object



6
7
8
# File 'lib/rackspace-fog/glesys/requests/compute/ip_details.rb', line 6

def ip_list_free(params)
  request("/ip/listfree", params)
end

#ip_list_own(options = {}) ⇒ Object



6
7
8
# File 'lib/rackspace-fog/glesys/requests/compute/ip_list_own.rb', line 6

def ip_list_own(options = {})
  request("/ip/listown", options)
end

#ip_release(params) ⇒ Object



6
7
8
# File 'lib/rackspace-fog/glesys/requests/compute/ip_release.rb', line 6

def ip_release(params)
  request("/ip/release", params)
end

#ip_remove(params) ⇒ Object



6
7
8
# File 'lib/rackspace-fog/glesys/requests/compute/ip_remove.rb', line 6

def ip_remove(params)
  request("/ip/remove", params)
end

#ip_take(params) ⇒ Object



6
7
8
# File 'lib/rackspace-fog/glesys/requests/compute/ip_take.rb', line 6

def ip_take(params)
  request("/ip/take", params)
end

#list_servers(serverid = nil, options = {}) ⇒ Object



6
7
8
9
10
11
12
13
# File 'lib/rackspace-fog/glesys/requests/compute/list_servers.rb', line 6

def list_servers(serverid = nil, options = {})

  unless serverid.nil?
    options[:serverid] = serverid
  end

  request("/server/list", options)
end

#reboot(param) ⇒ Object



6
7
8
# File 'lib/rackspace-fog/glesys/requests/compute/reboot.rb', line 6

def reboot(param)
  request("/server/reboot", param)
end

#request(method_name, options = {}) ⇒ Object



79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
# File 'lib/rackspace-fog/glesys/compute.rb', line 79

def request(method_name, options = {}) 

  options.merge!( {:format => 'json'})

  begin
    parser = options.delete(:parser)
    data = @connection.request(
      :expects => 200,
      :method  => "POST",
      :body    => urlencode(options),
      :parser  => parser,
      :path    => method_name,
      :headers => {
        'Authorization' => "Basic #{encoded_api_auth}",
        'Content-Type'  => 'application/x-www-form-urlencoded'
      }
    )

    data.body = Fog::JSON.decode(data.body)

    response_code =  data.body['response']['status']['code']

    unless response_code.to_i == 200
      raise Fog::Compute::Glesys::Error, "#{data.body['response']['status']['text']}"
    end
    data
  rescue Excon::Errors::HTTPStatusError => error
    raise case error
    when Excon::Errors::NotFound
      Fog::Compute::Glesys::NotFound.slurp(error)
    else
      error
    end 
  end 
end

#server_details(serverid) ⇒ Object



6
7
8
# File 'lib/rackspace-fog/glesys/requests/compute/server_details.rb', line 6

def server_details(serverid)
  request("/server/details", { :serverid => serverid })
end

#server_status(serverid) ⇒ Object



6
7
8
# File 'lib/rackspace-fog/glesys/requests/compute/server_status.rb', line 6

def server_status(serverid)
  request("/server/status", { :serverid => serverid } )
end

#start(param) ⇒ Object



6
7
8
# File 'lib/rackspace-fog/glesys/requests/compute/start.rb', line 6

def start(param)
  request("/server/start", param)
end

#stop(param) ⇒ Object



6
7
8
# File 'lib/rackspace-fog/glesys/requests/compute/stop.rb', line 6

def stop(param)
  request("/server/stop", param)
end

#template_list(options = {}) ⇒ Object



6
7
8
# File 'lib/rackspace-fog/glesys/requests/compute/template_list.rb', line 6

def template_list(options = {})
  request("/server/templates", options)
end