ilo-sdk 1.2.0 → 1.2.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6ab6bf099aad85914a4e0a9b4c9399d9f263e722
4
- data.tar.gz: ec8b5d88be00336190a2ee51f9f2e279c9fe75a9
3
+ metadata.gz: 3e3d66a47d72463a4564931c4c6764ccdcc9799f
4
+ data.tar.gz: 872a83c910c87089bc9ec82318f2ca9eb43a14c5
5
5
  SHA512:
6
- metadata.gz: cacb3f0f39fc3bba895f1b1d7d2d8297c5ea9e850b3e967856fd965332f09168ee39e09e3d6467d4fa97e708bcf604a4cb22c819b477bba0e19e0bb7ba1efc13
7
- data.tar.gz: 3e4a180967d557b4581d36c56042a39cf8cc945729db1ea4d0715da9d6ad9f7919f67e9a6886810edfeecf793be421f8e17ea3e3efabb450f316f9a3a512c693
6
+ metadata.gz: 1a184e445883fdaa526d4511d5a84bbccfbbbfcb56fc3fe530b161f73e2b72c9faeca92d69dcbef638db95fae104bdd68b8107e7430147bdde6fcc4b1f7a7ca0
7
+ data.tar.gz: 97689bb3dfb16e23afff23f3e232b7ad4df00cee038d4f3f241beff3986d71f078aab9bb6a57728ef6ac3056a52f035f3730431b6bc7420332cad218eb59935f
data/CHANGELOG.md CHANGED
@@ -1,8 +1,14 @@
1
1
  ### New (Unreleased)
2
+
3
+ #### v1.2.1
4
+ - Added rest command to cli
5
+
6
+ ### v1.2.0
2
7
  - Added custom exception classes
3
8
  - Added disable_proxy client option
4
9
  - Added CLI
5
10
  - Support environment variables
11
+ - New BIOS and ComputerSystem helper methods (deprecated old ones)
6
12
 
7
13
  ### v1.1.0
8
14
  - Added ManagerAccountHelper (to allow setting user permissions)
data/README.md CHANGED
@@ -1,6 +1,7 @@
1
1
  # Ruby SDK for HPE iLO
2
2
 
3
3
  [![Gem Version](https://badge.fury.io/rb/ilo-sdk.svg)](https://badge.fury.io/rb/ilo-sdk)
4
+ [![Yard Docs](http://img.shields.io/badge/yard-docs-blue.svg)](http://www.rubydoc.info/gems/ilo-sdk)
4
5
 
5
6
  Software Development Kit for interacting with the Hewlett Packard Enterprise iLO (Integrated Lights-Out) server management technology.
6
7
 
@@ -292,7 +293,7 @@ empty = client.logs_empty?(log_type)
292
293
  # Get a specific type of logs based on severity level and duration:
293
294
  severity_level = 'OK'
294
295
  duration = 10 # hours
295
- logs = client.get_log(severity_level, duration, log_type)
296
+ logs = client.get_logs(severity_level, duration, log_type)
296
297
  ```
297
298
 
298
299
  #### Manager Account
@@ -397,7 +398,7 @@ client.eject_virtual_media(id)
397
398
 
398
399
  ## Custom requests
399
400
 
400
- In most cases, interacting with the client object is enough, but sometimes you need to make your own custom requests to the iLO.
401
+ This gem includes some usefull helper methods, but sometimes you need to make your own custom requests to the iLO.
401
402
  This project makes it extremely easy to do with some built-in methods for the client object. Here are some examples:
402
403
 
403
404
  ```ruby
@@ -408,10 +409,18 @@ response = client.rest_get('/rest/v1/Schemas')
408
409
 
409
410
  # Then we can validate the response and convert the response body into a hash...
410
411
  data = client.response_handler(response)
412
+
413
+ # For updating iLO resources, use patch:
414
+ options = { ServiceName: 'iLO Admin', ServiceEmail: 'admin@domain.com' }
415
+ response = rest_patch('/redfish/v1/Systems/1/bios/Settings/', body: options)
416
+
417
+ # For creating new iLO resources, use post:
418
+ options = { UserName: 'admin', Password: '123' }
419
+ response = rest_post('/redfish/v1/AccountService/Accounts/', body: options)
411
420
  ```
412
421
 
413
- This example is about as basic as it gets, but you can make any type of iLO request.
414
- If a resource does not do what you need, this will allow you to do it.
422
+ These example are about as basic as it gets, but you can make any type of iLO API request.
423
+ If a helper does not do what you need, this will allow you to do it.
415
424
  Please refer to the documentation and [code](lib/ilo-sdk/rest.rb) for complete list of methods and information about how to use them.
416
425
 
417
426
 
data/lib/ilo-sdk/cli.rb CHANGED
@@ -60,6 +60,10 @@ module ILO_SDK
60
60
  desc: 'Username. Can also use ENV[\'ILO_USER\']',
61
61
  aliases: '-u'
62
62
 
63
+ class_option :password,
64
+ desc: 'Password. Can also use ENV[\'ILO_PASSWORD\']',
65
+ aliases: '-p'
66
+
63
67
  class_option :log_level,
64
68
  desc: 'Log level to use',
65
69
  aliases: '-l',
@@ -118,12 +122,56 @@ module ILO_SDK
118
122
  client_setup
119
123
  @client.response_handler(@client.rest_get('/redfish/v1/Sessions/'))
120
124
  puts 'Login Successful!'
125
+ rescue StandardError => e
126
+ fail_nice(e.message)
127
+ end
128
+
129
+ method_option :format,
130
+ desc: 'Output format (for response)',
131
+ aliases: '-f',
132
+ enum: %w(json yaml raw),
133
+ default: 'json'
134
+ method_option :data,
135
+ desc: 'Data to pass in the request body (in JSON format)',
136
+ aliases: '-d'
137
+ rest_examples = "\n ilo-ruby rest get redfish/v1/"
138
+ rest_examples << "\n ilo-ruby rest patch redfish/v1/Systems/1/bios/Settings/"
139
+ rest_examples << " -d '{\"ServiceName\":\"iLO Admin\",\"ServiceEmail\":\"admin@domain.com\"}'"
140
+ rest_examples << "\n ilo-ruby rest post redfish/v1/Managers/1/LogServices/IEL/ -d '{\"Action\":\"ClearLog\"}'"
141
+ desc 'rest METHOD URI', "Make REST call to the iLO API. Examples:#{rest_examples}"
142
+ def rest(method, uri)
143
+ client_setup('log_level' => :error)
144
+ uri_copy = uri.dup
145
+ uri_copy.prepend('/') unless uri_copy.start_with?('/')
146
+ if @options['data']
147
+ begin
148
+ data = { body: JSON.parse(@options['data']) }
149
+ rescue JSON::ParserError => e
150
+ fail_nice("Failed to parse data as JSON\n#{e.message}")
151
+ end
152
+ end
153
+ data ||= {}
154
+ response = @client.rest_api(method, uri_copy, data)
155
+ if response.code.to_i.between?(200, 299)
156
+ case @options['format']
157
+ when 'yaml'
158
+ puts JSON.parse(response.body).to_yaml
159
+ when 'json'
160
+ puts JSON.pretty_generate(JSON.parse(response.body))
161
+ else # raw
162
+ puts response.body
163
+ end
164
+ else
165
+ fail_nice("Request failed: #{response.inspect}\nHeaders: #{response.to_hash}\nBody: #{response.body}")
166
+ end
167
+ rescue ILO_SDK::InvalidRequest => e
168
+ fail_nice(e.message)
121
169
  end
122
170
 
123
171
  private
124
172
 
125
173
  def fail_nice(msg = nil)
126
- puts "ERROR: #{msg}" if msg
174
+ $stderr.puts "ERROR: #{msg}" if msg
127
175
  exit 1
128
176
  end
129
177
 
@@ -132,6 +180,7 @@ module ILO_SDK
132
180
  client_params['ssl_enabled'] = false if @options['ssl_verify'] == false
133
181
  client_params['host'] ||= @options['host'] if @options['host']
134
182
  client_params['user'] ||= @options['user'] if @options['user']
183
+ client_params['password'] ||= @options['password'] if @options['password']
135
184
  client_params['log_level'] ||= @options['log_level'].to_sym if @options['log_level']
136
185
  @client = ILO_SDK::Client.new(client_params)
137
186
  rescue StandardError => e
data/lib/ilo-sdk/rest.rb CHANGED
@@ -151,7 +151,7 @@ module ILO_SDK
151
151
  when 'delete', :delete
152
152
  request = Net::HTTP::Delete.new(uri.request_uri)
153
153
  else
154
- raise InvalidRequest, "Invalid rest call: #{type}"
154
+ raise InvalidRequest, "Invalid rest method: #{type}. Valid methods are: get, post, put, patch, delete"
155
155
  end
156
156
  options['Content-Type'] ||= 'application/json'
157
157
  options.delete('Content-Type') if [:none, 'none', nil].include?(options['Content-Type'])
@@ -11,5 +11,5 @@
11
11
 
12
12
  # Gem version defined here
13
13
  module ILO_SDK
14
- VERSION = '1.2.0'.freeze
14
+ VERSION = '1.2.1'.freeze
15
15
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ilo-sdk
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.0
4
+ version: 1.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Anirudh Gupta
@@ -11,7 +11,7 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2016-08-25 00:00:00.000000000 Z
14
+ date: 2016-08-31 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: thor