oneview-sdk 2.2.1 → 3.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (171) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +50 -0
  3. data/README.md +61 -15
  4. data/Rakefile +39 -1
  5. data/lib/oneview-sdk.rb +38 -3
  6. data/lib/oneview-sdk/cli.rb +85 -30
  7. data/lib/oneview-sdk/client.rb +21 -18
  8. data/lib/oneview-sdk/config_loader.rb +1 -1
  9. data/lib/oneview-sdk/resource.rb +44 -36
  10. data/lib/oneview-sdk/resource/api200.rb +34 -0
  11. data/lib/oneview-sdk/resource/api200/connection_template.rb +52 -0
  12. data/lib/oneview-sdk/resource/api200/datacenter.rb +81 -0
  13. data/lib/oneview-sdk/resource/api200/enclosure.rb +203 -0
  14. data/lib/oneview-sdk/resource/api200/enclosure_group.rb +86 -0
  15. data/lib/oneview-sdk/resource/api200/ethernet_network.rb +60 -0
  16. data/lib/oneview-sdk/resource/api200/fabric.rb +45 -0
  17. data/lib/oneview-sdk/resource/api200/fc_network.rb +34 -0
  18. data/lib/oneview-sdk/resource/api200/fcoe_network.rb +32 -0
  19. data/lib/oneview-sdk/resource/api200/firmware_bundle.rb +56 -0
  20. data/lib/oneview-sdk/resource/{fcoe_network.rb → api200/firmware_driver.rb} +21 -12
  21. data/lib/oneview-sdk/resource/api200/interconnect.rb +112 -0
  22. data/lib/oneview-sdk/resource/api200/lig_uplink_set.rb +84 -0
  23. data/lib/oneview-sdk/resource/api200/logical_downlink.rb +57 -0
  24. data/lib/oneview-sdk/resource/api200/logical_enclosure.rb +88 -0
  25. data/lib/oneview-sdk/resource/api200/logical_interconnect.rb +251 -0
  26. data/lib/oneview-sdk/resource/api200/logical_interconnect_group.rb +116 -0
  27. data/lib/oneview-sdk/resource/api200/logical_switch.rb +188 -0
  28. data/lib/oneview-sdk/resource/api200/logical_switch_group.rb +70 -0
  29. data/lib/oneview-sdk/resource/api200/managed_san.rb +83 -0
  30. data/lib/oneview-sdk/resource/api200/network_set.rb +68 -0
  31. data/lib/oneview-sdk/resource/api200/power_device.rb +178 -0
  32. data/lib/oneview-sdk/resource/api200/rack.rb +88 -0
  33. data/lib/oneview-sdk/resource/api200/resource.rb +18 -0
  34. data/lib/oneview-sdk/resource/api200/san_manager.rb +92 -0
  35. data/lib/oneview-sdk/resource/api200/server_hardware.rb +244 -0
  36. data/lib/oneview-sdk/resource/api200/server_hardware_type.rb +61 -0
  37. data/lib/oneview-sdk/resource/api200/server_profile.rb +385 -0
  38. data/lib/oneview-sdk/resource/api200/server_profile_template.rb +217 -0
  39. data/lib/oneview-sdk/resource/api200/storage_pool.rb +92 -0
  40. data/lib/oneview-sdk/resource/api200/storage_system.rb +157 -0
  41. data/lib/oneview-sdk/resource/api200/switch.rb +91 -0
  42. data/lib/oneview-sdk/resource/api200/unmanaged_device.rb +59 -0
  43. data/lib/oneview-sdk/resource/api200/uplink_set.rb +83 -0
  44. data/lib/oneview-sdk/resource/api200/volume.rb +192 -0
  45. data/lib/oneview-sdk/resource/api200/volume_attachment.rb +83 -0
  46. data/lib/oneview-sdk/resource/api200/volume_snapshot.rb +50 -0
  47. data/lib/oneview-sdk/resource/api200/volume_template.rb +99 -0
  48. data/lib/oneview-sdk/resource/api300.rb +66 -0
  49. data/lib/oneview-sdk/resource/api300/c7000.rb +27 -0
  50. data/lib/oneview-sdk/resource/api300/c7000/connection_template.rb +30 -0
  51. data/lib/oneview-sdk/resource/api300/c7000/datacenter.rb +22 -0
  52. data/lib/oneview-sdk/resource/api300/c7000/enclosure.rb +48 -0
  53. data/lib/oneview-sdk/resource/api300/c7000/enclosure_group.rb +37 -0
  54. data/lib/oneview-sdk/resource/api300/c7000/ethernet_network.rb +35 -0
  55. data/lib/oneview-sdk/resource/api300/c7000/fabric.rb +22 -0
  56. data/lib/oneview-sdk/resource/api300/c7000/fc_network.rb +37 -0
  57. data/lib/oneview-sdk/resource/api300/c7000/fcoe_network.rb +35 -0
  58. data/lib/oneview-sdk/resource/api300/c7000/firmware_bundle.rb +21 -0
  59. data/lib/oneview-sdk/resource/api300/c7000/firmware_driver.rb +22 -0
  60. data/lib/oneview-sdk/resource/api300/c7000/interconnect.rb +21 -0
  61. data/lib/oneview-sdk/resource/api300/c7000/lig_uplink_set.rb +21 -0
  62. data/lib/oneview-sdk/resource/api300/c7000/logical_downlink.rb +34 -0
  63. data/lib/oneview-sdk/resource/api300/c7000/logical_enclosure.rb +35 -0
  64. data/lib/oneview-sdk/resource/api300/c7000/logical_interconnect.rb +21 -0
  65. data/lib/oneview-sdk/resource/api300/c7000/logical_interconnect_group.rb +33 -0
  66. data/lib/oneview-sdk/resource/api300/c7000/logical_switch.rb +51 -0
  67. data/lib/oneview-sdk/resource/api300/c7000/logical_switch_group.rb +33 -0
  68. data/lib/oneview-sdk/resource/api300/c7000/managed_san.rb +36 -0
  69. data/lib/oneview-sdk/resource/api300/c7000/network_set.rb +37 -0
  70. data/lib/oneview-sdk/resource/api300/c7000/power_device.rb +21 -0
  71. data/lib/oneview-sdk/resource/api300/c7000/rack.rb +22 -0
  72. data/lib/oneview-sdk/resource/api300/c7000/resource.rb +21 -0
  73. data/lib/oneview-sdk/resource/api300/c7000/san_manager.rb +22 -0
  74. data/lib/oneview-sdk/resource/api300/c7000/server_hardware.rb +93 -0
  75. data/lib/oneview-sdk/resource/api300/c7000/server_hardware_type.rb +21 -0
  76. data/lib/oneview-sdk/resource/api300/c7000/server_profile.rb +33 -0
  77. data/lib/oneview-sdk/resource/api300/c7000/server_profile_template.rb +50 -0
  78. data/lib/oneview-sdk/resource/api300/c7000/storage_pool.rb +29 -0
  79. data/lib/oneview-sdk/resource/api300/c7000/storage_system.rb +21 -0
  80. data/lib/oneview-sdk/resource/api300/c7000/switch.rb +31 -0
  81. data/lib/oneview-sdk/resource/api300/c7000/unmanaged_device.rb +21 -0
  82. data/lib/oneview-sdk/resource/api300/c7000/uplink_set.rb +21 -0
  83. data/lib/oneview-sdk/resource/api300/c7000/volume.rb +22 -0
  84. data/lib/oneview-sdk/resource/api300/c7000/volume_attachment.rb +21 -0
  85. data/lib/oneview-sdk/resource/api300/c7000/volume_snapshot.rb +21 -0
  86. data/lib/oneview-sdk/resource/api300/c7000/volume_template.rb +32 -0
  87. data/lib/oneview-sdk/resource/api300/synergy.rb +27 -0
  88. data/lib/oneview-sdk/resource/api300/synergy/connection_template.rb +30 -0
  89. data/lib/oneview-sdk/resource/api300/synergy/datacenter.rb +22 -0
  90. data/lib/oneview-sdk/resource/api300/synergy/drive_enclosure.rb +71 -0
  91. data/lib/oneview-sdk/resource/api300/synergy/enclosure.rb +110 -0
  92. data/lib/oneview-sdk/resource/api300/synergy/enclosure_group.rb +43 -0
  93. data/lib/oneview-sdk/resource/api300/synergy/ethernet_network.rb +35 -0
  94. data/lib/oneview-sdk/resource/api300/synergy/fabric.rb +46 -0
  95. data/lib/oneview-sdk/resource/api300/synergy/fc_network.rb +37 -0
  96. data/lib/oneview-sdk/resource/api300/synergy/fcoe_network.rb +35 -0
  97. data/lib/oneview-sdk/resource/api300/synergy/firmware_bundle.rb +21 -0
  98. data/lib/oneview-sdk/resource/api300/synergy/firmware_driver.rb +22 -0
  99. data/lib/oneview-sdk/resource/api300/synergy/interconnect.rb +43 -0
  100. data/lib/oneview-sdk/resource/api300/synergy/lig_uplink_set.rb +21 -0
  101. data/lib/oneview-sdk/resource/api300/synergy/logical_downlink.rb +34 -0
  102. data/lib/oneview-sdk/resource/api300/synergy/logical_enclosure.rb +59 -0
  103. data/lib/oneview-sdk/resource/api300/synergy/logical_interconnect.rb +21 -0
  104. data/lib/oneview-sdk/resource/api300/synergy/logical_interconnect_group.rb +119 -0
  105. data/lib/oneview-sdk/resource/api300/synergy/logical_switch.rb +33 -0
  106. data/lib/oneview-sdk/resource/api300/synergy/logical_switch_group.rb +45 -0
  107. data/lib/oneview-sdk/resource/{firmware_driver.rb → api300/synergy/managed_san.rb} +7 -17
  108. data/lib/oneview-sdk/resource/api300/synergy/network_set.rb +37 -0
  109. data/lib/oneview-sdk/resource/api300/synergy/power_device.rb +21 -0
  110. data/lib/oneview-sdk/resource/api300/synergy/rack.rb +22 -0
  111. data/lib/oneview-sdk/resource/api300/synergy/resource.rb +21 -0
  112. data/lib/oneview-sdk/resource/api300/synergy/san_manager.rb +22 -0
  113. data/lib/oneview-sdk/resource/api300/synergy/sas_interconnect.rb +87 -0
  114. data/lib/oneview-sdk/resource/api300/synergy/sas_logical_interconnect.rb +110 -0
  115. data/lib/oneview-sdk/resource/api300/synergy/sas_logical_interconnect_group.rb +87 -0
  116. data/lib/oneview-sdk/resource/api300/synergy/server_hardware.rb +30 -0
  117. data/lib/oneview-sdk/resource/api300/synergy/server_hardware_type.rb +21 -0
  118. data/lib/oneview-sdk/resource/api300/synergy/server_profile.rb +78 -0
  119. data/lib/oneview-sdk/resource/api300/synergy/server_profile_template.rb +34 -0
  120. data/lib/oneview-sdk/resource/api300/synergy/storage_pool.rb +22 -0
  121. data/lib/oneview-sdk/resource/api300/synergy/storage_system.rb +21 -0
  122. data/lib/oneview-sdk/resource/api300/synergy/switch.rb +37 -0
  123. data/lib/oneview-sdk/resource/api300/synergy/unmanaged_device.rb +21 -0
  124. data/lib/oneview-sdk/resource/api300/synergy/uplink_set.rb +21 -0
  125. data/lib/oneview-sdk/resource/api300/synergy/volume.rb +22 -0
  126. data/lib/oneview-sdk/resource/api300/synergy/volume_attachment.rb +21 -0
  127. data/lib/oneview-sdk/resource/api300/synergy/volume_snapshot.rb +21 -0
  128. data/lib/oneview-sdk/resource/api300/synergy/volume_template.rb +32 -0
  129. data/lib/oneview-sdk/rest.rb +7 -10
  130. data/lib/oneview-sdk/ssl_helper.rb +3 -3
  131. data/lib/oneview-sdk/version.rb +1 -1
  132. data/oneview-sdk.gemspec +5 -5
  133. metadata +126 -47
  134. data/.gitattributes +0 -2
  135. data/.gitignore +0 -29
  136. data/.rubocop.yml +0 -80
  137. data/.travis.yml +0 -12
  138. data/lib/oneview-sdk/resource/connection_template.rb +0 -48
  139. data/lib/oneview-sdk/resource/datacenter.rb +0 -77
  140. data/lib/oneview-sdk/resource/enclosure.rb +0 -191
  141. data/lib/oneview-sdk/resource/enclosure_group.rb +0 -82
  142. data/lib/oneview-sdk/resource/ethernet_network.rb +0 -56
  143. data/lib/oneview-sdk/resource/fabric.rb +0 -41
  144. data/lib/oneview-sdk/resource/fc_network.rb +0 -30
  145. data/lib/oneview-sdk/resource/firmware_bundle.rb +0 -50
  146. data/lib/oneview-sdk/resource/interconnect.rb +0 -107
  147. data/lib/oneview-sdk/resource/lig_uplink_set.rb +0 -80
  148. data/lib/oneview-sdk/resource/logical_downlink.rb +0 -53
  149. data/lib/oneview-sdk/resource/logical_enclosure.rb +0 -86
  150. data/lib/oneview-sdk/resource/logical_interconnect.rb +0 -247
  151. data/lib/oneview-sdk/resource/logical_interconnect_group.rb +0 -112
  152. data/lib/oneview-sdk/resource/logical_switch.rb +0 -184
  153. data/lib/oneview-sdk/resource/logical_switch_group.rb +0 -66
  154. data/lib/oneview-sdk/resource/managed_san.rb +0 -79
  155. data/lib/oneview-sdk/resource/network_set.rb +0 -64
  156. data/lib/oneview-sdk/resource/power_device.rb +0 -174
  157. data/lib/oneview-sdk/resource/rack.rb +0 -83
  158. data/lib/oneview-sdk/resource/san_manager.rb +0 -88
  159. data/lib/oneview-sdk/resource/server_hardware.rb +0 -209
  160. data/lib/oneview-sdk/resource/server_hardware_type.rb +0 -58
  161. data/lib/oneview-sdk/resource/server_profile.rb +0 -380
  162. data/lib/oneview-sdk/resource/server_profile_template.rb +0 -213
  163. data/lib/oneview-sdk/resource/storage_pool.rb +0 -63
  164. data/lib/oneview-sdk/resource/storage_system.rb +0 -113
  165. data/lib/oneview-sdk/resource/switch.rb +0 -86
  166. data/lib/oneview-sdk/resource/unmanaged_device.rb +0 -55
  167. data/lib/oneview-sdk/resource/uplink_set.rb +0 -79
  168. data/lib/oneview-sdk/resource/volume.rb +0 -188
  169. data/lib/oneview-sdk/resource/volume_attachment.rb +0 -79
  170. data/lib/oneview-sdk/resource/volume_snapshot.rb +0 -46
  171. data/lib/oneview-sdk/resource/volume_template.rb +0 -95
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: dd1ac219db19a7c03bf16b3df31b5cccf12e22eb
4
- data.tar.gz: 0718886cb26a7ce15a2fe826f0b87bb68d79a06c
3
+ metadata.gz: 55ecd759a6f2a88d204976f9423649527ff616c9
4
+ data.tar.gz: 0efc8e08440bc9727f33f806e24fcc298372ca7e
5
5
  SHA512:
6
- metadata.gz: 86766ecbc79b8bc588235fe3a4d9e0517bfbb7ad530a2f86830ab33efa27e057347da245022fd84a3620a20c500fdada9406696a8292643c8affa7dd1f8726a2
7
- data.tar.gz: d43154cbc551777fb2e821c16123712d120c1ef4704046b752ebd6bd4c493e8834358813106cd11f0558883ca5512a31d19f1cccb8230eeb80f56ff218a8ef3b
6
+ metadata.gz: 30dd2a219225da9690450c94fcbbc02b00b89db7bb0e66fb97f10d3579e475e8771ab02452a70f44d1a42c4876aea070845e4a9297cf10ac36cbf9b853865ed6
7
+ data.tar.gz: 83044fcf64204982bd17adada045197af780f7d73a80d8644d95984a75efea6ad2eaf95784f6a4b374c2aae78d660c6079e7b484e5b40819faaef394defc0d4d
data/CHANGELOG.md CHANGED
@@ -1,3 +1,53 @@
1
+ # v3.0.0
2
+ ### Notes
3
+ 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.
4
+ This version of this SDK officially supports OneView appliances version 3.00.00 or higher, using the OneView Rest API version 300.
5
+ Support is provided for C7000 and Synergy enclosure types.
6
+
7
+ ### Major changes
8
+ 1. Added full support to OneView Rest API version 300 for the hardware variants C7000 and Synergy to the already existing features:
9
+ - Connection template
10
+ - Datacenter
11
+ - Enclosure
12
+ - Ethernet network
13
+ - Fabrics
14
+ - FC network
15
+ - FCoE network
16
+ - Firmware bundles
17
+ - Firmware drivers
18
+ - Logical downlink
19
+ - Logical enclosure
20
+ - Logical interconnect Group
21
+ - Logical switch
22
+ - Logical switch group
23
+ - Managed SANs
24
+ - Network set
25
+ - Power devices
26
+ - Racks
27
+ - SAN managers
28
+ - Server hardware
29
+ - Server hardware type
30
+ - Server profile
31
+ - Server profile template
32
+ - Storage pools
33
+ - Storage systems
34
+ - Switches
35
+ - Volume
36
+ - Volume template
37
+ 2. New features added:
38
+ - Drive Enclosures
39
+ - Interconnect Link Topology
40
+ - Internal Link Set
41
+ - SAS Interconnect
42
+ - SAS Interconnect Type
43
+ - SAS Logical Interconnect
44
+ - SAS Logical Interconnect Group
45
+ - SAS Logical JBOD Attachments
46
+ - SAS Logical JBODs
47
+ 3. Design changes:
48
+ - Split features into API modules for each hardware variant
49
+ - Fixed/updated/added CLI commands
50
+
1
51
  #### v2.2.1
2
52
  - Fixed issue #88 (firmware bundle file size). Uses multipart-post now
3
53
 
data/README.md CHANGED
@@ -8,7 +8,7 @@ The OneView SDK provides a Ruby library to easily interact with HPE OneView API.
8
8
  - Require the gem in your Gemfile:
9
9
 
10
10
  ```ruby
11
- gem 'oneview-sdk'
11
+ gem 'oneview-sdk', '~> 3.0'
12
12
  ```
13
13
 
14
14
  Then run `$ bundle install`
@@ -28,11 +28,11 @@ client = OneviewSDK::Client.new(
28
28
  url: 'https://oneview.example.com',
29
29
  user: 'Administrator', # This is the default
30
30
  password: 'secret123',
31
+ token: 'xxxx...', # Set EITHER this or the user & password
31
32
  ssl_enabled: true, # This is the default and strongly encouraged
32
33
  logger: Logger.new(STDOUT), # This is the default
33
34
  log_level: :info, # This is the default
34
- api_version: 200, # Defaults to minimum of (200 and appliance API version)
35
- token: 'xxxx...' # Set EITHER this or the user & password
35
+ api_version: 200 # Defaults to minimum of 200 and appliance's max API version
36
36
  )
37
37
  ```
38
38
 
@@ -72,7 +72,8 @@ Configuration files can also be used to define client configuration (json or yam
72
72
  {
73
73
  "url": "https://oneview.example.com",
74
74
  "user": "Administrator",
75
- "password": "secret123"
75
+ "password": "secret123",
76
+ "api_version": 200
76
77
  }
77
78
  ```
78
79
 
@@ -83,7 +84,7 @@ config = OneviewSDK::Config.load("full_file_path.json")
83
84
  client = OneviewSDK::Client.new(config)
84
85
  ```
85
86
 
86
- :lock: Tip: Check the file permissions because the password is stored in clear-text.
87
+ :lock: Tip: Check the file permissions if the password or token is stored in clear-text.
87
88
 
88
89
  ### Custom logging
89
90
  The default logger is a standard logger to STDOUT, but if you want to specify your own, you can. However, your logger must implement the following methods:
@@ -96,10 +97,55 @@ error(String)
96
97
  level=(Symbol, etc.) # The parameter here will be the log_level attribute
97
98
  ```
98
99
 
100
+ :lock: Tip: When the log_level is set to debug, API request options will be logged (including auth tokens and passwords); be careful to protect secret information.
101
+
102
+ ### OneView API versions and appliance types
103
+ You may notice resource classes being accessed in a few different ways; for example, `OneviewSDK::EthernetNetwork`, `OneviewSDK::API300::EthernetNetwork`, and `OneviewSDK::API300::C7000::EthernetNetwork`. However, each of these accessors may actually be referring to the same class. This is because in order to keep backwards compatibility and make examples a little more simple, there are module methods in place to redirect/resolve the shorthand accessors to their full namespace identifier. In order to automatically complete the full namespace identifier, there are some defaults in place. Here's some example code that should help clear things up (return values are commented behind the code):
104
+
105
+ ```ruby
106
+ require 'oneview-sdk'
107
+
108
+ # Show defaults:
109
+ OneviewSDK::SUPPORTED_API_VERSIONS # [200, 300]
110
+ OneviewSDK::DEFAULT_API_VERSION # 200
111
+ OneviewSDK.api_version # 200
112
+ OneviewSDK.api_version_updated? # false
113
+
114
+ # Notice the automatic redirection/resolution when we use the shorthand accessor:
115
+ OneviewSDK::EthernetNetwork # OneviewSDK::API200::EthernetNetwork
116
+
117
+ # Even this comparison is true:
118
+ OneviewSDK::EthernetNetwork == OneviewSDK::API200::EthernetNetwork # true
119
+
120
+ # Now let's set a new API version default:
121
+ OneviewSDK.api_version = 300
122
+ OneviewSDK.api_version # 300
123
+ OneviewSDK.api_version_updated? # true
124
+
125
+ # The API200 module has only 1 variant, but API300 has 2 (C7000 & Synergy):
126
+ OneviewSDK::API300::SUPPORTED_VARIANTS # ['C7000', 'Synergy']
127
+ OneviewSDK::API300::DEFAULT_VARIANT # 'C7000'
128
+ OneviewSDK::API300.variant # 'C7000'
129
+ OneviewSDK::API300.variant_updated? # false
130
+
131
+ # Therefore, there is 1 more namespace level to the real resource class name
132
+ OneviewSDK::EthernetNetwork # OneviewSDK::API300::C7000::EthernetNetwork
133
+ OneviewSDK::API300::EthernetNetwork # OneviewSDK::API300::C7000::EthernetNetwork
134
+
135
+ # Likewise, we can set a new default variant for the API300 module:
136
+ OneviewSDK::API300.variant = 'Synergy'
137
+ OneviewSDK::API300.variant # 'Synergy'
138
+ OneviewSDK::API300.variant_updated? # true
139
+ OneviewSDK::EthernetNetwork # OneviewSDK::API300::Synergy::EthernetNetwork
140
+ OneviewSDK::API300::EthernetNetwork # OneviewSDK::API300::Synergy::EthernetNetwork
141
+ ```
142
+
143
+ 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
+
99
145
  ## Resources
100
- Each OneView resource is exposed for usage with CRUD-like functionality.
146
+ Each OneView resource is exposed via a Ruby class, enabling CRUD-like functionality (with some exceptions).
101
147
 
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.
148
+ 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.
103
149
 
104
150
  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
151
 
@@ -125,7 +171,7 @@ end
125
171
  ```
126
172
 
127
173
  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']`.
174
+ The direct hash accessor on the resource converts first-level keys to strings; so `resource[:key]` and `resource['key']` access the same thing: `resource.data['key']`. We recommend using strings exclusively for keys, as the JSON data returned from OneView requests supports strings but not symbols.
129
175
 
130
176
  ##### Update a resource
131
177
 
@@ -144,17 +190,14 @@ ethernet.update(name: 'newName', vlanId: 1002, purpose: 'General', ethernetNetw
144
190
 
145
191
  You can use the `==` or `.eql?` method to compare resource equality, or `.like` to compare just a subset of attributes.
146
192
  ```ruby
147
- ethernet2 = OneviewSDK::EthernetNetwork.new(
148
- client, { name: 'OtherVlan', vlanId: 1000, purpose: 'General', smartLink: false, privateNetwork: false }
149
- )
193
+ ethernet2 = OneviewSDK::EthernetNetwork.new(client, { purpose: 'General' })
150
194
  ethernet == ethernet2 # Returns false
151
195
  ethernet.eql?(ethernet2) # Returns false
152
196
 
153
197
 
154
198
  # 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
199
+ ethernet.like?(ethernet2) # Returns true
200
+ ethernet.like?(name: 'TestVlan', purpose: 'General') # Returns true
158
201
  ```
159
202
 
160
203
 
@@ -222,7 +265,7 @@ Please refer to the documentation and [code](lib/oneview-sdk/rest.rb) for comple
222
265
  ## CLI
223
266
  This gem also comes with a command-line interface to make interacting with OneView possible without the need to create a Ruby program or script.
224
267
 
225
- Note: In order to use this, you will need to make sure your ruby `bin` directory is in your path.
268
+ Note: In order to use this, you will need to make sure your Ruby `bin` directory is in your path.
226
269
  Run `$ gem environment` to see where the executable paths are for your Ruby installation.
227
270
 
228
271
  To get started, run `$ oneview-sdk-ruby --help`.
@@ -260,6 +303,9 @@ $ oneview-sdk-ruby search ServerProfiles --filter state:Normal boot.manageBoot:t
260
303
  ##### Create or delete resource by file:
261
304
 
262
305
  ```bash
306
+ # Save resource details to a file (to be used with the create and delete methods below)
307
+ $ oneview-sdk-ruby to_file ServerProfile profile-1 /my-server-profile.json
308
+
263
309
  $ oneview-sdk-ruby create_from_file /my-server-profile.json
264
310
  $ oneview-sdk-ruby delete_from_file /my-server-profile.json
265
311
  ```
data/Rakefile CHANGED
@@ -84,7 +84,9 @@ RSpec::Core::RakeTask.new('spec:system:heavy') do |spec|
84
84
  spec.rspec_opts << ' --tag system'
85
85
  end
86
86
 
87
- RuboCop::RakeTask.new
87
+ RuboCop::RakeTask.new do |task|
88
+ task.options << '--display-cop-names'
89
+ end
88
90
 
89
91
  desc 'Runs rubocop and unit tests'
90
92
  task :test do
@@ -99,3 +101,39 @@ task 'test:all' do
99
101
  Rake::Task['spec:integration'].invoke
100
102
  Rake::Task['spec:system'].invoke
101
103
  end
104
+
105
+ desc 'Run rubocop & integration tests for specified path'
106
+ task 'test:path', [:path] do |_t, spec|
107
+ spec_pattern = spec['path']
108
+ Rake::Task[:rubocop].invoke
109
+ Rake::Task['spec:integration'].invoke
110
+ end
111
+
112
+ desc 'Run rubocop & integration tests for specified model & API. Defaults to model C7000 and API 300.'
113
+ task 'spec:integration:api', [:model, :api] do |_t, spec|
114
+ args = {}
115
+ args['model'] = spec['model'] || 'c7000'
116
+ args['api'] = spec['api'] || 300
117
+ spec_pattern = "spec/integration/resource/api#{args['api']}/#{args['model']}/**/*_spec.rb"
118
+ spec_pattern = 'spec/integration/resource/api200/**/*_spec.rb' if args['api'] == 200
119
+ Rake::Task[:rubocop].invoke
120
+ Rake::Task['spec:integration'].invoke
121
+ end
122
+
123
+ desc 'Run rubocop & integration tests for specified API. Defaults to API 300.'
124
+ task 'spec:integration:api_version', [:api] do |_t, spec|
125
+ args = spec['api'] || 300
126
+ spec_pattern = "spec/integration/resource/api#{args}/**/**/*_spec.rb"
127
+ spec_pattern = 'spec/integration/resource/api200/**/*_spec.rb' if args == 200
128
+ Rake::Task[:rubocop].invoke
129
+ Rake::Task['spec:integration'].invoke
130
+ end
131
+
132
+ desc 'Run rubocop & integration deletion tests for specified API. Defaults to API 300'
133
+ task 'spec:integration:delete:api_version', [:api] do |_t, spec|
134
+ args = spec['api'] || 300
135
+ spec_pattern = "spec/integration/resource/api#{args}/**/**/*delete_spec.rb"
136
+ spec_pattern = 'spec/integration/resource/api200/**/*delete_spec.rb' if args == 200
137
+ Rake::Task[:rubocop].invoke
138
+ Rake::Task['spec:integration'].invoke
139
+ end
data/lib/oneview-sdk.rb CHANGED
@@ -1,7 +1,7 @@
1
- # (C) Copyright 2016 Hewlett Packard Enterprise Development LP
1
+ # (c) Copyright 2016 Hewlett Packard Enterprise Development LP
2
2
  #
3
3
  # Licensed under the Apache License, Version 2.0 (the "License");
4
- # You may not use this file except in compliance with the License.
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
@@ -13,9 +13,44 @@ require_relative 'oneview-sdk/version'
13
13
  require_relative 'oneview-sdk/exceptions'
14
14
  require_relative 'oneview-sdk/client'
15
15
  require_relative 'oneview-sdk/resource'
16
+ Dir[File.dirname(__FILE__) + '/oneview-sdk/resource/*.rb'].each { |file| require file }
16
17
  require_relative 'oneview-sdk/cli'
17
18
 
18
- # Module for interracting with the HPE OneView API
19
+ # Module for interacting with the HPE OneView API
19
20
  module OneviewSDK
20
21
  ENV_VARS = %w(ONEVIEWSDK_URL ONEVIEWSDK_USER ONEVIEWSDK_PASSWORD ONEVIEWSDK_TOKEN ONEVIEWSDK_SSL_ENABLED).freeze
22
+ SUPPORTED_API_VERSIONS = [200, 300].freeze
23
+ DEFAULT_API_VERSION = 200
24
+ @api_version = DEFAULT_API_VERSION
25
+ @api_version_updated = false # Whether or not the API version has been set by the user
26
+
27
+ # Get the current API version
28
+ def self.api_version
29
+ @api_version
30
+ end
31
+
32
+ # Set the default API version
33
+ def self.api_version=(version)
34
+ version = version.to_i rescue version
35
+ raise "API version #{version} is not supported!" unless SUPPORTED_API_VERSIONS.include?(version)
36
+ raise "The module for API version #{@api_version} is undefined" unless constants.include?("API#{@api_version}".to_sym)
37
+ @api_version_updated = true
38
+ @api_version = version
39
+ end
40
+
41
+ # Has the API version been set by the user?
42
+ # @return [TrueClass, FalseClass]
43
+ def self.api_version_updated?
44
+ @api_version_updated
45
+ end
46
+
47
+ # This method will help redirect to resources within the API module that is currently in use.
48
+ # It should NOT be called directly. For example, if @@api_version is set to 200, then accessing
49
+ # OneviewSDK::EthernetNetwork will redirect to OneviewSDK::API200::EthernetNetwork
50
+ def self.const_missing(const)
51
+ api_module = OneviewSDK.const_get("API#{@api_version}")
52
+ api_module.const_get(const)
53
+ rescue NameError
54
+ raise NameError, "The #{const} method or resource does not exist for OneView API version #{@api_version}."
55
+ end
21
56
  end
@@ -15,7 +15,8 @@ require 'yaml'
15
15
  require 'highline/import'
16
16
 
17
17
  module OneviewSDK
18
- # cli for oneview-sdk
18
+ # command-line-interface for oneview-sdk
19
+ # When you install this gem, this cli should be available to you by running: `$ oneview-sdk-ruby`
19
20
  class Cli < Thor
20
21
  # Runner class to enable testing
21
22
  class Runner
@@ -67,12 +68,13 @@ module OneviewSDK
67
68
  desc: 'Log level to use',
68
69
  aliases: '-l',
69
70
  enum: %w(debug info warn error),
70
- default: 'warn'
71
+ default: :warn
71
72
 
72
73
  map ['-v', '--version'] => :version
73
74
 
74
75
 
75
76
  desc 'console', 'Open a Ruby console with a connection to OneView'
77
+ # Open a Ruby console with a connection to OneView
76
78
  def console
77
79
  client_setup({}, true, true)
78
80
  puts "Console Connected to #{@client.url}"
@@ -88,6 +90,7 @@ module OneviewSDK
88
90
  end
89
91
 
90
92
  desc 'version', 'Print gem and OneView appliance versions'
93
+ # Print gem and OneView appliance versions
91
94
  def version
92
95
  puts "Gem Version: #{OneviewSDK::VERSION}"
93
96
  client_setup({ 'log_level' => :error }, true)
@@ -102,12 +105,13 @@ module OneviewSDK
102
105
  enum: %w(json yaml human),
103
106
  default: 'human'
104
107
  desc 'env', 'Show environment variables for oneview-sdk-ruby'
108
+ # Show environment variables for oneview-sdk-ruby
105
109
  def env
106
110
  data = {}
107
111
  OneviewSDK::ENV_VARS.each { |k| data[k] = ENV[k] }
108
112
  if @options['format'] == 'human'
109
113
  data.each do |key, value|
110
- value = "'#{value}'" if value && ! %w(true false).include?(value)
114
+ value = "'#{value}'" if value && !%w(true false).include?(value)
111
115
  printf "%-#{data.keys.max_by(&:length).length}s = %s\n", key, value || 'nil'
112
116
  end
113
117
  else
@@ -116,6 +120,7 @@ module OneviewSDK
116
120
  end
117
121
 
118
122
  desc 'login', 'Attempt authentication and return token'
123
+ # Attempt authentication and return token
119
124
  def login
120
125
  client_setup
121
126
  puts "Login Successful! Token = #{@client.token}"
@@ -127,6 +132,7 @@ module OneviewSDK
127
132
  enum: %w(json yaml human),
128
133
  default: 'human'
129
134
  desc 'list TYPE', 'List names of resources'
135
+ # List names of resources
130
136
  def list(type)
131
137
  resource_class = parse_type(type)
132
138
  client_setup
@@ -145,6 +151,7 @@ module OneviewSDK
145
151
  desc: 'Comma-seperated list of attributes to show',
146
152
  aliases: '-a'
147
153
  desc 'show TYPE NAME', 'Show resource details'
154
+ # Show resource details
148
155
  def show(type, name)
149
156
  resource_class = parse_type(type)
150
157
  client_setup
@@ -175,6 +182,7 @@ module OneviewSDK
175
182
  desc: 'Hash of key/value pairs to filter on',
176
183
  required: true
177
184
  desc 'search TYPE', 'Search for resource by key/value pair(s)'
185
+ # Search for resource by key/value pair(s)
178
186
  def search(type)
179
187
  resource_class = parse_type(type)
180
188
  client_setup
@@ -213,8 +221,10 @@ module OneviewSDK
213
221
  rest_examples << "\n oneview-sdk-ruby rest PUT rest/fc-networks/<id> -d '{\"linkStabilityTime\": 20, ...}'"
214
222
  rest_examples << "\n oneview-sdk-ruby rest PUT rest/enclosures/<id>/configuration"
215
223
  desc 'rest METHOD URI', "Make REST call to the OneView API. Examples:#{rest_examples}"
224
+ # Make REST call to the OneView API
216
225
  def rest(method, uri)
217
- client_setup('log_level' => :error)
226
+ log_level = @options['log_level'] == :warn ? :error : @options['log_level'].to_sym # Default to :error
227
+ client_setup('log_level' => log_level)
218
228
  uri_copy = uri.dup
219
229
  uri_copy.prepend('/') unless uri_copy.start_with?('/')
220
230
  if @options['data']
@@ -253,6 +263,7 @@ module OneviewSDK
253
263
  update_examples = "\n oneview-sdk-ruby update FCNetwork FC1 -h linkStabilityTime:20"
254
264
  update_examples << "\n oneview-sdk-ruby update Volume VOL1 -j '{\"shareable\": true}'"
255
265
  desc 'update TYPE NAME --[hash|json] <data>', "Update resource by name. Examples:#{update_examples}"
266
+ # Update resource by name
256
267
  def update(type, name)
257
268
  resource_class = parse_type(type)
258
269
  client_setup
@@ -267,9 +278,8 @@ module OneviewSDK
267
278
  fail_nice 'Not Found' if matches.empty?
268
279
  resource = matches.first
269
280
  begin
270
- resource[:uri] = '/rest/storage-volumes/57A22A70-73EC-43C1-91B9-9FABD1E'
271
281
  resource.update(data)
272
- output 'Updated Successfully!'
282
+ puts 'Updated Successfully!'
273
283
  rescue StandardError => e
274
284
  fail_nice "Failed to update #{resource.class.name.split('::').last} '#{name}': #{e}"
275
285
  end
@@ -280,16 +290,17 @@ module OneviewSDK
280
290
  type: :boolean,
281
291
  aliases: '-f'
282
292
  desc 'delete TYPE NAME', 'Delete resource by name'
293
+ # Delete resource by name
283
294
  def delete(type, name)
284
295
  resource_class = parse_type(type)
285
296
  client_setup
286
297
  matches = resource_class.find_by(@client, name: name)
287
- fail_nice 'Not Found' if matches.empty?
298
+ fail_nice('Not Found', 2) if matches.empty?
288
299
  resource = matches.first
289
300
  return unless options['force'] || agree("Delete '#{name}'? [Y/N] ")
290
301
  begin
291
302
  resource.delete
292
- output 'Deleted Successfully!'
303
+ puts 'Deleted Successfully!'
293
304
  rescue StandardError => e
294
305
  fail_nice "Failed to delete #{resource.class.name.split('::').last} '#{name}': #{e}"
295
306
  end
@@ -300,23 +311,22 @@ module OneviewSDK
300
311
  type: :boolean,
301
312
  aliases: '-f'
302
313
  desc 'delete_from_file FILE_PATH', 'Delete resource defined in file'
314
+ # Delete resource defined in file
303
315
  def delete_from_file(file_path)
304
316
  client_setup
305
317
  resource = OneviewSDK::Resource.from_file(@client, file_path)
306
- fail_nice 'File must define name or uri' unless resource[:name] || resource[:uri]
307
- found = resource.retrieve! rescue false
308
- found ||= resource.refresh rescue false
309
- fail_nice "#{resource.class.name.split('::').last} '#{resource[:name] || resource[:uri]}' Not Found" unless found
310
- unless options['force'] || agree("Delete '#{resource[:name]}'? [Y/N] ")
311
- puts 'OK, exiting.'
312
- return
313
- end
318
+ fail_nice("#{resource.class.name.split('::').last} '#{resource[:name] || resource[:uri]}' Not Found", 2) unless resource.retrieve!
319
+ return unless options['force'] || agree("Delete '#{resource[:name]}'? [Y/N] ")
314
320
  begin
315
321
  resource.delete
316
- output 'Deleted Successfully!'
322
+ puts 'Deleted Successfully!'
317
323
  rescue StandardError => e
318
324
  fail_nice "Failed to delete #{resource.class.name.split('::').last} '#{resource[:name]}': #{e}"
319
325
  end
326
+ rescue IncompleteResource => e
327
+ fail_nice "Failed to delete #{resource.class.name.split('::').last} '#{resource[:name]}': #{e}"
328
+ rescue SystemCallError => e # File open errors
329
+ fail_nice e
320
330
  end
321
331
 
322
332
  method_option :if_missing,
@@ -324,35 +334,68 @@ module OneviewSDK
324
334
  type: :boolean,
325
335
  aliases: '-i'
326
336
  desc 'create_from_file FILE_PATH', 'Create/Update resource defined in file'
337
+ # Create/Update resource defined in file
327
338
  def create_from_file(file_path)
328
339
  client_setup
329
340
  resource = OneviewSDK::Resource.from_file(@client, file_path)
330
- resource[:uri] = nil
331
- fail_nice 'File must specify a resource name' unless resource[:name]
332
- existing_resource = resource.class.find_by(@client, name: resource[:name]).first
333
- if existing_resource
341
+ fail_nice 'Failed to determine resource type!' if resource.class == OneviewSDK::Resource
342
+ existing_resource = resource.class.new(@client, resource.data)
343
+ resource.data.delete('uri')
344
+ if existing_resource.retrieve!
334
345
  if options['if_missing']
335
- puts "Skipped: '#{resource[:name]}': #{resource.class.name.split('::').last} already exists."
346
+ puts "Skipped: #{resource.class.name.split('::').last} '#{resource[:name]}' already exists.\n#{existing_resource[:uri]}"
347
+ return
348
+ end
349
+ if existing_resource.like?(resource.data)
350
+ puts "Skipped: #{resource.class.name.split('::').last} '#{resource[:name]}' is up to date.\n#{existing_resource[:uri]}"
336
351
  return
337
352
  end
338
353
  begin
339
- resource.data.delete('uri')
340
354
  existing_resource.update(resource.data)
341
- output "Updated Successfully!\n#{resource[:uri]}"
355
+ puts "Updated Successfully!\n#{existing_resource[:uri]}"
342
356
  rescue StandardError => e
343
357
  fail_nice "Failed to update #{resource.class.name.split('::').last} '#{resource[:name]}': #{e}"
344
358
  end
345
359
  else
346
360
  begin
347
361
  resource.create
348
- output "Created Successfully!\n#{resource[:uri]}"
362
+ puts "Created Successfully!\n#{resource[:uri]}"
349
363
  rescue StandardError => e
350
364
  fail_nice "Failed to create #{resource.class.name.split('::').last} '#{resource[:name]}': #{e}"
351
365
  end
352
366
  end
367
+ rescue IncompleteResource => e
368
+ fail_nice "Failed to create #{resource.class.name.split('::').last} '#{resource[:name]}': #{e}"
369
+ rescue SystemCallError => e # File open errors
370
+ fail_nice e
371
+ end
372
+
373
+ method_option :path,
374
+ desc: 'File path to save resource in',
375
+ type: :string,
376
+ aliases: '-p',
377
+ required: true
378
+ method_option :format,
379
+ desc: 'Output format',
380
+ aliases: '-f',
381
+ enum: %w(json yaml),
382
+ default: 'json'
383
+ desc 'to_file TYPE NAME', 'Save resource details to file'
384
+ # Save resource details to file
385
+ def to_file(type, name)
386
+ file = File.expand_path(options['path'])
387
+ resource_class = parse_type(type)
388
+ client_setup
389
+ resource = resource_class.find_by(@client, name: name).first
390
+ fail_nice "#{resource_class.name.split('::').last} '#{name}' not found" unless resource
391
+ resource.to_file(file, options['format'])
392
+ puts "Output to #{file}"
393
+ rescue SystemCallError => e
394
+ fail_nice "Failed to create file! (You may need to create the necessary directories). Message: #{e}"
353
395
  end
354
396
 
355
397
  desc 'cert check|import|list URL', 'Check, import, or list OneView certs'
398
+ # Check, import, or list OneView certs
356
399
  def cert(type, url = ENV['ONEVIEWSDK_URL'])
357
400
  case type.downcase
358
401
  when 'check'
@@ -381,9 +424,9 @@ module OneviewSDK
381
424
 
382
425
  private
383
426
 
384
- def fail_nice(msg = nil)
427
+ def fail_nice(msg = nil, exit_code = 1)
385
428
  puts "ERROR: #{msg}" if msg
386
- exit 1
429
+ exit exit_code
387
430
  end
388
431
 
389
432
  def client_setup(client_params = {}, quiet = false, throw_errors = false)
@@ -391,6 +434,7 @@ module OneviewSDK
391
434
  client_params['ssl_enabled'] = false if @options['ssl_verify'] == false
392
435
  client_params['url'] ||= @options['url'] if @options['url']
393
436
  client_params['log_level'] ||= @options['log_level'].to_sym if @options['log_level']
437
+ client_params['api_version'] ||= @options['api_version'].to_i if @options['api_version']
394
438
  @client = OneviewSDK::Client.new(client_params)
395
439
  rescue StandardError => e
396
440
  raise e if throw_errors
@@ -400,14 +444,25 @@ module OneviewSDK
400
444
 
401
445
  # Get resource class from given string
402
446
  def parse_type(type)
447
+ api_ver = (@options['api_version'] || OneviewSDK.api_version).to_i
448
+ unless OneviewSDK::SUPPORTED_API_VERSIONS.include?(api_ver)
449
+ # Find and use the best available match for the desired API version (round down to nearest)
450
+ valid_api_ver = OneviewSDK::SUPPORTED_API_VERSIONS.select { |x| x <= api_ver }.max || OneviewSDK::SUPPORTED_API_VERSIONS.min
451
+ puts "WARNING: Module API version #{api_ver} is not supported. Using #{valid_api_ver}"
452
+ api_ver = valid_api_ver
453
+ 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
456
+ return r if r
403
457
  valid_classes = []
404
- OneviewSDK.constants.each do |c|
405
- klass = OneviewSDK.const_get(c)
458
+ api_module = OneviewSDK.const_get("API#{api_ver}")
459
+ api_module.constants.each do |c|
460
+ klass = api_module.const_get(c)
406
461
  next unless klass.is_a?(Class) && klass < OneviewSDK::Resource
407
462
  valid_classes.push(klass.name.split('::').last)
408
463
  end
409
464
  vc = valid_classes.sort_by!(&:downcase).join("\n ")
410
- OneviewSDK.resource_named(type) || fail_nice("Invalid resource type: '#{type}'. Valid options are:\n #{vc}")
465
+ fail_nice("Invalid resource type: '#{type}'. Valid options for API version #{api_ver} are:\n #{vc}")
411
466
  end
412
467
 
413
468
  # Parse options hash from input. Handles chaining and keywords such as true/false & nil