feat: Return both id and name of children volume for snapshots

Return both id and name of children volume for snapshots

Change-Id: I194e13a368d01178b5e4751a42f8f3e6d0faa4f1
This commit is contained in:
Boxiang Zhu 2022-08-23 16:41:37 +08:00
parent 22ea97f536
commit 40b30101c3
3 changed files with 37 additions and 5 deletions

View File

@ -862,7 +862,9 @@ async def list_volume_snapshots(
child_volumes: Dict[str, Any] = {} child_volumes: Dict[str, Any] = {}
for volume in volumes_from_snapshot: for volume in volumes_from_snapshot:
child_volumes.setdefault(volume.snapshot_id, []) child_volumes.setdefault(volume.snapshot_id, [])
child_volumes[volume.snapshot_id].append(volume.name) child_volumes[volume.snapshot_id].append(
{"volume_id": volume.id, "volume_name": volume.name}
)
for snapshot in result: for snapshot in result:
snapshot["project_name"] = proj_mappings.get(snapshot["project_id"]) snapshot["project_name"] = proj_mappings.get(snapshot["project_id"])

View File

@ -398,6 +398,13 @@ class VolumesResponse(BaseModel):
volumes: List[VolumesResponseBase] = Field(..., description="Volumes list") volumes: List[VolumesResponseBase] = Field(..., description="Volumes list")
class VolumeSnapshotChildVolume(BaseModel):
volume_id: str = Field(
None, description="ID of volume", example="00000000-0000-0000-0000-000000000000"
)
volume_name: str = Field(None, description="Name of volume", example="child-volume-demo")
class VolumeSnapshotsResponseBase(BaseModel): class VolumeSnapshotsResponseBase(BaseModel):
id: str = Field(..., description="Snapshot ID") id: str = Field(..., description="Snapshot ID")
origin_data: Dict[str, Any] = Field( origin_data: Dict[str, Any] = Field(
@ -405,8 +412,10 @@ class VolumeSnapshotsResponseBase(BaseModel):
) )
project_name: Optional[str] = Field(None, description="Project name") project_name: Optional[str] = Field(None, description="Project name")
host: Optional[str] = Field(None, description="Host name") host: Optional[str] = Field(None, description="Host name")
volume_name: Optional[str] = Field(None, description="Volume name") volume_name: Optional[str] = Field(None, description="Name of volume", example="volume-demo")
child_volumes: Optional[List] = Field(None, description="Child volumes") child_volumes: Optional[List[VolumeSnapshotChildVolume]] = Field(
None, description="Child volumes"
)
name: Optional[str] = Field( name: Optional[str] = Field(
description="Will be removed, please use origin_data[name]", description="Will be removed, please use origin_data[name]",

View File

@ -3442,6 +3442,24 @@
} }
} }
}, },
"VolumeSnapshotChildVolume": {
"title": "VolumeSnapshotChildVolume",
"type": "object",
"properties": {
"volume_id": {
"title": "Volume Id",
"type": "string",
"description": "ID of volume",
"example": "00000000-0000-0000-0000-000000000000"
},
"volume_name": {
"title": "Volume Name",
"type": "string",
"description": "Name of volume",
"example": "child-volume-demo"
}
}
},
"VolumeSnapshotSortKey": { "VolumeSnapshotSortKey": {
"title": "VolumeSnapshotSortKey", "title": "VolumeSnapshotSortKey",
"enum": [ "enum": [
@ -3519,12 +3537,15 @@
"volume_name": { "volume_name": {
"title": "Volume Name", "title": "Volume Name",
"type": "string", "type": "string",
"description": "Volume name" "description": "Name of volume",
"example": "volume-demo"
}, },
"child_volumes": { "child_volumes": {
"title": "Child Volumes", "title": "Child Volumes",
"type": "array", "type": "array",
"items": {}, "items": {
"$ref": "#/components/schemas/VolumeSnapshotChildVolume"
},
"description": "Child volumes" "description": "Child volumes"
}, },
"name": { "name": {