Compare commits

..

1 Commits

Author SHA1 Message Date
Gabriel Gunullu
2cb986b1a3 feat(xapi/VDI_importContent): add SR name_label to task name_label (#6979) 2023-10-10 10:43:08 +02:00
31 changed files with 146 additions and 475 deletions

View File

@@ -1,7 +1,7 @@
import assert from 'node:assert'
import { Socket } from 'node:net'
import { connect } from 'node:tls'
import { fromCallback, pRetry, pDelay, pTimeout } from 'promise-toolbox'
import { fromCallback, pRetry, pDelay, pTimeout, pFromCallback } from 'promise-toolbox'
import { readChunkStrict } from '@vates/read-chunk'
import { createLogger } from '@xen-orchestra/log'
@@ -112,18 +112,22 @@ export default class NbdClient {
}
async disconnect() {
warn('will try to disconnect', { serverAddress: this.#serverAddress })
if (!this.#connected) {
warn('was already disconnected', { serverAddress: this.#serverAddress })
return
}
warn('will really disconnect', { serverAddress: this.#serverAddress })
const buffer = Buffer.alloc(28)
buffer.writeInt32BE(NBD_REQUEST_MAGIC, 0) // it is a nbd request
buffer.writeInt16BE(0, 4) // no command flags for a disconnect
buffer.writeInt16BE(NBD_CMD_DISC, 6) // we want to disconnect from nbd server
await this.#write(buffer)
await this.#serverSocket.destroy()
warn('will send end buffer', { serverAddress: this.#serverAddress })
this.#connected = false // optimistically mark as disconnected to ensure we don' send another disconnection while handling this one
await pFromCallback(cb => this.#serverSocket.end(buffer, cb))
warn('end buffer sent', { serverAddress: this.#serverAddress })
this.#serverSocket = undefined
this.#connected = false
}
#clearReconnectPromise = () => {

View File

@@ -14,26 +14,7 @@ export class ImportVmBackup {
this._xapi = xapi
}
async #detectBaseVdis(){
const vmUuid = this._metadata.vm.uuid
const vm = await this._xapi.getRecordByUuid('VM', vmUuid)
const disks = vm.$getDisks()
const snapshots = {}
console.log({disks})
for (const disk of Object.values(disks)){
console.log({snapshots: disk.snapshots})
for(const snapshotRef of disk.snapshots){
const snapshot = await this._xapi.getRecordByUuid('VDI', snapshotRef)
snapshots[snapshot.uuid] = disk.uuid
}
}
console.log({snapshots})
return snapshots
}
async run() {
console.log('RUN')
const adapter = this._adapter
const metadata = this._metadata
const isFull = metadata.mode === 'full'
@@ -41,23 +22,18 @@ export class ImportVmBackup {
const sizeContainer = { size: 0 }
let backup
if (isFull) {
backup = await adapter.readFullVmBackup(metadata)
watchStreamSize(backup, sizeContainer)
} else {
console.log('restore delta')
assert.strictEqual(metadata.mode, 'delta')
const ignoredVdis = new Set(
Object.entries(this._importIncrementalVmSettings.mapVdisSrs)
.filter(([_, srUuid]) => srUuid === null)
.map(([vdiUuid]) => vdiUuid)
)
//const vdiSnap = await this._xapi.getRecord('VDI-snapshot','83c96977-9bc5-483d-b816-4c96622fb5e6')
//console.log({vdiSnap})
const baseVdis = this.#detectBaseVdis()
backup = await adapter.readIncrementalVmBackup(metadata, ignoredVdis, { baseVdis })
backup = await adapter.readIncrementalVmBackup(metadata, ignoredVdis)
Object.values(backup.streams).forEach(stream => watchStreamSize(stream, sizeContainer))
}
@@ -73,7 +49,7 @@ export class ImportVmBackup {
? await xapi.VM_import(backup, srRef)
: await importIncrementalVm(backup, await xapi.getRecord('SR', srRef), {
...this._importIncrementalVmSettings,
baseVdis
detectBase: false,
})
await Promise.all([

View File

@@ -2,7 +2,7 @@ import { asyncEach } from '@vates/async-each'
import { asyncMap, asyncMapSettled } from '@xen-orchestra/async-map'
import { compose } from '@vates/compose'
import { createLogger } from '@xen-orchestra/log'
import { createVhdDirectoryFromStream, openVhd, VhdAbstract, VhdDirectory, VhdSynthetic ,Constants} from 'vhd-lib'
import { createVhdDirectoryFromStream, openVhd, VhdAbstract, VhdDirectory, VhdSynthetic } from 'vhd-lib'
import { decorateMethodsWith } from '@vates/decorate-with'
import { deduped } from '@vates/disposable/deduped.js'
import { dirname, join, resolve } from 'node:path'
@@ -694,8 +694,8 @@ export class RemoteAdapter {
return container.size
}
// open the hierarchy of ancestors until we find a usable one
async _createVhdStream(handler, path, { useChain, snapshotedVdis }) {
// open the hierarchy of ancestors until we find a full one
async _createVhdStream(handler, path, { useChain }) {
const disposableSynthetic = useChain ? await VhdSynthetic.fromVhdChain(handler, path) : await openVhd(handler, path)
// I don't want the vhds to be disposed on return
// but only when the stream is done ( or failed )
@@ -713,67 +713,7 @@ export class RemoteAdapter {
}
const synthetic = disposableSynthetic.value
await synthetic.readBlockAllocationTable()
let stream
// try to create a stream that will reuse any data already present on the host storage
// by looking for an existing snapshot matching one of the vhd in the chain
// and transfer only the differential
if (snapshotedVdis) {
try{
let vhdPaths = await handler.list(dirname(path), {filter: path=>path.endsWith('.vhd')})
stream = await Disposable.use(async function *(){
const vhdChilds = {}
const vhds = yield Disposable.all(vhdPaths.map(path => openVhd(handler, path, opts)))
for(const vhd of vhds){
vhdChilds[vhd.header.parentUuid] = vhdChilds[vhd.header.parentUuid] ?? []
vhdChilds[vhd.header.parentUuid].push(vhd)
}
let chain = []
let current = synthetic
// @todo : special case : we want to restore a vdi
// that still have its snapshot => nothing to transfer
while(current != undefined){
// find the child VDI of path
const childs = vhdChilds[current.footer.uuid]
// more than one => break
// inexistant => break
if(childs.length !== 1){
break
}
const child = childs[0]
// not a differential => we won't have a list of block changed
// no need to continue looking
if(child.footer.diskType !== Constants.DISK_TYPES.DIFFERENCING){
break
}
// we have a snapshot
if(snapshotedVdis[current.footer.uuid] !== undefined){
const descendants = VhdSynthetic.open(handler)
negativeVhd = new NegativeVhd(synthetic, descendants)
return negative.stream()
} else {
// continue to look into the chain
// hoping we'll found a match deeper
current = child
chain.unshift(current)
}
}
})
}catch(error){
warn("error while trying to reuse a snapshot, fallback to legacy restore", {error})
}
}
// fallback
if (stream === undefined) {
stream = await synthetic.stream()
}
const stream = await synthetic.stream()
stream.on('end', disposeOnce)
stream.on('close', disposeOnce)
@@ -781,7 +721,7 @@ export class RemoteAdapter {
return stream
}
async readIncrementalVmBackup(metadata, ignoredVdis, { useChain = true, snapshotedVdis } = {}) {
async readIncrementalVmBackup(metadata, ignoredVdis, { useChain = true } = {}) {
const handler = this._handler
const { vbds, vhds, vifs, vm, vmSnapshot } = metadata
const dir = dirname(metadata._filename)
@@ -789,7 +729,7 @@ export class RemoteAdapter {
const streams = {}
await asyncMapSettled(Object.keys(vdis), async ref => {
streams[`${ref}.vhd`] = await this._createVhdStream(handler, join(dir, vhds[ref]), { useChain, snapshotedVdis })
streams[`${ref}.vhd`] = await this._createVhdStream(handler, join(dir, vhds[ref]), { useChain })
})
return {

View File

@@ -143,38 +143,11 @@ export async function exportIncrementalVm(
)
}
// @todo movve this to incremental replication
async function detectBaseVdis(vmRecord, sr) {
let baseVm
const xapi = sr.$xapi
const remoteBaseVmUuid = vmRecord.other_config[TAG_BASE_DELTA]
if (remoteBaseVmUuid) {
baseVm = find(
xapi.objects.all,
obj => (obj = obj.other_config) && obj[TAG_COPY_SRC] === remoteBaseVmUuid && obj[TAG_BACKUP_SR] === sr.$id
)
if (!baseVm) {
throw new Error(`could not find the base VM (copy of ${remoteBaseVmUuid})`)
}
}
const baseVdis = {}
baseVm &&
baseVm.$VBDs.forEach(vbd => {
const vdi = vbd.$VDI
if (vdi !== undefined) {
baseVdis[vdi.other_config[TAG_COPY_SRC]] = vbd.$VDI
}
})
return baseVdis
}
export const importIncrementalVm = defer(async function importIncrementalVm(
$defer,
incrementalVm,
sr,
{ baseVdis = {}, cancelToken = CancelToken.none, detectBase = true, mapVdisSrs = {}, newMacAddresses = false } = {}
{ cancelToken = CancelToken.none, detectBase = true, mapVdisSrs = {}, newMacAddresses = false } = {}
) {
const { version } = incrementalVm
if (compareVersions(version, '1.0.0') < 0) {
@@ -184,15 +157,35 @@ export const importIncrementalVm = defer(async function importIncrementalVm(
const vmRecord = incrementalVm.vm
const xapi = sr.$xapi
let baseVm
if (detectBase) {
const remoteBaseVmUuid = vmRecord.other_config[TAG_BASE_DELTA]
if (remoteBaseVmUuid) {
baseVm = find(
xapi.objects.all,
obj => (obj = obj.other_config) && obj[TAG_COPY_SRC] === remoteBaseVmUuid && obj[TAG_BACKUP_SR] === sr.$id
)
if (!baseVm) {
throw new Error(`could not find the base VM (copy of ${remoteBaseVmUuid})`)
}
}
}
const cache = new Map()
const mapVdisSrRefs = {}
for (const [vdiUuid, srUuid] of Object.entries(mapVdisSrs)) {
mapVdisSrRefs[vdiUuid] = await resolveUuid(xapi, cache, srUuid, 'SR')
}
if (detectBase) {
baseVdis = await detectBaseVdis(vmRecord, sr)
}
const baseVdis = {}
baseVm &&
baseVm.$VBDs.forEach(vbd => {
const vdi = vbd.$VDI
if (vdi !== undefined) {
baseVdis[vbd.VDI] = vbd.$VDI
}
})
const vdiRecords = incrementalVm.vdis
// 0. Create suspend_VDI
@@ -256,11 +249,10 @@ export const importIncrementalVm = defer(async function importIncrementalVm(
await asyncMap(Object.keys(vdiRecords), async vdiRef => {
const vdi = vdiRecords[vdiRef]
let newVdi
// @todo how to rewrite this condition when giving directly a baseVdi ?
const remoteBaseVdiUuid = detectBase && vdi.other_config[TAG_BASE_DELTA]
if (remoteBaseVdiUuid) {
const baseVdi = baseVdis[vdi.other_config[TAG_COPY_SRC]]
// @todo : should be an error only for detectBase
const baseVdi = find(baseVdis, vdi => vdi.other_config[TAG_COPY_SRC] === remoteBaseVdiUuid)
if (!baseVdi) {
throw new Error(`missing base VDI (copy of ${remoteBaseVdiUuid})`)
}

View File

@@ -2,8 +2,6 @@
## **next**
- Ability to snapshot/copy a VM from its view (PR [#7087](https://github.com/vatesfr/xen-orchestra/pull/7087))
## **0.1.4** (2023-10-03)
- Ability to migrate selected VMs to another host (PR [#7040](https://github.com/vatesfr/xen-orchestra/pull/7040))

View File

@@ -59,8 +59,6 @@
}
:root.dark {
color-scheme: dark;
--color-blue-scale-000: #ffffff;
--color-blue-scale-100: #e5e5e7;
--color-blue-scale-200: #9899a5;

View File

@@ -1,9 +1,6 @@
<template>
<MenuItem
v-tooltip="
!areAllSelectedVmsHalted &&
$t(isSingleAction ? 'vm-is-running' : 'selected-vms-in-execution')
"
v-tooltip="!areAllSelectedVmsHalted && $t('selected-vms-in-execution')"
:busy="areSomeSelectedVmsCloning"
:disabled="isDisabled"
:icon="faCopy"
@@ -25,7 +22,6 @@ import { computed } from "vue";
const props = defineProps<{
selectedRefs: XenApiVm["$ref"][];
isSingleAction?: boolean;
}>();
const { getByOpaqueRef, isOperationPending } = useVmCollection();

View File

@@ -11,23 +11,6 @@
</template>
<VmActionPowerStateItems :vm-refs="[vm.$ref]" />
</AppMenu>
<AppMenu v-if="vm !== undefined" placement="bottom-end" shadow>
<template #trigger="{ open, isOpen }">
<UiButton
:active="isOpen"
:icon="faEllipsisVertical"
@click="open"
transparent
class="more-actions-button"
v-tooltip="{
placement: 'left',
content: $t('more-actions'),
}"
/>
</template>
<VmActionCopyItem :selected-refs="[vm.$ref]" is-single-action />
<VmActionSnapshotItem :vm-refs="[vm.$ref]" />
</AppMenu>
</template>
</TitleBar>
</template>
@@ -38,15 +21,11 @@ import TitleBar from "@/components/TitleBar.vue";
import UiIcon from "@/components/ui/icon/UiIcon.vue";
import UiButton from "@/components/ui/UiButton.vue";
import VmActionPowerStateItems from "@/components/vm/VmActionItems/VmActionPowerStateItems.vue";
import VmActionSnapshotItem from "@/components/vm/VmActionItems/VmActionSnapshotItem.vue";
import VmActionCopyItem from "@/components/vm/VmActionItems/VmActionCopyItem.vue";
import { useVmCollection } from "@/stores/xen-api/vm.store";
import { vTooltip } from "@/directives/tooltip.directive";
import type { XenApiVm } from "@/libs/xen-api/xen-api.types";
import {
faAngleDown,
faDisplay,
faEllipsisVertical,
faPowerOff,
} from "@fortawesome/free-solid-svg-icons";
import { computed } from "vue";
@@ -61,9 +40,3 @@ const vm = computed(() =>
const name = computed(() => vm.value?.name_label);
</script>
<style lang="postcss">
.more-actions-button {
font-size: 1.2em;
}
</style>

View File

@@ -86,7 +86,6 @@
"loading-hosts": "Loading hosts…",
"log-out": "Log out",
"login": "Login",
"more-actions": "More actions",
"migrate": "Migrate",
"migrate-n-vms": "Migrate 1 VM | Migrate {n} VMs",
"n-hosts-awaiting-patch": "{n} host is awaiting this patch | {n} hosts are awaiting this patch",
@@ -174,7 +173,6 @@
"vcpus": "vCPUs",
"vcpus-used": "vCPUs used",
"version": "Version",
"vm-is-running": "The VM is running",
"vms": "VMs",
"xo-lite-under-construction": "XOLite is under construction"
}

View File

@@ -86,7 +86,6 @@
"loading-hosts": "Chargement des hôtes…",
"log-out": "Se déconnecter",
"login": "Connexion",
"more-actions": "Plus d'actions",
"migrate": "Migrer",
"migrate-n-vms": "Migrer 1 VM | Migrer {n} VMs",
"n-hosts-awaiting-patch": "{n} hôte attend ce patch | {n} hôtes attendent ce patch",
@@ -174,7 +173,6 @@
"vcpus": "vCPUs",
"vcpus-used": "vCPUs utilisés",
"version": "Version",
"vm-is-running": "La VM est en cours d'exécution",
"vms": "VMs",
"xo-lite-under-construction": "XOLite est en construction"
}

View File

@@ -5,4 +5,3 @@ export { default as VBD } from './vbd.mjs'
export { default as VDI } from './vdi.mjs'
export { default as VIF } from './vif.mjs'
export { default as VM } from './vm.mjs'
export { default as VTPM } from './vtpm.mjs'

View File

@@ -123,7 +123,7 @@ class Vdi {
error.SR = await this.getRecord('SR', vdi.SR)
error.VDI = vdi
error.nbdClient = nbdClient
nbdClient?.disconnect()
await nbdClient?.disconnect()
throw error
}
}

View File

@@ -1,37 +0,0 @@
import upperFirst from 'lodash/upperFirst.js'
import { incorrectState } from 'xo-common/api-errors.js'
export default class Vtpm {
async create({ is_unique = false, VM }) {
const pool = this.pool
// If VTPM.create is called on a pool that doesn't support VTPM, the errors aren't explicit.
// See https://github.com/xapi-project/xen-api/issues/5186
if (pool.restrictions.restrict_vtpm !== 'false') {
throw incorrectState({
actual: pool.restrictions.restrict_vtpm,
expected: 'false',
object: pool.uuid,
property: 'restrictions.restrict_vtpm',
})
}
try {
return await this.call('VTPM.create', VM, is_unique)
} catch (error) {
const { code, params } = error
if (code === 'VM_BAD_POWER_STATE') {
const [, expected, actual] = params
// In `VM_BAD_POWER_STATE` errors, the power state is lowercased
throw incorrectState({
actual: upperFirst(actual),
expected: upperFirst(expected),
object: await this.getField('VM', VM, 'uuid'),
property: 'power_state',
})
}
throw error
}
}
}

View File

@@ -9,20 +9,14 @@
- [Host/Advanced] Allow to force _Smart reboot_ if some resident VMs have the suspend operation blocked [Forum#7136](https://xcp-ng.org/forum/topic/7136/suspending-vms-during-host-reboot/23) (PR [#7025](https://github.com/vatesfr/xen-orchestra/pull/7025))
- [Plugin/backup-report] Errors are now listed in XO tasks
- [PIF] Show network name in PIF selectors (PR [#7081](https://github.com/vatesfr/xen-orchestra/pull/7081))
### Bug fixes
> Users must be able to say: “I had this issue, happy to know it's fixed”
- [Rolling Pool Update] After the update, when migrating VMs back to their host, do not migrate VMs that are already on the right host [Forum#7802](https://xcp-ng.org/forum/topic/7802) (PR [#7071](https://github.com/vatesfr/xen-orchestra/pull/7071))
- [RPU] Fix "XenServer credentials not found" when running a Rolling Pool Update on a XenServer pool (PR [#7089](https://github.com/vatesfr/xen-orchestra/pull/7089))
- [Usage report] Fix "Converting circular structure to JSON" error
- [Home] Fix OS icons alignment (PR [#7090](https://github.com/vatesfr/xen-orchestra/pull/7090))
- [SR/Advanced] Fix the total number of VDIs to coalesce by taking into account common chains [#7016](https://github.com/vatesfr/xen-orchestra/issues/7016) (PR [#7098](https://github.com/vatesfr/xen-orchestra/pull/7098))
- Don't require to sign in again in XO after losing connection to XO Server (e.g. when restarting or upgrading XO) (PR [#7103](https://github.com/vatesfr/xen-orchestra/pull/7103))
- [Usage report] Fix "Converting circular structure to JSON" error (PR [#7096](https://github.com/vatesfr/xen-orchestra/pull/7096))
- [Usage report] Fix "Cannot convert undefined or null to object" error (PR [#7092](https://github.com/vatesfr/xen-orchestra/pull/7092))
- [Backup/Mirror] Fix backup report not being sent (PR [#7049](https://github.com/vatesfr/xen-orchestra/pull/7049))
- [New VM] Only add MBR to cloud-init drive on Windows VMs to avoid booting issues (e.g. with Talos) (PR [#7050](https://github.com/vatesfr/xen-orchestra/pull/7050))
- [VDI Import] Add the SR name to the corresponding XAPI task (PR [#6979](https://github.com/vatesfr/xen-orchestra/pull/6979))
### Packages to release
@@ -44,8 +38,6 @@
- @xen-orchestra/xapi minor
- xo-server minor
- xo-server-backup-reports minor
- xo-server-netbox patch
- xo-server-usage-report patch
- xo-web minor
<!--packages-end-->

View File

@@ -362,7 +362,7 @@ XO will try to find the right prefix for each IP address. If it can't find a pre
- Assign it to object types:
- Virtualization > cluster
- Virtualization > virtual machine
- Virtualization > interface
- Virtualization > interface`
![](./assets/customfield.png)

View File

@@ -106,7 +106,7 @@ XO needs the following packages to be installed. Redis is used as a database by
For example, on Debian/Ubuntu:
```sh
apt-get install build-essential redis-server libpng-dev git python3-minimal libvhdi-utils lvm2 cifs-utils nfs-common
apt-get install build-essential redis-server libpng-dev git python3-minimal libvhdi-utils lvm2 cifs-utils
```
On Fedora/CentOS like:

View File

@@ -37,7 +37,7 @@ function mapProperties(object, mapping) {
}
async function showDetails(handler, path) {
const {value: vhd} = await openVhd(handler, resolve(path))
const vhd = new VhdFile(handler, resolve(path))
try {
await vhd.readHeaderAndFooter()

View File

@@ -103,8 +103,6 @@ class Netbox {
}
async test() {
await this.#checkCustomFields()
const randomSuffix = Math.random().toString(36).slice(2, 11)
const name = '[TMP] Xen Orchestra Netbox plugin test - ' + randomSuffix
await this.#request('/virtualization/cluster-types/', 'POST', {
@@ -115,6 +113,8 @@ class Netbox {
})
const nbClusterTypes = await this.#request(`/virtualization/cluster-types/?name=${encodeURIComponent(name)}`)
await this.#checkCustomFields()
if (nbClusterTypes.length !== 1) {
throw new Error('Could not properly write and read Netbox')
}

View File

@@ -12,9 +12,9 @@ import {
filter,
find,
forEach,
get,
isFinite,
map,
mapValues,
orderBy,
round,
values,
@@ -204,11 +204,6 @@ function computeMean(values) {
}
})
// No values to work with, return null
if (n === 0) {
return null
}
return sum / n
}
@@ -231,7 +226,7 @@ function getTop(objects, options) {
object => {
const value = object[opt]
return isNaN(value) || value === null ? -Infinity : value
return isNaN(value) ? -Infinity : value
},
'desc'
).slice(0, 3),
@@ -249,9 +244,7 @@ function computePercentage(curr, prev, options) {
return zipObject(
options,
map(options, opt =>
prev[opt] === 0 || prev[opt] === null || curr[opt] === null
? 'NONE'
: `${((curr[opt] - prev[opt]) * 100) / prev[opt]}`
prev[opt] === 0 || prev[opt] === null ? 'NONE' : `${((curr[opt] - prev[opt]) * 100) / prev[opt]}`
)
)
}
@@ -264,15 +257,7 @@ function getDiff(oldElements, newElements) {
}
function getMemoryUsedMetric({ memory, memoryFree = memory }) {
return map(memory, (value, key) => {
const tMemory = value
const tMemoryFree = memoryFree[key]
if (tMemory == null || tMemoryFree == null) {
return null
}
return tMemory - tMemoryFree
})
return map(memory, (value, key) => value - memoryFree[key])
}
const METRICS_MEAN = {
@@ -289,61 +274,51 @@ const DAYS_TO_KEEP = {
weekly: 7,
monthly: 30,
}
function getDeepLastValues(data, nValues) {
if (data == null) {
return {}
function getLastDays(data, periodicity) {
const daysToKeep = DAYS_TO_KEEP[periodicity]
const expectedData = {}
for (const [key, value] of Object.entries(data)) {
if (Array.isArray(value)) {
// slice only applies to array
expectedData[key] = value.slice(-daysToKeep)
} else {
expectedData[key] = value
}
}
if (Array.isArray(data)) {
return data.slice(-nValues)
}
if (typeof data !== 'object') {
throw new Error('data must be an object or an array')
}
return mapValues(data, value => getDeepLastValues(value, nValues))
return expectedData
}
// ===================================================================
async function getVmsStats({ runningVms, periodicity, xo }) {
const lastNValues = DAYS_TO_KEEP[periodicity]
return orderBy(
await Promise.all(
map(runningVms, async vm => {
const stats = getDeepLastValues(
(
await xo.getXapiVmStats(vm, GRANULARITY).catch(error => {
log.warn('Error on fetching VM stats', {
error,
vmId: vm.id,
})
return {
stats: {},
}
})
).stats,
lastNValues
)
const { stats } = await xo.getXapiVmStats(vm, GRANULARITY).catch(error => {
log.warn('Error on fetching VM stats', {
error,
vmId: vm.id,
})
return {
stats: {},
}
})
const iopsRead = METRICS_MEAN.iops(stats.iops?.r)
const iopsWrite = METRICS_MEAN.iops(stats.iops?.w)
const iopsRead = METRICS_MEAN.iops(getLastDays(get(stats.iops, 'r'), periodicity))
const iopsWrite = METRICS_MEAN.iops(getLastDays(get(stats.iops, 'w'), periodicity))
return {
uuid: vm.uuid,
name: vm.name_label,
addresses: Object.values(vm.addresses),
cpu: METRICS_MEAN.cpu(stats.cpus),
ram: METRICS_MEAN.ram(getMemoryUsedMetric(stats)),
diskRead: METRICS_MEAN.disk(stats.xvds?.r),
diskWrite: METRICS_MEAN.disk(stats.xvds?.w),
cpu: METRICS_MEAN.cpu(getLastDays(stats.cpus, periodicity)),
ram: METRICS_MEAN.ram(getLastDays(getMemoryUsedMetric(stats), periodicity)),
diskRead: METRICS_MEAN.disk(getLastDays(get(stats.xvds, 'r'), periodicity)),
diskWrite: METRICS_MEAN.disk(getLastDays(get(stats.xvds, 'w'), periodicity)),
iopsRead,
iopsWrite,
iopsTotal: iopsRead + iopsWrite,
netReception: METRICS_MEAN.net(stats.vifs?.rx),
netTransmission: METRICS_MEAN.net(stats.vifs?.tx),
netReception: METRICS_MEAN.net(getLastDays(get(stats.vifs, 'rx'), periodicity)),
netTransmission: METRICS_MEAN.net(getLastDays(get(stats.vifs, 'tx'), periodicity)),
}
})
),
@@ -353,34 +328,27 @@ async function getVmsStats({ runningVms, periodicity, xo }) {
}
async function getHostsStats({ runningHosts, periodicity, xo }) {
const lastNValues = DAYS_TO_KEEP[periodicity]
return orderBy(
await Promise.all(
map(runningHosts, async host => {
const stats = getDeepLastValues(
(
await xo.getXapiHostStats(host, GRANULARITY).catch(error => {
log.warn('Error on fetching host stats', {
error,
hostId: host.id,
})
return {
stats: {},
}
})
).stats,
lastNValues
)
const { stats } = await xo.getXapiHostStats(host, GRANULARITY).catch(error => {
log.warn('Error on fetching host stats', {
error,
hostId: host.id,
})
return {
stats: {},
}
})
return {
uuid: host.uuid,
name: host.name_label,
cpu: METRICS_MEAN.cpu(stats.cpus),
ram: METRICS_MEAN.ram(getMemoryUsedMetric(stats)),
load: METRICS_MEAN.load(stats.load),
netReception: METRICS_MEAN.net(stats.pifs?.rx),
netTransmission: METRICS_MEAN.net(stats.pifs?.tx),
cpu: METRICS_MEAN.cpu(getLastDays(stats.cpus, periodicity)),
ram: METRICS_MEAN.ram(getLastDays(getMemoryUsedMetric(stats), periodicity)),
load: METRICS_MEAN.load(getLastDays(stats.load, periodicity)),
netReception: METRICS_MEAN.net(getLastDays(get(stats.pifs, 'rx'), periodicity)),
netTransmission: METRICS_MEAN.net(getLastDays(get(stats.pifs, 'tx'), periodicity)),
}
})
),
@@ -390,8 +358,6 @@ async function getHostsStats({ runningHosts, periodicity, xo }) {
}
async function getSrsStats({ periodicity, xo, xoObjects }) {
const lastNValues = DAYS_TO_KEEP[periodicity]
return orderBy(
await asyncMapSettled(
filter(xoObjects, obj => obj.type === 'SR' && obj.size > 0 && obj.$PBDs.length > 0),
@@ -405,23 +371,18 @@ async function getSrsStats({ periodicity, xo, xoObjects }) {
name += ` (${container.name_label})`
}
const stats = getDeepLastValues(
(
await xo.getXapiSrStats(sr.id, GRANULARITY).catch(error => {
log.warn('Error on fetching SR stats', {
error,
srId: sr.id,
})
return {
stats: {},
}
})
).stats,
lastNValues
)
const { stats } = await xo.getXapiSrStats(sr.id, GRANULARITY).catch(error => {
log.warn('Error on fetching SR stats', {
error,
srId: sr.id,
})
return {
stats: {},
}
})
const iopsRead = computeMean(stats.iops?.r)
const iopsWrite = computeMean(stats.iops?.w)
const iopsRead = computeMean(getLastDays(get(stats.iops, 'r'), periodicity))
const iopsWrite = computeMean(getLastDays(get(stats.iops, 'w'), periodicity))
return {
uuid: sr.uuid,
@@ -516,7 +477,7 @@ async function getHostsMissingPatches({ runningHosts, xo }) {
.getXapi(host)
.listMissingPatches(host._xapiId)
.catch(error => {
log.warn('Error on fetching hosts missing patches', { error })
console.error('[WARN] error on fetching hosts missing patches:', JSON.stringify(error))
return []
})
@@ -780,7 +741,7 @@ class UsageReportPlugin {
try {
await this._sendReport(true)
} catch (error) {
log.warn('Scheduled usage report error', { error })
console.error('[WARN] scheduled function:', (error && error.stack) || error)
}
})

View File

@@ -5,7 +5,6 @@ import asyncMapSettled from '@xen-orchestra/async-map/legacy.js'
import { Task } from '@xen-orchestra/mixins/Tasks.mjs'
import concat from 'lodash/concat.js'
import hrp from 'http-request-plus'
import mapKeys from 'lodash/mapKeys.js'
import { createLogger } from '@xen-orchestra/log'
import { defer } from 'golike-defer'
import { format } from 'json-rpc-peer'
@@ -623,8 +622,6 @@ warmMigration.params = {
// -------------------------------------------------------------------
const autoPrefix = (pfx, str) => (str.startsWith(pfx) ? str : pfx + str)
export const set = defer(async function ($defer, params) {
const VM = extract(params, 'VM')
const xapi = this.getXapi(VM)
@@ -649,11 +646,6 @@ export const set = defer(async function ($defer, params) {
await xapi.call('VM.set_suspend_SR', VM._xapiRef, suspendSr === null ? Ref.EMPTY : suspendSr._xapiRef)
}
const xenStoreData = extract(params, 'xenStoreData')
if (xenStoreData !== undefined) {
await this.getXapiObject(VM).update_xenstore_data(mapKeys(xenStoreData, (v, k) => autoPrefix('vm-data/', k)))
}
return xapi.editVm(vmId, params, async (limits, vm) => {
const resourceSet = xapi.xo.getData(vm, 'resourceSet')
@@ -755,15 +747,6 @@ set.params = {
blockedOperations: { type: 'object', optional: true, properties: { '*': { type: ['boolean', 'null', 'string'] } } },
suspendSr: { type: ['string', 'null'], optional: true },
xenStoreData: {
description: 'properties that should be set or deleted (if null) in the VM XenStore',
optional: true,
type: 'object',
additionalProperties: {
type: ['null', 'string'],
},
},
}
set.resolve = {

View File

@@ -1,29 +0,0 @@
export async function create({ vm }) {
const xapi = this.getXapi(vm)
const vtpmRef = await xapi.VTPM_create({ VM: vm._xapiRef })
return xapi.getField('VTPM', vtpmRef, 'uuid')
}
create.description = 'create a VTPM'
create.params = {
id: { type: 'string' },
}
create.resolve = {
vm: ['id', 'VM', 'administrate'],
}
export async function destroy({ vtpm }) {
await this.getXapi(vtpm).call('VTPM.destroy', vtpm._xapiRef)
}
destroy.description = 'destroy a VTPM'
destroy.params = {
id: { type: 'string' },
}
destroy.resolve = {
vtpm: ['id', 'VTPM', 'administrate'],
}

View File

@@ -118,7 +118,6 @@ const TRANSFORMS = {
},
suspendSr: link(obj, 'suspend_image_SR'),
zstdSupported: obj.restrictions.restrict_zstd_export === 'false',
vtpmSupported: obj.restrictions.restrict_vtpm === 'false',
// TODO
// - ? networks = networksByPool.items[pool.id] (network.$pool.id)
@@ -414,7 +413,6 @@ const TRANSFORMS = {
suspendSr: link(obj, 'suspend_SR'),
tags: obj.tags,
VIFs: link(obj, 'VIFs'),
VTPMs: link(obj, 'VTPMs'),
virtualizationMode: domainType,
// deprecated, use pvDriversVersion instead
@@ -843,14 +841,6 @@ const TRANSFORMS = {
vgpus: link(obj, 'VGPUs'),
}
},
vtpm(obj) {
return {
type: 'VTPM',
vm: link(obj, 'VM'),
}
},
}
// ===================================================================

View File

@@ -405,11 +405,6 @@ export default {
},
_poolWideInstall: deferrable(async function ($defer, patches, xsCredentials) {
// New XS patching system: https://support.citrix.com/article/CTX473972/upcoming-changes-in-xencenter
if (xsCredentials?.username === undefined || xsCredentials?.apikey === undefined) {
throw new Error('XenServer credentials not found. See https://xen-orchestra.com/docs/updater.html#xenserver-updates')
}
// Legacy XS patches
if (!useUpdateSystem(this.pool.$master)) {
// for each patch: pool_patch.pool_apply
@@ -425,6 +420,11 @@ export default {
}
// ----------
// New XS patching system: https://support.citrix.com/article/CTX473972/upcoming-changes-in-xencenter
if (xsCredentials?.username === undefined || xsCredentials?.apikey === undefined) {
throw new Error('XenServer credentials not found. See https://xen-orchestra.com/docs/updater.html#xenserver-updates')
}
// for each patch: pool_update.introduce → pool_update.pool_apply
for (const p of patches) {
const [vdi] = await Promise.all([this._uploadPatch($defer, p.uuid, xsCredentials), this._ejectToolsIsos()])
@@ -493,7 +493,7 @@ export default {
},
@decorateWith(deferrable)
async rollingPoolUpdate($defer, { xsCredentials } = {}) {
async rollingPoolUpdate($defer) {
const isXcp = _isXcp(this.pool.$master)
if (this.pool.ha_enabled) {
@@ -530,7 +530,7 @@ export default {
// On XS/CH, start by installing patches on all hosts
if (!isXcp) {
log.debug('Install patches')
await this.installPatches({ xsCredentials })
await this.installPatches()
}
// Remember on which hosts the running VMs are
@@ -629,13 +629,7 @@ export default {
continue
}
const residentVms = host.$resident_VMs.map(vm => vm.uuid)
for (const vmId of vmIds) {
if (residentVms.includes(vmId)) {
continue
}
try {
await this.migrateVm(vmId, this, hostId)
} catch (err) {

View File

@@ -49,19 +49,18 @@ export default {
await this._unplugPbd(this.getObject(id))
},
_getVdiChainsInfo(uuid, childrenMap, cache, resultContainer) {
_getVdiChainsInfo(uuid, childrenMap, cache) {
let info = cache[uuid]
if (info === undefined) {
const children = childrenMap[uuid]
const unhealthyLength = children !== undefined && children.length === 1 ? 1 : 0
resultContainer.nUnhealthyVdis += unhealthyLength
const vdi = this.getObjectByUuid(uuid, undefined)
if (vdi === undefined) {
info = { unhealthyLength, missingParent: uuid }
} else {
const parent = vdi.sm_config['vhd-parent']
if (parent !== undefined) {
info = this._getVdiChainsInfo(parent, childrenMap, cache, resultContainer)
info = this._getVdiChainsInfo(parent, childrenMap, cache)
info.unhealthyLength += unhealthyLength
} else {
info = { unhealthyLength }
@@ -77,13 +76,12 @@ export default {
const unhealthyVdis = { __proto__: null }
const children = groupBy(vdis, 'sm_config.vhd-parent')
const vdisWithUnknownVhdParent = { __proto__: null }
const resultContainer = { nUnhealthyVdis: 0 }
const cache = { __proto__: null }
forEach(vdis, vdi => {
if (vdi.managed && !vdi.is_a_snapshot) {
const { uuid } = vdi
const { unhealthyLength, missingParent } = this._getVdiChainsInfo(uuid, children, cache, resultContainer)
const { unhealthyLength, missingParent } = this._getVdiChainsInfo(uuid, children, cache)
if (unhealthyLength !== 0) {
unhealthyVdis[uuid] = unhealthyLength
@@ -97,7 +95,6 @@ export default {
return {
vdisWithUnknownVhdParent,
unhealthyVdis,
...resultContainer,
}
},

View File

@@ -62,14 +62,11 @@ export default class Pools {
}
const patchesName = await Promise.all([targetXapi.findPatches(targetRequiredPatches), ...findPatchesPromises])
const { xsCredentials } = _app.apiContext.user.preferences
// Install patches in parallel.
const installPatchesPromises = []
installPatchesPromises.push(
targetXapi.installPatches({
patches: patchesName[0],
xsCredentials,
})
)
let i = 1
@@ -77,7 +74,6 @@ export default class Pools {
installPatchesPromises.push(
sourceXapis[sourceId].installPatches({
patches: patchesName[i++],
xsCredentials,
})
)
}

View File

@@ -686,7 +686,7 @@ export default class XenServers {
$defer(() => app.loadPlugin('load-balancer'))
}
await this.getXapi(pool).rollingPoolUpdate({ xsCredentials: app.apiContext.user.preferences.xsCredentials })
await this.getXapi(pool).rollingPoolUpdate()
}
}

View File

@@ -6,7 +6,7 @@ import React from 'react'
const Icon = ({ icon, size = 1, color, fixedWidth, ...props }) => {
props.className = classNames(
props.className,
icon != null ? `xo-icon-${icon}` : 'fa', // Misaligned problem modification: if no icon or null, apply 'fa'
icon !== undefined ? `xo-icon-${icon}` : 'fa', // Without icon prop, is a placeholder.
isInteger(size) ? `fa-${size}x` : `fa-${size}`,
color,
fixedWidth && 'fa-fw'

View File

@@ -299,63 +299,6 @@ Vdi.defaultProps = {
// ===================================================================
export const Pif = decorate([
connectStore(() => {
const getObject = createGetObject()
const getNetwork = createGetObject(createSelector(getObject, pif => get(() => pif.$network)))
// FIXME: props.self ugly workaround to get object as a self user
return (state, props) => ({
pif: getObject(state, props, props.self),
network: getNetwork(state, props),
})
}),
({ id, showNetwork, pif, network }) => {
if (pif === undefined) {
return unknowItem(id, 'PIF')
}
const { carrier, device, deviceName, vlan } = pif
const showExtraInfo = deviceName || vlan !== -1 || (showNetwork && network !== undefined)
return (
<span>
<Icon icon='network' color={carrier ? 'text-success' : 'text-danger'} /> {device}
{showExtraInfo && (
<span>
{' '}
({deviceName}
{vlan !== -1 && (
<span>
{' '}
-{' '}
{_('keyValue', {
key: _('pifVlanLabel'),
value: vlan,
})}
</span>
)}
{showNetwork && network !== undefined && <span> - {network.name_label}</span>})
</span>
)}
</span>
)
},
])
Pif.propTypes = {
id: PropTypes.string.isRequired,
self: PropTypes.bool,
showNetwork: PropTypes.bool,
}
Pif.defaultProps = {
self: false,
showNetwork: false,
}
// ===================================================================
export const Network = decorate([
connectStore(() => {
const getObject = createGetObject()
@@ -618,8 +561,24 @@ const xoItemToRender = {
),
// PIF.
PIF: props => <Pif {...props} />,
PIF: ({ carrier, device, deviceName, vlan }) => (
<span>
<Icon icon='network' color={carrier ? 'text-success' : 'text-danger'} /> {device}
{(deviceName !== '' || vlan !== -1) && (
<span>
{' '}
({deviceName}
{deviceName !== '' && vlan !== -1 && ' - '}
{vlan !== -1 &&
_('keyValue', {
key: _('pifVlanLabel'),
value: vlan,
})}
)
</span>
)}
</span>
),
// Tags.
tag: tag => (
<span>

View File

@@ -251,7 +251,6 @@ class GenericSelect extends React.Component {
? `${option.xoItem.type}-resourceSet`
: undefined,
memoryFree: option.xoItem.type === 'host' || undefined,
showNetwork: true,
})}
</span>
)

View File

@@ -109,13 +109,7 @@ const xo = invoke(() => {
credentials: { token },
})
xo.on('authenticationFailure', error => {
console.warn('authenticationFailure', error)
if (error.name !== 'ConnectionError') {
signOut(error)
}
})
xo.on('authenticationFailure', signOut)
xo.on('scheduledAttempt', ({ delay }) => {
console.warn('next attempt in %s ms', delay)
})

View File

@@ -10,7 +10,7 @@ import { CustomFields } from 'custom-fields'
import { createGetObjectsOfType } from 'selectors'
import { createSelector } from 'reselect'
import { createSrUnhealthyVdiChainsLengthSubscription, deleteSr, reclaimSrSpace, toggleSrMaintenanceMode } from 'xo'
import { flowRight, isEmpty, keys } from 'lodash'
import { flowRight, isEmpty, keys, sum, values } from 'lodash'
// ===================================================================
@@ -44,11 +44,11 @@ const UnhealthyVdiChains = flowRight(
connectStore(() => ({
vdis: createGetObjectsOfType('VDI').pick(createSelector((_, props) => props.chains?.unhealthyVdis, keys)),
}))
)(({ chains: { nUnhealthyVdis, unhealthyVdis } = {}, vdis }) =>
)(({ chains: { unhealthyVdis } = {}, vdis }) =>
isEmpty(vdis) ? null : (
<div>
<hr />
<h3>{_('srUnhealthyVdiTitle', { total: nUnhealthyVdis })}</h3>
<h3>{_('srUnhealthyVdiTitle', { total: sum(values(unhealthyVdis)) })}</h3>
<SortedTable collection={vdis} columns={COLUMNS} stateUrlParam='s_unhealthy_vdis' userData={unhealthyVdis} />
</div>
)