-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #363 from HewlettPackard/API200/Alerts
Adding a new resource Alerts
Showing
17 changed files
with
392 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
# (C) Copyright 2018 Hewlett Packard Enterprise Development LP | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# You may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software distributed | ||
# under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR | ||
# CONDITIONS OF ANY KIND, either express or implied. See the License for the | ||
# specific language governing permissions and limitations under the License. | ||
|
||
require_relative '../_client' # Gives access to @client | ||
|
||
# All supported APIs for Event: | ||
# - API200 for C7000 and Synergy | ||
# - API300 for C7000 and Synergy | ||
# - API400 for C7000 and Synergy | ||
# - API500 for C7000 and Synergy | ||
# - API600 for C7000 and Synergy | ||
|
||
# Resources classes that you can use for Event in this example: | ||
alert_class = OneviewSDK.resource_named('Alerts', @client.api_version) | ||
|
||
puts "\n\n Get all alerts:" | ||
alert_class.get_all(@client).each do |item| | ||
puts item.data | ||
end | ||
|
||
puts "\n\n Update Alert" | ||
alert_clr = alert_class.find_by(@client, alertState: 'Cleared').first | ||
puts "Data : '#{alert_clr.data}'" | ||
alert_to_update = { | ||
assignedToUser: 'Paul', | ||
alertState: 'Active', | ||
notes: 'A note to delete!' | ||
} | ||
alert_clr.update(alert_to_update) | ||
alert_clr.retrieve! | ||
puts "\nAlert updated successfully and assigned to = '#{alert_clr['assignedToUser']}'" | ||
|
||
puts "\n\n Get Alert by ID/URI" | ||
alert = alert_class.find_by(@client, alertState: 'Cleared').first | ||
alert_id = alert_class.find_by(@client, uri: alert[:uri])[0] | ||
puts "Alert by ID/URI: '#{alert_id.data}'" | ||
|
||
puts "\n\n Delete Alert by ID" | ||
alert_id.delete | ||
|
||
# NOTE: The Locked alerts and the AlertChangeLog generated by the system cannot be deleted by user. | ||
puts "\n\n Delete Alert by alert_change_log URI" | ||
alert_cl = alert_class.find_by(@client, alertState: 'Cleared').last | ||
puts alert_cl[:changeLog][0]['uri'] | ||
puts "Alert by Change log ID : '#{alert_cl.data}'" | ||
alert_cl.delete |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
# (C) Copyright 2018 Hewlett Packard Enterprise Development LP | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# You may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software distributed | ||
# under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR | ||
# CONDITIONS OF ANY KIND, either express or implied. See the License for the specific | ||
# language governing permissions and limitations under the License. | ||
|
||
require_relative 'resource' | ||
|
||
module OneviewSDK | ||
module API200 | ||
# Event resource implementation | ||
class Alerts < Resource | ||
BASE_URI = '/rest/alerts'.freeze | ||
# Create a resource object, associate it with a client, and set its properties. | ||
# @param [OneviewSDK::Client] client The client object for the OneView appliance | ||
# @param [Hash] params The options for this resource (key-value pairs) | ||
# @param [Integer] api_ver The api version to use when interracting with this resource. | ||
def initialize(client, params = {}, api_ver = nil) | ||
super | ||
# Default values: | ||
@data['type'] ||= 'AlertResourceV3' | ||
end | ||
|
||
def update(attributes = {}) | ||
set_all(attributes) | ||
ensure_client && ensure_uri | ||
data = @data.select { |k, _v| %w[alertState alertUrgency assignedToUser notes eTag].include?(k) } | ||
response = @client.rest_put(@data['uri'], { 'body' => data }, @api_version) | ||
@client.response_handler(response) | ||
self | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# (C) Copyright 2018 Hewlett Packard Enterprise Development LP | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# You may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software distributed | ||
# under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR | ||
# CONDITIONS OF ANY KIND, either express or implied. See the License for the specific | ||
# language governing permissions and limitations under the License. | ||
|
||
require_relative '../../api200/alerts' | ||
|
||
module OneviewSDK | ||
module API300 | ||
module C7000 | ||
# Alert resource implementation for API300 C7000 | ||
class Alerts < OneviewSDK::API200::Alerts | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# (C) Copyright 2018 Hewlett Packard Enterprise Development LP | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# You may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software distributed | ||
# under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR | ||
# CONDITIONS OF ANY KIND, either express or implied. See the License for the specific | ||
# language governing permissions and limitations under the License. | ||
|
||
require_relative '../../api200/alerts' | ||
|
||
module OneviewSDK | ||
module API300 | ||
module Synergy | ||
# Alerts resource implementation for API300 Synergy | ||
class Alerts < OneviewSDK::API200::Alerts | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# (C) Copyright 2018 Hewlett Packard Enterprise Development LP | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# You may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software distributed | ||
# under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR | ||
# CONDITIONS OF ANY KIND, either express or implied. See the License for the specific | ||
# language governing permissions and limitations under the License. | ||
|
||
require_relative '../../api300/c7000/alerts' | ||
|
||
module OneviewSDK | ||
module API500 | ||
module C7000 | ||
# Alerts resource implementation for API500 C7000 | ||
class Alerts < OneviewSDK::API300::C7000::Alerts | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# (C) Copyright 2018 Hewlett Packard Enterprise Development LP | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# You may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software distributed | ||
# under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR | ||
# CONDITIONS OF ANY KIND, either express or implied. See the License for the specific | ||
# language governing permissions and limitations under the License. | ||
|
||
require_relative '../../api300/synergy/alerts' | ||
|
||
module OneviewSDK | ||
module API500 | ||
module Synergy | ||
# Alerts resource implementation for API500 Synergy | ||
class Alerts < OneviewSDK::API300::Synergy::Alerts | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# (C) Copyright 2018 Hewlett Packard Enterprise Development LP | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# You may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software distributed | ||
# under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR | ||
# CONDITIONS OF ANY KIND, either express or implied. See the License for the specific | ||
# language governing permissions and limitations under the License. | ||
|
||
require_relative '../../api500/c7000/alerts' | ||
|
||
module OneviewSDK | ||
module API600 | ||
module C7000 | ||
# Alerts resource implementation for API600 C7000 | ||
class Alerts < OneviewSDK::API500::C7000::Alerts | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# (C) Copyright 2018 Hewlett Packard Enterprise Development LP | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# You may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software distributed | ||
# under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR | ||
# CONDITIONS OF ANY KIND, either express or implied. See the License for the specific | ||
# language governing permissions and limitations under the License. | ||
|
||
require_relative '../../api500/synergy/alerts' | ||
|
||
module OneviewSDK | ||
module API600 | ||
module Synergy | ||
# Alerts resource implementation for API600 Synergy | ||
class Alerts < OneviewSDK::API500::Synergy::Alerts | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
# (C) Copyright 2018 Hewlett Packard Enterprise Development LP | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# You may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software distributed | ||
# under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR | ||
# CONDITIONS OF ANY KIND, either express or implied. See the License for the | ||
# specific language governing permissions and limitations under the License. | ||
|
||
require 'spec_helper' | ||
|
||
RSpec.describe OneviewSDK::Alerts do | ||
include_context 'shared context' | ||
|
||
describe '#initialize' do | ||
it 'sets the defaults correctly' do | ||
alerts = described_class.new(@client_200) | ||
expect(alerts['type']).to eq('AlertResourceV3') | ||
end | ||
end | ||
|
||
describe '#update' do | ||
it 'requires a uri' do | ||
expect { OneviewSDK::Alerts.new(@client_200).update }.to raise_error(/Please set uri/) | ||
end | ||
|
||
it 'only includes alertState, alertUrgency, assignedToUser or notes in the PUT' do | ||
item = OneviewSDK::Alerts.new(@client_200, uri: '/rest/fake') | ||
data = { 'body' => { 'assignedToUser' => 'Name', 'alertState' => 'Active' } } | ||
expect(@client_200).to receive(:rest_put).with('/rest/fake', data, item.api_version).and_return(FakeResponse.new) | ||
item.update('assignedToUser' => 'Name', 'alertState' => 'Active') | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# (C) Copyright 2018 Hewlett Packard Enterprise Development LP | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# You may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software distributed | ||
# under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR | ||
# CONDITIONS OF ANY KIND, either express or implied. See the License for the | ||
# specific language governing permissions and limitations under the License. | ||
|
||
require 'spec_helper' | ||
|
||
RSpec.describe OneviewSDK::API300::C7000::Alerts do | ||
include_context 'shared context' | ||
|
||
it 'inherits from API200' do | ||
expect(described_class).to be < OneviewSDK::API200::Alerts | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# (C) Copyright 2018 Hewlett Packard Enterprise Development LP | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# You may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software distributed | ||
# under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR | ||
# CONDITIONS OF ANY KIND, either express or implied. See the License for the | ||
# specific language governing permissions and limitations under the License. | ||
|
||
require 'spec_helper' | ||
|
||
RSpec.describe OneviewSDK::API300::Synergy::Alerts do | ||
include_context 'shared context' | ||
|
||
it 'inherits from API200' do | ||
expect(described_class).to be < OneviewSDK::API200::Alerts | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# (C) Copyright 2018 Hewlett Packard Enterprise Development LP | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# You may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software distributed | ||
# under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR | ||
# CONDITIONS OF ANY KIND, either express or implied. See the License for the | ||
# specific language governing permissions and limitations under the License. | ||
|
||
require 'spec_helper' | ||
|
||
RSpec.describe OneviewSDK::API500::C7000::Alerts do | ||
include_context 'shared context' | ||
|
||
it 'inherits from API300' do | ||
expect(described_class).to be < OneviewSDK::API300::C7000::Alerts | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# (C) Copyright 2018 Hewlett Packard Enterprise Development LP | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# You may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software distributed | ||
# under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR | ||
# CONDITIONS OF ANY KIND, either express or implied. See the License for the | ||
# specific language governing permissions and limitations under the License. | ||
|
||
require 'spec_helper' | ||
|
||
RSpec.describe OneviewSDK::API500::Synergy::Alerts do | ||
include_context 'shared context' | ||
|
||
it 'inherits from API300' do | ||
expect(described_class).to be < OneviewSDK::API300::Synergy::Alerts | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# (C) Copyright 2018 Hewlett Packard Enterprise Development LP | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# You may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software distributed | ||
# under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR | ||
# CONDITIONS OF ANY KIND, either express or implied. See the License for the | ||
# specific language governing permissions and limitations under the License. | ||
|
||
require 'spec_helper' | ||
|
||
RSpec.describe OneviewSDK::API600::C7000::Alerts do | ||
include_context 'shared context' | ||
|
||
it 'inherits from API500' do | ||
expect(described_class).to be < OneviewSDK::API500::C7000::Alerts | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# (C) Copyright 2018 Hewlett Packard Enterprise Development LP | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# You may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software distributed | ||
# under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR | ||
# CONDITIONS OF ANY KIND, either express or implied. See the License for the | ||
# specific language governing permissions and limitations under the License. | ||
|
||
require 'spec_helper' | ||
|
||
RSpec.describe OneviewSDK::API600::Synergy::Alerts do | ||
include_context 'shared context' | ||
|
||
it 'inherits from API500' do | ||
expect(described_class).to be < OneviewSDK::API500::Synergy::Alerts | ||
end | ||
end |