poweriq_client 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +90 -3
- data/lib/poweriq_client/resource/base.rb +2 -4
- data/lib/poweriq_client/response.rb +12 -0
- data/lib/poweriq_client/version.rb +1 -2
- data/lib/poweriq_client.rb +1 -0
- data/poweriq_client.gemspec +3 -2
- metadata +4 -3
data/README.rdoc
CHANGED
@@ -23,7 +23,7 @@ The Power IQ client comes with a interactive console. To run the console:
|
|
23
23
|
-p, --password [PASSWORD] Password for authentication
|
24
24
|
-s, --server [HOST] Host name or IP of Power IQ
|
25
25
|
|
26
|
-
====
|
26
|
+
==== Configuration
|
27
27
|
|
28
28
|
Create a file named .poweriq_client in your home directory. The contents of the file
|
29
29
|
should look similiar to below, adjusted to your Power IQ server:
|
@@ -33,13 +33,13 @@ should look similiar to below, adjusted to your Power IQ server:
|
|
33
33
|
user: admin
|
34
34
|
password: raritan
|
35
35
|
|
36
|
-
If you do not use a configuration file, or
|
36
|
+
If you do not use a configuration file, or the command line options above, you'll
|
37
37
|
need to provide the configuration manually:
|
38
38
|
|
39
39
|
% poweriq_client
|
40
40
|
>> PowerIQ::Configuration.configure("user"=>"foo","password"=>"bar","host"=>"vm150")
|
41
41
|
|
42
|
-
====
|
42
|
+
==== Examples
|
43
43
|
|
44
44
|
Retrieve all outlets:
|
45
45
|
>> outlets_resource = PowerIQ::Resource::Outlet.new
|
@@ -58,6 +58,93 @@ Update an outlet:
|
|
58
58
|
>> outlet['outlet']['outlet_name'] = "New Name"
|
59
59
|
>> outlet_resource.put outlet.to_json
|
60
60
|
|
61
|
+
=== Error Handling
|
62
|
+
|
63
|
+
When an error occurs with API calls, the Power IQ server will return an appropriate HTTP response code, and include
|
64
|
+
a json response with error details. On the client side, an exception is thrown. Either the exception or the
|
65
|
+
resource object can be used to reveal details about what went wrong:
|
66
|
+
|
67
|
+
>> outlet_resource = PowerIQ::Resource::Outlet.new('/381')
|
68
|
+
https://vm163/api/v2/outlets/381
|
69
|
+
>> outlet_json = outlet_resource.get
|
70
|
+
{
|
71
|
+
"outlet" => {
|
72
|
+
"id" => 381,
|
73
|
+
"outlet_id" => 11,
|
74
|
+
"outlet_name" => "Outlet 11",
|
75
|
+
"device_id" => nil,
|
76
|
+
"state" => "ON",
|
77
|
+
"pdu_id" => 40,
|
78
|
+
"reading" => {}
|
79
|
+
}
|
80
|
+
}
|
81
|
+
>> outlet_json['outlet']['outlet_name']="foo"
|
82
|
+
"foo"
|
83
|
+
>> outlet_resource.put outlet_json.to_json
|
84
|
+
RestClient::UnprocessableEntity: 422 Unprocessable Entity
|
85
|
+
from /Users/tba/.rvm/gems/ruby-1.9.2-p180@poweriq_client/gems/rest-client-1.6.7/lib/restclient/abstract_response.rb:48:in `return!'
|
86
|
+
from /Users/tba/Workspaces/local/poweriq_client/lib/poweriq_client/resource/base.rb:11:in `block in create'
|
87
|
+
from /Users/tba/.rvm/gems/ruby-1.9.2-p180@poweriq_client/gems/rest-client-1.6.7/lib/restclient/request.rb:228:in `call'
|
88
|
+
from /Users/tba/.rvm/gems/ruby-1.9.2-p180@poweriq_client/gems/rest-client-1.6.7/lib/restclient/request.rb:228:in `process_result'
|
89
|
+
from /Users/tba/.rvm/gems/ruby-1.9.2-p180@poweriq_client/gems/rest-client-1.6.7/lib/restclient/request.rb:178:in `block in transmit'
|
90
|
+
from /Users/tba/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/net/http.rb:627:in `start'
|
91
|
+
from /Users/tba/.rvm/gems/ruby-1.9.2-p180@poweriq_client/gems/rest-client-1.6.7/lib/restclient/request.rb:172:in `transmit'
|
92
|
+
from /Users/tba/.rvm/gems/ruby-1.9.2-p180@poweriq_client/gems/rest-client-1.6.7/lib/restclient/request.rb:64:in `execute'
|
93
|
+
from /Users/tba/.rvm/gems/ruby-1.9.2-p180@poweriq_client/gems/rest-client-1.6.7/lib/restclient/request.rb:33:in `execute'
|
94
|
+
from /Users/tba/.rvm/gems/ruby-1.9.2-p180@poweriq_client/gems/rest-client-1.6.7/lib/restclient/resource.rb:76:in `put'
|
95
|
+
from (irb):4
|
96
|
+
from bin/poweriq_client:66:in `<main>'
|
97
|
+
|
98
|
+
The resource will always hold the last response from the latest rest invocation:
|
99
|
+
|
100
|
+
>> outlet_resource.response.json
|
101
|
+
{
|
102
|
+
"error" => "Job::JobError",
|
103
|
+
"messages" => [
|
104
|
+
[0] "Job(ID:5) with 1 error(s) and status COMPLETED completed",
|
105
|
+
[1] "Confirmed existence of foo",
|
106
|
+
[2] "Confirmed existence of 192.168.45.234 for outlet foo.",
|
107
|
+
[3] "Retrieved plugin for 192.168.45.234.",
|
108
|
+
[4] "Failed to set outlet id: 381 label on PDU 192.168.45.234. PowerIQ was unable to reach 192.168.45.234."
|
109
|
+
],
|
110
|
+
"job" => {
|
111
|
+
"description" => nil,
|
112
|
+
"end_time" => "2011/11/06 00:56:47 +0000",
|
113
|
+
"has_errors" => true,
|
114
|
+
"id" => 5,
|
115
|
+
"start_time" => "2011/11/06 00:56:28 +0000",
|
116
|
+
"status" => "COMPLETED",
|
117
|
+
"user_id" => 1
|
118
|
+
},
|
119
|
+
"trace" => "/var/oculan/home/tba/rails/src/lib/messaging/job_polling.rb:31:...."
|
120
|
+
}
|
121
|
+
|
122
|
+
You can also catch the exception, and the exception will have the response object in it:
|
123
|
+
|
124
|
+
>> exc = nil
|
125
|
+
>> begin outlet_resource.put outlet_json.to_json; rescue => exc; end
|
126
|
+
>> exc.response.json
|
127
|
+
{
|
128
|
+
"error" => "Job::JobError",
|
129
|
+
"messages" => [
|
130
|
+
[0] "Job(ID:5) with 1 error(s) and status COMPLETED completed",
|
131
|
+
[1] "Confirmed existence of foo",
|
132
|
+
[2] "Confirmed existence of 192.168.45.234 for outlet foo.",
|
133
|
+
[3] "Retrieved plugin for 192.168.45.234.",
|
134
|
+
[4] "Failed to set outlet id: 381 label on PDU 192.168.45.234. PowerIQ was unable to reach 192.168.45.234."
|
135
|
+
],
|
136
|
+
"job" => {
|
137
|
+
"description" => nil,
|
138
|
+
"end_time" => "2011/11/06 00:56:47 +0000",
|
139
|
+
"has_errors" => true,
|
140
|
+
"id" => 5,
|
141
|
+
"start_time" => "2011/11/06 00:56:28 +0000",
|
142
|
+
"status" => "COMPLETED",
|
143
|
+
"user_id" => 1
|
144
|
+
},
|
145
|
+
"trace" => "/var/oculan/home/tba/rails/src/lib/messaging/job_polling.rb:31:...."
|
146
|
+
}
|
147
|
+
|
61
148
|
== Development
|
62
149
|
|
63
150
|
The Power IQ rest client uses the rest-client gem, with some
|
@@ -8,10 +8,8 @@ module PowerIQ
|
|
8
8
|
Proc.new { |response,request,result,&block|
|
9
9
|
resource.request = request
|
10
10
|
resource.response = response
|
11
|
-
|
12
|
-
|
13
|
-
ActiveSupport::JSON.decode(body)
|
14
|
-
end
|
11
|
+
response.return!(request, result, &block)
|
12
|
+
response.json
|
15
13
|
}
|
16
14
|
end
|
17
15
|
end
|
data/lib/poweriq_client.rb
CHANGED
data/poweriq_client.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{poweriq_client}
|
8
|
-
s.version = "0.
|
8
|
+
s.version = "0.3.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = [%q{Trent Albright}]
|
12
|
-
s.date = %q{2011-11-
|
12
|
+
s.date = %q{2011-11-06}
|
13
13
|
s.description = %q{Power IQ Rest API client for Power IQ 3.1}
|
14
14
|
s.email = %q{trent.albright@raritan.com}
|
15
15
|
s.executables = [%q{poweriq_client}]
|
@@ -56,6 +56,7 @@ Gem::Specification.new do |s|
|
|
56
56
|
"lib/poweriq_client/resource/sensor_reading.rb",
|
57
57
|
"lib/poweriq_client/resource/sensor_readings_rollup.rb",
|
58
58
|
"lib/poweriq_client/resource/system_info.rb",
|
59
|
+
"lib/poweriq_client/response.rb",
|
59
60
|
"lib/poweriq_client/version.rb",
|
60
61
|
"poweriq_client.gemspec",
|
61
62
|
"spec/poweriq_client_spec.rb",
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: poweriq_client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.
|
5
|
+
version: 0.3.0
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Trent Albright
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2011-11-
|
13
|
+
date: 2011-11-06 00:00:00 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: rest-client
|
@@ -148,6 +148,7 @@ files:
|
|
148
148
|
- lib/poweriq_client/resource/sensor_reading.rb
|
149
149
|
- lib/poweriq_client/resource/sensor_readings_rollup.rb
|
150
150
|
- lib/poweriq_client/resource/system_info.rb
|
151
|
+
- lib/poweriq_client/response.rb
|
151
152
|
- lib/poweriq_client/version.rb
|
152
153
|
- poweriq_client.gemspec
|
153
154
|
- spec/poweriq_client_spec.rb
|
@@ -165,7 +166,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
165
166
|
requirements:
|
166
167
|
- - ">="
|
167
168
|
- !ruby/object:Gem::Version
|
168
|
-
hash: -
|
169
|
+
hash: -3473045824434038177
|
169
170
|
segments:
|
170
171
|
- 0
|
171
172
|
version: "0"
|