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/licenses): display XOSTOR licenses #7115

Merged
merged 4 commits into from
Oct 24, 2023
Merged
Show file tree
Hide file tree
Changes from 2 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
1 change: 1 addition & 0 deletions packages/xo-web/src/common/intl/messages.js
Original file line number Diff line number Diff line change
Expand Up @@ -2505,6 +2505,7 @@ const messages = {
xostorDisksDropdownLabel: '({nDisks, number} disk{nDisks, plural, one {} other {s}}) {hostname}',
xostorFailedVgAlreadyExists:
"Formatting disks failed because a VG group named 'linstor_group' already exists on the hosts. Do you want to delete these VG groups?",
xostorMultipleLicenses: 'This proxy has more than 1 license!',
pdonias marked this conversation as resolved.
Show resolved Hide resolved
xostorPackagesWillBeInstalled: '"xcp-ng-release-linstor" and "xcp-ng-linstor" will be installed on each host',
xostorReplicationWarning: 'If a disk dies, you will lose data',

Expand Down
2 changes: 1 addition & 1 deletion packages/xo-web/src/common/select-license.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import map from 'lodash/map.js'
import { renderXoItemFromId } from './render-xo-item'

const LicenseOptions = ({ license, formatDate }) => {
const productId = license.productId.split('-')[1]
const productId = license.productId.startsWith('xostor') ? license.productId : license.productId.split('-')[1]
pdonias marked this conversation as resolved.
Show resolved Hide resolved
return (
<option value={license.id}>
<span>
Expand Down
37 changes: 23 additions & 14 deletions packages/xo-web/src/xo-app/xoa/licenses/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { get } from '@xen-orchestra/defined'
import { getLicenses, selfBindLicense, subscribePlugins, subscribeProxies, subscribeSelfLicenses } from 'xo'

import Proxies from './proxies'
import Xosan from './xosan'
import Xostor from './xostor'

// -----------------------------------------------------------------------------

Expand Down Expand Up @@ -196,7 +196,7 @@ export default class Licenses extends Component {

return getLicenses()
.then(licenses => {
const { proxy, xcpng, xoa, xosan } = groupBy(licenses, license => {
const { proxy, xcpng, xoa, xosan, xostor } = groupBy(licenses, license => {
for (const productType of license.productTypes) {
if (productType === 'xo') {
return 'xoa'
Expand All @@ -210,6 +210,9 @@ export default class Licenses extends Component {
if (productType === 'xcpng') {
return 'xcpng'
}
if (productType === 'xostor') {
return 'xostor'
}
}
return 'other'
})
Expand All @@ -219,6 +222,7 @@ export default class Licenses extends Component {
xcpng,
xoa,
xosan,
xostor,
},
})
})
Expand Down Expand Up @@ -300,6 +304,21 @@ export default class Licenses extends Component {
}
})

// --- XOSTOR ---
forEach(licenses.xostor, license => {
// When `expires` is undefined, the license isn't expired
if (!(license.expires < now)) {
products.push({
buyer: license.buyer,
expires: license.expires,
id: license.id,
product: 'XOSTOR',
type: 'xostor',
srId: license.boundObjectId,
})
}
})

return products
}
)
Expand Down Expand Up @@ -377,18 +396,8 @@ export default class Licenses extends Component {
</Row>
<Row>
<Col>
<h2>
XOSAN
<a
className='btn btn-secondary ml-1'
href='https://xen-orchestra.com/#!/xosan-home'
target='_blank'
rel='noopener noreferrer'
>
<Icon icon='bug' /> {_('productSupport')}
</a>
</h2>
<Xosan xosanLicenses={this.state.licenses.xosan} updateLicenses={this._updateLicenses} />
<h2>XOSTOR</h2>
MathieuRA marked this conversation as resolved.
Show resolved Hide resolved
<Xostor xostorLicenses={this.state.licenses.xostor} updateLicenses={this._updateLicenses} />
</Col>
</Row>
<Row>
Expand Down
134 changes: 0 additions & 134 deletions packages/xo-web/src/xo-app/xoa/licenses/xosan.js

This file was deleted.

108 changes: 108 additions & 0 deletions packages/xo-web/src/xo-app/xoa/licenses/xostor.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
import _ from 'intl'
import ActionButton from 'action-button'
import Component from 'base-component'
import decorate from 'apply-decorators'
import Icon from 'icon'
import React from 'react'
import SelectLicense from 'select-license'
import SortedTable from 'sorted-table'
import Tooltip from 'tooltip'
import { bindLicense } from 'xo'
import { connectStore } from 'utils'
import { createGetObjectsOfType } from 'selectors'
import { groupBy } from 'lodash'
import { injectState, provideState } from 'reaclette'
import { Pool, Sr } from 'render-xo-item'

class XostorLicensesForm extends Component {
state = {
licenseId: 'none',
}

onChangeLicense = event => {
this.setState({ licenseId: event.target.value })
}
pdonias marked this conversation as resolved.
Show resolved Hide resolved

bind = () => {
const { item, userData } = this.props
return bindLicense(this.state.licenseId, item.uuid).then(userData.updateLicenses)
}

render() {
const { item, userData } = this.props
const { licenseId } = this.state
const licenses = userData.licensesByXostorUuid[item.id]

// Xostor bound to multiple licenses
if (licenses?.length > 1) {
return (
<div>
<span>{licenses.map(license => license.id.slice(-4)).join(',')}</span>{' '}
<Tooltip content={_('xostorMultipleLicenses')}>
<Icon color='text-danger' icon='alarm' />
</Tooltip>
</div>
)
}

const license = licenses?.[0]
return license !== undefined ? (
<span>{license.id.slice(-4)}</span>
) : (
<form className='form-inline'>
<SelectLicense onChange={this.onChangeLicense} productType='xostor' />
<ActionButton
btnStyle='primary'
className='ml-1'
disabled={licenseId === 'none'}
handler={this.bind}
handlerParam={licenseId}
icon='connect'
>
{_('bindLicense')}
</ActionButton>
</form>
pdonias marked this conversation as resolved.
Show resolved Hide resolved
)
}
}

const INDIVIDUAL_ACTIONS = [
{
label: _('productSupport'),
icon: 'support',
handler: () => window.open('https://xen-orchestra.com'),
},
]

const COLUMNS = [
{
default: true,
name: _('name'),
itemRenderer: sr => <Sr id={sr.id} link container={false} />,
sortCriteria: 'name_label',
},
{ name: _('pool'), itemRenderer: sr => <Pool id={sr.$pool} link /> },
{ name: _('license'), component: XostorLicensesForm },
]
const Xostor = decorate([
connectStore(() => ({
xostorSrs: createGetObjectsOfType('SR').filter([({ SR_type }) => SR_type === 'linstor']),
})),
provideState({
computed: {
licensesByXostorUuid: (state, { xostorLicenses }) => groupBy(xostorLicenses, 'boundObjectId'),
},
}),
injectState,
({ state, xostorSrs, updateLicenses }) => (
<SortedTable
collection={xostorSrs}
columns={COLUMNS}
data-updateLicenses={updateLicenses}
data-licensesByXostorUuid={state.licensesByXostorUuid}
individualActions={INDIVIDUAL_ACTIONS}
/>
),
])

export default Xostor