diff --git a/juju/client/connection.py b/juju/client/connection.py index cc708eba9..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]}, + 'Spaces': {'versions': [2, 3, 4, 5, 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..9342df475 100644 --- a/juju/tag.py +++ b/juju/tag.py @@ -50,3 +50,7 @@ def unit(unit_name): def action(action_uuid): return _prefix('action-', action_uuid) + + +def space(space_name): + return _prefix('space-', space_name)