Skip to content

Commit

Permalink
Convert StoppedPool to use pydantic
Browse files Browse the repository at this point in the history
Signed-off-by: mulhern <amulhern@redhat.com>
  • Loading branch information
mulkieran committed May 29, 2024
1 parent 8f8c7b4 commit 95c2400
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 26 deletions.
4 changes: 2 additions & 2 deletions src/stratis_cli/_actions/_list_pool.py
Original file line number Diff line number Diff line change
Expand Up @@ -534,7 +534,7 @@ def display(self):

(pool_uuid, pool) = stopped_pool

self._print_detail_view(pool_uuid, StoppedPool(pool))
self._print_detail_view(pool_uuid, StoppedPool(**pool))


class StoppedTable(Stopped): # pylint: disable=too-few-public-methods
Expand Down Expand Up @@ -582,7 +582,7 @@ def key_description_str(value):
clevis_str(sp.clevis_info),
)
for pool_uuid, sp in (
(pool_uuid, StoppedPool(info))
(pool_uuid, StoppedPool(**info))
for pool_uuid, info in stopped_pools.items()
)
]
Expand Down
34 changes: 10 additions & 24 deletions src/stratis_cli/_actions/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,12 @@

# isort: STDLIB
import json
from typing import List, Optional
from uuid import UUID

# isort: THIRDPARTY
from pydantic import BaseModel

from .._constants import Clevis
from .._stratisd_constants import (
CLEVIS_KEY_TANG_TRUST_URL,
Expand Down Expand Up @@ -151,33 +155,15 @@ def __init__(self, mapping):
self.devnode = str(mapping["devnode"])


class StoppedPool: # pylint: disable=too-few-public-methods
class StoppedPool(BaseModel):
"""
A representation of a single stopped pool.
A representaton of a single stopped pool.
"""

def __init__(self, pool_info):
"""
Initializer.
:param pool_info: a D-Bus structure
"""

self.devs = [Device(info) for info in pool_info["devs"]]

clevis_info = pool_info.get("clevis_info")
self.clevis_info = (
None if clevis_info is None else EncryptionInfoClevis(clevis_info)
)

key_description = pool_info.get("key_description")
self.key_description = (
None
if key_description is None
else EncryptionInfoKeyDescription(key_description)
)

name = pool_info.get("name")
self.name = None if name is None else str(name)
devs: List[Device]
clevis_info: Optional[EncryptionInfoClevis]
key_description: Optional[EncryptionInfoKeyDescription]
name: Optional[str]


class PoolSelector:
Expand Down

0 comments on commit 95c2400

Please sign in to comment.