fix(xo-web/New VM): filter out SRs that are not in the template's pool (#3070)

Fixes #3068, fixes #3267
This commit is contained in:
Rajaa.BARHTAOUI 2018-08-14 16:51:32 +02:00 committed by Pierre Donias
parent 561a9f140d
commit 7dc0c4cf15
4 changed files with 61 additions and 12 deletions

View File

@ -38,6 +38,8 @@
- [Pools] Filter GPU groups by pool [#3176](https://github.com/vatesfr/xen-orchestra/issues/3176) (PR [#3253](https://github.com/vatesfr/xen-orchestra/pull/3253)) - [Pools] Filter GPU groups by pool [#3176](https://github.com/vatesfr/xen-orchestra/issues/3176) (PR [#3253](https://github.com/vatesfr/xen-orchestra/pull/3253))
- [Backup NG] Fix delta backups with SMB remotes [#3224](https://github.com/vatesfr/xen-orchestra/issues/3224) (PR [#3278](https://github.com/vatesfr/xen-orchestra/pull/3278)) - [Backup NG] Fix delta backups with SMB remotes [#3224](https://github.com/vatesfr/xen-orchestra/issues/3224) (PR [#3278](https://github.com/vatesfr/xen-orchestra/pull/3278))
- Fix VM restoration getting stuck on local SRs [#3245](https://github.com/vatesfr/xen-orchestra/issues/3245) (PR [#3243](https://github.com/vatesfr/xen-orchestra/pull/3243)) - Fix VM restoration getting stuck on local SRs [#3245](https://github.com/vatesfr/xen-orchestra/issues/3245) (PR [#3243](https://github.com/vatesfr/xen-orchestra/pull/3243))
- [New VM / Self] Filter out SRs that are not in the template's pool [#3068](https://github.com/vatesfr/xen-orchestra/issues/3068) (PR [#3070](https://github.com/vatesfr/xen-orchestra/pull/3070))
- [New VM / Self] Fix 'unknown item' displayed in SR selector [#3267](https://github.com/vatesfr/xen-orchestra/issues/3267) (PR [#3070](https://github.com/vatesfr/xen-orchestra/pull/3070))
### Released packages ### Released packages

View File

@ -143,6 +143,32 @@ PoolItem.propTypes = XO_ITEM_PROP_TYPES
// =================================================================== // ===================================================================
export const SrResourceSetItem = [
connectStore(() => {
const getSr = createGetObject()
return (state, props) => ({
// true to bypass permissions as a self user
sr: getSr(state, props, true),
})
}),
({ sr, ...props }) => (
<XoItem item={sr} to={sr !== undefined && `/srs/${sr.id}`} {...props}>
{() => (
<span>
<Icon icon='sr' /> {sr.name_label || sr.id}
{isSrWritable(sr) && (
<span>{` (${formatSize(sr.size - sr.physical_usage)} free)`}</span>
)}
</span>
)}
</XoItem>
),
].reduceRight((value, decorator) => decorator(value))
SrResourceSetItem.propTypes = XO_ITEM_PROP_TYPES
// ===================================================================
// Host, Network, VM-template. // Host, Network, VM-template.
const PoolObjectItem = propTypes({ const PoolObjectItem = propTypes({
object: propTypes.object.isRequired, object: propTypes.object.isRequired,
@ -237,6 +263,7 @@ const xoItemToRender = {
// SR. // SR.
SR: ({ id }) => <SrItem id={id} />, SR: ({ id }) => <SrItem id={id} />,
'SR-resourceSet': ({ id }) => <SrResourceSetItem id={id} />,
// VM. // VM.
VM: ({ id }) => <VmItem id={id} />, VM: ({ id }) => <VmItem id={id} />,

View File

@ -221,6 +221,11 @@ class GenericSelect extends React.Component {
} }
// GroupBy: Display option with margin if not disabled and containers exists. // GroupBy: Display option with margin if not disabled and containers exists.
/* TODO: When all item components are implemented, change type to this:
type: this.props.resourceSet !== undefined && option.xoItem.type !== undefined
? `${option.xoItem.type}-resourceSet`
: undefined
*/
_renderOption = option => ( _renderOption = option => (
<span <span
className={ className={
@ -229,7 +234,12 @@ class GenericSelect extends React.Component {
: undefined : undefined
} }
> >
{renderXoItem(option.xoItem)} {renderXoItem(option.xoItem, {
type:
this.props.resourceSet && option.xoItem.type === 'SR'
? 'SR-resourceSet'
: undefined,
})}
</span> </span>
) )
@ -790,13 +800,16 @@ export class SelectResourceSetsSr extends React.PureComponent {
set value (value) { set value (value) {
this.refs.select.value = value this.refs.select.value = value
} }
_getSrs = createSelector(
() => this.props.resourceSet, _getSrs = createSort(
({ objectsByType }) => { createFilter(
const { predicate } = this.props () => this.props.resourceSet.objectsByType.SR,
const srs = objectsByType['SR'] createSelector(
return sortBy(predicate ? filter(srs, predicate) : srs, 'name_label') () => this.props.predicate,
} predicate => predicate || (() => true)
)
),
'name_label'
) )
render () { render () {

View File

@ -549,10 +549,14 @@ export default class NewVm extends BaseComponent {
_getSrPredicate = createSelector( _getSrPredicate = createSelector(
this._getIsInPool, this._getIsInPool,
this._getIsInResourceSet, this._getIsInResourceSet,
(isInPool, isInResourceSet) => disk => () => this.state.state.template,
(isInResourceSet(disk.id) || isInPool(disk)) && () => this.props.pool === undefined,
(isInPool, isInResourceSet, template, self) => disk =>
(self ? isInResourceSet(disk.id) : isInPool(disk)) &&
disk.content_type !== 'iso' && disk.content_type !== 'iso' &&
disk.size > 0 disk.size > 0 &&
template !== undefined &&
template.$pool === disk.$pool
) )
_getIsoPredicate = createSelector( _getIsoPredicate = createSelector(
() => this.props.pool && this.props.pool.id, () => this.props.pool && this.props.pool.id,
@ -715,7 +719,10 @@ export default class NewVm extends BaseComponent {
resolveIds( resolveIds(
filter( filter(
this._getResolvedResourceSet().objectsByType.SR, this._getResolvedResourceSet().objectsByType.SR,
this._getSrPredicate() sr =>
sr.$pool === template.$pool &&
sr.content_type !== 'iso' &&
sr.size > 0
) )
), ),
defaultSr defaultSr