Compare commits

...

2 Commits

Author SHA1 Message Date
Pierre Donias
0fad24d757 Handle clone and copy 2019-07-23 17:05:02 +02:00
Pierre Donias
3f0878940f WiP: VM owner 2019-07-23 17:05:01 +02:00
4 changed files with 78 additions and 17 deletions

View File

@@ -150,6 +150,8 @@ export async function create(params) {
}
const xapiVm = await xapi.createVm(template._xapiId, params, checkLimits)
await xapiVm.update_other_config('owner', user.id)
const vm = xapi.xo.addObject(xapiVm)
if (resourceSet) {
@@ -663,15 +665,16 @@ export const clone = defer(async function(
await checkPermissionOnSrs.call(this, vm)
const xapi = this.getXapi(vm)
const { $id: cloneId } = await xapi.cloneVm(vm._xapiRef, {
const xapiVm = await xapi.cloneVm(vm._xapiRef, {
nameLabel: name,
fast: !fullCopy,
})
$defer.onFailure(() => xapi.deleteVm(cloneId))
$defer.onFailure(() => xapi.deleteVm(xapiVm.$id))
await xapiVm.update_other_config('owner', this.user.id)
const isAdmin = this.user.permission === 'admin'
if (!isAdmin) {
await this.addAcl(this.user.id, cloneId, 'admin')
await this.addAcl(this.user.id, xapiVm.$id, 'admin')
}
if (vm.resourceSet !== undefined) {
@@ -682,7 +685,7 @@ export const clone = defer(async function(
)
}
return cloneId
return xapiVm.$id
})
clone.params = {
@@ -704,19 +707,26 @@ export async function copy({ compress, name: nameLabel, sr, vm }) {
await checkPermissionOnSrs.call(this, vm)
}
return this.getXapi(vm)
.copyVm(vm._xapiId, sr._xapiId, {
nameLabel,
})
.then(vm => vm.$id)
}
return this.getXapi(vm)
.remoteCopyVm(vm._xapiId, this.getXapi(sr), sr._xapiId, {
compress,
const xapiVm = await this.getXapi(vm).copyVm(vm._xapiId, sr._xapiId, {
nameLabel,
})
.then(({ vm }) => vm.$id)
await xapiVm.update_other_config('owner', this.user.id)
return xapiVm.$id
}
const { vm: xapiVm } = await this.getXapi(vm).remoteCopyVm(
vm._xapiId,
this.getXapi(sr),
sr._xapiId,
{
compress,
nameLabel,
}
)
await xapiVm.update_other_config('owner', this.user.id)
return xapiVm.$id
}
copy.params = {

View File

@@ -49,6 +49,7 @@ const messages = {
backupJobs: 'Backup jobs',
iscsiSessions:
'({ nSessions, number }) iSCSI session{nSessions, plural, one {} other {s}}',
owner: 'Owner',
// ----- Modals -----
alertOk: 'OK',

View File

@@ -12,7 +12,7 @@ import Tooltip from './tooltip'
import { addSubscriptions, connectStore, formatSize } from './utils'
import { createGetObject, createSelector } from './selectors'
import { FormattedDate } from 'react-intl'
import { isSrWritable, subscribeRemotes } from './xo'
import { isSrWritable, subscribeRemotes, subscribeUsers } from './xo'
// ===================================================================
@@ -392,6 +392,40 @@ Vgpu.propTypes = {
// ===================================================================
export const User = decorate([
addSubscriptions(({ id }) => ({
user: cb => subscribeUsers(users => cb(find(users, { id }))),
})),
({ id, user, link, newTab }) => {
if (user === undefined) {
return unknowItem(id, 'user')
}
return (
<LinkWrapper
link={link}
newTab={newTab}
to={`/settings/acls?s=subject:id:${id}`}
>
<Icon icon='user' /> {user.email}
</LinkWrapper>
)
},
])
User.propTypes = {
id: PropTypes.string.isRequired,
link: PropTypes.bool,
newTab: PropTypes.bool,
}
User.defaultProps = {
link: false,
newTab: false,
}
// ===================================================================
const xoItemToRender = {
// Subscription objects.
cloudConfig: template => (

View File

@@ -6,7 +6,7 @@ import isEmpty from 'lodash/isEmpty'
import map from 'lodash/map'
import React from 'react'
import HomeTags from 'home-tags'
import renderXoItem from 'render-xo-item'
import renderXoItem, { User } from 'render-xo-item'
import Tooltip from 'tooltip'
import { addTag, editVm, removeTag } from 'xo'
import { BlockLink } from 'link'
@@ -19,6 +19,7 @@ import {
createGetObjectsOfType,
createGetVmLastShutdownTime,
createSelector,
isAdmin,
} from 'selectors'
import {
connectStore,
@@ -48,6 +49,7 @@ export default connectStore(() => {
)
return {
isAdmin,
lastShutdownTime: createGetVmLastShutdownTime(),
tasks: createGetObjectsOfType('task')
.pick(
@@ -63,6 +65,7 @@ export default connectStore(() => {
}
})(
({
isAdmin,
lastShutdownTime,
statsOverview,
tasks,
@@ -78,6 +81,7 @@ export default connectStore(() => {
installTime,
memory,
os_version: osVersion,
other,
power_state: powerState,
startTime,
tags,
@@ -209,6 +213,18 @@ export default connectStore(() => {
</BlockLink>
</Col>
</Row>
{isAdmin && other.owner !== undefined && (
<Row className='text-xs-center'>
<Col>
{_('keyValue', {
key: _('owner'),
value: (
<User id={other.owner} link={process.env.XOA_PLAN > 2} />
),
})}
</Col>
</Row>
)}
{!xenTools && powerState === 'Running' && (
<Row className='text-xs-center'>
<Col>