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/VM): display creator email and template name #6771

Merged
merged 7 commits into from
Apr 25, 2023
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: 3 additions & 0 deletions CHANGELOG.unreleased.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

> Users must be able to say: “Nice enhancement, I'm eager to test it”

- [VM/General] Displays the template name used to create the VM, as well as the email address of the VM creator for admin users (PR [#6771](https://github.com/vatesfr/xen-orchestra/pull/6771))

### Bug fixes

> Users must be able to say: “I had this issue, happy to know it's fixed”
Expand All @@ -28,5 +30,6 @@
<!--packages-start-->

- xo-server minor
- xo-web minor

<!--packages-end-->
3 changes: 2 additions & 1 deletion packages/xo-web/src/common/intl/messages.js
Original file line number Diff line number Diff line change
Expand Up @@ -1120,11 +1120,12 @@ const messages = {
noIpv4Record: 'No IPv4 record',
noIpRecord: 'No IP record',
started: 'Started {ago}',
created: 'Created on {date}',
paraVirtualizedMode: 'Paravirtualization (PV)',
hardwareVirtualizedMode: 'Hardware virtualization (HVM)',
hvmModeWithPvDriversEnabled: 'Hardware virtualization with paravirtualization drivers enabled (PVHVM)',
pvInPvhMode: 'PV inside a PVH container (PV in PVH)',
vmCreatedAdmin: 'Created by {user}\non {date}\nwith template {template}',
vmCreatedNonAdmin: 'Created on {date}\nwith template {template}',
windowsUpdateTools: 'Manage Citrix PV drivers via Windows Update',
windowsToolsModalTitle: 'Windows Update Tools',
windowsToolsModalMessage:
Expand Down
4 changes: 0 additions & 4 deletions packages/xo-web/src/xo-app/vm/tab-advanced.js
Original file line number Diff line number Diff line change
Expand Up @@ -914,10 +914,6 @@ export default class TabAdvanced extends Component {
<h3>{_('miscLabel')}</h3>
<table className='table table-hover'>
<tbody>
<tr>
Rajaa-BARHTAOUI marked this conversation as resolved.
Show resolved Hide resolved
<th>{_('originalTemplate')}</th>
<td>{vm.other.base_template_name ? vm.other.base_template_name : _('unknownOriginalTemplate')}</td>
</tr>
<tr>
<th>{_('resourceSet')}</th>
<td>
Expand Down
57 changes: 46 additions & 11 deletions packages/xo-web/src/xo-app/vm/tab-general.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ 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, { VmTemplate } from 'render-xo-item'
import Tooltip from 'tooltip'
import { addTag, editVm, removeTag } from 'xo'
import { addTag, editVm, removeTag, subscribeUsers } from 'xo'
import { BlockLink } from 'link'
import { FormattedRelative, FormattedDate } from 'react-intl'
import { Container, Row, Col } from 'grid'
Expand All @@ -20,10 +20,12 @@ import {
createGetVmLastShutdownTime,
createSelector,
getResolvedPendingTasks,
isAdmin,
} from 'selectors'
import { connectStore, formatSizeShort, getVirtualizationModeLabel, osFamily } from 'utils'
import { addSubscriptions, connectStore, formatSizeShort, getVirtualizationModeLabel, osFamily } from 'utils'
import { CpuSparkLines, MemorySparkLines, NetworkSparkLines, XvdSparkLines } from 'xo-sparklines'
import { injectState, provideState } from 'reaclette'
import { find } from 'lodash'

const GuestToolsDetection = ({ vm }) => {
if (vm.power_state !== 'Running' || vm.pvDriversDetected === undefined) {
Expand Down Expand Up @@ -93,13 +95,25 @@ const GeneralTab = decorate([
)

return (state, props) => ({
isAdmin: isAdmin(state, props),
lastShutdownTime: createGetVmLastShutdownTime()(state, props),
// true: useResourceSet to bypass permissions
resolvedPendingTasks: getResolvedPendingTasks(state, props, true),
vgpu: getAttachedVgpu(state, props),
vgpuTypes: getVgpuTypes(state, props),
vmTemplate: createGetObjectsOfType('VM-template').find(
(_, { pool, vm }) =>
template =>
template.$poolId === pool.id && template.uuid === vm.creation?.template
)(state, props),
})
}),
addSubscriptions(
({ isAdmin, vm }) =>
isAdmin && {
vmCreator: cb => subscribeUsers(users => cb(find(users, user => user.id === vm.creation?.user))),
}
),
provideState({
computed: {
vmResolvedPendingTasks: (_, { resolvedPendingTasks, vm }) => {
Expand All @@ -109,7 +123,18 @@ const GeneralTab = decorate([
},
}),
injectState,
({ state: { vmResolvedPendingTasks }, lastShutdownTime, statsOverview, vgpu, vgpuTypes, vm, vmTotalDiskSpace }) => {
({
isAdmin,
state: { vmResolvedPendingTasks },
lastShutdownTime,
statsOverview,
vgpu,
vgpuTypes,
vm,
vmCreator,
vmTemplate,
vmTotalDiskSpace,
}) => {
const {
CPUs: cpus,
id,
Expand All @@ -122,6 +147,22 @@ const GeneralTab = decorate([
tags,
VIFs: vifs,
} = vm

const vmCreatedStyles = {
whiteSpace: 'pre-line',
}
Rajaa-BARHTAOUI marked this conversation as resolved.
Show resolved Hide resolved
const vmCreatedI18nArgs = {
Rajaa-BARHTAOUI marked this conversation as resolved.
Show resolved Hide resolved
user: vmCreator?.email ?? _('unknown'),
date:
installTime !== null ? (
<FormattedDate day='2-digit' month='long' value={installTime * 1000} year='numeric' />
) : (
_('unknown')
),
template:
vmTemplate !== undefined ? <VmTemplate id={vmTemplate.id} /> : vm.other.base_template_name ?? _('unknown'),
}

return (
<Container>
{/* TODO: use CSS style */}
Expand Down Expand Up @@ -165,13 +206,7 @@ const GeneralTab = decorate([
<br />
<Row className='text-xs-center'>
<Col mediumSize={3}>
{installTime !== null && (
<div className='text-xs-center'>
{_('created', {
date: <FormattedDate day='2-digit' month='long' value={installTime * 1000} year='numeric' />,
})}
</div>
)}
<p style={vmCreatedStyles}>{_(isAdmin ? 'vmCreatedAdmin' : 'vmCreatedNonAdmin', vmCreatedI18nArgs)}</p>
{powerState === 'Running' || powerState === 'Paused' ? (
<div>
<p className='text-xs-center'>
Expand Down