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.
- checksums.yaml +4 -4
- data/.rubocop.yml +4 -0
- data/CHANGELOG.md +81 -2
- data/README.md +118 -113
- data/Rakefile +11 -0
- data/lib/oneview-sdk/cli.rb +21 -15
- data/lib/oneview-sdk/client.rb +34 -21
- data/lib/oneview-sdk/config_loader.rb +12 -1
- data/lib/oneview-sdk/exceptions.rb +55 -0
- data/lib/oneview-sdk/resource/connection_template.rb +48 -0
- data/lib/oneview-sdk/resource/datacenter.rb +77 -0
- data/lib/oneview-sdk/resource/enclosure.rb +46 -24
- data/lib/oneview-sdk/resource/enclosure_group.rb +20 -36
- data/lib/oneview-sdk/resource/ethernet_network.rb +19 -23
- data/lib/oneview-sdk/resource/fabric.rb +41 -0
- data/lib/oneview-sdk/resource/fc_network.rb +15 -16
- data/lib/oneview-sdk/resource/fcoe_network.rb +15 -12
- data/lib/oneview-sdk/resource/firmware_bundle.rb +23 -24
- data/lib/oneview-sdk/resource/firmware_driver.rb +21 -9
- data/lib/oneview-sdk/resource/interconnect.rb +29 -9
- data/lib/oneview-sdk/resource/lig_uplink_set.rb +22 -28
- data/lib/oneview-sdk/resource/logical_downlink.rb +53 -0
- data/lib/oneview-sdk/resource/logical_enclosure.rb +35 -33
- data/lib/oneview-sdk/resource/logical_interconnect.rb +29 -65
- data/lib/oneview-sdk/resource/logical_interconnect_group.rb +26 -6
- data/lib/oneview-sdk/resource/logical_switch.rb +184 -0
- data/lib/oneview-sdk/resource/logical_switch_group.rb +66 -0
- data/lib/oneview-sdk/resource/managed_san.rb +79 -0
- data/lib/oneview-sdk/resource/network_set.rb +64 -0
- data/lib/oneview-sdk/resource/power_device.rb +174 -0
- data/lib/oneview-sdk/resource/rack.rb +83 -0
- data/lib/oneview-sdk/resource/san_manager.rb +88 -0
- data/lib/oneview-sdk/resource/server_hardware.rb +139 -18
- data/lib/oneview-sdk/resource/server_hardware_type.rb +32 -1
- data/lib/oneview-sdk/resource/server_profile.rb +352 -9
- data/lib/oneview-sdk/resource/server_profile_template.rb +193 -4
- data/lib/oneview-sdk/resource/storage_pool.rb +42 -20
- data/lib/oneview-sdk/resource/storage_system.rb +64 -14
- data/lib/oneview-sdk/resource/switch.rb +86 -0
- data/lib/oneview-sdk/resource/unmanaged_device.rb +55 -0
- data/lib/oneview-sdk/resource/uplink_set.rb +24 -64
- data/lib/oneview-sdk/resource/volume.rb +29 -29
- data/lib/oneview-sdk/resource/volume_attachment.rb +79 -0
- data/lib/oneview-sdk/resource/volume_snapshot.rb +20 -1
- data/lib/oneview-sdk/resource/volume_template.rb +22 -33
- data/lib/oneview-sdk/resource.rb +66 -28
- data/lib/oneview-sdk/rest.rb +69 -24
- data/lib/oneview-sdk/ssl_helper.rb +20 -9
- data/lib/oneview-sdk/version.rb +12 -1
- data/lib/oneview-sdk.rb +12 -0
- data/oneview-sdk.gemspec +11 -0
- metadata +17 -2
@@ -1,9 +1,25 @@
|
|
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
|
-
# Logical
|
13
|
+
# Logical interconnect group resource implementation
|
3
14
|
class LogicalInterconnectGroup < Resource
|
4
15
|
BASE_URI = '/rest/logical-interconnect-groups'.freeze
|
16
|
+
|
5
17
|
attr_reader :bay_count
|
6
18
|
|
19
|
+
# Create a resource object, associate it with a client, and set its properties.
|
20
|
+
# @param [OneviewSDK::Client] client The client object for the OneView appliance
|
21
|
+
# @param [Hash] params The options for this resource (key-value pairs)
|
22
|
+
# @param [Integer] api_ver The api version to use when interracting with this resource.
|
7
23
|
def initialize(client, params = {}, api_ver = nil)
|
8
24
|
super
|
9
25
|
# Default values:
|
@@ -21,9 +37,10 @@ module OneviewSDK
|
|
21
37
|
parse_interconnect_map_template if @data['interconnectMapTemplate']['interconnectMapEntryTemplates'] == []
|
22
38
|
end
|
23
39
|
|
24
|
-
#
|
40
|
+
# Adds an interconnect
|
25
41
|
# @param [Fixnum] bay Bay number
|
26
42
|
# @param [String] type Interconnect type
|
43
|
+
# @raise [StandardError] if a invalid type is given then raises an error
|
27
44
|
def add_interconnect(bay, type)
|
28
45
|
@data['interconnectMapTemplate']['interconnectMapEntryTemplates'].each do |entry|
|
29
46
|
entry['logicalLocation']['locationEntries'].each do |location|
|
@@ -37,20 +54,22 @@ module OneviewSDK
|
|
37
54
|
raise "Interconnect type #{type} not found! Supported types: #{list}"
|
38
55
|
end
|
39
56
|
|
40
|
-
#
|
57
|
+
# Adds an uplink set
|
41
58
|
# @param [OneviewSDK::LIGUplinkSet] uplink_set
|
42
59
|
def add_uplink_set(uplink_set)
|
43
60
|
@data['uplinkSets'] << uplink_set.data
|
44
61
|
end
|
45
62
|
|
46
|
-
# Get the default settings
|
63
|
+
# Get the logical interconnect group default settings
|
64
|
+
# @return [Hash] The logical interconnect group settings
|
47
65
|
def get_default_settings
|
48
66
|
get_uri = self.class::BASE_URI + '/defaultSettings'
|
49
67
|
response = @client.rest_get(get_uri, @api_version)
|
50
68
|
@client.response_handler(response)
|
51
69
|
end
|
52
70
|
|
53
|
-
#
|
71
|
+
# Gets the logical interconnect group settings
|
72
|
+
# @return [Hash] The logical interconnect group settings
|
54
73
|
def get_settings
|
55
74
|
get_uri = @data['uri'] + '/settings'
|
56
75
|
response = @client.rest_get(get_uri, @api_version)
|
@@ -58,6 +77,7 @@ module OneviewSDK
|
|
58
77
|
end
|
59
78
|
|
60
79
|
# Saves the current data attributes to the Logical Interconnect Group
|
80
|
+
# @param [Hash] attributes attributes to be updated
|
61
81
|
# @return Updated instance of the Logical Interconnect Group
|
62
82
|
def update(attributes = {})
|
63
83
|
set_all(attributes)
|
@@ -72,6 +92,7 @@ module OneviewSDK
|
|
72
92
|
|
73
93
|
private
|
74
94
|
|
95
|
+
# Parse interconnect map template structure
|
75
96
|
def parse_interconnect_map_template
|
76
97
|
1.upto(@bay_count) do |bay_number|
|
77
98
|
entry = {
|
@@ -87,6 +108,5 @@ module OneviewSDK
|
|
87
108
|
@data['interconnectMapTemplate']['interconnectMapEntryTemplates'] << entry
|
88
109
|
end
|
89
110
|
end
|
90
|
-
|
91
111
|
end
|
92
112
|
end
|
@@ -0,0 +1,184 @@
|
|
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
|
+
# Logical switch resource implementation
|
14
|
+
class LogicalSwitch < Resource
|
15
|
+
BASE_URI = '/rest/logical-switches'.freeze
|
16
|
+
|
17
|
+
attr_accessor :logical_switch_credentials
|
18
|
+
|
19
|
+
# Create a resource object, associate it with a client, and set its properties.
|
20
|
+
# @param [OneviewSDK::Client] client The client object for the OneView appliance
|
21
|
+
# @param [Hash] params The options for this resource (key-value pairs)
|
22
|
+
# @param [Integer] api_ver The api version to use when interracting with this resource.
|
23
|
+
def initialize(client, params = {}, api_ver = nil)
|
24
|
+
super
|
25
|
+
# Default values
|
26
|
+
@data['type'] ||= 'logical-switch'
|
27
|
+
@logical_switch_credentials = {}
|
28
|
+
end
|
29
|
+
|
30
|
+
# Create method
|
31
|
+
# @raise [OneviewSDK::IncompleteResource] if the client is not set
|
32
|
+
# @raise [StandardError] if the resource creation fails
|
33
|
+
# @return [OneviewSDK::LogicalSwitch] self
|
34
|
+
def create
|
35
|
+
ensure_client
|
36
|
+
request_body = {}
|
37
|
+
request_body['logicalSwitchCredentials'] = generate_logical_switch_credentials
|
38
|
+
request_body['logicalSwitch'] = @data.clone
|
39
|
+
request_body['logicalSwitch']['switchCredentialConfiguration'] = generate_logical_switch_credential_configuration
|
40
|
+
response = @client.rest_post(self.class::BASE_URI, { 'body' => request_body }, @api_version)
|
41
|
+
body = @client.response_handler(response)
|
42
|
+
set_all(body)
|
43
|
+
self
|
44
|
+
end
|
45
|
+
|
46
|
+
# Updates this object using the data that exists on OneView
|
47
|
+
# @note Will overwrite any data that differs from OneView
|
48
|
+
# @return [Resource] self
|
49
|
+
def refresh
|
50
|
+
response = @client.rest_put(@data['uri'] + '/refresh')
|
51
|
+
@client.response_handler(response)
|
52
|
+
end
|
53
|
+
|
54
|
+
|
55
|
+
# @!group Credentials
|
56
|
+
CredentialsSSH = Struct.new(:user, :password)
|
57
|
+
|
58
|
+
CredentialsSNMPV1 = Struct.new(:port, :community_string, :version) do
|
59
|
+
# @return [String] Returns SNMPv1
|
60
|
+
def version
|
61
|
+
'SNMPv1'
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
CredentialsSNMPV3 = Struct.new(:port, :user, :auth_protocol, :auth_password, :privacy_protocol, :privacy_password, :version) do
|
66
|
+
# @return [String] Returns SNMPv3
|
67
|
+
def version
|
68
|
+
'SNMPv3'
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
# Sets switch credentials
|
73
|
+
# @param [String] host IP address or host name
|
74
|
+
# @param [CredentialsSSH] ssh_credentials SSH credentials
|
75
|
+
# @param [CredentialsSNMP] snmp_credentials SNMP credentials
|
76
|
+
# @return [Array] An Array containing the SSH and SNMP credentials
|
77
|
+
def set_switch_credentials(host, ssh_credentials, snmp_credentials)
|
78
|
+
fail TypeError, 'Use struct<OneviewSDK::LogicalSwitch::CredentialsSSH>' if ssh_credentials.class != OneviewSDK::LogicalSwitch::CredentialsSSH
|
79
|
+
fail TypeError, 'Use struct<OneviewSDK::LogicalSwitch::CredentialsSNMP>' unless snmp_credentials.respond_to?('version')
|
80
|
+
fail TypeError, 'Use struct<OneviewSDK::LogicalSwitch::CredentialsSNMP>' if snmp_credentials.version != 'SNMPv1' &&
|
81
|
+
snmp_credentials.version != 'SNMPv3'
|
82
|
+
@logical_switch_credentials[host] = [ssh_credentials.clone, snmp_credentials.clone]
|
83
|
+
@logical_switch_credentials[host]
|
84
|
+
end
|
85
|
+
|
86
|
+
# @!endgroup
|
87
|
+
|
88
|
+
|
89
|
+
# Sets the logical switch group
|
90
|
+
# @param [OneviewSDK::logicalSwitchGroup] logical_switch_group Logical switch group
|
91
|
+
def set_logical_switch_group(logical_switch_group)
|
92
|
+
@data['logicalSwitchGroupUri'] = logical_switch_group['uri']
|
93
|
+
end
|
94
|
+
|
95
|
+
private
|
96
|
+
|
97
|
+
# Generates the logical switch credentials for POST and PUT requests
|
98
|
+
# @return [Array] List of connection properties for each logical switch
|
99
|
+
def generate_logical_switch_credentials
|
100
|
+
credentials = []
|
101
|
+
@logical_switch_credentials.each do |_, switch|
|
102
|
+
switch_credentials = []
|
103
|
+
switch_credentials << {
|
104
|
+
'valueFormat' => 'Unknown',
|
105
|
+
'propertyName' => 'SshBasicAuthCredentialUser',
|
106
|
+
'valueType' => 'String',
|
107
|
+
'value' => switch[0].user
|
108
|
+
}
|
109
|
+
|
110
|
+
switch_credentials << {
|
111
|
+
'valueFormat' => 'SecuritySensitive',
|
112
|
+
'propertyName' => 'SshBasicAuthCredentialPassword',
|
113
|
+
'valueType' => 'String',
|
114
|
+
'value' => switch[0].password
|
115
|
+
}
|
116
|
+
|
117
|
+
if switch[1].version == 'SNMPv3'
|
118
|
+
switch_credentials << {
|
119
|
+
'valueFormat' => 'SecuritySensitive',
|
120
|
+
'propertyName' => 'SnmpV3AuthorizationPassword',
|
121
|
+
'valueType' => 'String',
|
122
|
+
'value' => switch[1].auth_password
|
123
|
+
}
|
124
|
+
|
125
|
+
switch_credentials << {
|
126
|
+
'valueFormat' => 'Unknown',
|
127
|
+
'propertyName' => 'SnmpV3User',
|
128
|
+
'valueType' => 'String',
|
129
|
+
'value' => switch[1].user
|
130
|
+
}
|
131
|
+
|
132
|
+
if switch[1].privacy_password
|
133
|
+
switch_credentials << {
|
134
|
+
'valueFormat' => 'SecuritySensitive',
|
135
|
+
'propertyName' => 'SnmpV3PrivacyPassword',
|
136
|
+
'valueType' => 'String',
|
137
|
+
'value' => switch[1].privacy_password
|
138
|
+
}
|
139
|
+
end
|
140
|
+
end
|
141
|
+
|
142
|
+
credentials << { 'connectionProperties' => switch_credentials }
|
143
|
+
end
|
144
|
+
credentials
|
145
|
+
end
|
146
|
+
|
147
|
+
# Generates the logical switch credential configuration for POST and PUT requests
|
148
|
+
# @return [Array] List of logical switch credential configuration for each switch
|
149
|
+
def generate_logical_switch_credential_configuration
|
150
|
+
configuration = []
|
151
|
+
@logical_switch_credentials.each do |host, switch|
|
152
|
+
switch_configuration = {
|
153
|
+
'snmpPort' => switch[1].port,
|
154
|
+
'snmpV3Configuration' => nil,
|
155
|
+
'snmpV1Configuration' => nil,
|
156
|
+
'logicalSwitchManagementHost' => host,
|
157
|
+
'snmpVersion' => switch[1].version
|
158
|
+
}
|
159
|
+
|
160
|
+
if switch[1].version == 'SNMPv3'
|
161
|
+
switch_configuration['snmpV1Configuration'] = nil
|
162
|
+
switch_configuration['snmpV3Configuration'] = {
|
163
|
+
'authorizationProtocol' => switch[1].auth_protocol
|
164
|
+
}
|
165
|
+
|
166
|
+
if switch[1].privacy_protocol
|
167
|
+
switch_configuration['snmpV3Configuration']['securityLevel'] = 'AuthPrivacy'
|
168
|
+
switch_configuration['snmpV3Configuration']['privacyProtocol'] = switch[1].privacy_protocol
|
169
|
+
else
|
170
|
+
switch_configuration['snmpV3Configuration']['securityLevel'] = 'Auth'
|
171
|
+
end
|
172
|
+
|
173
|
+
elsif switch[1].version == 'SNMPv1'
|
174
|
+
switch_configuration['snmpV3Configuration'] = nil
|
175
|
+
switch_configuration['snmpV1Configuration'] = {
|
176
|
+
'communityString' => switch[1].community_string
|
177
|
+
}
|
178
|
+
end
|
179
|
+
configuration << switch_configuration
|
180
|
+
end
|
181
|
+
configuration
|
182
|
+
end
|
183
|
+
end
|
184
|
+
end
|
@@ -0,0 +1,66 @@
|
|
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
|
+
# Logical switch group resource implementation
|
14
|
+
class LogicalSwitchGroup < Resource
|
15
|
+
BASE_URI = '/rest/logical-switch-groups'.freeze
|
16
|
+
|
17
|
+
# Create a resource object, associate it with a client, and set its properties.
|
18
|
+
# @param [OneviewSDK::Client] client The client object for the OneView appliance
|
19
|
+
# @param [Hash] params The options for this resource (key-value pairs)
|
20
|
+
# @param [Integer] api_ver The api version to use when interracting with this resource.
|
21
|
+
def initialize(client, params = {}, api_ver = nil)
|
22
|
+
super
|
23
|
+
# Default values:
|
24
|
+
@data['category'] ||= 'logical-switch-groups'
|
25
|
+
@data['state'] ||= 'Active'
|
26
|
+
@data['type'] ||= 'logical-switch-group'
|
27
|
+
@data['switchMapTemplate'] ||= {}
|
28
|
+
end
|
29
|
+
|
30
|
+
# Define how the switches will be grouped, setting the number and the type of the switches
|
31
|
+
# @param [Fixnum] number_of_switches The number of the switch inside the group [1,2]
|
32
|
+
# @param [String] type Switch type name
|
33
|
+
# @raise [StandardError]
|
34
|
+
def set_grouping_parameters(number_of_switches, type)
|
35
|
+
@data['switchMapTemplate']['switchMapEntryTemplates'] = []
|
36
|
+
parse_switch_map_template(number_of_switches)
|
37
|
+
switch_type_uri = OneviewSDK::Switch.get_type(@client, type)['uri']
|
38
|
+
@data['switchMapTemplate']['switchMapEntryTemplates'].each do |entry|
|
39
|
+
entry['logicalLocation']['locationEntries'].each do |location|
|
40
|
+
entry['permittedSwitchTypeUri'] = switch_type_uri if location['type'] == 'StackingMemberId'
|
41
|
+
end
|
42
|
+
end
|
43
|
+
rescue StandardError
|
44
|
+
list = OneviewSDK::Switch.get_types(@client).map { |t| t['name'] }
|
45
|
+
raise "Switch type #{type} not found! Supported types: #{list}"
|
46
|
+
end
|
47
|
+
|
48
|
+
private
|
49
|
+
|
50
|
+
# Parse switch map template structure
|
51
|
+
# @param [Integer] number_of_switches number of switches
|
52
|
+
def parse_switch_map_template(number_of_switches)
|
53
|
+
1.upto(number_of_switches) do |stacking_member_id|
|
54
|
+
entry = {
|
55
|
+
'logicalLocation' => {
|
56
|
+
'locationEntries' => [
|
57
|
+
{ 'relativeValue' => stacking_member_id, 'type' => 'StackingMemberId' }
|
58
|
+
]
|
59
|
+
},
|
60
|
+
'permittedSwitchTypeUri' => nil
|
61
|
+
}
|
62
|
+
@data['switchMapTemplate']['switchMapEntryTemplates'] << entry
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
@@ -0,0 +1,79 @@
|
|
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
|
+
# Power device resource implementation
|
14
|
+
class ManagedSAN < Resource
|
15
|
+
BASE_URI = '/rest/fc-sans/managed-sans'.freeze
|
16
|
+
|
17
|
+
# Method is not available
|
18
|
+
# @raise [OneviewSDK::MethodUnavailable] method is not available
|
19
|
+
def create
|
20
|
+
unavailable_method
|
21
|
+
end
|
22
|
+
|
23
|
+
# Method is not available
|
24
|
+
# @raise [OneviewSDK::MethodUnavailable] method is not available
|
25
|
+
def delete
|
26
|
+
unavailable_method
|
27
|
+
end
|
28
|
+
|
29
|
+
# Method is not available
|
30
|
+
# @raise [OneviewSDK::MethodUnavailable] method is not available
|
31
|
+
def update
|
32
|
+
unavailable_method
|
33
|
+
end
|
34
|
+
|
35
|
+
# Retrieves a list of endpoints
|
36
|
+
# @return [Array] List of endpoints
|
37
|
+
def get_endpoints
|
38
|
+
response = @client.rest_get(@data['uri'] + '/endpoints')
|
39
|
+
@client.response_handler(response)['members']
|
40
|
+
end
|
41
|
+
|
42
|
+
# Set refresh state for managed SAN
|
43
|
+
# @param [String] state Desired refresh state
|
44
|
+
def set_refresh_state(state)
|
45
|
+
response = @client.rest_put(@data['uri'], 'body' => { refreshState: state })
|
46
|
+
@client.response_handler(response)
|
47
|
+
end
|
48
|
+
|
49
|
+
# Set public attributes
|
50
|
+
# @param [Hash] attributes Public attributes
|
51
|
+
# @option attributes [String] :name
|
52
|
+
# @option attributes [String] :value
|
53
|
+
# @option attributes [String] :valueType
|
54
|
+
# @option attributes [String] :valueFormat
|
55
|
+
def set_public_attributes(attributes)
|
56
|
+
response = @client.rest_put(@data['uri'], 'body' => { publicAttributes: attributes })
|
57
|
+
@client.response_handler(response)
|
58
|
+
end
|
59
|
+
|
60
|
+
# Set public attributes
|
61
|
+
# @param [Hash] policy SAN policy
|
62
|
+
# @option attributes [String] :zoningPolicy
|
63
|
+
# @option attributes [String] :zoneNameFormat
|
64
|
+
# @option attributes [String] :enableAliasing
|
65
|
+
# @option attributes [String] :initiatorNameFormat
|
66
|
+
# @option attributes [String] :targetNameFormat
|
67
|
+
# @option attributes [String] :targetGroupNameFormat
|
68
|
+
def set_san_policy(policy)
|
69
|
+
response = @client.rest_put(@data['uri'], 'body' => { sanPolicy: policy })
|
70
|
+
@client.response_handler(response)
|
71
|
+
end
|
72
|
+
|
73
|
+
# Creates unexpected zoning report for a SAN
|
74
|
+
def get_zoning_report
|
75
|
+
response = @client.rest_post(@data['uri'] + '/issues', 'body' => {})
|
76
|
+
@client.response_handler(response)
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
@@ -0,0 +1,64 @@
|
|
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
|
+
# Network set resource implementation
|
14
|
+
class NetworkSet < Resource
|
15
|
+
BASE_URI = '/rest/network-sets'.freeze
|
16
|
+
|
17
|
+
# Create a resource object, associate it with a client, and set its properties.
|
18
|
+
# @param [OneviewSDK::Client] client The client object for the OneView appliance
|
19
|
+
# @param [Hash] params The options for this resource (key-value pairs)
|
20
|
+
# @param [Integer] api_ver The api version to use when interracting with this resource.
|
21
|
+
def initialize(client, params = {}, api_ver = nil)
|
22
|
+
super
|
23
|
+
# Default values:
|
24
|
+
@data['connectionTemplateUri'] ||= nil
|
25
|
+
@data['nativeNetworkUri'] ||= nil
|
26
|
+
@data['networkUris'] ||= []
|
27
|
+
@data['type'] ||= 'network-set'
|
28
|
+
end
|
29
|
+
|
30
|
+
# Sets the native network for the network set
|
31
|
+
# @param [OneviewSDK::EthernetNetwork] ethernet_network Ethernet Network
|
32
|
+
def set_native_network(ethernet_network)
|
33
|
+
@data['nativeNetworkUri'] = ethernet_network['uri']
|
34
|
+
@data['networkUris'] << ethernet_network['uri'] unless @data['networkUris'].include?(ethernet_network['uri'])
|
35
|
+
end
|
36
|
+
|
37
|
+
# Adds an ethernet network to the network set
|
38
|
+
# @param [OneviewSDK::EthernetNetwork] ethernet_network Ethernet Network
|
39
|
+
def add_ethernet_network(ethernet_network)
|
40
|
+
@data['networkUris'] << ethernet_network['uri'] unless @data['networkUris'].include?(ethernet_network['uri'])
|
41
|
+
end
|
42
|
+
|
43
|
+
# Removes an ethernet network from the network set
|
44
|
+
# @param [OneviewSDK::EthernetNetwork] ethernet_network Ethernet Network
|
45
|
+
def remove_ethernet_network(ethernet_network)
|
46
|
+
@data['networkUris'].delete(ethernet_network['uri']) if @data['networkUris'].include?(ethernet_network['uri'])
|
47
|
+
end
|
48
|
+
|
49
|
+
# Lists network sets excluding ethernet networks
|
50
|
+
# @param [OneviewSDK::Client] client The client object for the OneView appliance
|
51
|
+
# @return [Array] List of network sets
|
52
|
+
def self.get_without_ethernet(client)
|
53
|
+
response = client.rest_get(BASE_URI + '/withoutEthernet')
|
54
|
+
client.response_handler(response)
|
55
|
+
end
|
56
|
+
|
57
|
+
# Lists network set excluding ethernet networks
|
58
|
+
# @return [OneviewSDK::NetworkSet] Network set
|
59
|
+
def get_without_ethernet
|
60
|
+
response = @client.rest_get(@data['uri'] + '/withoutEthernet')
|
61
|
+
@client.response_handler(response)
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
@@ -0,0 +1,174 @@
|
|
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
|
+
# Power device resource implementation
|
14
|
+
class PowerDevice < Resource
|
15
|
+
BASE_URI = '/rest/power-devices'.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::PowerDevice] 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['deviceType'] ||= 'BranchCircuit'
|
36
|
+
@data['phaseType'] ||= 'Unknown'
|
37
|
+
@data['powerConnections'] ||= []
|
38
|
+
end
|
39
|
+
|
40
|
+
# Method is not available
|
41
|
+
# @raise [OneviewSDK::MethodUnavailable] method is not available
|
42
|
+
def create
|
43
|
+
unavailable_method
|
44
|
+
end
|
45
|
+
|
46
|
+
# Method is not available
|
47
|
+
# @raise [OneviewSDK::MethodUnavailable] method is not available
|
48
|
+
def delete
|
49
|
+
unavailable_method
|
50
|
+
end
|
51
|
+
|
52
|
+
# Adds an iPDU and bring all components under management by discovery of its management modules
|
53
|
+
# @param [OneviewSDK::Client] client The client object for the OneView appliance
|
54
|
+
# @param [Hash] options options for the iPDU
|
55
|
+
# @return [OneviewSDK::PowerDevice] The iPDU power device created in OneView
|
56
|
+
def self.discover(client, options)
|
57
|
+
options['force'] ||= options[:force] || false
|
58
|
+
response = client.rest_post(BASE_URI + '/discover', 'body' => options)
|
59
|
+
power_device_info = client.response_handler(response)
|
60
|
+
new(client, power_device_info)
|
61
|
+
end
|
62
|
+
|
63
|
+
# Retrieves the list of power devices given an iPDU hostname
|
64
|
+
# @param [OneviewSDK::Client] client The client object for the OneView appliance
|
65
|
+
# @param [String] hostname The iPDU hostname
|
66
|
+
# @return [Array] array of OneviewSDK::PowerDevice
|
67
|
+
def self.get_ipdu_devices(client, hostname)
|
68
|
+
find_by(client, managedBy: { hostName: hostname })
|
69
|
+
end
|
70
|
+
|
71
|
+
# Gets the power state of a power device
|
72
|
+
# @return [String] Power state
|
73
|
+
def get_power_state
|
74
|
+
response = @client.rest_get(@data['uri'] + '/powerState')
|
75
|
+
response.body
|
76
|
+
end
|
77
|
+
|
78
|
+
# Adds a power connection
|
79
|
+
# @param [OneviewSDK::Resource] resource
|
80
|
+
# @param [Integer] connection connection number
|
81
|
+
def add_connection(resource, connection)
|
82
|
+
@data['powerConnections'] << {
|
83
|
+
'connectionUri' => resource['uri'],
|
84
|
+
'deviceConnection' => connection,
|
85
|
+
'sourceConnection' => connection
|
86
|
+
}
|
87
|
+
end
|
88
|
+
|
89
|
+
# Removes the power connection
|
90
|
+
# @param [OneviewSDK::Resource] resource
|
91
|
+
# @param [Integer] connection connection number
|
92
|
+
def remove_connection(resource, connection)
|
93
|
+
@data['powerConnections'].reject! do |conn|
|
94
|
+
conn['connectionUri'] == resource['uri'] && conn['deviceConnection'] == connection
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
# Sets the power state of the power delivery device
|
99
|
+
# @param [String] state On|Off
|
100
|
+
def set_power_state(state)
|
101
|
+
response = @client.rest_put(@data['uri'] + '/powerState', 'body' => { powerState: state })
|
102
|
+
@client.response_handler(response)
|
103
|
+
end
|
104
|
+
|
105
|
+
# Refreshes a power delivery device
|
106
|
+
# @param [Hash] options
|
107
|
+
# @option options [String] :refreshState
|
108
|
+
# @option options [String] :username
|
109
|
+
# @option options [String] :password
|
110
|
+
def set_refresh_state(options)
|
111
|
+
response = @client.rest_put(@data['uri'] + '/refreshState', 'body' => options)
|
112
|
+
@client.response_handler(response)
|
113
|
+
end
|
114
|
+
|
115
|
+
# Retrieves the unit identification state of the specified power outlet
|
116
|
+
# @return [String] Uid state
|
117
|
+
def get_uid_state
|
118
|
+
response = @client.rest_get(@data['uri'] + '/uidState')
|
119
|
+
response.body
|
120
|
+
end
|
121
|
+
|
122
|
+
# Sets the unit identification light state of the power delivery device
|
123
|
+
# @param [String] state On|Off
|
124
|
+
def set_uid_state(state)
|
125
|
+
response = @client.rest_put(@data['uri'] + '/uidState', 'body' => { uidState: state })
|
126
|
+
@client.response_handler(response)
|
127
|
+
end
|
128
|
+
|
129
|
+
# Retrieves historical utilization
|
130
|
+
# @param [Hash] queryParameters query parameters (ie :startDate, :endDate, :fields, :view, etc.)
|
131
|
+
# @option queryParameters [Array] :fields
|
132
|
+
# @option queryParameters [Time, Date, String] :startDate
|
133
|
+
# @option queryParameters [Time, Date, String] :endDate
|
134
|
+
# @return [Hash] Utilization data
|
135
|
+
def utilization(queryParameters = {})
|
136
|
+
ensure_client && ensure_uri
|
137
|
+
uri = "#{@data['uri']}/utilization?"
|
138
|
+
|
139
|
+
queryParameters[:endDate] = convert_time(queryParameters[:endDate])
|
140
|
+
queryParameters[:startDate] = convert_time(queryParameters[:startDate])
|
141
|
+
|
142
|
+
queryParameters.each do |key, value|
|
143
|
+
next if value.nil?
|
144
|
+
uri += case key.to_sym
|
145
|
+
when :fields
|
146
|
+
"fields=#{value.join(',')}"
|
147
|
+
when :startDate, :endDate
|
148
|
+
"filter=#{key}=#{value}"
|
149
|
+
else
|
150
|
+
"#{key}=#{value}"
|
151
|
+
end
|
152
|
+
uri += '&'
|
153
|
+
end
|
154
|
+
uri.chop! # Get rid of trailing '&' or '?'
|
155
|
+
response = @client.rest_get(uri, @api_version)
|
156
|
+
@client.response_handler(response)
|
157
|
+
end
|
158
|
+
|
159
|
+
private
|
160
|
+
|
161
|
+
# Converts Date, Time, or String objects to iso8601 string
|
162
|
+
def convert_time(t)
|
163
|
+
case t
|
164
|
+
when nil then nil
|
165
|
+
when Date then t.to_time.utc.iso8601(3)
|
166
|
+
when Time then t.utc.iso8601(3)
|
167
|
+
when String then Time.parse(t).utc.iso8601(3)
|
168
|
+
else fail "Invalid time format '#{t.class}'. Valid options are Time, Date, or String"
|
169
|
+
end
|
170
|
+
rescue StandardError => e
|
171
|
+
raise "Failed to parse time value '#{t}'. #{e.message}"
|
172
|
+
end
|
173
|
+
end
|
174
|
+
end
|