oneview-sdk 2.1.0 → 2.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +7 -0
- data/README.md +15 -1
- data/lib/oneview-sdk/cli.rb +79 -10
- data/lib/oneview-sdk/resource/firmware_bundle.rb +23 -9
- data/lib/oneview-sdk/rest.rb +1 -1
- data/lib/oneview-sdk/version.rb +1 -1
- data/oneview-sdk.gemspec +1 -0
- metadata +17 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: dd1ac219db19a7c03bf16b3df31b5cccf12e22eb
|
4
|
+
data.tar.gz: 0718886cb26a7ce15a2fe826f0b87bb68d79a06c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 86766ecbc79b8bc588235fe3a4d9e0517bfbb7ad530a2f86830ab33efa27e057347da245022fd84a3620a20c500fdada9406696a8292643c8affa7dd1f8726a2
|
7
|
+
data.tar.gz: d43154cbc551777fb2e821c16123712d120c1ef4704046b752ebd6bd4c493e8834358813106cd11f0558883ca5512a31d19f1cccb8230eeb80f56ff218a8ef3b
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,10 @@
|
|
1
|
+
#### v2.2.1
|
2
|
+
- Fixed issue #88 (firmware bundle file size). Uses multipart-post now
|
3
|
+
|
4
|
+
### v2.2.0
|
5
|
+
- Added the 'rest' and 'update' commands to the CLI
|
6
|
+
- Removed the --force option from the create_from_file CLI command
|
7
|
+
|
1
8
|
### v2.1.0
|
2
9
|
- Fixed issue with the :resource_named method for OneViewSDK::Resource in Ruby 2.3
|
3
10
|
|
data/README.md
CHANGED
@@ -101,7 +101,7 @@ Each OneView resource is exposed for usage with CRUD-like functionality.
|
|
101
101
|
|
102
102
|
For example, once you instantiate a resource object, you can call intuitive methods such as `resource.create`, `resource.udpate` and `resource.delete`. In addition, resources respond to helpful methods such as `.each`, `.eql?(other_resource)`, `.like(other_resource)`, `.retrieve!`, and many others.
|
103
103
|
|
104
|
-
Please see the [rubydoc.info](http://www.rubydoc.info/gems/oneview-sdk) documentation for the
|
104
|
+
Please see the [rubydoc.info](http://www.rubydoc.info/gems/oneview-sdk) documentation for complete usage details and the [examples](examples/) directory for more examples and test-scripts, but here are a few examples to get you started:
|
105
105
|
|
106
106
|
##### Create a resource
|
107
107
|
|
@@ -264,6 +264,20 @@ $ oneview-sdk-ruby create_from_file /my-server-profile.json
|
|
264
264
|
$ oneview-sdk-ruby delete_from_file /my-server-profile.json
|
265
265
|
```
|
266
266
|
|
267
|
+
##### Update resources by name:
|
268
|
+
|
269
|
+
```bash
|
270
|
+
$ oneview-sdk-ruby update FCNetwork FC1 -h linkStabilityTime:20 # Using hash format
|
271
|
+
$ oneview-sdk-ruby update Volume VOL_01 -j '{"shareable": true}' # Using json format
|
272
|
+
```
|
273
|
+
|
274
|
+
##### Make REST calls:
|
275
|
+
|
276
|
+
```bash
|
277
|
+
$ oneview-sdk-ruby rest get rest/fc-networks
|
278
|
+
$ oneview-sdk-ruby rest PUT rest/enclosures/<id>/configuration
|
279
|
+
```
|
280
|
+
|
267
281
|
##### Start an interactive console session with a OneView connection:
|
268
282
|
|
269
283
|
```bash
|
data/lib/oneview-sdk/cli.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
|
-
# (
|
1
|
+
# (c) Copyright 2016 Hewlett Packard Enterprise Development LP
|
2
2
|
#
|
3
3
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
-
#
|
4
|
+
# you may not use this file except in compliance with the License.
|
5
5
|
# You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
|
6
6
|
#
|
7
7
|
# Unless required by applicable law or agreed to in writing, software distributed
|
@@ -201,6 +201,80 @@ module OneviewSDK
|
|
201
201
|
end
|
202
202
|
end
|
203
203
|
|
204
|
+
method_option :format,
|
205
|
+
desc: 'Output format',
|
206
|
+
aliases: '-f',
|
207
|
+
enum: %w(json yaml raw),
|
208
|
+
default: 'json'
|
209
|
+
method_option :data,
|
210
|
+
desc: 'Data to pass in the request body (in JSON format)',
|
211
|
+
aliases: '-d'
|
212
|
+
rest_examples = "\n oneview-sdk-ruby rest GET rest/fc-networks"
|
213
|
+
rest_examples << "\n oneview-sdk-ruby rest PUT rest/fc-networks/<id> -d '{\"linkStabilityTime\": 20, ...}'"
|
214
|
+
rest_examples << "\n oneview-sdk-ruby rest PUT rest/enclosures/<id>/configuration"
|
215
|
+
desc 'rest METHOD URI', "Make REST call to the OneView API. Examples:#{rest_examples}"
|
216
|
+
def rest(method, uri)
|
217
|
+
client_setup('log_level' => :error)
|
218
|
+
uri_copy = uri.dup
|
219
|
+
uri_copy.prepend('/') unless uri_copy.start_with?('/')
|
220
|
+
if @options['data']
|
221
|
+
begin
|
222
|
+
data = { body: JSON.parse(@options['data']) }
|
223
|
+
rescue JSON::ParserError => e
|
224
|
+
fail_nice("Failed to parse data as JSON\n#{e.message}")
|
225
|
+
end
|
226
|
+
end
|
227
|
+
data ||= {}
|
228
|
+
response = @client.rest_api(method, uri_copy, data)
|
229
|
+
if response.code.to_i.between?(200, 299)
|
230
|
+
case @options['format']
|
231
|
+
when 'yaml'
|
232
|
+
puts JSON.parse(response.body).to_yaml
|
233
|
+
when 'json'
|
234
|
+
puts JSON.pretty_generate(JSON.parse(response.body))
|
235
|
+
else # raw
|
236
|
+
puts response.body
|
237
|
+
end
|
238
|
+
else
|
239
|
+
body = JSON.pretty_generate(JSON.parse(response.body)) rescue response.body
|
240
|
+
fail_nice("Request failed: #{response.inspect}\nHeaders: #{response.to_hash}\nBody: #{body}")
|
241
|
+
end
|
242
|
+
rescue OneviewSDK::InvalidRequest => e
|
243
|
+
fail_nice(e.message)
|
244
|
+
end
|
245
|
+
|
246
|
+
method_option :hash,
|
247
|
+
type: :hash,
|
248
|
+
desc: 'Hash of key/value pairs to update',
|
249
|
+
aliases: '-h'
|
250
|
+
method_option :json,
|
251
|
+
desc: 'JSON data to pass in the request body',
|
252
|
+
aliases: '-j'
|
253
|
+
update_examples = "\n oneview-sdk-ruby update FCNetwork FC1 -h linkStabilityTime:20"
|
254
|
+
update_examples << "\n oneview-sdk-ruby update Volume VOL1 -j '{\"shareable\": true}'"
|
255
|
+
desc 'update TYPE NAME --[hash|json] <data>', "Update resource by name. Examples:#{update_examples}"
|
256
|
+
def update(type, name)
|
257
|
+
resource_class = parse_type(type)
|
258
|
+
client_setup
|
259
|
+
fail_nice 'Must set the hash or json option' unless @options['hash'] || @options['json']
|
260
|
+
fail_nice 'Must set the hash OR json option. Not both' if @options['hash'] && @options['json']
|
261
|
+
begin
|
262
|
+
data = @options['hash'] || JSON.parse(@options['json'])
|
263
|
+
rescue JSON::ParserError => e
|
264
|
+
fail_nice("Failed to parse json\n#{e.message}")
|
265
|
+
end
|
266
|
+
matches = resource_class.find_by(@client, name: name)
|
267
|
+
fail_nice 'Not Found' if matches.empty?
|
268
|
+
resource = matches.first
|
269
|
+
begin
|
270
|
+
resource[:uri] = '/rest/storage-volumes/57A22A70-73EC-43C1-91B9-9FABD1E'
|
271
|
+
resource.update(data)
|
272
|
+
output 'Updated Successfully!'
|
273
|
+
rescue StandardError => e
|
274
|
+
fail_nice "Failed to update #{resource.class.name.split('::').last} '#{name}': #{e}"
|
275
|
+
end
|
276
|
+
end
|
277
|
+
|
204
278
|
method_option :force,
|
205
279
|
desc: 'Delete without confirmation',
|
206
280
|
type: :boolean,
|
@@ -245,17 +319,12 @@ module OneviewSDK
|
|
245
319
|
end
|
246
320
|
end
|
247
321
|
|
248
|
-
method_option :force,
|
249
|
-
desc: 'Overwrite without confirmation',
|
250
|
-
type: :boolean,
|
251
|
-
aliases: '-f'
|
252
322
|
method_option :if_missing,
|
253
323
|
desc: 'Only create if missing (Don\'t update)',
|
254
324
|
type: :boolean,
|
255
325
|
aliases: '-i'
|
256
|
-
desc 'create_from_file FILE_PATH', 'Create/
|
326
|
+
desc 'create_from_file FILE_PATH', 'Create/Update resource defined in file'
|
257
327
|
def create_from_file(file_path)
|
258
|
-
fail_nice "Can't use the 'force' and 'if_missing' flags at the same time." if options['force'] && options['if_missing']
|
259
328
|
client_setup
|
260
329
|
resource = OneviewSDK::Resource.from_file(@client, file_path)
|
261
330
|
resource[:uri] = nil
|
@@ -266,7 +335,6 @@ module OneviewSDK
|
|
266
335
|
puts "Skipped: '#{resource[:name]}': #{resource.class.name.split('::').last} already exists."
|
267
336
|
return
|
268
337
|
end
|
269
|
-
fail_nice "#{resource.class.name.split('::').last} '#{resource[:name]}' already exists." unless options['force']
|
270
338
|
begin
|
271
339
|
resource.data.delete('uri')
|
272
340
|
existing_resource.update(resource.data)
|
@@ -338,7 +406,8 @@ module OneviewSDK
|
|
338
406
|
next unless klass.is_a?(Class) && klass < OneviewSDK::Resource
|
339
407
|
valid_classes.push(klass.name.split('::').last)
|
340
408
|
end
|
341
|
-
|
409
|
+
vc = valid_classes.sort_by!(&:downcase).join("\n ")
|
410
|
+
OneviewSDK.resource_named(type) || fail_nice("Invalid resource type: '#{type}'. Valid options are:\n #{vc}")
|
342
411
|
end
|
343
412
|
|
344
413
|
# Parse options hash from input. Handles chaining and keywords such as true/false & nil
|
@@ -8,12 +8,13 @@
|
|
8
8
|
# under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
|
9
9
|
# CONDITIONS OF ANY KIND, either express or implied. See the License for the specific
|
10
10
|
# language governing permissions and limitations under the License.
|
11
|
+
require 'openssl'
|
12
|
+
require 'net/http/post/multipart'
|
11
13
|
|
12
14
|
module OneviewSDK
|
13
15
|
# Firmware bundle resource implementation
|
14
16
|
class FirmwareBundle
|
15
17
|
BASE_URI = '/rest/firmware-bundles'.freeze
|
16
|
-
BOUNDARY = '----011000010111000001101001'.freeze
|
17
18
|
|
18
19
|
# Uploads a firmware bundle file
|
19
20
|
# @param [OneviewSDK::Client] client The client object for the OneView appliance
|
@@ -22,15 +23,28 @@ module OneviewSDK
|
|
22
23
|
def self.add(client, file_path)
|
23
24
|
fail NotFound, "ERROR: File '#{file_path}' not found!" unless File.file?(file_path)
|
24
25
|
options = {}
|
25
|
-
options['Content-Type'] =
|
26
|
+
options['Content-Type'] = 'multipart/form-data'
|
27
|
+
options['X-Api-Version'] = client.api_version.to_s
|
28
|
+
options['auth'] = client.token
|
26
29
|
options['uploadfilename'] = File.basename(file_path)
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
30
|
+
url = URI.parse(URI.escape("#{client.url}#{BASE_URI}"))
|
31
|
+
|
32
|
+
File.open(file_path) do |file|
|
33
|
+
req = Net::HTTP::Post::Multipart.new(
|
34
|
+
url.path,
|
35
|
+
{ 'file' => UploadIO.new(file, 'application/octet-stream', File.basename(file_path)) },
|
36
|
+
options
|
37
|
+
)
|
38
|
+
|
39
|
+
http_request = Net::HTTP.new(url.host, url.port)
|
40
|
+
http_request.use_ssl = true
|
41
|
+
http_request.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
42
|
+
http_request.start do |http|
|
43
|
+
response = http.request(req)
|
44
|
+
data = client.response_handler(response)
|
45
|
+
return OneviewSDK::FirmwareDriver.new(client, data)
|
46
|
+
end
|
47
|
+
end
|
34
48
|
end
|
35
49
|
end
|
36
50
|
end
|
data/lib/oneview-sdk/rest.rb
CHANGED
@@ -180,7 +180,7 @@ module OneviewSDK
|
|
180
180
|
when :delete
|
181
181
|
request = Net::HTTP::Delete.new(uri.request_uri)
|
182
182
|
else
|
183
|
-
fail InvalidRequest, "Invalid rest
|
183
|
+
fail InvalidRequest, "Invalid rest method: #{type}. Valid methods are: get, post, put, patch, delete"
|
184
184
|
end
|
185
185
|
|
186
186
|
options['X-API-Version'] ||= api_ver
|
data/lib/oneview-sdk/version.rb
CHANGED
data/oneview-sdk.gemspec
CHANGED
@@ -32,6 +32,7 @@ Gem::Specification.new do |spec|
|
|
32
32
|
spec.add_runtime_dependency 'thor'
|
33
33
|
spec.add_runtime_dependency 'highline'
|
34
34
|
spec.add_runtime_dependency 'pry'
|
35
|
+
spec.add_runtime_dependency 'multipart-post'
|
35
36
|
|
36
37
|
spec.add_development_dependency 'bundler'
|
37
38
|
spec.add_development_dependency 'rspec'
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: oneview-sdk
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.1
|
4
|
+
version: 2.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Henrique Diomede
|
@@ -11,7 +11,7 @@ authors:
|
|
11
11
|
autorequire:
|
12
12
|
bindir: bin
|
13
13
|
cert_chain: []
|
14
|
-
date: 2016-09-
|
14
|
+
date: 2016-09-30 00:00:00.000000000 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: thor
|
@@ -55,6 +55,20 @@ dependencies:
|
|
55
55
|
- - ">="
|
56
56
|
- !ruby/object:Gem::Version
|
57
57
|
version: '0'
|
58
|
+
- !ruby/object:Gem::Dependency
|
59
|
+
name: multipart-post
|
60
|
+
requirement: !ruby/object:Gem::Requirement
|
61
|
+
requirements:
|
62
|
+
- - ">="
|
63
|
+
- !ruby/object:Gem::Version
|
64
|
+
version: '0'
|
65
|
+
type: :runtime
|
66
|
+
prerelease: false
|
67
|
+
version_requirements: !ruby/object:Gem::Requirement
|
68
|
+
requirements:
|
69
|
+
- - ">="
|
70
|
+
- !ruby/object:Gem::Version
|
71
|
+
version: '0'
|
58
72
|
- !ruby/object:Gem::Dependency
|
59
73
|
name: bundler
|
60
74
|
requirement: !ruby/object:Gem::Requirement
|
@@ -212,7 +226,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
212
226
|
version: '0'
|
213
227
|
requirements: []
|
214
228
|
rubyforge_project:
|
215
|
-
rubygems_version: 2.
|
229
|
+
rubygems_version: 2.6.6
|
216
230
|
signing_key:
|
217
231
|
specification_version: 4
|
218
232
|
summary: Gem to interact with oneview API
|