Skip to content

Commit

Permalink
Address review
Browse files Browse the repository at this point in the history
  • Loading branch information
themylogin committed Dec 17, 2024
1 parent 411ac37 commit 394daf3
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 26 deletions.
12 changes: 4 additions & 8 deletions src/middlewared/middlewared/api/v25_04_0/enclosure_label.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
from middlewared.api.base import BaseModel, ForUpdateMetaclass
from middlewared.api.base import BaseModel

__all__ = ["EnclosureLabelUpdateData", "EnclosureLabelUpdateArgs", "EnclosureLabelUpdateResult"]
__all__ = ["EnclosureLabelSetArgs", "EnclosureLabelUpdateResult"]


class EnclosureLabelUpdateData(BaseModel, metaclass=ForUpdateMetaclass):
label: str


class EnclosureLabelUpdateArgs(BaseModel):
class EnclosureLabelSetArgs(BaseModel):
id: str
enclosure_update: EnclosureLabelUpdateData
label: str


class EnclosureLabelUpdateResult(BaseModel):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ def query(self, filters, options):
# this feature is only available on hardware that ix sells
return enclosures

labels = self.middleware.call_sync('enclosure.get_labels')
labels = self.middleware.call_sync('enclosure.label.get_all')
for i in self.get_ses_enclosures() + self.map_nvme() + self.middleware.call_sync('enclosure2.map_jbof'):
if i.pop('should_ignore'):
continue
Expand Down
31 changes: 15 additions & 16 deletions src/middlewared/middlewared/plugins/enclosure_/enclosure_label.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import middlewared.sqlalchemy as sa

from middlewared.api import api_method
from middlewared.api.current import EnclosureLabelUpdateArgs, EnclosureLabelUpdateResult
from middlewared.api.current import EnclosureLabelSetArgs, EnclosureLabelUpdateResult
from middlewared.service import private, Service


Expand All @@ -15,24 +15,23 @@ class EnclosureLabelModel(sa.Model):

class EnclosureService(Service):
class Config:
namespace = "enclosure"
cli_namespace = "storage.enclosure"

@api_method(EnclosureLabelUpdateArgs, EnclosureLabelUpdateResult)
async def update(self, id_, data):
if "label" in data:
await self.middleware.call(
"datastore.delete", "enclosure.label", [["encid", "=", id_]]
)
await self.middleware.call(
"datastore.insert",
"enclosure.label",
{"encid": id_, "label": data["label"]},
)
namespace = "enclosure.label"
cli_namespace = "storage.enclosure.label"

@private
async def get_labels(self):
async def get_all(self):
return {
label["encid"]: label["label"]
for label in await self.middleware.call("datastore.query", "enclosure.label")
}

@api_method(EnclosureLabelSetArgs, EnclosureLabelUpdateResult)
async def set(self, id_, label):
await self.middleware.call(
"datastore.delete", "enclosure.label", [["encid", "=", id_]]
)
await self.middleware.call(
"datastore.insert",
"enclosure.label",
{"encid": id_, "label": label},
)
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def test_enclosure2_query(enc2_data):
e.middleware._resolve_methods([Enclosure2Service], [])
e.middleware['truenas.get_chassis_hardware'] = Mock(return_value=enc2_mocked.chassis)
e.middleware['truenas.is_ix_hardware'] = Mock(return_value=True)
e.middleware['enclosure.get_labels'] = Mock(return_value=enc2_mocked.labels)
e.middleware['enclosure.label.get_all'] = Mock(return_value=enc2_mocked.labels)
e.middleware['system.dmidecode_info'] = Mock(return_value=enc2_mocked.dmi)
e.middleware['jbof.query'] = Mock(return_value=[])
e.middleware['enclosure2.map_jbof'] = Mock(return_value=[])
Expand Down

0 comments on commit 394daf3

Please sign in to comment.