Class: Deltacloud::Drivers::RimuHosting::RimuHostingClient

Inherits:
Object
  • Object
show all
Defined in:
lib/deltacloud/drivers/rimuhosting/rimuhosting_client.rb

Instance Method Summary collapse

Constructor Details

#initialize(credentials, baseuri = 'https://rimuhosting.com/r') ⇒ RimuHostingClient

Returns a new instance of RimuHostingClient.



31
32
33
34
35
36
# File 'lib/deltacloud/drivers/rimuhosting/rimuhosting_client.rb', line 31

def initialize(credentials ,baseuri = 'https://rimuhosting.com/r')
  @uri = URI.parse(baseuri)
  @service = Net::HTTP.new(@uri.host, @uri.port)
  @service.use_ssl = true
  @auth = "rimuhosting apikey=#{credentials.password}"
end

Instance Method Details

#create_server(image_id, plan_code, name) ⇒ Object



76
77
78
79
80
# File 'lib/deltacloud/drivers/rimuhosting/rimuhosting_client.rb', line 76

def create_server(image_id, plan_code, name)
  json = {:new_vps => {:instantiation_options => {:domain_name => name, :distro => image_id},
                      :pricing_plan_code => plan_code}}.to_json
  request('/orders/new-vps',json, 'POST')[:about_order]
end

#delete_server(id) ⇒ Object



72
73
74
# File 'lib/deltacloud/drivers/rimuhosting/rimuhosting_client.rb', line 72

def delete_server(id)
  request("/orders/order-#{id}-a/vps",'', 'DELETE')
end

#list_imagesObject



55
56
57
# File 'lib/deltacloud/drivers/rimuhosting/rimuhosting_client.rb', line 55

def list_images
  request('/distributions')["distro_infos"]
end

#list_nodesObject



63
64
65
# File 'lib/deltacloud/drivers/rimuhosting/rimuhosting_client.rb', line 63

def list_nodes
  request('/orders;include_inactive=N')["about_orders"]
end

#list_plansObject



59
60
61
# File 'lib/deltacloud/drivers/rimuhosting/rimuhosting_client.rb', line 59

def list_plans
  request('/pricing-plans;server-type=VPS')["pricing_plan_infos"]
end

#request(resource, data = '', method = 'GET') ⇒ Object



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/deltacloud/drivers/rimuhosting/rimuhosting_client.rb', line 38

def request(resource, data='', method='GET')
  headers = {"Accept" => "application/json", "Content-Type" => "application/json"}
  if(!@auth.nil?)
    headers["Authorization"] = @auth
  end
  r = @service.send_request(method, @uri.path + resource, data, headers)
       puts r.body
  res = JSON.parse(r.body)
  res = res[res.keys[0]]

  if(res['response_type'] == "ERROR" and ( (res['error_info']['error_class'] == "PermissionException") or
			     (res['error_info']['error_class'] == "LoginRequired") )) 
    raise Deltacloud::AuthException.new
  end
  res
end

#set_server_state(id, state) ⇒ Object



67
68
69
70
# File 'lib/deltacloud/drivers/rimuhosting/rimuhosting_client.rb', line 67

def set_server_state(id, state)
  json = {"reboot_request" => {"running_state" => state}}.to_json
  request("/orders/order-#{id}-a/vps/running-state", json, 'PUT')
end