Class: Tama::Apis::WakameApi
- Inherits:
-
Object
- Object
- Tama::Apis::WakameApi
- Includes:
- InstanceHashBuilder
- Defined in:
- lib/apis/wakame.rb
Constant Summary collapse
- Protocols =
["http","https"]
Instance Attribute Summary collapse
-
#account ⇒ Object
Returns the value of attribute account.
-
#host ⇒ Object
Returns the value of attribute host.
-
#port ⇒ Object
Returns the value of attribute port.
-
#private_network_name ⇒ Object
Returns the value of attribute private_network_name.
-
#protocol ⇒ Object
Returns the value of attribute protocol.
Instance Method Summary collapse
-
#initialize(account = nil, host = nil, port = nil, protocol = "http", private_network_name = "nw-data") ⇒ WakameApi
constructor
A new instance of WakameApi.
- #make_request(uri, type, accesskey, list = []) ⇒ Object
- #show_host_nodes(list = [], account = self.account) ⇒ Object (also: #describe_host_nodes)
- #show_instance_specs(list = [], account = self.account) ⇒ Object (also: #describe_instance_specs)
-
#show_instances(list = []) ⇒ Object
(also: #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.
- #web_api ⇒ Object
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.
95 96 97 98 99 100 101 102 103 104 |
# File 'lib/apis/wakame.rb', line 95 def initialize(account = 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.account = account self.private_network_name = private_network_name end |
Instance Attribute Details
#account ⇒ Object
Returns the value of attribute account.
88 89 90 |
# File 'lib/apis/wakame.rb', line 88 def account @account end |
#host ⇒ Object
Returns the value of attribute host.
85 86 87 |
# File 'lib/apis/wakame.rb', line 85 def host @host end |
#port ⇒ Object
Returns the value of attribute port.
86 87 88 |
# File 'lib/apis/wakame.rb', line 86 def port @port end |
#private_network_name ⇒ Object
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 |
#protocol ⇒ Object
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 = [], account = self.account) make_request("#{self.web_api}/api/host_nodes",Net::HTTP::Get,account, 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 = [], account = self.account) make_request("#{self.web_api}/api/instance_specs",Net::HTTP::Get,account, 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,account, list) build_instances_hash(instances,account) end |
#web_api ⇒ Object
147 148 149 |
# File 'lib/apis/wakame.rb', line 147 def web_api protocol.to_s + "://" + host.to_s + ":" + port.to_s end |