oneview-sdk 1.0.0 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (52) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +4 -0
  3. data/CHANGELOG.md +81 -2
  4. data/README.md +118 -113
  5. data/Rakefile +11 -0
  6. data/lib/oneview-sdk/cli.rb +21 -15
  7. data/lib/oneview-sdk/client.rb +34 -21
  8. data/lib/oneview-sdk/config_loader.rb +12 -1
  9. data/lib/oneview-sdk/exceptions.rb +55 -0
  10. data/lib/oneview-sdk/resource/connection_template.rb +48 -0
  11. data/lib/oneview-sdk/resource/datacenter.rb +77 -0
  12. data/lib/oneview-sdk/resource/enclosure.rb +46 -24
  13. data/lib/oneview-sdk/resource/enclosure_group.rb +20 -36
  14. data/lib/oneview-sdk/resource/ethernet_network.rb +19 -23
  15. data/lib/oneview-sdk/resource/fabric.rb +41 -0
  16. data/lib/oneview-sdk/resource/fc_network.rb +15 -16
  17. data/lib/oneview-sdk/resource/fcoe_network.rb +15 -12
  18. data/lib/oneview-sdk/resource/firmware_bundle.rb +23 -24
  19. data/lib/oneview-sdk/resource/firmware_driver.rb +21 -9
  20. data/lib/oneview-sdk/resource/interconnect.rb +29 -9
  21. data/lib/oneview-sdk/resource/lig_uplink_set.rb +22 -28
  22. data/lib/oneview-sdk/resource/logical_downlink.rb +53 -0
  23. data/lib/oneview-sdk/resource/logical_enclosure.rb +35 -33
  24. data/lib/oneview-sdk/resource/logical_interconnect.rb +29 -65
  25. data/lib/oneview-sdk/resource/logical_interconnect_group.rb +26 -6
  26. data/lib/oneview-sdk/resource/logical_switch.rb +184 -0
  27. data/lib/oneview-sdk/resource/logical_switch_group.rb +66 -0
  28. data/lib/oneview-sdk/resource/managed_san.rb +79 -0
  29. data/lib/oneview-sdk/resource/network_set.rb +64 -0
  30. data/lib/oneview-sdk/resource/power_device.rb +174 -0
  31. data/lib/oneview-sdk/resource/rack.rb +83 -0
  32. data/lib/oneview-sdk/resource/san_manager.rb +88 -0
  33. data/lib/oneview-sdk/resource/server_hardware.rb +139 -18
  34. data/lib/oneview-sdk/resource/server_hardware_type.rb +32 -1
  35. data/lib/oneview-sdk/resource/server_profile.rb +352 -9
  36. data/lib/oneview-sdk/resource/server_profile_template.rb +193 -4
  37. data/lib/oneview-sdk/resource/storage_pool.rb +42 -20
  38. data/lib/oneview-sdk/resource/storage_system.rb +64 -14
  39. data/lib/oneview-sdk/resource/switch.rb +86 -0
  40. data/lib/oneview-sdk/resource/unmanaged_device.rb +55 -0
  41. data/lib/oneview-sdk/resource/uplink_set.rb +24 -64
  42. data/lib/oneview-sdk/resource/volume.rb +29 -29
  43. data/lib/oneview-sdk/resource/volume_attachment.rb +79 -0
  44. data/lib/oneview-sdk/resource/volume_snapshot.rb +20 -1
  45. data/lib/oneview-sdk/resource/volume_template.rb +22 -33
  46. data/lib/oneview-sdk/resource.rb +66 -28
  47. data/lib/oneview-sdk/rest.rb +69 -24
  48. data/lib/oneview-sdk/ssl_helper.rb +20 -9
  49. data/lib/oneview-sdk/version.rb +12 -1
  50. data/lib/oneview-sdk.rb +12 -0
  51. data/oneview-sdk.gemspec +11 -0
  52. metadata +17 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2f224fcb81143087867edc94a434b56d65a78659
4
- data.tar.gz: 03a1ef013585d8f80554745aa9f2910b18dd797f
3
+ metadata.gz: a7edacad4f95e018c2c4155c5d7bcbf502a14c7e
4
+ data.tar.gz: 3bd46a95ff7f58444d0b19f90939746d225ffa82
5
5
  SHA512:
6
- metadata.gz: 5d524a3027585fabc531bd9726b5780f71d92f84f17f0891824313d999124ecbbb43e4e9b2449408549816853e58be6a28df0a669f316d59c1525c3f68ffb3b5
7
- data.tar.gz: cf2ec71583906adb14782aadaeb81da5e41063ac79529040918b537688011416781b60ac8771e03bc74924ec8cf62e3329b58890a118713fae54e3706fbde9e4
6
+ metadata.gz: abd9687dfe8752cf416d1a4079e2dc99f3e29b3a43d8f77ae9ca8ad1f7f965238029381e92c658c58f4825e9322df23477fa6c80b197324cc44aaf29d4056f59
7
+ data.tar.gz: d90567809d527d9aa8990b0294e04e3e54ad7eab40f43fd5de331b39aaa1a5f936f33a9f2685cdae87e92deef9b90140d5916953a726b0c5af0cc6801f3d0a19
data/.rubocop.yml CHANGED
@@ -1,5 +1,9 @@
1
1
  # See default at https://github.com/bbatsov/rubocop/blob/master/config/default.yml
2
2
 
3
+ AllCops:
4
+ Exclude:
5
+ - 'examples/_client.rb'
6
+
3
7
  Metrics/ClassLength:
4
8
  Max: 200
5
9
  Exclude:
data/CHANGELOG.md CHANGED
@@ -1,6 +1,85 @@
1
+ # v2.0.0
2
+ ### Notes
3
+ This is the second version of the Ruby SDK for HPE OneView. It was given support to the major features of OneView, refactor in some of the already existing code, and also a full set of exceptions to make some common exceptions more explicit in the debugging process.
4
+ This version of this SDK officially supports OneView appliances version 2.00.00 or higher, using the OneView Rest API version 200.
5
+ For now only C7000 enclosure types are being supported.
6
+
7
+ ### Major changes
8
+ 1. Added full support to the already existing features:
9
+ - Server Profile
10
+ - Server Profile Template
11
+ - Server Hardware
12
+ 2. New features added:
13
+ - Connection Templates
14
+ - Datacenter
15
+ - Fabrics
16
+ - Logical downlinks
17
+ - Logical switch groups
18
+ - Logical switches
19
+ - Switches
20
+ - SAN managers
21
+ - Managed SANs
22
+ - Network sets
23
+ - Power devices
24
+ - Racks
25
+ - Server hardware types
26
+ - Unmanaged devices
27
+ 3. New exceptions to address the most common issues (Check them in *lib/oneview-sdk/resource/exceptions.rb*)
28
+
29
+ ### Breaking changes
30
+ 1. Refactored some method names that may cause incompatibility with older SDK versions. Due to the nature of OneView, the `create` and `delete` methods did not fit the physical infrastructure elements like Enclosures, or Switches, so they now have `add` and `remove` methods that act the same as before, but now it leaves no margin to misunderstand that OneView could actually create these resources. They are:
31
+ - Datacenters
32
+ - Enclosure
33
+ - Power devices
34
+ - Racks
35
+ - Storage systems
36
+ - Storage pools
37
+ - Firmware drivers
38
+ - Firmware bundles (Only `add`)
39
+ - SAN managers
40
+ - Server hardwares
41
+ - Server hardware types
42
+ - Switches
43
+ - Unmanaged devices
44
+
45
+ ### Features supported
46
+ - Ethernet network
47
+ - FC network
48
+ - FCOE network
49
+ - Network set
50
+ - Connection template
51
+ - Fabric
52
+ - SAN manager
53
+ - Managed SAN
54
+ - Interconnect
55
+ - Logical interconnect
56
+ - Logical interconnect group
57
+ - Uplink set
58
+ - Logical downlink
59
+ - Enclosure
60
+ - Logical enclosure
61
+ - Enclosure group
62
+ - Firmware bundle
63
+ - Firmware driver
64
+ - Storage system
65
+ - Storage pool
66
+ - Volume
67
+ - Volume template
68
+ - Datacenter
69
+ - Racks
70
+ - Logical switch group
71
+ - Logical switch
72
+ - Switch
73
+ - Power devices
74
+ - Server profile
75
+ - Server profile template
76
+ - Server hardware
77
+ - Server hardware type
78
+ - Unmanaged devices
79
+
1
80
  # v1.0.0
2
81
  ### Notes
3
- This is the first release of the OneView SDK in Ruby and it adds full support to some core features listed bellow, with some execptions that are explicit.
82
+ This is the first release of the OneView SDK in Ruby and it adds full support to some core features listed bellow, with some execeptions that are explicit.
4
83
  This version of this SDK supports OneView appliances version 2.00.00 or higher, using the OneView Rest API version 200.
5
84
  For now it only supports C7000 enclosure types.
6
85
 
@@ -26,7 +105,7 @@
26
105
  - Server Profile Template (CRUD supported)
27
106
  - Server Hardware (CRUD Supported)
28
107
 
29
- ### Know Issues
108
+ ### Known issues
30
109
  The integration tests may warn about 3 issues:
31
110
 
32
111
  1. OneviewSDK::LogicalInterconnect Firmware Updates perform the actions Stage
data/README.md CHANGED
@@ -2,7 +2,7 @@
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 integration and scalable solutions with HPE OneView.
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.
6
6
 
7
7
  ## Installation
8
8
  - Require the gem in your Gemfile:
@@ -38,7 +38,7 @@ client = OneviewSDK::Client.new(
38
38
 
39
39
  :lock: Tip: Check the file permissions because the password is stored in clear-text.
40
40
 
41
- **Environment Variables**
41
+ ##### Environment Variables
42
42
 
43
43
  You can also set the url and credentials or an authentication token using environment variables. For bash:
44
44
 
@@ -64,7 +64,7 @@ client = OneviewSDK::Client.new
64
64
  ```
65
65
  NOTE: Run `$ oneview-sdk-ruby env` to see a list of available environment variables and their current values.
66
66
 
67
- **Configuration Files**
67
+ ##### Configuration Files
68
68
 
69
69
  Configuration files can also be used to define client configuration (json or yaml formats). Here's an example json file:
70
70
 
@@ -103,85 +103,85 @@ For example, once you instantiate a resource object, you can call intuitive meth
103
103
 
104
104
  Please see the [rubydoc.info](http://www.rubydoc.info/gems/oneview-sdk) documentation for the complete list and usage details, but here are a few examples to get you started:
105
105
 
106
- - **Create a resource**
106
+ ##### Create a resource
107
107
 
108
- ```ruby
109
- ethernet = OneviewSDK::EthernetNetwork.new(
110
- client, { name: 'TestVlan', vlanId: 1001, purpose: 'General', smartLink: false, privateNetwork: false }
111
- )
112
- ethernet.create # Tells OneView to create this resource
113
- ```
108
+ ```ruby
109
+ ethernet = OneviewSDK::EthernetNetwork.new(
110
+ client, { name: 'TestVlan', vlanId: 1001, purpose: 'General', smartLink: false, privateNetwork: false }
111
+ )
112
+ ethernet.create # Tells OneView to create this resource
113
+ ```
114
114
 
115
- - **Access resource attributes**
115
+ ##### Access resource attributes
116
116
 
117
- ```ruby
118
- ethernet['name'] # Returns 'TestVlan'
117
+ ```ruby
118
+ ethernet['name'] # Returns 'TestVlan'
119
119
 
120
- ethernet.data # Returns hash of all data
120
+ ethernet.data # Returns hash of all data
121
121
 
122
- ethernet.each do |key, value|
123
- puts "Attribute #{key} = #{value}"
124
- end
125
- ```
122
+ ethernet.each do |key, value|
123
+ puts "Attribute #{key} = #{value}"
124
+ end
125
+ ```
126
126
 
127
- The resource's data is stored in its @data attribute. However, you can access the data directly using a hash-like syntax on the resource object (recommended). `resource['key']` functions a lot like `resource.data['key']`. The difference is that when using the data attribute, you must be cautious to use the correct key type (Hash vs Symbol).
128
- The direct hash accessor on the resource converts all keys to strings, so `resource[:key]` and `resource['key']` access the same thing: `resource.data['key']`.
127
+ The resource's data is stored in its @data attribute. However, you can access the data directly using a hash-like syntax on the resource object (recommended). `resource['key']` functions a lot like `resource.data['key']`. The difference is that when using the data attribute, you must be cautious to use the correct key type (Hash vs Symbol).
128
+ The direct hash accessor on the resource converts all keys to strings, so `resource[:key]` and `resource['key']` access the same thing: `resource.data['key']`.
129
129
 
130
- - **Update a resource**
130
+ ##### Update a resource
131
131
 
132
- Notice that there's a few different ways to do things, so pick your poison!
133
- ```ruby
134
- ethernet.set_all(name: 'newName', vlanId: 1002)
135
- ethernet['purpose'] = 'General'
136
- ethernet['ethernetNetworkType'] = 'Tagged'
137
- ethernet.update # Saves current state to OneView
132
+ Notice that there are a few different ways to do things, so pick your poison!
133
+ ```ruby
134
+ ethernet.set_all(name: 'newName', vlanId: 1002)
135
+ ethernet['purpose'] = 'General'
136
+ ethernet['ethernetNetworkType'] = 'Tagged'
137
+ ethernet.update # Saves current state to OneView
138
138
 
139
- # Alternatively, you could do this in 1 step with:
140
- ethernet.update(name: 'newName', vlanId: 1002, purpose: 'General', ethernetNetworkType: 'Tagged')
141
- ```
139
+ # Alternatively, you could do this in 1 step with:
140
+ ethernet.update(name: 'newName', vlanId: 1002, purpose: 'General', ethernetNetworkType: 'Tagged')
141
+ ```
142
142
 
143
- - **Check resource equality**
143
+ ##### Check resource equality
144
144
 
145
- You can use the `==` or `.eql?` method to compare resource equality, or `.like` to compare just a subset of attributes.
146
- ```ruby
147
- ethernet2 = OneviewSDK::EthernetNetwork.new(
148
- client, { name: 'OtherVlan', vlanId: 1000, purpose: 'General', smartLink: false, privateNetwork: false }
149
- )
150
- ethernet == ethernet2 # Returns false
151
- ethernet.eql?(ethernet2) # Returns false
145
+ You can use the `==` or `.eql?` method to compare resource equality, or `.like` to compare just a subset of attributes.
146
+ ```ruby
147
+ ethernet2 = OneviewSDK::EthernetNetwork.new(
148
+ client, { name: 'OtherVlan', vlanId: 1000, purpose: 'General', smartLink: false, privateNetwork: false }
149
+ )
150
+ ethernet == ethernet2 # Returns false
151
+ ethernet.eql?(ethernet2) # Returns false
152
152
 
153
153
 
154
- # To compare a subset of attributes:
155
- ethernet3 = OneviewSDK::EthernetNetwork.new(client, { purpose: 'General' })
156
- ethernet.like?(ethernet3) # Returns true
157
- ethernet.like?(name: TestVlan, purpose: 'General') # Returns true
158
- ```
154
+ # To compare a subset of attributes:
155
+ ethernet3 = OneviewSDK::EthernetNetwork.new(client, { purpose: 'General' })
156
+ ethernet.like?(ethernet3) # Returns true
157
+ ethernet.like?(name: TestVlan, purpose: 'General') # Returns true
158
+ ```
159
159
 
160
160
 
161
- - **Find resources**
161
+ ##### Find resources
162
162
 
163
- ```ruby
164
- ethernet = OneviewSDK::EthernetNetwork.new(client, { name: 'OtherVlan' })
165
- ethernet.retrieve! # Uses the name attribute to search for the resource on the server and update the data in this object.
163
+ ```ruby
164
+ ethernet = OneviewSDK::EthernetNetwork.new(client, { name: 'OtherVlan' })
165
+ ethernet.retrieve! # Uses the name attribute to search for the resource on the server and update the data in this object.
166
166
 
167
167
 
168
- # Each resource class also has a searching method (NOTE: class method, not instance method)
169
- ethernet = OneviewSDK::EthernetNetwork.find_by(client, { name: 'OtherVlan' }).first
168
+ # Each resource class also has a searching method (NOTE: class method, not instance method)
169
+ ethernet = OneviewSDK::EthernetNetwork.find_by(client, { name: 'OtherVlan' }).first
170
170
 
171
- OneviewSDK::EthernetNetwork.find_by(client, { purpose: 'General' }).each do |network|
172
- puts " #{network['name']}"
173
- end
171
+ OneviewSDK::EthernetNetwork.find_by(client, { purpose: 'General' }).each do |network|
172
+ puts " #{network['name']}"
173
+ end
174
174
 
175
- # Get all resources:
176
- networks = client.get_all(:EthernetNetwork)
177
- ```
175
+ # Get all resources:
176
+ networks = client.get_all(:EthernetNetwork)
177
+ ```
178
178
 
179
- - **Delete a resource**
179
+ ##### Delete a resource
180
180
 
181
- ```ruby
182
- ethernet = OneviewSDK::EthernetNetwork.find_by(client, { name: 'OtherVlan' }).first
183
- ethernet.delete # Tells OneView to delete this resource
184
- ```
181
+ ```ruby
182
+ ethernet = OneviewSDK::EthernetNetwork.find_by(client, { name: 'OtherVlan' }).first
183
+ ethernet.delete # Tells OneView to delete this resource
184
+ ```
185
185
 
186
186
  ### Save/Load resources with files
187
187
  Resources can be saved to files and loaded again very easily using the built-in `.to_file` & `.from_file` methods.
@@ -191,7 +191,7 @@ Resources can be saved to files and loaded again very easily using the built-in
191
191
  ```ruby
192
192
  ethernet.to_file("full_file_path.json")
193
193
  ```
194
- - To load a Resource from a file: (note the class method, not instance method)
194
+ - To load a resource from a file: (note the class method, not instance method)
195
195
 
196
196
  ```ruby
197
197
  ethernet4 = OneviewSDK::Resource.from_file(client, "full_file_path.json")
@@ -231,58 +231,63 @@ To communicate with an appliance, you will need to set up a few environment vari
231
231
 
232
232
  The CLI does not expose everything in the SDK, but it is great for doing simple tasks such as creating or deleting resources from files, listing resources, and searching. Here are a few examples:
233
233
 
234
- - List ServerProfiles:
235
- ```bash
236
- $ oneview-sdk-ruby list ServerProfiles
237
- # Or to show in yaml format (json is also supported):
238
- $ oneview-sdk-ruby list ServerProfiles -f yaml
239
- ```
240
-
241
- - Show details for a specific resource:
242
- ```bash
243
- $ oneview-sdk-ruby show ServerProfile profile-1
244
- # Or to show specific attributes only:
245
- $ oneview-sdk-ruby show ServerProfile profile-1 -a name,uri,enclosureBay
246
- ```
247
-
248
- - Search by an attribute:
249
- ```bash
250
- $ oneview-sdk-ruby search ServerProfiles --filter state:Normal affinity:Bay
251
- # By default, it will just show a list of names of matching resources,
252
- # but again, you can show only certain attributes by using the -a option
253
- # You can also chain keys together to search in nested hashes:
254
- $ oneview-sdk-ruby search ServerProfiles --filter state:Normal boot.manageBoot:true
255
- ```
256
-
257
- - Create or delete resource by file:
258
- ```bash
259
- $ oneview-sdk-ruby create_from_file /my-server-profile.json
260
- $ oneview-sdk-ruby delete_from_file /my-server-profile.json
261
- ```
262
-
263
- - Start an interactive console session with a OneView connection:
264
- ```bash
265
- $ oneview-sdk-ruby console
266
- Console Connected to https://oneview.example.com
267
- HINT: The @client object is available to you
268
- >
269
- ```
270
-
271
- - Import a self-signed SSL certificate from your OneView instance:
272
-
273
- Although you can disable ssl validation altogether for the client, this is strongly discouraged.
274
- Instead, please import the certificate using the built-in cli cert command:
275
- ```bash
276
- # Check the certificate first:
277
- $ oneview-sdk-ruby cert check https://oneview.example.com
278
- Checking certificate for 'https://oneview.example.com' ...
279
- ERROR: Certificate Validation Failed!
280
-
281
- # Import the certificate:
282
- $ oneview-sdk-ruby cert import https://oneview.example.com
283
- Importing certificate for 'https://oneview.example.com' into '/home/users/user1/.oneview-sdk-ruby/trusted_certs.cer'...
284
- Cert added to '/home/users/user1/.oneview-sdk-ruby/trusted_certs.cer'
285
- ```
234
+ ##### List ServerProfiles:
235
+
236
+ ```bash
237
+ $ oneview-sdk-ruby list ServerProfiles
238
+ # Or to show in yaml format (json is also supported):
239
+ $ oneview-sdk-ruby list ServerProfiles -f yaml
240
+ ```
241
+
242
+ ##### Show details for a specific resource:
243
+
244
+ ```bash
245
+ $ oneview-sdk-ruby show ServerProfile profile-1
246
+ # Or to show specific attributes only:
247
+ $ oneview-sdk-ruby show ServerProfile profile-1 -a name,uri,enclosureBay
248
+ ```
249
+
250
+ ##### Search by an attribute:
251
+
252
+ ```bash
253
+ $ oneview-sdk-ruby search ServerProfiles --filter state:Normal affinity:Bay
254
+ # By default, it will just show a list of names of matching resources,
255
+ # but again, you can show only certain attributes by using the -a option
256
+ # You can also chain keys together to search in nested hashes:
257
+ $ oneview-sdk-ruby search ServerProfiles --filter state:Normal boot.manageBoot:true
258
+ ```
259
+
260
+ ##### Create or delete resource by file:
261
+
262
+ ```bash
263
+ $ oneview-sdk-ruby create_from_file /my-server-profile.json
264
+ $ oneview-sdk-ruby delete_from_file /my-server-profile.json
265
+ ```
266
+
267
+ ##### Start an interactive console session with a OneView connection:
268
+
269
+ ```bash
270
+ $ oneview-sdk-ruby console
271
+ Console Connected to https://oneview.example.com
272
+ HINT: The @client object is available to you
273
+ >
274
+ ```
275
+
276
+ ##### Import a self-signed SSL certificate from your OneView instance:
277
+
278
+ Although you can disable SSL validation altogether for the client, this is strongly discouraged.
279
+ Instead, please import the certificate using the built-in CLI cert command:
280
+ ```bash
281
+ # Check the certificate first:
282
+ $ oneview-sdk-ruby cert check https://oneview.example.com
283
+ Checking certificate for 'https://oneview.example.com' ...
284
+ ERROR: Certificate Validation Failed!
285
+
286
+ # Import the certificate:
287
+ $ oneview-sdk-ruby cert import https://oneview.example.com
288
+ Importing certificate for 'https://oneview.example.com' into '/home/users/user1/.oneview-sdk-ruby/trusted_certs.cer'...
289
+ Cert added to '/home/users/user1/.oneview-sdk-ruby/trusted_certs.cer'
290
+ ```
286
291
 
287
292
  ## License
288
293
  This project is licensed under the Apache 2.0 license. Please see [LICENSE](LICENSE) for more info.
data/Rakefile CHANGED
@@ -1,3 +1,14 @@
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
+
1
12
  require 'bundler'
2
13
  require 'bundler/gem_tasks'
3
14
  require 'bundler/setup'
@@ -1,3 +1,14 @@
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
+
1
12
  require 'thor'
2
13
  require 'json'
3
14
  require 'yaml'
@@ -180,9 +191,9 @@ module OneviewSDK
180
191
  options['attribute'].split(',').each do |attr|
181
192
  temp[attr] = d[attr]
182
193
  end
183
- data.push temp
194
+ data.push(d['name'] => temp)
184
195
  end
185
- output data
196
+ output data, -2 # Shift left by 2 so things look right
186
197
  else # List names only by default
187
198
  names = []
188
199
  matches.each { |m| names.push(m['name']) }
@@ -366,34 +377,29 @@ module OneviewSDK
366
377
  when 'yaml'
367
378
  puts data.to_yaml
368
379
  else
380
+ # rubocop:disable Metrics/BlockNesting
369
381
  if data.class == Hash || data.class <= OneviewSDK::Resource
370
382
  data.each do |k, v|
371
383
  if v.class == Hash || v.class == Array
372
- puts "#{' ' * indent}#{k}:"
384
+ puts "#{' ' * indent}#{k.nil? ? 'nil' : k}:"
373
385
  output(v, indent + 2)
374
386
  else
375
- puts "#{' ' * indent}#{k}: #{v}"
387
+ puts "#{' ' * indent}#{k.nil? ? 'nil' : k}: #{v.nil? ? 'nil' : v}"
376
388
  end
377
389
  end
378
390
  elsif data.class == Array
379
391
  data.each do |d|
380
392
  if d.class == Hash || d.class == Array
381
- # rubocop:disable Metrics/BlockNesting
382
- if indent == 0
383
- puts ''
384
- output(d, indent)
385
- else
386
- output(d, indent + 2)
387
- end
388
- # rubocop:enable Metrics/BlockNesting
393
+ output(d, indent + 2)
389
394
  else
390
- puts "#{' ' * indent}#{d}"
395
+ puts "#{' ' * indent}#{d.nil? ? 'nil' : d}"
391
396
  end
392
397
  end
393
- puts "\nTotal: #{data.size}" if indent == 0
398
+ puts "\nTotal: #{data.size}" if indent < 1
394
399
  else
395
- puts "#{' ' * indent}#{data}"
400
+ puts "#{' ' * indent}#{data.nil? ? 'nil' : data}"
396
401
  end
402
+ # rubocop:enable Metrics/BlockNesting
397
403
  end
398
404
  end
399
405
  end
@@ -1,3 +1,14 @@
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
+
1
12
  require 'logger'
2
13
  require_relative 'config_loader'
3
14
  require_relative 'rest'
@@ -9,32 +20,33 @@ module OneviewSDK
9
20
  DEFAULT_API_VERSION = 200
10
21
 
11
22
  attr_reader :url, :user, :token, :password, :max_api_version
12
- attr_accessor :ssl_enabled, :api_version, :logger, :log_level, :cert_store, :print_wait_dots
23
+ attr_accessor :ssl_enabled, :api_version, :logger, :log_level, :cert_store, :print_wait_dots, :timeout
13
24
 
14
25
  include Rest
15
26
 
16
- # Create client object, establish connection, and set up logging and api version.
27
+ # Creates client object, establish connection, and set up logging and api version.
17
28
  # @param [Hash] options the options to configure the client
18
29
  # @option options [Logger] :logger (Logger.new(STDOUT)) Logger object to use.
19
30
  # Must implement debug(String), info(String), warn(String), error(String), & level=
20
31
  # @option options [Symbol] :log_level (:info) Log level. Logger must define a constant with this name. ie Logger::INFO
21
- # @option options [Boolean] :print_wait_dots (false) When true, prints status dots while waiting on tasks to complete.
32
+ # @option options [Boolean] :print_wait_dots (false) When true, prints status dots while waiting on the tasks to complete.
22
33
  # @option options [String] :url URL of OneView appliance
23
- # @option options [String] :user ('Administrator') Username to use for authentication with OneView appliance
24
- # @option options [String] :password (ENV['ONEVIEWSDK_PASSWORD']) Password to use for authentication with OneView appliance
25
- # @option options [String] :token (ENV['ONEVIEWSDK_TOKEN']) Token to use for authentication with OneView appliance
26
- # Use this OR the username and password (not both). Token has precedence.
27
- # @option options [Integer] :api_version (200) API Version to use by default for requests
34
+ # @option options [String] :user ('Administrator') The username to use for authentication with the OneView appliance
35
+ # @option options [String] :password (ENV['ONEVIEWSDK_PASSWORD']) The password to use for authentication with OneView appliance
36
+ # @option options [String] :token (ENV['ONEVIEWSDK_TOKEN']) The token to use for authentication with OneView appliance
37
+ # Use the token or the username and password (not both). The token has precedence.
38
+ # @option options [Integer] :api_version (200) This is the API version to use by default for requests
28
39
  # @option options [Boolean] :ssl_enabled (true) Use ssl for requests? Respects ENV['ONEVIEWSDK_SSL_ENABLED']
40
+ # @option options [Integer] :timeout (nil) Override the default request timeout value
29
41
  def initialize(options = {})
30
42
  options = Hash[options.map { |k, v| [k.to_sym, v] }] # Convert string hash keys to symbols
31
43
  @logger = options[:logger] || Logger.new(STDOUT)
32
- [:debug, :info, :warn, :error, :level=].each { |m| fail "Logger must respond to #{m} method " unless @logger.respond_to?(m) }
44
+ [:debug, :info, :warn, :error, :level=].each { |m| fail InvalidClient, "Logger must respond to #{m} method " unless @logger.respond_to?(m) }
33
45
  @log_level = options[:log_level] || :info
34
46
  @logger.level = @logger.class.const_get(@log_level.upcase) rescue @log_level
35
47
  @print_wait_dots = options.fetch(:print_wait_dots, false)
36
48
  @url = options[:url] || ENV['ONEVIEWSDK_URL']
37
- fail 'Must set the url option' unless @url
49
+ fail InvalidClient, 'Must set the url option' unless @url
38
50
  @max_api_version = appliance_api_version
39
51
  if options[:api_version] && options[:api_version].to_i > @max_api_version
40
52
  logger.warn "API version #{options[:api_version]} is greater than the appliance API version (#{@max_api_version})"
@@ -49,24 +61,25 @@ module OneviewSDK
49
61
  end
50
62
  end
51
63
  @ssl_enabled = options[:ssl_enabled] unless options[:ssl_enabled].nil?
64
+ @timeout = options[:timeout] unless options[:timeout].nil?
52
65
  @cert_store = OneviewSDK::SSLHelper.load_trusted_certs if @ssl_enabled
53
66
  @token = options[:token] || ENV['ONEVIEWSDK_TOKEN']
54
67
  return if @token
55
68
  @logger.warn 'User option not set. Using default (Administrator)' unless options[:user] || ENV['ONEVIEWSDK_USER']
56
69
  @user = options[:user] || ENV['ONEVIEWSDK_USER'] || 'Administrator'
57
70
  @password = options[:password] || ENV['ONEVIEWSDK_PASSWORD']
58
- fail 'Must set user & password options or token option' unless @password
71
+ fail InvalidClient, 'Must set user & password options or token option' unless @password
59
72
  @token = login
60
73
  end
61
74
 
62
- # Tell OneView to create the resource using the current attribute data
75
+ # Tells OneView to create the resource using the current attribute data
63
76
  # @param [Resource] resource the object to create
64
77
  def create(resource)
65
78
  resource.client = self
66
79
  resource.create
67
80
  end
68
81
 
69
- # Set attribute data and save to OneView
82
+ # Sets the attribute data, and then saves to OneView
70
83
  # @param [Resource] resource the object to update
71
84
  def update(resource, attributes = {})
72
85
  resource.client = self
@@ -95,15 +108,15 @@ module OneviewSDK
95
108
  def get_all(type)
96
109
  OneviewSDK.resource_named(type).get_all(self)
97
110
  rescue StandardError
98
- raise "Invalid resource type '#{type}'"
111
+ raise TypeError, "Invalid resource type '#{type}'"
99
112
  end
100
113
 
101
114
  # Wait for a task to complete
102
115
  # @param [String] task_uri
103
- # @raise [RuntimeError] if the task resulted in an error or early termination.
104
- # @return [Hash] if the task completed sucessfully, return the task details
116
+ # @raise [OneviewSDK::TaskError] if the task resulted in an error or early termination.
117
+ # @return [Hash] if the task completed successfully, return the task details
105
118
  def wait_for(task_uri)
106
- fail 'Must specify a task_uri!' if task_uri.nil? || task_uri.empty?
119
+ fail ArgumentError, 'Must specify a task_uri!' if task_uri.nil? || task_uri.empty?
107
120
  loop do
108
121
  task_uri.gsub!(%r{/https:(.*)\/rest/}, '/rest')
109
122
  task = rest_get(task_uri)
@@ -117,7 +130,7 @@ module OneviewSDK
117
130
  when 'error', 'killed', 'terminated'
118
131
  msg = "Task ended with bad state: '#{body['taskState']}'.\nResponse: "
119
132
  msg += body['taskErrors'] ? JSON.pretty_generate(body['taskErrors']) : JSON.pretty_generate(body)
120
- fail(msg)
133
+ fail TaskError, msg
121
134
  else
122
135
  print '.' if @print_wait_dots
123
136
  sleep 10
@@ -133,10 +146,10 @@ module OneviewSDK
133
146
  options = { 'Content-Type' => :none, 'X-API-Version' => :none, 'auth' => :none }
134
147
  response = rest_api(:get, '/rest/version', options)
135
148
  version = response_handler(response)['currentVersion']
136
- fail "Couldn't get API version" unless version
149
+ fail ConnectionError, "Couldn't get API version" unless version
137
150
  version = version.to_i if version.class != Fixnum
138
151
  version
139
- rescue
152
+ rescue ConnectionError
140
153
  @logger.warn "Failed to get OneView max api version. Using default (#{DEFAULT_API_VERSION})"
141
154
  DEFAULT_API_VERSION
142
155
  end
@@ -153,7 +166,7 @@ module OneviewSDK
153
166
  response = rest_post('/rest/login-sessions', options)
154
167
  body = response_handler(response)
155
168
  return body['sessionID'] if body['sessionID']
156
- fail "\nERROR! Couldn't log into OneView server at #{@url}. Response: #{response}\n#{response.body}"
169
+ fail ConnectionError, "\nERROR! Couldn't log into OneView server at #{@url}. Response: #{response}\n#{response.body}"
157
170
  rescue StandardError => e
158
171
  raise e unless retries > 0
159
172
  @logger.debug 'Failed to log in to OneView. Retrying...'
@@ -1,8 +1,19 @@
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
+
1
12
  require 'yaml'
2
13
  require 'json'
3
14
 
4
15
  module OneviewSDK
5
- # Configuration helper class to allow .yaml & .json files to be easily used to specify OneView Configuration
16
+ # Configuration helper class to allow .yaml and .json files to be easily used to specify OneView Configuration
6
17
  class Config
7
18
 
8
19
  # Load config from .yaml or .json file