diff --git a/esi/lease/v1/_proxy.py b/esi/lease/v1/_proxy.py index d4a87eb..508d5a6 100644 --- a/esi/lease/v1/_proxy.py +++ b/esi/lease/v1/_proxy.py @@ -11,6 +11,7 @@ # under the License. from esi.lease.v1 import _common +from esi.lease.v1 import console_auth_token as _console_auth_token from esi.lease.v1 import event as _event from esi.lease.v1 import lease as _lease from esi.lease.v1 import node as _node @@ -25,7 +26,8 @@ class Proxy(proxy.Proxy): "offer": _offer.Offer, "lease": _lease.Lease, "node": _node.Node, - "event": _event.Event + "event": _event.Event, + "console_auth_token": _console_auth_token.ConsoleAuthToken, } skip_discovery = True @@ -245,3 +247,31 @@ def events(self, **query): :returns: A generator of event instances. """ return _event.Event.list(self, **query) + + def create_console_auth_token(self, **attrs): + """Create a new console auth token from attributes. + + :param string node_uuid_or_name: node uuid or name + + :returns: The results of token creation. + :rtype: :class:`~esi_leap.v1.console_auth_token.ConsoleAuthToken`. + """ + return self._create(_console_auth_token.ConsoleAuthToken, **attrs) + + def delete_console_auth_token(self, node_uuid_or_name, ignore_missing=True): + """Delete a console auth token for a node. + + :param string node_uuid_or_name: node uuid or name + :param bool ignore_missing: When set to ``False``, an exception + :class:`~openstack.exceptions.ResourceNotFound` will be raised + when the node could not be found. When set to ``True``, no + exception will be raised when attempting to delete a non-existent + offer. + + :returns: The result of delete. + :rtype: :class:`~esi_leap.v1.console_auth_token.ConsoleAuthToken`. + """ + return self._delete( + _console_auth_token.ConsoleAuthToken, + node_uuid_or_name, + ignore_missing=ignore_missing) diff --git a/esi/lease/v1/console_auth_token.py b/esi/lease/v1/console_auth_token.py new file mode 100644 index 0000000..088eaa3 --- /dev/null +++ b/esi/lease/v1/console_auth_token.py @@ -0,0 +1,35 @@ +# 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 openstack import resource + + +class ConsoleAuthToken(resource.Resource): + resources_key = 'console_auth_tokens' + base_path = '/console_auth_tokens' + + # capabilities + allow_create = True + allow_fetch = False + allow_commit = True + allow_delete = True + allow_list = False + commit_method = 'PATCH' + commit_jsonpatch = True + + #: The transaction date and time. + timestamp = resource.Header("x-timestamp") + #: The value of the resource. Also available in headers. + node_uuid = resource.Body("node_uuid", alternate_id=True) + node_uuid_or_name = resource.Body("node_uuid_or_name") + token = resource.Body("token") + access_url = resource.Body("access_url") diff --git a/esi/tests/unit/lease/v1/test_console_auth_token.py b/esi/tests/unit/lease/v1/test_console_auth_token.py new file mode 100644 index 0000000..d0663a1 --- /dev/null +++ b/esi/tests/unit/lease/v1/test_console_auth_token.py @@ -0,0 +1,40 @@ +# 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 esi.lease.v1 import console_auth_token +from openstack.tests.unit import base + + +FAKE = {'node_uuid': 'node_001', + 'token': 'fake_token', + 'access_url': 'ws://0.0.0.0:7777?token=fake_token', + } + + +class TestConsoleAuthToken(base.TestCase): + def test_basic(self): + c = console_auth_token.ConsoleAuthToken() + self.assertIsNone(c.resource_key) + self.assertEqual('console_auth_tokens', c.resources_key) + self.assertEqual('/console_auth_tokens', c.base_path) + self.assertTrue(c.allow_create) + self.assertFalse(c.allow_fetch) + self.assertTrue(c.allow_commit) + self.assertTrue(c.allow_delete) + self.assertFalse(c.allow_list) + self.assertEqual('PATCH', c.commit_method) + + def test_instantiate(self): + c = console_auth_token.ConsoleAuthToken(**FAKE) + self.assertEqual(FAKE['node_uuid'], c.node_uuid) + self.assertEqual(FAKE['token'], c.token) + self.assertEqual(FAKE['access_url'], c.access_url) diff --git a/esi/tests/unit/lease/v1/test_proxy.py b/esi/tests/unit/lease/v1/test_proxy.py index 3777652..f165356 100644 --- a/esi/tests/unit/lease/v1/test_proxy.py +++ b/esi/tests/unit/lease/v1/test_proxy.py @@ -13,6 +13,7 @@ from unittest import mock from esi.lease.v1 import _proxy +from esi.lease.v1 import console_auth_token from esi.lease.v1 import event from esi.lease.v1 import lease from esi.lease.v1 import node @@ -93,3 +94,13 @@ def test_events(self, mock_list): result = self.proxy.events(query=1) self.assertIs(result, mock_list.return_value) mock_list.assert_called_once_with(self.proxy, query=1) + + +class TestConsoleAuthToken(TestESILEAPProxy): + def test_create_console_auth_token(self): + self.verify_create(self.proxy.create_console_auth_token, + console_auth_token.ConsoleAuthToken) + + def test_delete_console_auth_token(self): + self.verify_delete(self.proxy.delete_console_auth_token, + console_auth_token.ConsoleAuthToken, False)