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
@@ -0,0 +1,91 @@
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 'resource'
13
+
14
+ module OneviewSDK
15
+ module API200
16
+ # Switch resource implementation
17
+ class Switch < Resource
18
+ BASE_URI = '/rest/switches'.freeze
19
+ TYPE_URI = '/rest/switch-types'.freeze
20
+ UNIQUE_IDENTIFIERS = %w(name uri serialNumber).freeze
21
+
22
+ # Remove resource from OneView
23
+ # @return [true] if resource was removed successfully
24
+ alias remove delete
25
+
26
+ # Method is not available
27
+ # @raise [OneviewSDK::MethodUnavailable] method is not available
28
+ def create
29
+ unavailable_method
30
+ end
31
+
32
+ # Method is not available
33
+ # @raise [OneviewSDK::MethodUnavailable] method is not available
34
+ def update
35
+ unavailable_method
36
+ end
37
+
38
+ # Method is not available
39
+ # @raise [OneviewSDK::MethodUnavailable] method is not available
40
+ def refresh
41
+ unavailable_method
42
+ end
43
+
44
+ # Method is not available
45
+ # @raise [OneviewSDK::MethodUnavailable] method is not available
46
+ def delete
47
+ unavailable_method
48
+ end
49
+
50
+ # Retrieves the switch types
51
+ # @param [OneviewSDK::Client] client The client object for the OneView appliance
52
+ # @return [Array] All the Switch types
53
+ def self.get_types(client)
54
+ response = client.rest_get(TYPE_URI)
55
+ response = client.response_handler(response)
56
+ response['members']
57
+ end
58
+
59
+ # Retrieves the switch type with the name
60
+ # @param [OneviewSDK::Client] client The client object for the OneView appliance
61
+ # @param [String] name Switch type name
62
+ # @return [Array] Switch type
63
+ def self.get_type(client, name)
64
+ results = get_types(client)
65
+ results.find { |switch_type| switch_type['name'] == name }
66
+ end
67
+
68
+ # Get statistics for an interconnect, for the specified port or subport
69
+ # @param [String] port_name port to retrieve statistics
70
+ # @param [String] subport_number subport to retrieve statistics
71
+ # @return [Hash] Switch statistics
72
+ def statistics(port_name = nil, subport_number = nil)
73
+ uri = if subport_number
74
+ "#{@data['uri']}/statistics/#{port_name}/subport/#{subport_number}"
75
+ else
76
+ "#{@data['uri']}/statistics/#{port_name}"
77
+ end
78
+ response = @client.rest_get(uri)
79
+ response.body
80
+ end
81
+
82
+ # Get settings that describe the environmental configuration
83
+ # @return [Hash] Configuration parameters
84
+ def environmental_configuration
85
+ ensure_client && ensure_uri
86
+ response = @client.rest_get(@data['uri'] + '/environmentalConfiguration', @api_version)
87
+ @client.response_handler(response)
88
+ end
89
+ end
90
+ end
91
+ end
@@ -0,0 +1,59 @@
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 'resource'
13
+
14
+ module OneviewSDK
15
+ module API200
16
+ # Storage system resource implementation
17
+ class UnmanagedDevice < Resource
18
+ BASE_URI = '/rest/unmanaged-devices'.freeze
19
+
20
+ # Add the resource on OneView using the current data
21
+ # @note Calls the refresh method to set additional data
22
+ # @raise [OneviewSDK::IncompleteResource] if the client is not set
23
+ # @raise [StandardError] if the resource creation fails
24
+ # @return [OneviewSDK::UnmanagedDevice] self
25
+ alias add create
26
+
27
+ # Remove resource from OneView
28
+ # @return [true] if resource was removed successfully
29
+ alias remove delete
30
+
31
+ # Method is not available
32
+ # @raise [OneviewSDK::MethodUnavailable] method is not available
33
+ def create
34
+ unavailable_method
35
+ end
36
+
37
+ # Method is not available
38
+ # @raise [OneviewSDK::MethodUnavailable] method is not available
39
+ def delete
40
+ unavailable_method
41
+ end
42
+
43
+ # Gets a list of unmanaged devices
44
+ # @param [OneviewSDK::Client] client The client object for the OneView appliance
45
+ # @return [Array] list of unmanaged devices
46
+ def self.get_devices(client)
47
+ response = client.rest_get(BASE_URI)
48
+ client.response_handler(response)['members']
49
+ end
50
+
51
+ # Get settings that describe the environmental configuration
52
+ def environmental_configuration
53
+ ensure_client && ensure_uri
54
+ response = @client.rest_get(@data['uri'] + '/environmentalConfiguration')
55
+ @client.response_handler(response)
56
+ end
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,83 @@
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 'resource'
13
+
14
+ module OneviewSDK
15
+ module API200
16
+ # Uplink set resource implementation
17
+ class UplinkSet < Resource
18
+ BASE_URI = '/rest/uplink-sets'.freeze
19
+
20
+ # Create a resource object, associate it with a client, and set its properties.
21
+ # @param [OneviewSDK::Client] client The client object for the OneView appliance
22
+ # @param [Hash] params The options for this resource (key-value pairs)
23
+ # @param [Integer] api_ver The api version to use when interracting with this resource.
24
+ def initialize(client, params = {}, api_ver = nil)
25
+ super
26
+ # Default values
27
+ @data['fcNetworkUris'] ||= []
28
+ @data['fcoeNetworkUris'] ||= []
29
+ @data['networkUris'] ||= []
30
+ @data['portConfigInfos'] ||= []
31
+ @data['primaryPortLocation'] = nil
32
+ @data['type'] ||= 'uplink-setV3'
33
+ end
34
+
35
+ # Adds the portConfigInfos to the array
36
+ # @param [String] portUri
37
+ # @param [String] speed
38
+ # @param [Hash] locationEntries
39
+ def add_port_config(portUri, speed, locationEntries)
40
+ entry = {
41
+ 'portUri' => portUri,
42
+ 'desiredSpeed' => speed,
43
+ 'location' => {
44
+ 'locationEntries' => locationEntries
45
+ }
46
+ }
47
+ @data['portConfigInfos'] << entry
48
+ end
49
+
50
+ # Sets the logical interconnect uri
51
+ # @param [OneviewSDK::LogicalInterconnect, Hash] logical_interconnect
52
+ def set_logical_interconnect(logical_interconnect)
53
+ uri = logical_interconnect[:uri] || logical_interconnect['uri']
54
+ raise IncompleteResource, 'Invalid object' unless uri
55
+ @data['logicalInterconnectUri'] = uri
56
+ end
57
+
58
+ # Adds an ethernet network to the uplink set
59
+ # @param [OneviewSDK::EthernetNetwork, Hash] network
60
+ def add_network(network)
61
+ uri = network[:uri] || network['uri']
62
+ raise IncompleteResource, 'Must set network uri attribute' unless uri
63
+ @data['networkUris'].push(uri)
64
+ end
65
+
66
+ # Adds an fc network to the uplink set
67
+ # @param [OneviewSDK::FCNetwork, Hash] network must accept hash syntax
68
+ def add_fcnetwork(network)
69
+ uri = network[:uri] || network['uri']
70
+ raise IncompleteResource, 'Must set network uri attribute' unless uri
71
+ @data['fcNetworkUris'].push(uri)
72
+ end
73
+
74
+ # Adds an fcoe network to the uplink set
75
+ # @param [OneviewSDK::FCoENetwork, Hash] network must accept hash syntax
76
+ def add_fcoenetwork(network)
77
+ uri = network[:uri] || network['uri']
78
+ raise IncompleteResource, 'Must set network uri attribute' unless uri
79
+ @data['fcoeNetworkUris'].push(uri)
80
+ end
81
+ end
82
+ end
83
+ end
@@ -0,0 +1,192 @@
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 'resource'
13
+
14
+ module OneviewSDK
15
+ module API200
16
+ # Volume resource implementation
17
+ class Volume < Resource
18
+ BASE_URI = '/rest/storage-volumes'.freeze
19
+
20
+ # It's possible to create the volume in 6 different ways:
21
+ # 1) Common = Storage System + Storage Pool
22
+ # 2) Template = Storage Volume Template
23
+ # 3) Common with snapshots = Storage System + Storage Pool + Snapshot Pool
24
+ # 4) Management = Storage System + wwn
25
+ # 5) Management by name = Storage System + Storage System Volume Name
26
+ # 6) Snapshot = Snapshot Pool + Storage Pool + Snapshot
27
+
28
+ # Creates the volume
29
+ # @note provisioning parameters are required for creation, but not afterwards; after creation, they will be removed.
30
+ # @raise [OneviewSDK::IncompleteResource] if the client is not set
31
+ # @raise [StandardError] if the resource creation fails
32
+ # @return [Resource] self
33
+ def create
34
+ ensure_client
35
+ response = @client.rest_post(self.class::BASE_URI, { 'body' => @data }, @api_version)
36
+ body = @client.response_handler(response)
37
+ set_all(body)
38
+ @data.delete('provisioningParameters')
39
+ self
40
+ end
41
+
42
+ # Deletes the resource from OneView or from Oneview and storage system
43
+ # @param [Symbol] flag Delete storage system from Oneview only or in storage system as well
44
+ # @return [true] if resource was deleted successfully
45
+ def delete(flag = :all)
46
+ ensure_client && ensure_uri
47
+ case flag
48
+ when :oneview
49
+ response = @client.rest_api(:delete, @data['uri'], { 'exportOnly' => true }, @api_version)
50
+ @client.response_handler(response)
51
+ when :all
52
+ response = @client.rest_api(:delete, @data['uri'], {}, @api_version)
53
+ @client.response_handler(response)
54
+ else
55
+ raise InvalidResource, 'Invalid flag value, use :oneview or :all'
56
+ end
57
+ true
58
+ end
59
+
60
+ # Sets the storage system to the volume
61
+ # @param [OneviewSDK::StorageSystem] storage_system Storage System
62
+ def set_storage_system(storage_system)
63
+ assure_uri(storage_system)
64
+ set('storageSystemUri', storage_system['uri'])
65
+ end
66
+
67
+ # Sets the storage pool to the volume
68
+ # @param [OneviewSDK::StoragePool] storage_pool Storage pool
69
+ def set_storage_pool(storage_pool)
70
+ assure_uri(storage_pool)
71
+ self['provisioningParameters'] ||= {}
72
+ self['provisioningParameters']['storagePoolUri'] = storage_pool['uri']
73
+ end
74
+
75
+ # Adds the storage volume template to the volume
76
+ # @param [OneviewSDK::VolumeTemplate] storage_volume_template Storage Volume Template
77
+ def set_storage_volume_template(storage_volume_template)
78
+ assure_uri(storage_volume_template)
79
+ set('templateUri', storage_volume_template['uri'])
80
+ end
81
+
82
+ # Sets the snapshot pool to the volume
83
+ # @param [OneviewSDK::StoragePool] storage_pool Storage Pool to use for snapshots
84
+ def set_snapshot_pool(storage_pool)
85
+ assure_uri(storage_pool)
86
+ set('snapshotPoolUri', storage_pool['uri'])
87
+ end
88
+
89
+ # Creates a snapshot of the volume
90
+ # @param [String, OneviewSDK::VolumeSnapshot] snapshot String or OneviewSDK::VolumeSnapshot object
91
+ # @param [String] description Provide a description
92
+ # @return [true] if snapshot was created successfully
93
+ def create_snapshot(snapshot, description = nil)
94
+ ensure_uri && ensure_client
95
+ if snapshot.is_a?(OneviewSDK::Resource) || snapshot.is_a?(Hash)
96
+ name = snapshot[:name] || snapshot['name']
97
+ description ||= snapshot[:description] || snapshot['description']
98
+ else
99
+ name = snapshot
100
+ end
101
+ data = {
102
+ type: 'Snapshot',
103
+ description: description,
104
+ name: name
105
+ }
106
+ response = @client.rest_post("#{@data['uri']}/snapshots", { 'body' => data }, @api_version)
107
+ @client.response_handler(response)
108
+ true
109
+ end
110
+
111
+ # Deletes a snapshot of the volume
112
+ # @param [String] name snapshot name
113
+ # @return [true] if snapshot was created successfully
114
+ def delete_snapshot(name)
115
+ result = get_snapshot(name)
116
+ response = @client.rest_api(:delete, result['uri'], {}, @api_version)
117
+ @client.response_handler(response)
118
+ true
119
+ end
120
+
121
+ # Retrieves a snapshot by name
122
+ # @param [String] name
123
+ # @return [Hash] snapshot data
124
+ def get_snapshot(name)
125
+ results = get_snapshots
126
+ results.each do |snapshot|
127
+ return snapshot if snapshot['name'] == name
128
+ end
129
+ end
130
+
131
+ # Gets all the snapshots of this volume
132
+ # @return [Array] Array of snapshots
133
+ def get_snapshots
134
+ ensure_uri && ensure_client
135
+ results = []
136
+ uri = "#{@data['uri']}/snapshots"
137
+ loop do
138
+ response = @client.rest_get(uri, @api_version)
139
+ body = @client.response_handler(response)
140
+ members = body['members']
141
+ members.each do |member|
142
+ results.push(member)
143
+ end
144
+ break unless body['nextPageUri']
145
+ uri = body['nextPageUri']
146
+ end
147
+ results
148
+ end
149
+
150
+ # Gets all the attachable volumes managed by the appliance
151
+ # @param [OneviewSDK::Client] client The client object for the OneView appliance
152
+ # @return [Array<OneviewSDK::Volume>] Array of volumes
153
+ def self.get_attachable_volumes(client)
154
+ results = []
155
+ uri = "#{BASE_URI}/attachable-volumes"
156
+ loop do
157
+ response = client.rest_get(uri)
158
+ body = client.response_handler(response)
159
+ members = body['members']
160
+ members.each { |member| results.push(OneviewSDK::Volume.new(client, member)) }
161
+ break unless body['nextPageUri']
162
+ uri = body['nextPageUri']
163
+ end
164
+ results
165
+ end
166
+
167
+ # Gets the list of extra managed storage volume paths
168
+ # @param [OneviewSDK::Client] client The client object for the OneView appliance
169
+ # @return response
170
+ def self.get_extra_managed_volume_paths(client)
171
+ response = client.rest_get(BASE_URI + '/repair?alertFixType=ExtraManagedStorageVolumePaths')
172
+ client.response_handler(response)
173
+ end
174
+
175
+ # Removes extra presentation from the volume
176
+ # @return response
177
+ def repair
178
+ response = client.rest_post(BASE_URI + '/repair', 'body' => { resourceUri: @data['uri'], type: 'ExtraManagedStorageVolumePaths' })
179
+ client.response_handler(response)
180
+ end
181
+
182
+ private
183
+
184
+ # Verify if the resource has a URI
185
+ # If not, first it tries to retrieve, and then verify for its existence
186
+ def assure_uri(resource)
187
+ resource.retrieve! unless resource['uri']
188
+ raise IncompleteResource, "#{resource.class}: #{resource['name']} not found" unless resource['uri']
189
+ end
190
+ end
191
+ end
192
+ end
@@ -0,0 +1,83 @@
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 'resource'
13
+
14
+ module OneviewSDK
15
+ module API200
16
+ # Storage volume attachment resource implementation
17
+ class VolumeAttachment < Resource
18
+ BASE_URI = '/rest/storage-volume-attachments'.freeze
19
+
20
+ # Create a resource object, associate it with a client, and set its properties.
21
+ # @param [OneviewSDK::Client] client The client object for the OneView appliance
22
+ # @param [Hash] params The options for this resource (key-value pairs)
23
+ # @param [Integer] api_ver The api version to use when interracting with this resource.
24
+ def initialize(client, params = {}, api_ver = nil)
25
+ super
26
+ # Default values:
27
+ @data['type'] ||= 'StorageVolumeAttachment'
28
+ end
29
+
30
+ # Method is not available
31
+ # @raise [OneviewSDK::MethodUnavailable] method is not available
32
+ def create
33
+ unavailable_method
34
+ end
35
+
36
+ # Method is not available
37
+ # @raise [OneviewSDK::MethodUnavailable] method is not available
38
+ def update
39
+ unavailable_method
40
+ end
41
+
42
+ # Method is not available
43
+ # @raise [OneviewSDK::MethodUnavailable] method is not available
44
+ def delete
45
+ unavailable_method
46
+ end
47
+
48
+ # Gets the list of extra unmanaged storage volumes
49
+ # @param [OneviewSDK::Client] client The client object for the OneView appliance
50
+ def self.get_extra_unmanaged_volumes(client)
51
+ response = client.rest_get(BASE_URI + '/repair?alertFixType=ExtraUnmanagedStorageVolumes')
52
+ client.response_handler(response)
53
+ end
54
+
55
+ # Removes extra presentations from a specific server profile
56
+ # @param [OneviewSDK::Client] client The client object for the OneView appliance
57
+ # @param [OneviewSDK::Resource] resource Oneview resource
58
+ def self.remove_extra_unmanaged_volume(client, resource)
59
+ requestBody = {
60
+ type: 'ExtraUnmanagedStorageVolumes',
61
+ resourceUri: resource['uri']
62
+ }
63
+ response = client.rest_post(BASE_URI + '/repair', 'body' => requestBody)
64
+ client.response_handler(response)
65
+ end
66
+
67
+ # Gets all volume attachment paths
68
+ # @return [Array] List of the storage volume attachments paths
69
+ def get_paths
70
+ response = @client.rest_get(@data['uri'] + '/paths')
71
+ @client.response_handler(response)
72
+ end
73
+
74
+ # Gets a volume attachment path by id
75
+ # @param [String] id Volume attachament path id
76
+ # @return [OneviewSDK::VolumeAttachmentPath]
77
+ def get_path(id)
78
+ response = @client.rest_get("#{@data['uri']}/paths/#{id}")
79
+ @client.response_handler(response)
80
+ end
81
+ end
82
+ end
83
+ end