-
Notifications
You must be signed in to change notification settings - Fork 493
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
NAS-132961 / 25.04 / Move enclosure label to its own file (#15215)
* Move enclosure label to its own file * Address review
- Loading branch information
1 parent
48ed775
commit 9da3a5b
Showing
7 changed files
with
80 additions
and
42 deletions.
There are no files selected for viewing
28 changes: 28 additions & 0 deletions
28
src/middlewared/middlewared/alembic/versions/25.04/2024-12-16_12-49_enclosure_label.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 ### |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
src/middlewared/middlewared/api/v25_04_0/enclosure_label.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
src/middlewared/middlewared/plugins/enclosure_/enclosure_label.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters