Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(xo-web/SR): show suspend VDIs VMs #7391

Merged
merged 8 commits into from
Feb 29, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion CHANGELOG.unreleased.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

- Disable search engine indexing via a `robots.txt`
- [Stats] Support format used by XAPI 23.31
- [Storage/Disks] Handle link to VM for suspended VDIs (PR [#7391](https://github.com/vatesfr/xen-orchestra/pull/7391))

### Bug fixes

Expand Down Expand Up @@ -40,6 +41,6 @@
- vhd-lib patch
- xo-server minor
- xo-server-audit patch
- xo-web patch
- xo-web minor
pdonias marked this conversation as resolved.
Show resolved Hide resolved

<!--packages-end-->
124 changes: 69 additions & 55 deletions packages/xo-web/src/xo-app/sr/tab-disks.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ import PropTypes from 'prop-types'
import React from 'react'
import SortedTable from 'sorted-table'
import TabButton from 'tab-button'
import renderXoItem, { Vdi } from 'render-xo-item'
import renderXoItem, { Vdi, Vm } from 'render-xo-item'
import { confirm } from 'modal'
import { injectIntl } from 'react-intl'
import { Text } from 'editable'
import { SizeInput, Toggle } from 'form'
import { Container, Row, Col } from 'grid'
import { connectStore, formatSize, noop } from 'utils'
import { concat, every, groupBy, isEmpty, map, mapValues, pick, some, sortBy } from 'lodash'
import { concat, every, groupBy, isEmpty, keyBy, map, mapValues, pick, some, sortBy } from 'lodash'
import { createCollectionWrapper, createGetObjectsOfType, createSelector, getCheckPermissions } from 'selectors'
import {
connectVbd,
Expand Down Expand Up @@ -123,67 +123,77 @@ const COLUMNS = [
vms: getAllVms(state, props),
vbds: getVbds(state, props),
})
})(({ vbds, vms }) => {
if (isEmpty(vms)) {
})(({ item: vdi, vbds, vms, userData: { vmsSnapshotsBySuspendVdi } }) => {
const vmSnapshot = vmsSnapshotsBySuspendVdi[vdi.uuid]

if (vmSnapshot === undefined) {
pdonias marked this conversation as resolved.
Show resolved Hide resolved
pdonias marked this conversation as resolved.
Show resolved Hide resolved
return null
}

return (
<Container>
{map(vbds, (vbd, index) => {
const vm = vms[vbd.VM]
{vbds.length > 0 ? (
pdonias marked this conversation as resolved.
Show resolved Hide resolved
map(vbds, (vbd, index) => {
const vm = vms[vbd.VM]

if (vm === undefined) {
return null
}
if (vm === undefined) {
return null
}

const type = vm.type
let link
if (type === 'VM') {
link = `/vms/${vm.id}`
} else if (type === 'VM-template') {
link = `/home?s=${vm.id}&t=VM-template`
} else {
link = vm.$snapshot_of === undefined ? '/dashboard/health' : `/vms/${vm.$snapshot_of}/snapshots`
}
const type = vm.type
let link
if (type === 'VM') {
link = `/vms/${vm.id}`
} else if (type === 'VM-template') {
link = `/home?s=${vm.id}&t=VM-template`
} else {
link = vm.$snapshot_of === undefined ? '/dashboard/health' : `/vms/${vm.$snapshot_of}/snapshots`
}

return (
<Row className={index > 0 && 'mt-1'}>
<Col mediumSize={8}>
<Link to={link}>{renderXoItem(vm)}</Link>
</Col>
<Col mediumSize={4}>
<ButtonGroup>
{vbd.attached ? (
return (
<Row className={index > 0 && 'mt-1'}>
<Col mediumSize={8}>
<Link to={link}>{renderXoItem(vm)}</Link>
</Col>
<Col mediumSize={4}>
<ButtonGroup>
{vbd.attached ? (
<ActionRowButton
btnStyle='danger'
handler={disconnectVbd}
handlerParam={vbd}
icon='disconnect'
tooltip={_('vbdDisconnect')}
/>
) : (
<ActionRowButton
btnStyle='primary'
disabled={some(vbds, 'attached') || !isVmRunning(vm)}
handler={connectVbd}
handlerParam={vbd}
icon='connect'
tooltip={_('vbdConnect')}
/>
)}
<ActionRowButton
btnStyle='danger'
handler={disconnectVbd}
handlerParam={vbd}
icon='disconnect'
tooltip={_('vbdDisconnect')}
/>
) : (
<ActionRowButton
btnStyle='primary'
disabled={some(vbds, 'attached') || !isVmRunning(vm)}
handler={connectVbd}
handler={deleteVbd}
handlerParam={vbd}
icon='connect'
tooltip={_('vbdConnect')}
icon='vdi-forget'
tooltip={_('vdiForget')}
/>
)}
<ActionRowButton
btnStyle='danger'
handler={deleteVbd}
handlerParam={vbd}
icon='vdi-forget'
tooltip={_('vdiForget')}
/>
</ButtonGroup>
</Col>
</Row>
)
})}
</ButtonGroup>
</Col>
</Row>
)
})
) : (
<Col mediumSize={8}>
<Link to={`/vms/${vmSnapshot.$snapshot_of}/snapshots`}>
<Vm id={vmSnapshot.$snapshot_of} />
</Link>
</Col>
)}
</Container>
)
}),
Expand Down Expand Up @@ -301,10 +311,13 @@ class NewDisk extends Component {
}
}

@connectStore(() => ({
checkPermissions: getCheckPermissions,
vbds: createGetObjectsOfType('VBD'),
}))
@connectStore(() => {
return (state, props) => ({
checkPermissions: getCheckPermissions(state, props),
vbds: createGetObjectsOfType('VBD')(state, props),
vmsSnapshotsBySuspendVdi: keyBy(createGetObjectsOfType('VM-snapshot')(state, props), 'suspendVdi'),
pdonias marked this conversation as resolved.
Show resolved Hide resolved
})
})
export default class SrDisks extends Component {
_closeNewDiskForm = () => this.setState({ newDisk: false })

Expand Down Expand Up @@ -434,6 +447,7 @@ export default class SrDisks extends Component {
columns={COLUMNS}
data-isVdiAttached={this._getIsVdiAttached()}
data-vdisByBaseCopy={this._getVdisByBaseCopy()}
data-vmsSnapshotsBySuspendVdi={this.props.vmsSnapshotsBySuspendVdi}
defaultFilter='filterOnlyManaged'
filters={FILTERS}
groupedActions={GROUPED_ACTIONS}
Expand Down
Loading