Skip to content

Commit

Permalink
Merge pull request #1 from XtratusCloud/allow-reservation-tags
Browse files Browse the repository at this point in the history
Allow reservation tags
  • Loading branch information
XtratusCloud committed Feb 21, 2023
2 parents 28255d4 + 973418e commit de57542
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 4 deletions.
7 changes: 6 additions & 1 deletion engine/app/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,13 +104,15 @@ class SpaceCIDRReq(BaseModel):
size: int
reverse_search: Optional[bool] = False
smallest_cidr: Optional[bool] = False
tags: Optional[dict]

class BlockCIDRReq(BaseModel):
"""DOCSTRING"""

size: int
reverse_search: Optional[bool] = False
smallest_cidr: Optional[bool] = False
tags: Optional[dict]

class DeleteResvReq(List[str]):
"""DOCSTRING"""
Expand Down Expand Up @@ -182,7 +184,10 @@ class Reservation(BaseModel):

@root_validator
def format_tag(cls, values) -> dict:
values["tag"] = { "X-IPAM-RES-ID": values["id"]}
if not values["tag"]:
values["tag"] = { "X-IPAM-RES-ID": values["id"]}
elif "X-IPAM-RES-ID" not in values["tag"].keys():
values["tag"]["X-IPAM-RES-ID"] = values["id"]

return values

Expand Down
12 changes: 10 additions & 2 deletions engine/app/routers/space.py
Original file line number Diff line number Diff line change
Expand Up @@ -627,8 +627,12 @@ async def create_multi_block_reservation(
"cidr": str(next_cidr),
"userId": creator_id,
"createdOn": time.time(),
"status": "wait"
"status": "wait",
"tag": {}
}
if req.tags:
for key, value in req.tags.items():
new_cidr["tag"][key] = value

target_block['resv'].append(new_cidr)

Expand Down Expand Up @@ -1245,8 +1249,12 @@ async def create_block_reservation(
"cidr": str(next_cidr),
"userId": creator_id,
"createdOn": time.time(),
"status": "wait"
"status": "wait",
"tag": {}
}
if req.tags:
for key, value in req.tags.items():
new_cidr["tag"][key] = value

target_block['resv'].append(new_cidr)

Expand Down
41 changes: 40 additions & 1 deletion ui/src/features/configure/block/Utils/editReservations.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ export default function EditReservations(props) {
{ name: "cidr", header: "CIDR", defaultFlex: 0.5 },
{ name: "userId", header: "User ID", defaultFlex: 1 },
{ name: "createdOn", header: "Created Date", defaultFlex: 0.75, render: ({value}) => new Date(value * 1000).toLocaleString() },
{ name: "tag", header: "Tags", headerAlign: "left", defaultFlex: 1.3, render: renderTags },
{ name: "status", header: "Status", headerAlign: "center", width: 90, resizable: false, hideable: false, sortable: false, showColumnMenuTool: false, render: renderStatus },
{ name: "id", header: "", width: 25, resizable: false, hideable: false, showColumnMenuTool: false, sortable: false, renderHeader: () => "", render: renderId }
];
Expand Down Expand Up @@ -187,6 +188,44 @@ export default function EditReservations(props) {
);
}

function renderTags(params) {
const multilineTags = Object.entries(params.value).map(([key, value]) => {
return key + ": " + value + "\n";
})
const multilineTagsLite = Object.keys(params.value).map((item, index) => {
if (index == 1 && Object.keys(params.value).length > 2) {
return item + ": " + params.value[item] + "(...)\n";
} else if (index < 2 ) {
return item + ": " + params.value[item] + "\n";
}
})

const flexLeftMultiline = {
display: "flex",
textAlign: "left",
alignItems: "left",
justifyContent: "left",
whiteSpace: "pre"
}

return (
<Tooltip
arrow
disableFocusListener
placement="top"
title={
<div style={{ textAlign: "center" }}>
Tags
<br />
<span style={{ ...flexLeftMultiline }}>{multilineTags}</span>
</div>
}
>
<div style={{ whiteSpace: "pre", fontSize: ".85em" }}>{multilineTagsLite}</div>
</Tooltip>
);
}

const refreshData = React.useCallback(() => {
const request = {
scopes: apiRequest.scopes,
Expand Down Expand Up @@ -273,7 +312,7 @@ export default function EditReservations(props) {

return (
<div sx={{ height: "300px", width: "100%" }}>
<Dialog open={open} onClose={handleClose} maxWidth="md" fullWidth>
<Dialog open={open} onClose={handleClose} maxWidth="lg" fullWidth>
<DialogTitle>
<Box sx={{ display: "flex", flexDirection: "row" }}>
<Box>
Expand Down

0 comments on commit de57542

Please sign in to comment.