Skip to content

Commit

Permalink
NAS-132961 / 25.04 / Move enclosure label to its own file (#15215)
Browse files Browse the repository at this point in the history
* Move enclosure label to its own file

* Address review
  • Loading branch information
themylogin authored Dec 18, 2024
1 parent 48ed775 commit 9da3a5b
Show file tree
Hide file tree
Showing 7 changed files with 80 additions and 42 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
"""Rename `enclosure_label` table
Revision ID: 19cdc9f2d2df
Revises: b44c092bfa30
Create Date: 2024-12-16 12:49:19.950812+00:00
"""
from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision = '19cdc9f2d2df'
down_revision = 'b44c092bfa30'
branch_labels = None
depends_on = None


def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.execute("ALTER TABLE truenas_enclosurelabel RENAME TO enclosure_label")
# ### end Alembic commands ###


def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
pass
# ### end Alembic commands ###
1 change: 1 addition & 0 deletions src/middlewared/middlewared/api/v25_04_0/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
from .disk import * # noqa
from .docker import * # noqa
from .docker_network import * # noqa
from .enclosure_label import * # noqa
from .failover_reboot import * # noqa
from .fc_host import * # noqa
from .fcport import * # noqa
Expand Down
12 changes: 12 additions & 0 deletions src/middlewared/middlewared/api/v25_04_0/enclosure_label.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from middlewared.api.base import BaseModel

__all__ = ["EnclosureLabelSetArgs", "EnclosureLabelUpdateResult"]


class EnclosureLabelSetArgs(BaseModel):
id: str
label: str


class EnclosureLabelUpdateResult(BaseModel):
result: None
37 changes: 0 additions & 37 deletions src/middlewared/middlewared/plugins/enclosure.py

This file was deleted.

5 changes: 1 addition & 4 deletions src/middlewared/middlewared/plugins/enclosure_/enclosure2.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,10 +139,7 @@ def query(self, filters, options):
# this feature is only available on hardware that ix sells
return enclosures

labels = {
label['encid']: label['label']
for label in self.middleware.call_sync('datastore.query', 'truenas.enclosurelabel')
}
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
37 changes: 37 additions & 0 deletions src/middlewared/middlewared/plugins/enclosure_/enclosure_label.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import middlewared.sqlalchemy as sa

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


class EnclosureLabelModel(sa.Model):
__tablename__ = "enclosure_label"

id = sa.Column(sa.Integer(), primary_key=True)
encid = sa.Column(sa.String(200), unique=True)
label = sa.Column(sa.String(200))


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

@private
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['datastore.query'] = 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 9da3a5b

Please sign in to comment.