Add Events support

Adds support to POST events to the /v1/events API
endpoint.

Updates LAST_KNOWN_API_VERSION to 51.

Co-Authored-By: Harald Jensås <hjensas@redhat.com>
Story: 1304673
Task: 22149
Depends-On: https://review.openstack.org/631946
Change-Id: I6bc2d711687350ee3000b6898b68c3d05db62260
This commit is contained in:
Vasyl Saienko 2016-07-21 09:49:29 -04:00 committed by Harald Jensås
parent d15877f0fb
commit e8a6d447f8
5 changed files with 102 additions and 1 deletions

View File

@ -43,7 +43,7 @@ from ironicclient import exc
# http://specs.openstack.org/openstack/ironic-specs/specs/kilo/api-microversions.html # noqa
# for full details.
DEFAULT_VER = '1.9'
LAST_KNOWN_API_VERSION = 50
LAST_KNOWN_API_VERSION = 54
LATEST_VERSION = '1.{}'.format(LAST_KNOWN_API_VERSION)
LOG = logging.getLogger(__name__)

View File

@ -0,0 +1,58 @@
# 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.
import testtools
from ironicclient.tests.unit import utils
from ironicclient.v1 import events
FAKE_EVENT = {"event": "type.event"}
FAKE_NETWORK_PORT_EVENT = {
'event': "network.bind_port",
'port_id': '11111111-aaaa-bbbb-cccc-555555555555',
'mac_address': 'de:ad:ca:fe:ba:be',
'status': 'ACTIVE',
'device_id': '22222222-aaaa-bbbb-cccc-555555555555',
'binding:host_id': '22222222-aaaa-bbbb-cccc-555555555555',
'binding:vnic_type': 'baremetal',
}
FAKE_EVENTS = {'events': [FAKE_EVENT]}
FAKE_NETWORK_PORT_EVENTS = {'events': [FAKE_NETWORK_PORT_EVENT]}
fake_responses = {
'/v1/events':
{
'POST': (
{},
None
)
}
}
class EventManagerTest(testtools.TestCase):
def setUp(self):
super(EventManagerTest, self).setUp()
self.api = utils.FakeAPI(fake_responses)
self.mgr = events.EventManager(self.api)
def test_event(self):
evts = self.mgr.create(**FAKE_EVENTS)
expect = [('POST', '/v1/events', {}, FAKE_EVENTS)]
self.assertEqual(expect, self.api.calls)
self.assertIsNone(evts)
def test_network_port_event(self):
evts = self.mgr.create(**FAKE_NETWORK_PORT_EVENTS)
expect = [('POST', '/v1/events', {}, FAKE_NETWORK_PORT_EVENTS)]
self.assertEqual(expect, self.api.calls)
self.assertIsNone(evts)

View File

@ -23,6 +23,7 @@ from ironicclient import exc
from ironicclient.v1 import chassis
from ironicclient.v1 import conductor
from ironicclient.v1 import driver
from ironicclient.v1 import events
from ironicclient.v1 import node
from ironicclient.v1 import port
from ironicclient.v1 import portgroup
@ -99,6 +100,7 @@ class Client(object):
self.driver = driver.DriverManager(self.http_client)
self.portgroup = portgroup.PortgroupManager(self.http_client)
self.conductor = conductor.ConductorManager(self.http_client)
self.events = events.EventManager(self.http_client)
@property
def current_api_version(self):

29
ironicclient/v1/events.py Normal file
View File

@ -0,0 +1,29 @@
#
# Copyright 2016 Mirantis, Inc.
# All Rights Reserved.
#
# 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.
from ironicclient.common import base
class Event(base.Resource):
def __repr__(self):
return "<Event: %s>" % self.name
class EventManager(base.CreateManager):
resource_class = Event
_creation_attributes = ['events']
_resource_name = 'events'

View File

@ -0,0 +1,12 @@
---
features:
- |
Added ``Event`` resource , used to notify Ironic of external events.
.. Note:: Events are not intended for end-user usage. (Internal use only.)
- |
Added the ``client.events.create`` Python SDK method to support publishing
events to Ironic using the /v1/events API endpoint.
(available starting with API version 1.54).
.. Note:: Events are not intended for end-user usage. (Internal use only.)