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
@@ -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
10
+ # specific language governing permissions and limitations under the License.
11
+
12
+ module OneviewSDK
13
+ # Rack resource implementation
14
+ class Rack < Resource
15
+ BASE_URI = '/rest/racks'.freeze
16
+
17
+ # Add the resource on OneView using the current data
18
+ # @note Calls the refresh method to set additional data
19
+ # @raise [OneviewSDK::IncompleteResource] if the client is not set
20
+ # @raise [StandardError] if the resource creation fails
21
+ # @return [OneviewSDK::Rack] self
22
+ alias add create
23
+
24
+ # Remove resource from OneView
25
+ # @return [true] if resource was removed successfully
26
+ alias remove delete
27
+
28
+ # Create a resource object, associate it with a client, and set its properties.
29
+ # @param [OneviewSDK::Client] client The client object for the OneView appliance
30
+ # @param [Hash] params The options for this resource (key-value pairs)
31
+ # @param [Integer] api_ver The api version to use when interracting with this resource.
32
+ def initialize(client, params = {}, api_ver = nil)
33
+ super
34
+ # Default values:
35
+ @data['rackMounts'] ||= []
36
+ end
37
+
38
+ # Method is not available
39
+ # @raise [OneviewSDK::MethodUnavailable] method is not available
40
+ def create
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
+ # Adds the rack resource with specified options
51
+ # @param [OneviewSDK::Resource] resource Resource to be added
52
+ # @param [String] options rack options
53
+ def add_rack_resource(resource, options = {})
54
+ rack_resource_options = {}
55
+ # Write values to hash and transform any symbol to string
56
+ options.each { |key, val| rack_resource_options[key.to_s] = val }
57
+
58
+ # Verify if the rack resource exists in the rack, if not init add it
59
+ rack_resource = @data['rackMounts'].find { |resource_from_rack| resource_from_rack['mountUri'] == resource['uri'] }
60
+ if rack_resource
61
+ rack_resource_options.each { |key, val| rack_resource[key] = val }
62
+ else
63
+ # Set default values if not given
64
+ rack_resource_options['mountUri'] = resource['uri']
65
+ rack_resource_options['location'] = 'CenterFront' unless rack_resource_options['location']
66
+ @data['rackMounts'] << rack_resource_options
67
+ end
68
+ end
69
+
70
+ # Remove resources from the rack
71
+ # @param [OneviewSDK::Resource] resource Resource to be removed from rack
72
+ def remove_rack_resource(resource)
73
+ @data['rackMounts'].reject! { |rack_resource| rack_resource['mountUri'] == resource['uri'] }
74
+ end
75
+
76
+ # Gets topology information for the rack
77
+ # @return [Hash] Environmental analysis
78
+ def get_device_topology
79
+ response = @client.rest_get(@data['uri'] + '/deviceTopology')
80
+ @client.response_handler(response)
81
+ end
82
+ end
83
+ end
@@ -0,0 +1,88 @@
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
+ module OneviewSDK
13
+ # SAN manager resource implementation
14
+ class SANManager < Resource
15
+ BASE_URI = '/rest/fc-sans/device-managers'.freeze
16
+ PROVIDERS_URI = '/rest/fc-sans/providers'.freeze
17
+
18
+ # Remove resource from OneView
19
+ # @return [true] if resource was removed successfully
20
+ alias remove delete
21
+
22
+ # Create a resource object, associate it with a client, and set its properties.
23
+ # @param [OneviewSDK::Client] client The client object for the OneView appliance
24
+ # @param [Hash] params The options for this resource (key-value pairs)
25
+ # @param [Integer] api_ver The api version to use when interracting with this resource.
26
+ def initialize(client, params = {}, api_ver = nil)
27
+ super
28
+ # Default values:
29
+ @data['type'] = 'FCDeviceManagerV2'
30
+ end
31
+
32
+ # Adds the resource on OneView using the current data
33
+ # @return [OneviewSDK::SANManager] self
34
+ def add
35
+ ensure_client
36
+ fail 'providerDisplayName' unless @data['providerDisplayName']
37
+ @data['providerUri'] = get_provider_uri
38
+ response = @client.rest_post(@data['providerUri'] + '/device-managers', { 'body' => @data }, @api_version)
39
+ body = @client.response_handler(response)
40
+ set_all(body)
41
+ self
42
+ end
43
+
44
+ # Method is not available
45
+ # @raise [OneviewSDK::MethodUnavailable] method is not available
46
+ def create
47
+ unavailable_method
48
+ end
49
+
50
+ # Method is not available
51
+ # @raise [OneviewSDK::MethodUnavailable] method is not available
52
+ def delete
53
+ unavailable_method
54
+ end
55
+
56
+ # Refreshes the san manager state or change connection information
57
+ # @param [Hash] options
58
+ def update(options)
59
+ ensure_client && ensure_uri
60
+ response = @client.rest_put(@data['uri'], 'body' => options)
61
+ new_data = @client.response_handler(response)
62
+ set_all(new_data)
63
+ end
64
+
65
+ # Retrieves the default connection information for a specific provider
66
+ # @param [OneviewSDK::Client] client The client object for the OneView appliance
67
+ # @param [String] provider_name Providers name
68
+ # @return [Hash] A hash with default connectionInfo information
69
+ def self.get_default_connection_info(client, provider_name)
70
+ response = client.rest_get(PROVIDERS_URI)
71
+ providers = client.response_handler(response)['members']
72
+ desired_provider = providers.find { |provider| provider['displayName'] == provider_name || provider['name'] == provider_name }
73
+ desired_provider['defaultConnectionInfo']
74
+ end
75
+
76
+ private
77
+
78
+ # Gets the provider uri
79
+ # @return [String] provider uri
80
+ def get_provider_uri
81
+ return @data['providerUri'] if @data['providerUri']
82
+ response = @client.rest_get(PROVIDERS_URI)
83
+ providers = @client.response_handler(response)['members']
84
+ desired_provider = providers.find { |provider| provider['displayName'] == @data['providerDisplayName'] }
85
+ desired_provider['uri']
86
+ end
87
+ end
88
+ end
@@ -1,32 +1,52 @@
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
  module OneviewSDK
2
13
  # Server hardware resource implementation
3
14
  class ServerHardware < Resource
4
15
  BASE_URI = '/rest/server-hardware'.freeze
5
16
 
17
+ # Remove resource from OneView
18
+ # @return [true] if resource was removed successfully
19
+ alias remove delete
20
+
21
+ # Create a resource object, associate it with a client, and set its properties.
22
+ # @param [OneviewSDK::Client] client The client object for the OneView appliance
23
+ # @param [Hash] params The options for this resource (key-value pairs)
24
+ # @param [Integer] api_ver The api version to use when interracting with this resource.
6
25
  def initialize(client, params = {}, api_ver = nil)
7
26
  super
8
27
  # Default values
9
28
  @data['type'] ||= 'server-hardware-4'
10
29
  end
11
30
 
12
- # @!group Validates
13
-
14
- VALID_LICENSING_INTENTS = ['OneView', 'OneViewNoiLO', 'OneViewStandard', nil].freeze
15
- def validate_licensingIntent(value)
16
- fail 'Invalid licensingIntent' unless VALID_LICENSING_INTENTS.include?(value)
31
+ # Method is not available
32
+ # @raise [OneviewSDK::MethodUnavailable] method is not available
33
+ def create
34
+ unavailable_method
17
35
  end
18
36
 
19
- VALID_CONFIGURATION_STATES = ['Managed', 'Monitored', nil].freeze
20
- def validate_configurationState(value)
21
- fail 'Invalid configurationState' unless VALID_CONFIGURATION_STATES.include?(value)
37
+ # Method is not available
38
+ # @raise [OneviewSDK::MethodUnavailable] method is not available
39
+ def delete
40
+ unavailable_method
22
41
  end
23
42
 
24
- # @!endgroup
25
-
26
- def create
43
+ # Adds the resource on OneView using the current data
44
+ # @raise [OneviewSDK::IncompleteResource] if the client is not set or required attributes are missing
45
+ # @return [OneviewSDK::ServerHardware] self
46
+ def add
27
47
  ensure_client
28
48
  required_attributes = %w(hostname username password licensingIntent)
29
- required_attributes.each { |k| fail "Missing required attribute: '#{k}'" unless @data.key?(k) }
49
+ required_attributes.each { |k| fail IncompleteResource, "Missing required attribute: '#{k}'" unless @data.key?(k) }
30
50
 
31
51
  optional_attrs = %w(configurationState force restore)
32
52
  temp_data = @data.select { |k, _v| required_attributes.include?(k) || optional_attrs.include?(k) }
@@ -37,26 +57,128 @@ module OneviewSDK
37
57
  self
38
58
  end
39
59
 
60
+ # Method is not available
61
+ # @raise [OneviewSDK::MethodUnavailable] method is not available
40
62
  def update(*)
41
- fail 'Method not available for this resource!'
63
+ unavailable_method
42
64
  end
43
65
 
44
66
  # Power on the server hardware
45
- # @param [String] force Use 'PressAndHold' action
46
- # @return [Boolean] Whether or not server was powered on
67
+ # @param [Boolean] force Use 'PressAndHold' action?
68
+ # @return [Boolean] Returns whether or not the server was powered on
47
69
  def power_on(force = false)
48
70
  set_power_state('on', force)
49
71
  end
50
72
 
51
73
  # Power off the server hardware
52
- # @param [String] force Use 'PressAndHold' action
53
- # @return [Boolean] Whether or not server was powered off
74
+ # @param [Boolean] force Use 'PressAndHold' action?
75
+ # @return [Boolean] Returns whether or not the server was powered off
54
76
  def power_off(force = false)
55
77
  set_power_state('off', force)
56
78
  end
57
79
 
80
+ # Gets a list of BIOS/UEFI values on the physical server
81
+ # @return [Hash] List with BIOS/UEFI settings
82
+ def get_bios
83
+ response = @client.rest_get(@data['uri'] + '/bios')
84
+ @client.response_handler(response)
85
+ end
86
+
87
+ # Gets a url to the iLO web interface
88
+ # @return [Hash] url
89
+ def get_ilo_sso_url
90
+ response = @client.rest_get(@data['uri'] + '/iloSsoUrl')
91
+ @client.response_handler(response)
92
+ end
93
+
94
+ # Gets a Single Sign-On session for the Java Applet console
95
+ # @return [Hash] url
96
+ def get_java_remote_sso_url
97
+ response = @client.rest_get(@data['uri'] + '/javaRemoteConsoleUrl')
98
+ @client.response_handler(response)
99
+ end
100
+
101
+ # Gets a url to the iLO web interface
102
+ # @return [Hash] url
103
+ def get_remote_console_url
104
+ response = @client.rest_get(@data['uri'] + '/remoteConsoleUrl')
105
+ @client.response_handler(response)
106
+ end
107
+
108
+ # Refreshes the enclosure along with all of its components
109
+ # @param [String] state NotRefreshing, RefreshFailed, RefreshPending, Refreshing
110
+ # @param [Hash] options Optional force fields for refreshing the enclosure
111
+ def set_refresh_state(state, options = {})
112
+ ensure_client && ensure_uri
113
+ s = state.to_s rescue state
114
+ requestBody = {
115
+ 'body' => {
116
+ refreshState: s
117
+ }
118
+ }
119
+ requestBody['body'].merge(options)
120
+ response = @client.rest_put(@data['uri'] + '/refreshState', requestBody, @api_version)
121
+ new_data = @client.response_handler(response)
122
+ set_all(new_data)
123
+ end
124
+
125
+ # Updates the iLO firmware on a physical server to a minimum iLO firmware required by OneView
126
+ def update_ilo_firmware
127
+ response = @client.rest_put(@data['uri'] + '/mpFirmwareVersion')
128
+ @client.response_handler(response)
129
+ end
130
+
131
+ # Gets the settings that describe the environmental configuration
132
+ def environmental_configuration
133
+ ensure_client && ensure_uri
134
+ response = @client.rest_get(@data['uri'] + '/environmentalConfiguration', @api_version)
135
+ @client.response_handler(response)
136
+ end
137
+
138
+ # Retrieves historical utilization
139
+ # @param [Hash] queryParameters query parameters (ie :startDate, :endDate, :fields, :view, etc.)
140
+ # @option queryParameters [Array] :fields
141
+ # @option queryParameters [Time, Date, String] :startDate
142
+ # @option queryParameters [Time, Date, String] :endDate
143
+ def utilization(queryParameters = {})
144
+ ensure_client && ensure_uri
145
+ uri = "#{@data['uri']}/utilization?"
146
+
147
+ queryParameters[:endDate] = convert_time(queryParameters[:endDate])
148
+ queryParameters[:startDate] = convert_time(queryParameters[:startDate])
149
+
150
+ queryParameters.each do |key, value|
151
+ next if value.nil?
152
+ uri += case key.to_sym
153
+ when :fields
154
+ "fields=#{value.join(',')}"
155
+ when :startDate, :endDate
156
+ "filter=#{key}=#{value}"
157
+ else
158
+ "#{key}=#{value}"
159
+ end
160
+ uri += '&'
161
+ end
162
+ uri.chop! # Get rid of trailing '&' or '?'
163
+ response = @client.rest_get(uri, @api_version)
164
+ @client.response_handler(response)
165
+ end
166
+
58
167
  private
59
168
 
169
+ # Converts Date, Time, or String objects to iso8601 string
170
+ def convert_time(t)
171
+ case t
172
+ when nil then nil
173
+ when Date then t.to_time.utc.iso8601(3)
174
+ when Time then t.utc.iso8601(3)
175
+ when String then Time.parse(t).utc.iso8601(3)
176
+ else fail InvalidResource, "Invalid time format '#{t.class}'. Valid options are Time, Date, or String"
177
+ end
178
+ rescue StandardError => e
179
+ raise InvalidResource, "Failed to parse time value '#{t}'. #{e.message}"
180
+ end
181
+
60
182
  # Set power state. Takes into consideration the current state and does the right thing
61
183
  def set_power_state(state, force)
62
184
  refresh
@@ -83,6 +205,5 @@ module OneviewSDK
83
205
  set_all(body)
84
206
  true
85
207
  end
86
-
87
208
  end
88
209
  end
@@ -1,18 +1,50 @@
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
  module OneviewSDK
2
13
  # Server hardware type resource implementation
3
14
  class ServerHardwareType < Resource
4
15
  BASE_URI = '/rest/server-hardware-types'.freeze
5
16
 
17
+ # Remove resource from OneView
18
+ # @return [true] if resource was removed successfully
19
+ alias remove delete
20
+
21
+ # Create a resource object, associate it with a client, and set its properties.
22
+ # @param [OneviewSDK::Client] client The client object for the OneView appliance
23
+ # @param [Hash] params The options for this resource (key-value pairs)
24
+ # @param [Integer] api_ver The api version to use when interracting with this resource.
6
25
  def initialize(client, params = {}, api_ver = nil)
7
26
  super
8
27
  # Default values
9
28
  @data['type'] ||= 'server-hardware-type-4'
10
29
  end
11
30
 
31
+ # Method is not available
32
+ # @raise [OneviewSDK::MethodUnavailable] method is not available
12
33
  def create
13
34
  unavailable_method
14
35
  end
15
36
 
37
+ # Method is not available
38
+ # @raise [OneviewSDK::MethodUnavailable] method is not available
39
+ def delete
40
+ unavailable_method
41
+ end
42
+
43
+ # Update resource attributes
44
+ # @param [Hash] attributes attributes to be updated
45
+ # @option attributes [String] :name server hardware type name
46
+ # @option attributes [String] :description server hardware type description
47
+ # @return [OneviewSDK::ServerHardwareType] self
16
48
  def update(attributes = {})
17
49
  set_all(attributes)
18
50
  ensure_client && ensure_uri
@@ -22,6 +54,5 @@ module OneviewSDK
22
54
  @client.response_handler(response)
23
55
  self
24
56
  end
25
-
26
57
  end
27
58
  end