diff --git a/lower-constraints.txt b/lower-constraints.txt index f4796606d..2fa93b0b2 100644 --- a/lower-constraints.txt +++ b/lower-constraints.txt @@ -129,6 +129,7 @@ python-tackerclient==0.8.0 python-troveclient==2.2.0 python-vitrageclient==2.0.0 python-zaqarclient==1.0.0 +python-zunclient==1.0.0 pytz==2013.6 PyYAML==3.12 reno==2.5.0 diff --git a/mistral/actions/generator_factory.py b/mistral/actions/generator_factory.py index 8bd040380..cb8a8ac43 100644 --- a/mistral/actions/generator_factory.py +++ b/mistral/actions/generator_factory.py @@ -21,7 +21,7 @@ SUPPORTED_MODULES = [ 'Nova', 'Glance', 'Keystone', 'Heat', 'Neutron', 'Cinder', 'Trove', 'Ironic', 'Baremetal Introspection', 'Swift', 'SwiftService', 'Zaqar', 'Barbican', 'Mistral', 'Designate', 'Magnum', 'Murano', 'Tacker', - 'Aodh', 'Gnocchi', 'Glare', 'Vitrage', 'Senlin' + 'Aodh', 'Gnocchi', 'Glare', 'Vitrage', 'Senlin', 'Zun' ] diff --git a/mistral/actions/openstack/actions.py b/mistral/actions/openstack/actions.py index 157d6191b..e4166740f 100644 --- a/mistral/actions/openstack/actions.py +++ b/mistral/actions/openstack/actions.py @@ -72,6 +72,7 @@ tackerclient = _try_import('tackerclient.v1_0.client') troveclient = _try_import('troveclient.v1.client') vitrageclient = _try_import('vitrageclient.v1.client') zaqarclient = _try_import('zaqarclient.queues.client') +zunclient = _try_import('zunclient.v1.client') class NovaAction(base.OpenStackAction): @@ -940,3 +941,36 @@ class VitrageAction(base.OpenStackAction): @classmethod def _get_fake_client(cls): return cls._get_client_class()() + + +class ZunAction(base.OpenStackAction): + _service_name = 'appcontainer' + + @classmethod + def _get_client_class(cls): + return zunclient.Client + + def _create_client(self, context): + + LOG.debug("Zun action security context: %s", context) + + keystone_endpoint = keystone_utils.get_keystone_endpoint_v2() + zun_endpoint = self.get_service_endpoint() + session_and_auth = self.get_session_and_auth(context) + + client = self._get_client_class()( + '1', + endpoint_override=zun_endpoint.url, + auth_url=keystone_endpoint.url, + session=session_and_auth['session'] + ) + + return client + + @classmethod + def _get_fake_client(cls): + session = keystone_utils.get_admin_session() + return cls._get_client_class()( + endpoint_override="http://127.0.0.1:9517/", + session=session + ) diff --git a/mistral/actions/openstack/mapping.json b/mistral/actions/openstack/mapping.json index a6d02ed6e..55ffb6585 100644 --- a/mistral/actions/openstack/mapping.json +++ b/mistral/actions/openstack/mapping.json @@ -1268,5 +1268,42 @@ "webhook_show": "webhook.show", "webhook_add": "webhook.add", "webhook_delete": "webhook.delete" + }, + "zun":{ + "_comment": "It uses zunclient.v1. ", + "containers_add_security_group": "containers.add_security_group", + "containers_attach": "containers.attach", + "containers_commit": "containers.commit", + "containers_create": "containers.create", + "containers_delete": "containers.delete", + "containers_execute": "containers.execute", + "containers_execute_resize": "containers.execute_resize", + "containers_get": "containers.get", + "containers_get_archive": "containers.get_archive", + "containers_kill": "containers.kill", + "containers_list": "containers.list", + "containers_logs": "containers.logs", + "containers_network_attach": "containers.network_attach", + "containers_network_detach": "containers.network_detach", + "containers_pause": "containers.pause", + "containers_put_archive": "containers.put_archive", + "containers_remove_security_group": "containers.remove_security_group", + "containers_rename": "containers.rename", + "containers_resize": "containers.resize", + "containers_restart": "containers.restart", + "containers_run": "containers.run", + "containers_start": "containers.start", + "containers_stats": "containers.stats", + "containers_stop": "containers.stop", + "containers_top": "containers.top", + "containers_update": "containers.update", + "hosts_list": "hosts.list", + "hosts_get": "hosts.get", + "images_delete": "images.delete", + "images_list": "images.list", + "services_delete": "services.delete", + "services_disable": "services.disable", + "services_enable": "services.enable", + "services_list": "services.list" } } diff --git a/mistral/tests/unit/actions/openstack/test_generator.py b/mistral/tests/unit/actions/openstack/test_generator.py index 8c96bddab..abd74cb04 100644 --- a/mistral/tests/unit/actions/openstack/test_generator.py +++ b/mistral/tests/unit/actions/openstack/test_generator.py @@ -55,7 +55,8 @@ MODULE_MAPPING = { 'aodh': ['aodh.alarm_list', actions.AodhAction], 'gnocchi': ['gnocchi.metric_list', actions.GnocchiAction], 'glare': ['glare.artifacts_list', actions.GlareAction], - 'vitrage': ['vitrage.alarm_get', actions.VitrageAction] + 'vitrage': ['vitrage.alarm_get', actions.VitrageAction], + 'zun': ['zun.containers_list', actions.ZunAction] } EXTRA_MODULES = ['neutron', 'swift', 'zaqar', 'tacker', 'senlin'] diff --git a/mistral/tests/unit/actions/openstack/test_openstack_actions.py b/mistral/tests/unit/actions/openstack/test_openstack_actions.py index 44d4da136..84df98582 100644 --- a/mistral/tests/unit/actions/openstack/test_openstack_actions.py +++ b/mistral/tests/unit/actions/openstack/test_openstack_actions.py @@ -359,3 +359,18 @@ class OpenStackActionTest(base.BaseTestCase): self.assertTrue(mocked().alarm.get.called) mocked().alarm.get.assert_called_once_with(vitrage_id="1234-abcd") + + @mock.patch.object(actions.ZunAction, '_get_client') + def test_zun_action(self, mocked): + mock_ctx = mock.Mock() + method_name = "containers.get" + action_class = actions.ZunAction + action_class.client_method_name = method_name + params = {'container_id': '1234-abcd'} + action = action_class(**params) + action.run(mock_ctx) + + self.assertTrue(mocked().containers.get.called) + mocked().containers.get.assert_called_once_with( + container_id="1234-abcd" + ) diff --git a/releasenotes/notes/support-zun-action-3263350334d1d34f.yaml b/releasenotes/notes/support-zun-action-3263350334d1d34f.yaml new file mode 100644 index 000000000..96a895cc1 --- /dev/null +++ b/releasenotes/notes/support-zun-action-3263350334d1d34f.yaml @@ -0,0 +1,4 @@ +--- +features: + - | + Add Mistral actions for Openstack Zun, the container service. diff --git a/requirements.txt b/requirements.txt index bb5b281f2..3e40e2015 100644 --- a/requirements.txt +++ b/requirements.txt @@ -50,6 +50,7 @@ python-ironicclient>=2.3.0 # Apache-2.0 python-ironic-inspector-client>=1.5.0 # Apache-2.0 python-vitrageclient>=2.0.0 # Apache-2.0 python-zaqarclient>=1.0.0 # Apache-2.0 +python-zunclient>=1.0.0 # Apache-2.0 PyJWT>=1.0.1 # MIT PyYAML>=3.12 # MIT requests>=2.14.2 # Apache-2.0