diff --git a/ironicclient/common/http.py b/ironicclient/common/http.py index 735cebce9..57652bb32 100644 --- a/ironicclient/common/http.py +++ b/ironicclient/common/http.py @@ -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__) diff --git a/ironicclient/tests/unit/v1/test_events.py b/ironicclient/tests/unit/v1/test_events.py new file mode 100644 index 000000000..c70693265 --- /dev/null +++ b/ironicclient/tests/unit/v1/test_events.py @@ -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) diff --git a/ironicclient/v1/client.py b/ironicclient/v1/client.py index 81f73d428..dc5480493 100644 --- a/ironicclient/v1/client.py +++ b/ironicclient/v1/client.py @@ -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): diff --git a/ironicclient/v1/events.py b/ironicclient/v1/events.py new file mode 100644 index 000000000..8c7b2f771 --- /dev/null +++ b/ironicclient/v1/events.py @@ -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 "" % self.name + + +class EventManager(base.CreateManager): + resource_class = Event + _creation_attributes = ['events'] + _resource_name = 'events' diff --git a/releasenotes/notes/add-events-support-53c461d28abf010b.yaml b/releasenotes/notes/add-events-support-53c461d28abf010b.yaml new file mode 100644 index 000000000..9cdeee464 --- /dev/null +++ b/releasenotes/notes/add-events-support-53c461d28abf010b.yaml @@ -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.)