From cc84118ce48616405ee0c16492304ee4f0ee4683 Mon Sep 17 00:00:00 2001 From: Liam Young Date: Sat, 30 Jan 2021 12:48:44 +0000 Subject: [PATCH 1/3] Implement add_space and get_spaces This PR implements add_space and get_spaces. Since spaces are not implemented with the LXD provider there is not corresponding functional test. Closes issue #466. --- juju/client/connection.py | 2 +- juju/model.py | 20 ++++++++++++++------ juju/tag.py | 3 +++ 3 files changed, 18 insertions(+), 7 deletions(-) diff --git a/juju/client/connection.py b/juju/client/connection.py index cc708eba9..9e091a088 100644 --- a/juju/client/connection.py +++ b/juju/client/connection.py @@ -99,7 +99,7 @@ 'RetryStrategy': {'versions': [1]}, 'Singular': {'versions': [2]}, 'SSHClient': {'versions': [1, 2]}, - 'Spaces': {'versions': [2, 3]}, + 'Spaces': {'versions': [2, 3, 6]}, 'StatusHistory': {'versions': [2]}, 'Storage': {'versions': [3, 4]}, 'StorageProvisioner': {'versions': [3, 4]}, diff --git a/juju/model.py b/juju/model.py index 5937525f4..416ffba77 100644 --- a/juju/model.py +++ b/juju/model.py @@ -1222,17 +1222,22 @@ def _find_relation(*specs): await self.block_until(lambda: _find_relation(*specs) is not None) return _find_relation(*specs) - def add_space(self, name, *cidrs): + async def add_space(self, name, cidrs=None, public=True): """Add a new network space. Adds a new space with the given name and associates the given (optional) list of existing subnet CIDRs with it. :param str name: Name of the space - :param *cidrs: Optional list of existing subnet CIDRs - + :param List[str] cidrs: Optional list of existing subnet CIDRs """ - raise NotImplementedError() + space_facade = client.SpacesFacade.from_connection(self.connection()) + spaces = [ + { + "cidrs": cidrs, + "space-tag": tag.space(name), + "public": public}] + return await space_facade.CreateSpaces(spaces=spaces) async def add_ssh_key(self, user, key): """Add a public SSH key to this model. @@ -1668,11 +1673,14 @@ def get_shares(self): """ raise NotImplementedError() - def get_spaces(self): + async def get_spaces(self): """Return list of all known spaces, including associated subnets. + Returns a List of :class:`~juju._definitions.Space` instances. """ - raise NotImplementedError() + space_facade = client.SpacesFacade.from_connection(self.connection()) + response = await space_facade.ListSpaces() + return response.results async def get_ssh_key(self, raw_ssh=False): """Return known SSH keys for this model. diff --git a/juju/tag.py b/juju/tag.py index 78ab4e48b..4c140ba4e 100644 --- a/juju/tag.py +++ b/juju/tag.py @@ -50,3 +50,6 @@ def unit(unit_name): def action(action_uuid): return _prefix('action-', action_uuid) + +def space(space_name): + return _prefix('space-', space_name) From 7c2294a33a682b812a005a777c3a3221e62f7491 Mon Sep 17 00:00:00 2001 From: Liam Young Date: Sun, 31 Jan 2021 15:30:53 +0000 Subject: [PATCH 2/3] Add facade versions 4 & 5 to Spaces --- juju/client/connection.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/juju/client/connection.py b/juju/client/connection.py index 9e091a088..bea64bb7f 100644 --- a/juju/client/connection.py +++ b/juju/client/connection.py @@ -99,7 +99,7 @@ 'RetryStrategy': {'versions': [1]}, 'Singular': {'versions': [2]}, 'SSHClient': {'versions': [1, 2]}, - 'Spaces': {'versions': [2, 3, 6]}, + 'Spaces': {'versions': [2, 3, 4, 5, 6]}, 'StatusHistory': {'versions': [2]}, 'Storage': {'versions': [3, 4]}, 'StorageProvisioner': {'versions': [3, 4]}, From 2a20c2b62259ac6780de5916ea408427a3f8a70e Mon Sep 17 00:00:00 2001 From: Liam Young Date: Mon, 1 Feb 2021 09:25:31 +0000 Subject: [PATCH 3/3] Fix blank line lint --- juju/tag.py | 1 + 1 file changed, 1 insertion(+) diff --git a/juju/tag.py b/juju/tag.py index 4c140ba4e..9342df475 100644 --- a/juju/tag.py +++ b/juju/tag.py @@ -51,5 +51,6 @@ def unit(unit_name): def action(action_uuid): return _prefix('action-', action_uuid) + def space(space_name): return _prefix('space-', space_name)