diff --git a/openstack/compute/v2/_proxy.py b/openstack/compute/v2/_proxy.py index 675b47003..7d28bbdee 100644 --- a/openstack/compute/v2/_proxy.py +++ b/openstack/compute/v2/_proxy.py @@ -1267,7 +1267,7 @@ class Proxy(proxy.Proxy): :param server: Either the ID of a server or a :class:`~openstack.compute.v2.server.Server` instance. - :param security_group: Either the ID, Name of a security group or a + :param security_group: Either the ID or name of a security group or a :class:`~openstack.network.v2.security_group.SecurityGroup` instance. @@ -1275,14 +1275,17 @@ class Proxy(proxy.Proxy): """ server = self._get_resource(_server.Server, server) security_group = self._get_resource(_sg.SecurityGroup, security_group) - server.add_security_group(self, security_group.name) + server.add_security_group( + self, + security_group.name or security_group.id, + ) def remove_security_group_from_server(self, server, security_group): """Remove a security group from a server :param server: Either the ID of a server or a :class:`~openstack.compute.v2.server.Server` instance. - :param security_group: Either the ID of a security group or a + :param security_group: Either the ID or name of a security group or a :class:`~openstack.network.v2.security_group.SecurityGroup` instance. @@ -1290,7 +1293,10 @@ class Proxy(proxy.Proxy): """ server = self._get_resource(_server.Server, server) security_group = self._get_resource(_sg.SecurityGroup, security_group) - server.remove_security_group(self, security_group.name) + server.remove_security_group( + self, + security_group.name or security_group.id, + ) # ========== Server IPs ========== diff --git a/openstack/tests/unit/compute/v2/test_proxy.py b/openstack/tests/unit/compute/v2/test_proxy.py index 996ccb88b..7de6c5e69 100644 --- a/openstack/tests/unit/compute/v2/test_proxy.py +++ b/openstack/tests/unit/compute/v2/test_proxy.py @@ -1522,7 +1522,7 @@ class TestCompute(TestComputeProxy): self._verify( 'openstack.compute.v2.server.Server.add_security_group', self.proxy.add_security_group_to_server, - method_args=["value", {'id': 'id', 'name': 'sg'}], + method_args=["value", 'sg'], expected_args=[self.proxy, 'sg'], ) @@ -1530,7 +1530,7 @@ class TestCompute(TestComputeProxy): self._verify( 'openstack.compute.v2.server.Server.remove_security_group', self.proxy.remove_security_group_from_server, - method_args=["value", {'id': 'id', 'name': 'sg'}], + method_args=["value", 'sg'], expected_args=[self.proxy, 'sg'], )