Skip to content

Commit

Permalink
Merge pull request #363 from HewlettPackard/API200/Alerts
Browse files Browse the repository at this point in the history
Adding a new resource Alerts
Sowmyahsg authored Jun 15, 2018
2 parents 17d3c09 + c72cc2f commit d1c046c
Showing 17 changed files with 392 additions and 8 deletions.
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
## v5.5.1 (Unreleased)
## v5.6.0

#### Notes
This release fixes few bugs which are listed below.

#### New Resource
Alerts

#### Bug fixes & Enhancements
- Added helper method to change request body for Server Profile for API600.
- [#354](https://github.com/HewlettPackard/oneview-sdk-ruby/issues/354) Input data has be to be a part of body, but not the header for import certificate method in enclosure.
14 changes: 7 additions & 7 deletions endpoints-support.md
Original file line number Diff line number Diff line change
@@ -24,13 +24,13 @@ OneviewSDK::Datacenter.find_by(@client, width: 11000).map(&:remove)

| Endpoints | Verb | V200 | V300 | V500 | V600 |
| --------------------------------------------------------------------------------------- | -------- | :------------------: | :------------------: | :------------------: | :------------------: |
| **Alerts** |
|<sub>/rest/alerts </sub> |GET | | |
|<sub>/rest/alerts </sub> |DELETE | | |
|<sub>/rest/alerts/{id} </sub> |GET | | |
|<sub>/rest/alerts/{id} </sub> |PUT | | |
|<sub>/rest/alerts/{id} </sub> |DELETE | | |
|<sub>/rest/alerts/AlertChangeLog/{id}</sub> |DELETE | | |
| **Alerts** |
|<sub>/rest/alerts</sub> |GET | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: |
|<sub>/rest/alerts</sub> |DELETE | :heavy_multiplication_x: | :heavy_multiplication_x: | :heavy_multiplication_x: | :heavy_multiplication_x: |
|<sub>/rest/alerts/{id}</sub> |GET | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: |
|<sub>/rest/alerts/{id}</sub> |PUT | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: |
|<sub>/rest/alerts/{id}</sub> |DELETE | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: |
|<sub>/rest/alerts/AlertChangeLog/{id}</sub> |DELETE | :white_check_mark: | :white_check_mark: |:white_check_mark: | :white_check_mark: |
| **Appliance Time and Locale Configuration** |
|<sub>/rest/appliance/configuration/time-locale</sub> |GET | :heavy_multiplication_x: | :heavy_multiplication_x: | :heavy_multiplication_x: |
|<sub>/rest/appliance/configuration/time-locale</sub> |POST | :heavy_multiplication_x: | :heavy_multiplication_x: | :heavy_multiplication_x: |
54 changes: 54 additions & 0 deletions examples/shared_samples/alerts.rb
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
39 changes: 39 additions & 0 deletions lib/oneview-sdk/resource/api200/alerts.rb
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
22 changes: 22 additions & 0 deletions lib/oneview-sdk/resource/api300/c7000/alerts.rb
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
22 changes: 22 additions & 0 deletions lib/oneview-sdk/resource/api300/synergy/alerts.rb
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
22 changes: 22 additions & 0 deletions lib/oneview-sdk/resource/api500/c7000/alerts.rb
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
22 changes: 22 additions & 0 deletions lib/oneview-sdk/resource/api500/synergy/alerts.rb
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
22 changes: 22 additions & 0 deletions lib/oneview-sdk/resource/api600/c7000/alerts.rb
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
22 changes: 22 additions & 0 deletions lib/oneview-sdk/resource/api600/synergy/alerts.rb
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
36 changes: 36 additions & 0 deletions spec/unit/resource/api200/alerts_spec.rb
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
20 changes: 20 additions & 0 deletions spec/unit/resource/api300/c7000/alerts_spec.rb
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
20 changes: 20 additions & 0 deletions spec/unit/resource/api300/synergy/alerts_spec.rb
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
20 changes: 20 additions & 0 deletions spec/unit/resource/api500/c7000/alerts_spec.rb
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
20 changes: 20 additions & 0 deletions spec/unit/resource/api500/synergy/alerts_spec.rb
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
20 changes: 20 additions & 0 deletions spec/unit/resource/api600/c7000/alerts_spec.rb
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
20 changes: 20 additions & 0 deletions spec/unit/resource/api600/synergy/alerts_spec.rb
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

0 comments on commit d1c046c

Please sign in to comment.