From 8782151c5d561580c93980d7731571dbd05d40de Mon Sep 17 00:00:00 2001 From: "Rajaa.BARHTAOUI" Date: Fri, 21 Jun 2019 16:33:32 +0200 Subject: [PATCH] feat(xo-web/host): warning when host and XOA's time differ too much (#4173) Fixes #4113 --- CHANGELOG.unreleased.md | 1 + packages/xo-server/src/api/host.js | 19 ++++++++++++ packages/xo-server/src/xapi/index.js | 2 +- .../common/inconsistent-host-time-warning.js | 30 +++++++++++++++++++ packages/xo-web/src/common/intl/messages.js | 2 ++ packages/xo-web/src/common/xo/index.js | 3 ++ packages/xo-web/src/xo-app/home/host-item.js | 3 ++ packages/xo-web/src/xo-app/host/index.js | 3 ++ 8 files changed, 62 insertions(+), 1 deletion(-) create mode 100644 packages/xo-web/src/common/inconsistent-host-time-warning.js diff --git a/CHANGELOG.unreleased.md b/CHANGELOG.unreleased.md index 7229724ca..16d6380de 100644 --- a/CHANGELOG.unreleased.md +++ b/CHANGELOG.unreleased.md @@ -9,6 +9,7 @@ - [VM/Backup] Create backup bulk action [#2573](https://github.com/vatesfr/xen-orchestra/issues/2573) (PR [#4257](https://github.com/vatesfr/xen-orchestra/pull/4257)) - [Sr/new] Ability to select NFS version when creating NFS storage [#3951](https://github.com/vatesfr/xen-orchestra/issues/#3951) (PR [#4277](https://github.com/vatesfr/xen-orchestra/pull/4277)) - [SR/new] Create ZFS storage [#4260](https://github.com/vatesfr/xen-orchestra/issues/4260) (PR [#4266](https://github.com/vatesfr/xen-orchestra/pull/4266)) +- [Host] Display warning when host's time differs too much from XOA's time [#4113](https://github.com/vatesfr/xen-orchestra/issues/4113) (PR [#4173](https://github.com/vatesfr/xen-orchestra/pull/4173)) ### Bug fixes diff --git a/packages/xo-server/src/api/host.js b/packages/xo-server/src/api/host.js index ef1729cb0..865f91f6b 100644 --- a/packages/xo-server/src/api/host.js +++ b/packages/xo-server/src/api/host.js @@ -211,6 +211,25 @@ emergencyShutdownHost.resolve = { // ------------------------------------------------------------------- +export async function isHostServerTimeConsistent({ host }) { + try { + await this.getXapi(host).assertConsistentHostServerTime(host._xapiRef) + return true + } catch (e) { + return false + } +} + +isHostServerTimeConsistent.params = { + host: { type: 'string' }, +} + +isHostServerTimeConsistent.resolve = { + host: ['host', 'host', 'administrate'], +} + +// ------------------------------------------------------------------- + export function stats({ host, granularity }) { return this.getXapiHostStats(host._xapiId, granularity) } diff --git a/packages/xo-server/src/xapi/index.js b/packages/xo-server/src/xapi/index.js index 10d48197d..bd3f9928b 100644 --- a/packages/xo-server/src/xapi/index.js +++ b/packages/xo-server/src/xapi/index.js @@ -2336,7 +2336,7 @@ export default class Xapi extends XapiBase { ) } - async _assertConsistentHostServerTime(hostRef) { + async assertConsistentHostServerTime(hostRef) { const delta = parseDateTime(await this.call('host.get_servertime', hostRef)).getTime() - Date.now() diff --git a/packages/xo-web/src/common/inconsistent-host-time-warning.js b/packages/xo-web/src/common/inconsistent-host-time-warning.js new file mode 100644 index 000000000..8711015c7 --- /dev/null +++ b/packages/xo-web/src/common/inconsistent-host-time-warning.js @@ -0,0 +1,30 @@ +import _ from 'intl' +import decorate from 'apply-decorators' +import Icon from 'icon' +import PropTypes from 'prop-types' +import React from 'react' +import Tooltip from 'tooltip' +import { injectState, provideState } from 'reaclette' +import { isHostTimeConsistentWithXoaTime } from 'xo' + +const InconsistentHostTimeWarning = decorate([ + provideState({ + computed: { + isHostTimeConsistentWithXoaTime: (_, { hostId }) => + isHostTimeConsistentWithXoaTime(hostId), + }, + }), + injectState, + ({ state: { isHostTimeConsistentWithXoaTime = true } }) => + isHostTimeConsistentWithXoaTime ? null : ( + + + + ), +]) + +InconsistentHostTimeWarning.propTypes = { + hostId: PropTypes.string.isRequired, +} + +export { InconsistentHostTimeWarning as default } diff --git a/packages/xo-web/src/common/intl/messages.js b/packages/xo-web/src/common/intl/messages.js index b79145949..82a5da9ec 100644 --- a/packages/xo-web/src/common/intl/messages.js +++ b/packages/xo-web/src/common/intl/messages.js @@ -218,6 +218,8 @@ const messages = { homeResourceSet: 'Resource set: {resourceSet}', highAvailability: 'High Availability', srSharedType: 'Shared {type}', + warningHostTimeTooltip: + 'Host time and XOA time are not consistent with each other', // ----- Home snapshots ----- snapshotVmsName: 'Name', diff --git a/packages/xo-web/src/common/xo/index.js b/packages/xo-web/src/common/xo/index.js index 9e30c3dc9..210e2c804 100644 --- a/packages/xo-web/src/common/xo/index.js +++ b/packages/xo-web/src/common/xo/index.js @@ -777,6 +777,9 @@ export const emergencyShutdownHosts = hosts => { }).then(() => map(hosts, host => emergencyShutdownHost(host)), noop) } +export const isHostTimeConsistentWithXoaTime = host => + _call('host.isHostServerTimeConsistent', { host: resolveId(host) }) + // for XCP-ng now export const installAllPatchesOnHost = ({ host }) => confirm({ diff --git a/packages/xo-web/src/xo-app/home/host-item.js b/packages/xo-web/src/xo-app/home/host-item.js index 382c5bd33..61f8180b2 100644 --- a/packages/xo-web/src/xo-app/home/host-item.js +++ b/packages/xo-web/src/xo-app/home/host-item.js @@ -1,5 +1,6 @@ import _ from 'intl' import Component from 'base-component' +import InconsistentHostTimeWarning from 'inconsistent-host-time-warning' import Ellipsis, { EllipsisContainer } from 'ellipsis' import Icon from 'icon' import isEmpty from 'lodash/isEmpty' @@ -128,6 +129,8 @@ export default class HostItem extends Component { )}   + +   {hasLicenseRestrictions(host) && } diff --git a/packages/xo-web/src/xo-app/host/index.js b/packages/xo-web/src/xo-app/host/index.js index 5ea94c92a..59212a078 100644 --- a/packages/xo-web/src/xo-app/host/index.js +++ b/packages/xo-web/src/xo-app/host/index.js @@ -1,4 +1,5 @@ import _ from 'intl' +import InconsistentHostTimeWarning from 'inconsistent-host-time-warning' import Copiable from 'copiable' import HostActionBar from './action-bar' import Icon from 'icon' @@ -254,6 +255,8 @@ export default class Host extends Component { )} +   + {host.uuid}