Class: Tama::Apis::WakameApi

Inherits:
Object
  • Object
show all
Includes:
InstanceHashBuilder
Defined in:
lib/apis/wakame.rb

Constant Summary collapse

Protocols =
["http","https"]

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from InstanceHashBuilder

#build_instances_hash, #dns_list, #ip_list, #private_dns, #private_ip

Constructor Details

#initialize(account = nil, host = nil, port = nil, protocol = "http", private_network_name = "nw-data") ⇒ WakameApi

Returns a new instance of WakameApi.

Raises:

  • (ArgumentError)


95
96
97
98
99
100
101
102
103
104
# File 'lib/apis/wakame.rb', line 95

def initialize( = nil,host = nil, port = nil, protocol = "http",private_network_name = "nw-data")
  raise ArgumentError, "Unknown protocol: #{protocol}. Can be either of the following: #{Protocols.join(",")}" unless Protocols.member?(protocol)
  
  self.host = host
  self.port = port
  self.protocol = protocol
  self. = 
  
  self.private_network_name = private_network_name
end

Instance Attribute Details

#accountObject

Returns the value of attribute account.



88
89
90
# File 'lib/apis/wakame.rb', line 88

def 
  @account
end

#hostObject

Returns the value of attribute host.



85
86
87
# File 'lib/apis/wakame.rb', line 85

def host
  @host
end

#portObject

Returns the value of attribute port.



86
87
88
# File 'lib/apis/wakame.rb', line 86

def port
  @port
end

#private_network_nameObject

Returns the value of attribute private_network_name.



89
90
91
# File 'lib/apis/wakame.rb', line 89

def private_network_name
  @private_network_name
end

#protocolObject

Returns the value of attribute protocol.



87
88
89
# File 'lib/apis/wakame.rb', line 87

def protocol
  @protocol
end

Instance Method Details

#make_request(uri, type, accesskey, list = []) ⇒ Object



125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
# File 'lib/apis/wakame.rb', line 125

def make_request(uri,type,accesskey,list = [])
  api = URI.parse(uri)
  
  req = type.new(api.path)
  req.add_field("X_VDC_ACCOUNT_UUID", accesskey)
  
  req.body = ""
  #req.set_form_data(form_data) unless form_data.nil?

  session = Net::HTTP.new(api.host, api.port)
  session.use_ssl = (self.protocol == "https")

  res = session.start do |http|
    http.request(req)
  end
  
  body = JSON.parse(res.body)
  body.first["results"].delete_if {|item| not list.member?(item["id"])} unless list.empty?
  
  body
end

#show_host_nodes(list = [], account = self.account) ⇒ Object Also known as: describe_host_nodes



106
107
108
# File 'lib/apis/wakame.rb', line 106

def show_host_nodes(list = [],  = self.)
  make_request("#{self.web_api}/api/host_nodes",Net::HTTP::Get,, list).first["results"]
end

#show_instance_specs(list = [], account = self.account) ⇒ Object Also known as: describe_instance_specs



111
112
113
# File 'lib/apis/wakame.rb', line 111

def show_instance_specs(list = [],  = self.)
  make_request("#{self.web_api}/api/instance_specs",Net::HTTP::Get,, list).first["results"]
end

#show_instances(list = []) ⇒ Object Also known as: describe_instances

This method could be taken care of by the EC2 adapter but since we want to show ip addresses differently from EC2, we add it to the Wakame part of Tama



119
120
121
122
# File 'lib/apis/wakame.rb', line 119

def show_instances(list = [])
  instances = make_request("#{self.web_api}/api/instances",Net::HTTP::Get,, list)
  build_instances_hash(instances,)
end

#web_apiObject



147
148
149
# File 'lib/apis/wakame.rb', line 147

def web_api
  protocol.to_s + "://" + host.to_s + ":" + port.to_s
end