Compare commits

...

10 Commits

Author SHA1 Message Date
Pizzosaure
12786511bb Changes after review 2024-02-23 10:24:10 +01:00
Pizzosaure
edcbf22d3f Changes after review 2024-02-19 10:59:30 +01:00
mathieuRA
4fa4638e00 remove not needed code 2024-02-09 11:53:48 +01:00
mathieuRA
e23ff07792 changelog 2024-02-09 10:41:15 +01:00
mathieuRA
26eb727ae3 fix 2024-02-09 10:40:11 +01:00
mathieuRA
b750d277aa fixes 2024-02-09 10:40:11 +01:00
Pizzosaure
bd2b6dbe2a Changes after review 2024-02-09 10:39:49 +01:00
Pizzosaure
2cd87e1b2c Changelog entry added 2024-02-09 10:39:49 +01:00
Pizzosaure
6eed3196bb UI modifications 2024-02-09 10:39:49 +01:00
mathieuRA
662c2bd8cb feat(xo-server/resourceSet): add 'usage' property resourceSet 2024-02-09 10:39:49 +01:00
4 changed files with 68 additions and 58 deletions

View File

@@ -7,6 +7,8 @@
> Users must be able to say: “Nice enhancement, I'm eager to test it”
- [Self service] From user POV, show used resources even when they are unlimited (PR [#7353](https://github.com/vatesfr/xen-orchestra/pull/7353))
### Bug fixes
> Users must be able to say: “I had this issue, happy to know it's fixed”
@@ -27,4 +29,7 @@
<!--packages-start-->
- xo-server minor
- xo-web minor
<!--packages-end-->

View File

@@ -55,10 +55,10 @@ const normalize = set => ({
limits: set.limits
? map(set.limits, limit =>
isObject(limit)
? limit
? { ...limit, usage: limit.usage ?? 0 }
: {
available: limit,
total: limit,
usage: 0,
}
)
: {},
@@ -217,25 +217,32 @@ export default class {
if (objects) {
set.objects = objects
}
if (limits) {
const previousLimits = set.limits
set.limits = map(limits, (quantity, id) => {
const previous = previousLimits[id]
if (!previous) {
return {
available: quantity,
total: quantity,
}
}
const { available, total } = previous
return {
available: available - total + quantity,
const previousLimits = set.limits
const newLimits = {}
forEach(limits, (quantity, id) => {
const previous = previousLimits[id]
if (previous !== undefined) {
newLimits[id] = {
total: quantity,
usage: previous.usage,
}
})
}
} else {
newLimits[id] = {
total: quantity,
usage: 0,
}
}
})
const removedLimits = Object.keys(previousLimits).filter(key => !(key in newLimits))
removedLimits.forEach(id => {
newLimits[id] = {
usage: previousLimits[id].usage ?? 0,
}
})
set.limits = newLimits
if (ipPools) {
set.ipPools = ipPools
}
@@ -332,15 +339,16 @@ export default class {
forEach(limits, (quantity, id) => {
const limit = set.limits[id]
if (!limit) {
set.limits[id] = { usage: quantity }
return
}
if ((limit.available -= quantity) < 0 && !force) {
if ((limit.usage += quantity) > limit.total && !force) {
throw notEnoughResources([
{
resourceSet: setId,
resourceType: id,
available: limit.available + quantity,
available: limit.total - (limit.usage - quantity),
requested: quantity,
},
])
@@ -358,8 +366,8 @@ export default class {
return
}
if ((limit.available += quantity) > limit.total) {
limit.available = limit.total
if ((limit.usage -= quantity) < 0) {
limit.usage = 0
}
})
await this._save(set)
@@ -371,7 +379,7 @@ export default class {
forEach(limits, (limit, id) => {
if (VM_RESOURCES[id] || id.startsWith('ipPool:')) {
// only reset VMs related limits
limit.available = limit.total
limit.usage = 0
}
})
})
@@ -397,7 +405,9 @@ export default class {
forEach(await this.computeResourcesUsage(this._app.getObject(object.$id)), (usage, resource) => {
const limit = limits[resource]
if (limit) {
limit.available -= usage
limit.usage += usage
} else {
limits[resource] = { usage }
}
})
})

View File

@@ -31,11 +31,10 @@ export default class ResourceSetQuotas extends Component {
forEach(RESOURCES, resource => {
if (limits[resource] != null) {
const { available, total } = limits[resource]
const { total, usage } = limits[resource]
quotas[resource] = {
available,
total,
usage: total - available,
usage,
}
}
})
@@ -89,22 +88,26 @@ export default class ResourceSetQuotas extends Component {
<CardBlock className='text-center'>
{quota !== undefined ? (
<div>
<ChartistGraph
data={{
labels,
series: [quota.available, quota.usage],
}}
options={{
donut: true,
donutWidth: 40,
showLabel: false,
}}
type='Pie'
/>
{Number.isFinite(quota.total) ? (
<ChartistGraph
data={{
labels,
series: [quota.total - quota.usage, quota.usage],
}}
options={{
donut: true,
donutWidth: 40,
showLabel: false,
}}
type='Pie'
/>
) : (
<p className='text-xs-center display-1'>&infin;</p>
)}
<p className='text-xs-center'>
{_('resourceSetQuota', {
total: validFormat ? quota.total.toString() : formatSize(quota.total),
usage: validFormat ? quota.usage.toString() : formatSize(quota.usage),
total: !Number.isFinite(quota.total) ? Infinity : formatSize(quota.total),
usage: validFormat ? quota.usage?.toString() : formatSize(quota.usage),
})}
</p>
</div>

View File

@@ -1870,29 +1870,21 @@ export default class NewVm extends BaseComponent {
{limits && (
<Row>
<Col size={3}>
{cpusLimits && (
<Limits
limit={cpusLimits.total}
toBeUsed={CPUs * factor}
used={cpusLimits.total - cpusLimits.available}
/>
{cpusLimits?.total !== undefined && (
<Limits limit={cpusLimits.total} toBeUsed={CPUs * factor} used={cpusLimits.usage} />
)}
</Col>
<Col size={3}>
{memoryLimits && (
<Limits
limit={memoryLimits.total}
toBeUsed={_memory * factor}
used={memoryLimits.total - memoryLimits.available}
/>
{memoryLimits?.total !== undefined && (
<Limits limit={memoryLimits.total} toBeUsed={_memory * factor} used={memoryLimits.usage} />
)}
</Col>
<Col size={3}>
{diskLimits && (
{diskLimits?.total !== undefined && (
<Limits
limit={diskLimits.total}
toBeUsed={(sumBy(VDIs, 'size') + sum(map(existingDisks, disk => disk.size))) * factor}
used={diskLimits.total - diskLimits.available}
used={diskLimits.usage}
/>
)}
</Col>
@@ -1923,10 +1915,10 @@ export default class NewVm extends BaseComponent {
const factor = multipleVms ? nameLabels.length : 1
return !(
CPUs * factor > get(() => resourceSet.limits.cpus.available) ||
_memory * factor > get(() => resourceSet.limits.memory.available) ||
CPUs * factor > get(() => resourceSet.limits.cpus.total - resourceSet.limits.cpus.usage) ||
_memory * factor > get(() => resourceSet.limits.memory.total - resourceSet.limits.memory.usage) ||
(sumBy(VDIs, 'size') + sum(map(existingDisks, disk => disk.size))) * factor >
get(() => resourceSet.limits.disk.available)
get(() => resourceSet.limits.disk.total - resourceSet.limits.disk.usage)
)
}
}