Skip to content

Commit

Permalink
Add filesystem selection which is always None
Browse files Browse the repository at this point in the history
Signed-off-by: mulhern <amulhern@redhat.com>
  • Loading branch information
mulkieran committed Jan 15, 2024
1 parent 04043a1 commit 9014e03
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 5 deletions.
8 changes: 6 additions & 2 deletions src/stratis_cli/_actions/_list_filesystem.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,15 @@
from ._formatting import TOTAL_USED_FREE, get_property, print_table, size_triple


def list_filesystems(uuid_formatter, *, pool_selection=None):
def list_filesystems(uuid_formatter, *, pool_selection=None, fs_selection=None):
"""
List the specified information about filesystems.
"""
klass = List(uuid_formatter, pool_selection=pool_selection)
if fs_selection is None:
klass = List(uuid_formatter, pool_selection=pool_selection)
else: # pragma: no cover
klass = List(uuid_formatter, pool_selection=pool_selection)

klass.list_filesystems()


Expand Down
18 changes: 15 additions & 3 deletions src/stratis_cli/_actions/_logical.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
from ._constants import TOP_OBJECT
from ._formatting import get_uuid_formatter
from ._list_filesystem import list_filesystems
from ._utils import PoolSelector
from ._utils import FsSelector, PoolSelector


class LogicalActions:
Expand Down Expand Up @@ -120,15 +120,27 @@ def list_volumes(namespace):
"""
# This method is invoked as the default for "stratis filesystem";
# these namespace fields may not have been set.
pool_name = getattr(namespace, "pool_name", None)
(pool_name, fs_name, fs_uuid) = (
getattr(namespace, "pool_name", None),
getattr(namespace, "uuid", None),
getattr(namespace, "name", None),
)

uuid_formatter = get_uuid_formatter(namespace.unhyphenated_uuids)

pool_selection = (
None if pool_name is None else PoolSelector(Id(IdType.NAME, pool_name))
)

return list_filesystems(uuid_formatter, pool_selection=pool_selection)
fs_selection = (
(None if fs_name is None else FsSelector(Id(IdType.NAME, fs_name)))
if fs_uuid is None
else FsSelector(Id(IdType.UUID, fs_uuid))
)

return list_filesystems(
uuid_formatter, pool_selection=pool_selection, fs_selection=fs_selection
)

@staticmethod
def destroy_volumes(namespace):
Expand Down
26 changes: 26 additions & 0 deletions src/stratis_cli/_actions/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,3 +230,29 @@ def selection_func(_uuid, info):

def __str__(self):
return f"pool with {self.pool_id}"


class FsSelector:
"""
Methods to help locate a filesystem by one of its identifiers.
"""

def __init__(self, fs_id):
"""
Initializer.
:param Id pool_id: the id
"""
self.fs_id = fs_id

def managed_objects_key(self, pool_object_path):
"""
Get the key for searching GetManagedObjects result.
:param str pool_object_path: object path of this filesystem's pool
:rtype: dict of str * object
:returns: a dict containing a configuration for filesystems() method
"""
return self.fs_id.managed_objects_key() | {"Pool": pool_object_path}

def __str__(self):
return f"filesystem with {self.fs_id}"

0 comments on commit 9014e03

Please sign in to comment.