From 6d98de4f331b3ebbbe735689eb077631d3881493 Mon Sep 17 00:00:00 2001 From: Stephen Finucane Date: Thu, 9 May 2024 12:51:20 +0100 Subject: [PATCH] compute: Add server tag proxy methods To add a tag, remove a tag, and remove all tags. Change-Id: I4c7533007bcc85e713c532830b979b9d3fedb612 Signed-off-by: Stephen Finucane --- doc/source/user/proxies/compute.rst | 7 ++++ openstack/compute/v2/_proxy.py | 33 +++++++++++++++++++ openstack/tests/unit/compute/v2/test_proxy.py | 24 ++++++++++++++ ...er-tag-proxy-methods-c791a36d8d4d85f6.yaml | 8 +++++ 4 files changed, 72 insertions(+) create mode 100644 releasenotes/notes/add-server-tag-proxy-methods-c791a36d8d4d85f6.yaml diff --git a/doc/source/user/proxies/compute.rst b/doc/source/user/proxies/compute.rst index b2b693bbf..681db0b10 100644 --- a/doc/source/user/proxies/compute.rst +++ b/doc/source/user/proxies/compute.rst @@ -121,6 +121,13 @@ Server Interface Operations :members: create_server_interface, delete_server_interface, get_server_interface, server_interfaces, +Server Tag Operations +^^^^^^^^^^^^^^^^^^^^^ + +.. autoclass:: openstack.compute.v2._proxy.Proxy + :noindex: + :members: add_tag_to_server, remove_tag_from_server, remove_tags_from_server + Availability Zone Operations ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/openstack/compute/v2/_proxy.py b/openstack/compute/v2/_proxy.py index f7c7ab7bd..744e7cd21 100644 --- a/openstack/compute/v2/_proxy.py +++ b/openstack/compute/v2/_proxy.py @@ -1195,6 +1195,39 @@ class Proxy(proxy.Proxy): server = self._get_resource(_server.Server, server) server.trigger_crash_dump(self) + def add_tag_to_server(self, server, tag): + """Add a tag to a server. + + :param server: Either the ID of a server or a + :class:`~openstack.compute.v2.server.Server` instance. + :param tag: The tag to add. + :returns: None + """ + server = self._get_resource(_server.Server, server) + server.add_tag(self, tag) + + def remove_tag_from_server(self, server, tag): + """Remove a tag from a server. + + :param server: Either the ID of a server or a + :class:`~openstack.compute.v2.server.Server` instance. + :param tag: The tag to remove. + :returns: None + """ + server = self._get_resource(_server.Server, server) + server.remove_tag(self, tag) + + def remove_tags_from_server(self, server): + """Remove all tags from a server. + + :param server: Either the ID of a server or a + :class:`~openstack.compute.v2.server.Server` instance. + :param tag: The tag to remove. + :returns: None + """ + server = self._get_resource(_server.Server, server) + server.remove_all_tags(self) + # ========== Server security groups ========== def fetch_server_security_groups(self, server): diff --git a/openstack/tests/unit/compute/v2/test_proxy.py b/openstack/tests/unit/compute/v2/test_proxy.py index a5aa9805a..e7a28d314 100644 --- a/openstack/tests/unit/compute/v2/test_proxy.py +++ b/openstack/tests/unit/compute/v2/test_proxy.py @@ -1277,6 +1277,30 @@ class TestCompute(TestComputeProxy): expected_args=[self.proxy], ) + def test_server_add_tag(self): + self._verify( + "openstack.compute.v2.server.Server.add_tag", + self.proxy.add_tag_to_server, + method_args=["value", "tag"], + expected_args=[self.proxy, "tag"], + ) + + def test_server_remove_tag(self): + self._verify( + "openstack.compute.v2.server.Server.remove_tag", + self.proxy.remove_tag_from_server, + method_args=["value", "tag"], + expected_args=[self.proxy, "tag"], + ) + + def test_server_remove_tags(self): + self._verify( + "openstack.compute.v2.server.Server.remove_all_tags", + self.proxy.remove_tags_from_server, + method_args=["value"], + expected_args=[self.proxy], + ) + def test_get_server_output(self): self._verify( "openstack.compute.v2.server.Server.get_console_output", diff --git a/releasenotes/notes/add-server-tag-proxy-methods-c791a36d8d4d85f6.yaml b/releasenotes/notes/add-server-tag-proxy-methods-c791a36d8d4d85f6.yaml new file mode 100644 index 000000000..f502d6102 --- /dev/null +++ b/releasenotes/notes/add-server-tag-proxy-methods-c791a36d8d4d85f6.yaml @@ -0,0 +1,8 @@ +--- +features: + - | + The following new compute proxy methods have been added: + + - ``add_tag_to_server`` + - ``remove_tag_from_server`` + - ``remove_tags_from_server``