oneview-sdk 3.1.0 → 4.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (65) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +40 -8
  3. data/README.md +41 -11
  4. data/Rakefile +47 -0
  5. data/lib/oneview-sdk.rb +6 -1
  6. data/lib/oneview-sdk/cli.rb +21 -6
  7. data/lib/oneview-sdk/client.rb +23 -7
  8. data/lib/oneview-sdk/image-streamer/client.rb +96 -0
  9. data/lib/oneview-sdk/image-streamer/resource/api300/artifacts_bundle.rb +26 -0
  10. data/lib/oneview-sdk/image-streamer/resource/api300/build_plan.rb +26 -0
  11. data/lib/oneview-sdk/image-streamer/resource/api300/deployment_plan.rb +26 -0
  12. data/lib/oneview-sdk/image-streamer/resource/api300/golden_image.rb +26 -0
  13. data/lib/oneview-sdk/{resource/api300/synergy/logical_switch_group.rb → image-streamer/resource/api300/os_volume.rb} +17 -13
  14. data/lib/oneview-sdk/image-streamer/resource/api300/plan_script.rb +42 -0
  15. data/lib/oneview-sdk/image-streamer/resource/api300/resource.rb +21 -0
  16. data/lib/oneview-sdk/image-streamer/resource/api_300.rb +39 -0
  17. data/lib/oneview-sdk/image_streamer.rb +68 -0
  18. data/lib/oneview-sdk/resource.rb +13 -1
  19. data/lib/oneview-sdk/resource/api200/connection_template.rb +2 -2
  20. data/lib/oneview-sdk/resource/api200/datacenter.rb +2 -2
  21. data/lib/oneview-sdk/resource/api200/enclosure.rb +2 -2
  22. data/lib/oneview-sdk/resource/api200/enclosure_group.rb +6 -0
  23. data/lib/oneview-sdk/resource/api200/fabric.rb +4 -4
  24. data/lib/oneview-sdk/resource/api200/firmware_driver.rb +2 -2
  25. data/lib/oneview-sdk/resource/api200/interconnect.rb +3 -3
  26. data/lib/oneview-sdk/resource/api200/logical_downlink.rb +3 -3
  27. data/lib/oneview-sdk/resource/api200/logical_interconnect_group.rb +8 -8
  28. data/lib/oneview-sdk/resource/api200/logical_switch.rb +2 -4
  29. data/lib/oneview-sdk/resource/api200/managed_san.rb +3 -3
  30. data/lib/oneview-sdk/resource/api200/power_device.rb +2 -2
  31. data/lib/oneview-sdk/resource/api200/rack.rb +2 -2
  32. data/lib/oneview-sdk/resource/api200/san_manager.rb +2 -2
  33. data/lib/oneview-sdk/resource/api200/server_hardware.rb +2 -2
  34. data/lib/oneview-sdk/resource/api200/server_hardware_type.rb +2 -2
  35. data/lib/oneview-sdk/resource/api200/storage_pool.rb +3 -3
  36. data/lib/oneview-sdk/resource/api200/storage_system.rb +2 -2
  37. data/lib/oneview-sdk/resource/api200/switch.rb +4 -4
  38. data/lib/oneview-sdk/resource/api200/unmanaged_device.rb +2 -2
  39. data/lib/oneview-sdk/resource/api200/user.rb +79 -0
  40. data/lib/oneview-sdk/resource/api200/volume_attachment.rb +3 -3
  41. data/lib/oneview-sdk/resource/api200/volume_snapshot.rb +2 -2
  42. data/lib/oneview-sdk/resource/api300.rb +2 -2
  43. data/lib/oneview-sdk/resource/api300/c7000/enclosure.rb +3 -15
  44. data/lib/oneview-sdk/resource/api300/c7000/enclosure_group.rb +54 -1
  45. data/lib/oneview-sdk/resource/api300/c7000/logical_downlink.rb +2 -2
  46. data/lib/oneview-sdk/resource/api300/c7000/logical_switch.rb +4 -0
  47. data/lib/oneview-sdk/resource/api300/c7000/managed_san.rb +1 -1
  48. data/lib/oneview-sdk/resource/api300/c7000/scope.rb +142 -0
  49. data/lib/oneview-sdk/resource/api300/c7000/server_hardware.rb +3 -17
  50. data/lib/oneview-sdk/resource/api300/c7000/user.rb +22 -0
  51. data/lib/oneview-sdk/resource/api300/synergy/drive_enclosure.rb +3 -3
  52. data/lib/oneview-sdk/resource/api300/synergy/enclosure.rb +4 -31
  53. data/lib/oneview-sdk/resource/api300/synergy/enclosure_group.rb +3 -6
  54. data/lib/oneview-sdk/resource/api300/synergy/logical_downlink.rb +2 -2
  55. data/lib/oneview-sdk/resource/api300/synergy/logical_enclosure.rb +1 -1
  56. data/lib/oneview-sdk/resource/api300/synergy/logical_interconnect_group.rb +24 -23
  57. data/lib/oneview-sdk/resource/api300/synergy/logical_switch.rb +2 -0
  58. data/lib/oneview-sdk/resource/api300/synergy/sas_interconnect.rb +3 -3
  59. data/lib/oneview-sdk/resource/api300/synergy/sas_logical_interconnect.rb +2 -2
  60. data/lib/oneview-sdk/resource/api300/synergy/scope.rb +22 -0
  61. data/lib/oneview-sdk/resource/api300/synergy/user.rb +22 -0
  62. data/lib/oneview-sdk/rest.rb +7 -2
  63. data/lib/oneview-sdk/version.rb +2 -2
  64. data/oneview-sdk.gemspec +1 -0
  65. metadata +32 -4
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 372d3a8311ef4dcf063cb3f676f80a50b0f0cbad
4
- data.tar.gz: f9b40be85309db48aeb5fb1c46c6360e24cc25de
3
+ metadata.gz: b2cf0ee2e24d1983a8a7bdd7f5e37cf9980117b3
4
+ data.tar.gz: 38377447be77b778441fd237d8ff1e6c25a89140
5
5
  SHA512:
6
- metadata.gz: 32078616e43270abf2f7f66dbb8b91b57c07f712ebe7d41a76e5dd4628ae47c87cb54cb7c6e2f365ce370836f0eb2766f6c2fc91315aeefb793ec07db642bd1f
7
- data.tar.gz: 1f1d3498c12f5feebf1631f45e170fa6d49ab9b2d893c0de1ff46bfb4d65ab8513cbf8d41aa6baafdfbec5347139f1f502fb4f87e2fd5e39920ca2a5f98fc2da
6
+ metadata.gz: c288b678eeca3f9bc01230993f76d351410d76a402b1bc85be631177fc09a758eebf9f9e3c130419c9c16632d3a62aab986f0a5a0863810747011071ab6927d8
7
+ data.tar.gz: 5e2a9af5bd94afdbdf6438fac6a03a2250117dfa87299d6ddce45e1a77491e16ab68c557a9a41714a819f1768f28190a273fb46460ff6aa92e4dc9659ea77f96
data/CHANGELOG.md CHANGED
@@ -1,12 +1,47 @@
1
+ # Unreleased Changes
2
+
3
+ # v4.0.0
4
+
5
+ #### Breaking changes:
6
+ - [#93](https://github.com/HewlettPackard/oneview-sdk-ruby/issues/93) Fixed Logical Switch refresh conflict
7
+ - [#134](https://github.com/HewlettPackard/oneview-sdk-ruby/issues/134) Remove API300::Synergy::LogicalSwitchGroup resource, which is not defined in the API
8
+
9
+ #### Bug fixes & Enhancements:
10
+ - [#131](https://github.com/HewlettPackard/oneview-sdk-ruby/issues/131) Unavailable methods can take any number of arguments
11
+ - [#132](https://github.com/HewlettPackard/oneview-sdk-ruby/issues/132) Made get_default_settings in API200 a class method instead of an instance method
12
+ - [#141](https://github.com/HewlettPackard/oneview-sdk-ruby/issues/141) Fixes for API300::Synergy::LogicalInterconnectGroup
13
+ - [#142](https://github.com/HewlettPackard/oneview-sdk-ruby/issues/142) EnclosureGroup should raise error in `#add_logical_interconnect_group` if LIG could not be retrieved
14
+ - [#145](https://github.com/HewlettPackard/oneview-sdk-ruby/issues/145) REST methods now handle redirects
15
+ - [#147](https://github.com/HewlettPackard/oneview-sdk-ruby/issues/147) [API300] Missing #patch in Logical Switch
16
+ - [#149](https://github.com/HewlettPackard/oneview-sdk-ruby/issues/149) API300::EnclosureGroup resources support enclosureIndex in interconnectBayMappings
17
+ - [#152](https://github.com/HewlettPackard/oneview-sdk-ruby/issues/152) Update client logger's log level with `client.log_level=`
18
+ - [#161](https://github.com/HewlettPackard/oneview-sdk-ruby/issues/161) Allow client attributes to be set after initialization, and token to be refreshed
19
+ - Client #get_all method now supports an (optional) variant parameter
20
+ - Support API modules & variants with the CLI
21
+
22
+ #### New Resources:
23
+ - Scope
24
+ - User
25
+ - Image Streamer API v300 Resources (experimental):
26
+ - OS Volume
27
+ - Plan Script
28
+ - Artifacts Bundle (unimplemented)
29
+ - Build Plan (unimplemented)
30
+ - Deployment Plan (unimplemented)
31
+ - Golden Image (unimplemented)
32
+
1
33
  # v3.1.0
2
- 1. Added full support to OneView Rest API version 300 for the hardware variants C7000 and Synergy to the already existing features:
34
+ Added full support to OneView Rest API version 300 for the hardware variants C7000 and Synergy to the already existing features:
3
35
  - Interconnect
4
36
  - Logical Interconnect
5
37
  - Uplink Set
6
38
  - Volume attachment
7
39
  - Unmanaged devices
8
40
 
9
- ### Features supported
41
+ #### Bug fixes
42
+ - Fixed issue #124 Missing argument in API300 C7000 Managed SAN method.
43
+
44
+ #### Features supported
10
45
  - Connection template
11
46
  - Datacenter
12
47
  - Enclosure
@@ -50,9 +85,6 @@
50
85
  - SAS Logical JBODs
51
86
  - Unmanaged devices
52
87
 
53
- 2. Bug fixes:
54
- - Fixed issue #124 Missing argument in API300 C7000 Managed SAN method.
55
-
56
88
  # v3.0.0
57
89
  ### Notes
58
90
  This is the Third major version of the Ruby SDK for HPE OneView. It features a split in the API support, allowing for C7000 and Synergy hardware variants to be used, while maintaining compatibility to older versions. There are some code improvements applied throughout the release, as well as additional endpoints support.
@@ -100,10 +132,10 @@
100
132
  - SAS Logical JBOD Attachments
101
133
  - SAS Logical JBODs
102
134
  3. Design changes:
103
- - Split features into API modules for each hardware variant
104
- - Fixed/updated/added CLI commands
135
+ - Split features into API modules for each hardware variant
136
+ - Fixed/updated/added CLI commands
105
137
 
106
- #### v2.2.1
138
+ ### v2.2.1
107
139
  - Fixed issue #88 (firmware bundle file size). Uses multipart-post now
108
140
 
109
141
  ### v2.2.0
data/README.md CHANGED
@@ -2,13 +2,16 @@
2
2
  [![Gem Version](https://badge.fury.io/rb/oneview-sdk.svg)](https://badge.fury.io/rb/oneview-sdk)
3
3
 
4
4
 
5
- The OneView SDK provides a Ruby library to easily interact with HPE OneView API. The Ruby SDK enables developers to easily build integrations and scalable solutions with HPE OneView.
5
+ The OneView SDK provides a Ruby library to easily interact with HPE OneView and Image Streamer APIs. The Ruby SDK enables developers to easily build integrations and scalable solutions with HPE OneView and Image Streamer.
6
+
7
+ Note that currently the Image Streamer resources are a work in progress, so should be treated as experimental.
8
+ Many of these resources are unimplemented, and all are subject to change in ways that are incompatible with current usage & docs.
6
9
 
7
10
  ## Installation
8
11
  - Require the gem in your Gemfile:
9
12
 
10
13
  ```ruby
11
- gem 'oneview-sdk', '~> 3.0'
14
+ gem 'oneview-sdk', '~> 4.0'
12
15
  ```
13
16
 
14
17
  Then run `$ bundle install`
@@ -20,9 +23,10 @@ The OneView SDK provides a Ruby library to easily interact with HPE OneView API.
20
23
 
21
24
 
22
25
  ## Configuration
23
- The client has a few configuration options, which you can pass in during creation:
26
+ The OneView client has a few configuration options, which you can pass in during creation:
24
27
 
25
28
  ```ruby
29
+ # Create a OneView client object:
26
30
  require 'oneview-sdk'
27
31
  client = OneviewSDK::Client.new(
28
32
  url: 'https://oneview.example.com',
@@ -38,20 +42,43 @@ client = OneviewSDK::Client.new(
38
42
 
39
43
  :lock: Tip: Check the file permissions because the password is stored in clear-text.
40
44
 
45
+ The Image Streamer (I3S) client is very similar to the OneView client, but has one key difference:
46
+ it cannot generate it's own token. However, it uses the same token given to or generated by the OneView client,
47
+ so if you need to generate a token, create a OneView client using a user & password, then pass the generated token
48
+ into the Image Streamer client.
49
+
50
+ ```ruby
51
+ # Create an Image Streamer client object:
52
+ require 'oneview-sdk'
53
+ i3s_client = OneviewSDK::ImageStreamer::Client.new(
54
+ url: 'https://image-streamer.example.com',
55
+ token: 'xxxx...', # Required. Note that you cannot pass the user & password options
56
+ ssl_enabled: true, # This is the default and strongly encouraged
57
+ logger: Logger.new(STDOUT), # This is the default
58
+ log_level: :info, # This is the default
59
+ api_version: 300 # Defaults to minimum of 300 and appliance's max API version
60
+ )
61
+ ```
62
+
41
63
  ##### Environment Variables
42
64
 
43
- You can also set the url and credentials or an authentication token using environment variables. For bash:
65
+ You can also set many of the client attributes using environment variables. To set these variables in bash:
44
66
 
45
67
  ```bash
68
+ # OneView client options:
46
69
  export ONEVIEWSDK_URL='https://oneview.example.com'
70
+ # You can set the token if you know it, or set the user and password to generate one:
71
+ export ONEVIEWSDK_TOKEN='xxxx...'
72
+ export ONEVIEWSDK_USER='Administrator'
73
+ export ONEVIEWSDK_PASSWORD='secret123'
47
74
  export ONEVIEWSDK_SSL_ENABLED=false
48
75
  # NOTE: Disabling SSL is strongly discouraged. Please see the CLI section for import instructions.
49
76
 
50
- # Credentials
51
- export ONEVIEWSDK_USER='Administrator'
52
- export ONEVIEWSDK_PASSWORD='secret123'
53
- # or auth token
54
- export ONEVIEWSDK_TOKEN='xxxx...'
77
+ # Image Streamer (I3S) client options:
78
+ export I3S_URL='https://image-streamer.example.com'
79
+ export I3S_TOKEN='xxxx...'
80
+ export I3S_SSL_ENABLED=false
81
+ # NOTE: Disabling SSL is strongly discouraged. Please see the CLI section for import instructions.
55
82
  ```
56
83
 
57
84
  :lock: Tip: Be sure nobody has access to your environment variables, as the password or token is stored in clear-text.
@@ -61,7 +88,10 @@ Then you can leave out these options from your config, enabling you to just do:
61
88
  ```ruby
62
89
  require 'oneview-sdk'
63
90
  client = OneviewSDK::Client.new
91
+ # and/or
92
+ i3s_client = OneviewSDK::ImageStreamer::Client.new
64
93
  ```
94
+
65
95
  NOTE: Run `$ oneview-sdk-ruby env` to see a list of available environment variables and their current values.
66
96
 
67
97
  ##### Configuration Files
@@ -143,7 +173,7 @@ OneviewSDK::API300::EthernetNetwork # OneviewSDK::API300::Synergy::EthernetN
143
173
  We understand that this can be confusing, so to avoid any confusion or unexpected behavior, we recommend specifying the full namespace identifier in your code. At the very least, set defaults explicitly using `OneviewSDK.api_version = <ver>` and `OneviewSDK::API300.variant = <variant>`, as the defaults may change.
144
174
 
145
175
  ## Resources
146
- Each OneView resource is exposed via a Ruby class, enabling CRUD-like functionality (with some exceptions).
176
+ Each OneView and Image Streamer resource is exposed via a Ruby class, enabling CRUD-like functionality (with some exceptions).
147
177
 
148
178
  Once you instantiate a resource object, you can call intuitive methods such as `resource.create`, `resource.update` and `resource.delete`. In addition, resources respond to helpful methods such as `.each`, `.eql?(other_resource)`, `.like(other_resource)`, `.retrieve!`, and many others.
149
179
 
@@ -333,7 +363,7 @@ HINT: The @client object is available to you
333
363
  >
334
364
  ```
335
365
 
336
- ##### Import a self-signed SSL certificate from your OneView instance:
366
+ ##### Import a self-signed SSL certificate from your OneView or Image Streamer instance:
337
367
 
338
368
  Although you can disable SSL validation altogether for the client, this is strongly discouraged.
339
369
  Instead, please import the certificate using the built-in CLI cert command:
data/Rakefile CHANGED
@@ -26,6 +26,7 @@ RSpec::Core::RakeTask.new(:spec) do |spec|
26
26
  spec.rspec_opts = def_spec_options
27
27
  spec.rspec_opts << ' --tag ~integration'
28
28
  spec.rspec_opts << ' --tag ~system'
29
+ spec.rspec_opts << ' --tag ~integration_i3s'
29
30
  end
30
31
 
31
32
  desc 'Run integration tests only'
@@ -208,3 +209,49 @@ task 'spec:integration:delete:api_version', [:ver] do |_t, spec|
208
209
  Rake::Task[:rubocop].invoke
209
210
  Rake::Task['spec:integration'].invoke
210
211
  end
212
+
213
+ desc 'Run rubocop & integration tests for Image Streamer.'
214
+ RSpec::Core::RakeTask.new('spec:integration:i3s') do |spec|
215
+ Rake::Task[:rubocop].invoke
216
+ spec.pattern = spec_pattern
217
+ spec.rspec_opts = def_int_spec_options
218
+ spec.rspec_opts << ' --tag integration_i3s'
219
+ end
220
+
221
+ desc 'Run rubocop & integration creation tests for Image Streamer only'
222
+ RSpec::Core::RakeTask.new('spec:integration:i3s:create') do |spec|
223
+ Rake::Task[:rubocop].invoke
224
+ spec.pattern = 'spec/**/*create_spec.rb'
225
+ spec.rspec_opts = def_int_spec_options
226
+ spec.rspec_opts << ' --tag integration_i3s'
227
+ end
228
+
229
+ desc 'Run rubocop & integration update tests for Image Streamer only'
230
+ RSpec::Core::RakeTask.new('spec:integration:i3s:update') do |spec|
231
+ Rake::Task[:rubocop].invoke
232
+ spec.pattern = 'spec/**/*update_spec.rb'
233
+ spec.rspec_opts = def_int_spec_options
234
+ spec.rspec_opts << ' --tag integration_i3s'
235
+ end
236
+
237
+ desc 'Run rubocop & integration deletion tests for Image Streamer only'
238
+ RSpec::Core::RakeTask.new('spec:integration:i3s:delete') do |spec|
239
+ Rake::Task[:rubocop].invoke
240
+ spec.pattern = 'spec/**/*delete_spec.rb'
241
+ spec.rspec_opts = def_int_spec_options
242
+ spec.rspec_opts << ' --tag integration_i3s'
243
+ end
244
+
245
+ desc 'Run rubocop & integration tests for specified API version of Image Streamer. Default: 300'
246
+ task 'spec:integration:i3s:api_version', [:ver] do |_t, spec|
247
+ version = spec['ver'] || 300
248
+ spec_pattern = "spec/integration/image-streamer/api#{version}/**/*_spec.rb"
249
+ Rake::Task['spec:integration:i3s'].invoke
250
+ end
251
+
252
+ desc 'Run rubocop & integration tests for Image Streamer & specified path'
253
+ task 'test:i3s:path', [:path] do |_t, spec|
254
+ spec_pattern = spec['path']
255
+ Rake::Task[:rubocop].invoke
256
+ Rake::Task['spec:integration:i3s'].invoke
257
+ end
data/lib/oneview-sdk.rb CHANGED
@@ -15,10 +15,15 @@ require_relative 'oneview-sdk/client'
15
15
  require_relative 'oneview-sdk/resource'
16
16
  Dir[File.dirname(__FILE__) + '/oneview-sdk/resource/*.rb'].each { |file| require file }
17
17
  require_relative 'oneview-sdk/cli'
18
+ require_relative 'oneview-sdk/image_streamer'
18
19
 
19
20
  # Module for interacting with the HPE OneView API
20
21
  module OneviewSDK
21
- ENV_VARS = %w(ONEVIEWSDK_URL ONEVIEWSDK_USER ONEVIEWSDK_PASSWORD ONEVIEWSDK_TOKEN ONEVIEWSDK_SSL_ENABLED).freeze
22
+ env_sdk = %w(ONEVIEWSDK_URL ONEVIEWSDK_USER ONEVIEWSDK_PASSWORD ONEVIEWSDK_TOKEN)
23
+ env_sdk.concat %w(ONEVIEWSDK_SSL_ENABLED ONEVIEWSDK_API_VERSION ONEVIEWSDK_VARIANT)
24
+ env_i3s = %w(I3S_URL I3S_TOKEN I3S_SSL_ENABLED)
25
+ ENV_VARS = env_sdk.concat(env_i3s).freeze
26
+
22
27
  SUPPORTED_API_VERSIONS = [200, 300].freeze
23
28
  DEFAULT_API_VERSION = 200
24
29
  @api_version = DEFAULT_API_VERSION
@@ -50,19 +50,25 @@ module OneviewSDK
50
50
  end
51
51
  end
52
52
 
53
+ SUPPORTED_VARIANTS = OneviewSDK::API300::SUPPORTED_VARIANTS
54
+
53
55
  class_option :ssl_verify,
54
56
  type: :boolean,
55
57
  desc: 'Enable/Disable SSL verification for requests. Can also use ENV[\'ONEVIEWSDK_SSL_ENABLED\']',
56
58
  default: nil
57
59
 
58
60
  class_option :url,
59
- desc: 'URL of OneView appliance. Can also use ENV[\'ONEVIEWSDK_URL\']',
61
+ desc: "URL of OneView appliance. Uses ENV['ONEVIEWSDK_URL']",
60
62
  aliases: '-u'
61
63
 
62
64
  class_option :api_version,
63
65
  type: :numeric,
64
66
  banner: 'VERSION',
65
- desc: 'API version to use'
67
+ desc: "API version to use. Uses ENV['ONEVIEWSDK_API_VERSION']"
68
+
69
+ class_option :variant,
70
+ desc: "API variant to use. Uses ENV['ONEVIEWSDK_VARIANT']",
71
+ enum: SUPPORTED_VARIANTS
66
72
 
67
73
  class_option :log_level,
68
74
  desc: 'Log level to use',
@@ -435,6 +441,7 @@ module OneviewSDK
435
441
  client_params['url'] ||= @options['url'] if @options['url']
436
442
  client_params['log_level'] ||= @options['log_level'].to_sym if @options['log_level']
437
443
  client_params['api_version'] ||= @options['api_version'].to_i if @options['api_version']
444
+ client_params['api_version'] ||= ENV['ONEVIEWSDK_API_VERSION'].to_i if ENV['ONEVIEWSDK_API_VERSION']
438
445
  @client = OneviewSDK::Client.new(client_params)
439
446
  rescue StandardError => e
440
447
  raise e if throw_errors
@@ -444,25 +451,33 @@ module OneviewSDK
444
451
 
445
452
  # Get resource class from given string
446
453
  def parse_type(type)
447
- api_ver = (@options['api_version'] || OneviewSDK.api_version).to_i
454
+ api_ver = (@options['api_version'] || ENV['ONEVIEWSDK_API_VERSION'] || OneviewSDK.api_version).to_i
448
455
  unless OneviewSDK::SUPPORTED_API_VERSIONS.include?(api_ver)
449
456
  # Find and use the best available match for the desired API version (round down to nearest)
450
457
  valid_api_ver = OneviewSDK::SUPPORTED_API_VERSIONS.select { |x| x <= api_ver }.max || OneviewSDK::SUPPORTED_API_VERSIONS.min
451
458
  puts "WARNING: Module API version #{api_ver} is not supported. Using #{valid_api_ver}"
452
459
  api_ver = valid_api_ver
453
460
  end
454
- r = OneviewSDK.resource_named(type, api_ver)
455
- r ||= OneviewSDK.resource_named(type) unless api_ver == OneviewSDK.api_version # Try default API version as last resort
461
+ variant = @options['variant'] || ENV['ONEVIEWSDK_VARIANT']
462
+ variant ||= OneviewSDK::API300.variant if api_ver == 300
463
+ if variant && !SUPPORTED_VARIANTS.include?(variant)
464
+ fail_nice "Variant '#{variant}' is not supported. Try one of #{SUPPORTED_VARIANTS}"
465
+ end
466
+ r = OneviewSDK.resource_named(type, api_ver, variant)
467
+ # Try default API version as last resort
468
+ r ||= OneviewSDK.resource_named(type, OneviewSDK.api_version, variant) unless api_ver == OneviewSDK.api_version
456
469
  return r if r
457
470
  valid_classes = []
458
471
  api_module = OneviewSDK.const_get("API#{api_ver}")
472
+ api_module = api_module.const_get(variant.to_s) unless api_ver.to_i == 200
459
473
  api_module.constants.each do |c|
460
474
  klass = api_module.const_get(c)
461
475
  next unless klass.is_a?(Class) && klass < OneviewSDK::Resource
462
476
  valid_classes.push(klass.name.split('::').last)
463
477
  end
464
478
  vc = valid_classes.sort_by!(&:downcase).join("\n ")
465
- fail_nice("Invalid resource type: '#{type}'. Valid options for API version #{api_ver} are:\n #{vc}")
479
+ var = variant ? " (variant #{variant})" : ''
480
+ fail_nice("Invalid resource type: '#{type}'. Valid options for API version #{api_ver}#{var} are:\n #{vc}")
466
481
  end
467
482
 
468
483
  # Parse options hash from input. Handles chaining and keywords such as true/false & nil
@@ -17,8 +17,9 @@ require_relative 'ssl_helper'
17
17
  module OneviewSDK
18
18
  # The client defines the connection to the OneView server and handles communication with it.
19
19
  class Client
20
- attr_reader :url, :user, :token, :password, :max_api_version
21
- attr_accessor :ssl_enabled, :api_version, :logger, :log_level, :cert_store, :print_wait_dots, :timeout
20
+ attr_reader :max_api_version
21
+ attr_accessor :url, :user, :token, :password, :ssl_enabled, :api_version, \
22
+ :logger, :log_level, :cert_store, :print_wait_dots, :timeout
22
23
 
23
24
  include Rest
24
25
 
@@ -41,8 +42,7 @@ module OneviewSDK
41
42
  STDOUT.sync = true
42
43
  @logger = options[:logger] || Logger.new(STDOUT)
43
44
  [:debug, :info, :warn, :error, :level=].each { |m| raise InvalidClient, "Logger must respond to #{m} method " unless @logger.respond_to?(m) }
44
- @log_level = options[:log_level] || :info
45
- @logger.level = @logger.class.const_get(@log_level.upcase) rescue @log_level
45
+ self.log_level = options[:log_level] || :info
46
46
  @print_wait_dots = options.fetch(:print_wait_dots, false)
47
47
  @url = options[:url] || ENV['ONEVIEWSDK_URL']
48
48
  raise InvalidClient, 'Must set the url option' unless @url
@@ -73,6 +73,11 @@ module OneviewSDK
73
73
  @token = login
74
74
  end
75
75
 
76
+ def log_level=(level)
77
+ @logger.level = @logger.class.const_get(level.upcase) rescue level
78
+ @log_level = level
79
+ end
80
+
76
81
  # Tells OneView to create the resource using the current attribute data
77
82
  # @param [Resource] resource the object to create
78
83
  def create(resource)
@@ -104,12 +109,14 @@ module OneviewSDK
104
109
  # Get array of all resources of a specified type
105
110
  # @param [String] type Resource type
106
111
  # @param [Integer] api_ver API module version to fetch resources from
112
+ # @param [String] variant API module variant to fetch resource from
107
113
  # @return [Array<Resource>] Results
108
114
  # @example Get all Ethernet Networks
109
115
  # networks = @client.get_all('EthernetNetworks')
116
+ # synergy_networks = @client.get_all('EthernetNetworks', 300, 'Synergy')
110
117
  # @raise [TypeError] if the type is invalid
111
- def get_all(type, api_ver = @api_version)
112
- klass = OneviewSDK.resource_named(type, api_ver)
118
+ def get_all(type, api_ver = @api_version, variant = nil)
119
+ klass = OneviewSDK.resource_named(type, api_ver, variant)
113
120
  raise TypeError, "Invalid resource type '#{type}'. OneviewSDK::API#{api_ver} does not contain a class like it." unless klass
114
121
  klass.get_all(self)
115
122
  end
@@ -141,6 +148,15 @@ module OneviewSDK
141
148
  end
142
149
  end
143
150
 
151
+ # Refresh the client's session token & max_api_version.
152
+ # Call this after a token expires or the user and/or password is updated on the client object.
153
+ # @return [OneviewSDK::Client] self
154
+ def refresh_login
155
+ @max_api_version = appliance_api_version
156
+ @token = login
157
+ self
158
+ end
159
+
144
160
 
145
161
  private
146
162
 
@@ -157,7 +173,7 @@ module OneviewSDK
157
173
  OneviewSDK::DEFAULT_API_VERSION
158
174
  end
159
175
 
160
- # Log in to OneView appliance and set max_api_version
176
+ # Log in to OneView appliance and return the session token
161
177
  def login(retries = 2)
162
178
  options = {
163
179
  'body' => {
@@ -0,0 +1,96 @@
1
+ # (C) Copyright 2016 Hewlett Packard Enterprise Development LP
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # You may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
6
+ #
7
+ # Unless required by applicable law or agreed to in writing, software distributed
8
+ # under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
9
+ # CONDITIONS OF ANY KIND, either express or implied. See the License for the specific
10
+ # language governing permissions and limitations under the License.
11
+
12
+ require_relative '../client'
13
+
14
+ module OneviewSDK
15
+ module ImageStreamer
16
+ # The client defines the connection to the Image Streamer server and handles communication with it.
17
+ class Client < OneviewSDK::Client
18
+ undef :user
19
+ undef :user=
20
+ undef :password
21
+ undef :password=
22
+ undef :refresh_login
23
+
24
+ # Creates client object, establish connection, and set up logging and api version.
25
+ # @param [Hash] options the options to configure the client
26
+ # @option options [Logger] :logger (Logger.new(STDOUT)) Logger object to use.
27
+ # Must implement debug(String), info(String), warn(String), error(String), & level=
28
+ # @option options [Symbol] :log_level (:info) Log level. Logger must define a constant with this name. ie Logger::INFO
29
+ # @option options [Boolean] :print_wait_dots (false) When true, prints status dots while waiting on the tasks to complete.
30
+ # @option options [String] :url URL of Image Streamer
31
+ # @option options [String] :token (ENV['I3S_TOKEN']) The token to use for authentication with Image Streamer
32
+ # @option options [Integer] :api_version (300) This is the API version to use by default for requests
33
+ # @option options [Boolean] :ssl_enabled (true) Use ssl for requests? Respects ENV['I3S_SSL_ENABLED']
34
+ # @option options [Integer] :timeout (nil) Override the default request timeout value
35
+ def initialize(options = {})
36
+ options = Hash[options.map { |k, v| [k.to_sym, v] }] # Convert string hash keys to symbols
37
+ STDOUT.sync = true
38
+ @logger = options[:logger] || Logger.new(STDOUT)
39
+ [:debug, :info, :warn, :error, :level=].each { |m| raise InvalidClient, "Logger must respond to #{m} method " unless @logger.respond_to?(m) }
40
+ self.log_level = options[:log_level] || :info
41
+ @print_wait_dots = options.fetch(:print_wait_dots, false)
42
+ @url = options[:url] || ENV['I3S_URL']
43
+ raise InvalidClient, 'Must set the url option' unless @url
44
+ @max_api_version = appliance_i3s_api_version
45
+ if options[:api_version] && options[:api_version].to_i > @max_api_version
46
+ logger.warn "API version #{options[:api_version]} is greater than the Image Streamer API version (#{@max_api_version})"
47
+ end
48
+ @api_version = options[:api_version] || [OneviewSDK::ImageStreamer::DEFAULT_API_VERSION, @max_api_version].min
49
+ # Set the default Image Streamer module API version
50
+ OneviewSDK::ImageStreamer.api_version = @api_version unless
51
+ OneviewSDK::ImageStreamer.api_version_updated? || !OneviewSDK::ImageStreamer::SUPPORTED_API_VERSIONS.include?(@api_version)
52
+ @ssl_enabled = true
53
+ if ENV.key?('I3S_SSL_ENABLED')
54
+ if %w(true false 1 0).include?(ENV['I3S_SSL_ENABLED'])
55
+ @ssl_enabled = !%w(false 0).include?(ENV['I3S_SSL_ENABLED'])
56
+ else
57
+ @logger.warn "Unrecognized ssl_enabled value '#{ENV['I3S_SSL_ENABLED']}'. Valid options are 'true' & 'false'"
58
+ end
59
+ end
60
+ @ssl_enabled = options[:ssl_enabled] unless options[:ssl_enabled].nil?
61
+ @timeout = options[:timeout] unless options[:timeout].nil?
62
+ @cert_store = OneviewSDK::SSLHelper.load_trusted_certs if @ssl_enabled
63
+ raise InvalidClient, 'Must set token option' unless options[:token] || ENV['I3S_TOKEN']
64
+ @token = options[:token] || ENV['I3S_TOKEN']
65
+ end
66
+
67
+ # Get array of all resources of a specified type
68
+ # @param [String] type Resource type
69
+ # @param [Integer] api_ver API module version to fetch resources from
70
+ # @return [Array<Resource>] Results
71
+ # @example Get all Deployment Plans
72
+ # deployment_plans = @client.get_all('DeploymentPlans')
73
+ # @raise [TypeError] if the type is invalid
74
+ def get_all(type, api_ver = @api_version)
75
+ klass = OneviewSDK::ImageStreamer.resource_named(type, api_ver)
76
+ raise TypeError, "Invalid resource type '#{type}'. OneviewSDK::ImageStreamer::API#{api_ver} does not contain a class like it." unless klass
77
+ klass.get_all(self)
78
+ end
79
+
80
+ private
81
+
82
+ # Get current api version from the Image Streamer
83
+ def appliance_i3s_api_version
84
+ options = { 'Content-Type' => :none, 'X-API-Version' => :none, 'auth' => :none }
85
+ response = rest_api(:get, '/rest/version', options)
86
+ version = response_handler(response)['currentVersion']
87
+ raise ConnectionError, "Couldn't get API version" unless version
88
+ version = version.to_i if version.class != Fixnum
89
+ version
90
+ rescue ConnectionError
91
+ @logger.warn "Failed to get Image Streamer max api version. Using default (#{OneviewSDK::ImageStreamer::DEFAULT_API_VERSION})"
92
+ OneviewSDK::ImageStreamer::DEFAULT_API_VERSION
93
+ end
94
+ end
95
+ end
96
+ end