Skip to content
Draft
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ export function createHostOperations(xenApi: XenApi) {

const shutdown = (hostRef: HostRef) => xenApi.call('host.shutdown', [hostRef])

const destroy = (hostRef: HostRef) => xenApi.call('host.destroy', [hostRef])

const clearHost = async (hostRef: HostRef, force: boolean) => {
await disable(hostRef)

Expand All @@ -37,6 +39,7 @@ export function createHostOperations(xenApi: XenApi) {
reboot,
powerOn,
shutdown,
destroy,
cleanReboot: async (hostRef: HostRef, forceReboot: boolean) => {
await clearHost(hostRef, forceReboot)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@
<HostPowerStateActions :host />
</template>
</MenuItem>
<HostForgetButton :host />
<VtsDivider type="stretch" />
<HostDownloadButton :host-opaque-ref="host.$ref" />
</template>

<script setup lang="ts">
import type { XenApiHost } from '@/libs/xen-api/xen-api.types.ts'
import HostDownloadButton from '@/modules/host/components/actions/download/HostDownloadButton.vue'
import HostForgetButton from '@/modules/host/components/actions/forget/HostForgetButton.vue'
import HostPowerStateActions from '@/modules/host/components/actions/HostPowerStateActions.vue'
import VtsDivider from '@core/components/divider/VtsDivider.vue'
import MenuItem from '@core/components/menu/MenuItem.vue'
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<template>
<MenuItem
v-tooltip="!canForgetHost && forgetHostErrorMessage"
:busy="isForgettingHost"
class="host-forget-button"
:disabled="!canForgetHost"
icon="action:forget"
@click="forgetHost()"
>
{{ t('action:forget') }}
</MenuItem>
</template>

<script lang="ts" setup>
import type { XenApiHost } from '@/libs/xen-api/xen-api.types.ts'
import { useHostForgetJob } from '@/modules/host/jobs/host-forget.job.ts'
import MenuItem from '@core/components/menu/MenuItem.vue'
import { useActionModal } from '@core/composables/modals/use-action-modal.ts'
import { vTooltip } from '@core/directives/tooltip.directive.ts'
import { useI18n } from 'vue-i18n'

const { host } = defineProps<{
host: XenApiHost
}>()

const { t } = useI18n()

const { open: openActionModal } = useActionModal()

const {
run,
canRun: canForgetHost,
isRunning: isForgettingHost,
errorMessage: forgetHostErrorMessage,
} = useHostForgetJob(() => host)

async function forgetHost() {
const { event } = await openActionModal({
props: {
accent: 'danger',
action: 'forget',
object: 'host',
hostName: host.name_label,
icon: 'status:danger-circle',
},
})

if (event !== 'onConfirm') {
return
}

try {
await run()
} catch (error) {
console.error('Error when forgetting host:', error)
}
}
</script>

<style lang="postcss" scoped>
.host-forget-button {
color: var(--color-danger-item-base);
}
</style>
29 changes: 29 additions & 0 deletions @xen-orchestra/lite/src/modules/host/jobs/host-forget.job.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { hostArg } from '@/modules/host/jobs/host-args.ts'
import { useHostMetricsStore } from '@/stores/xen-api/host-metrics.store.ts'
import { useXenApiStore } from '@/stores/xen-api.store.ts'
import { defineJob, JobError, JobRunningError } from '@core/packages/job'
import { useI18n } from 'vue-i18n'

export const useHostForgetJob = defineJob('host.forget', [hostArg], () => {
const xapi = useXenApiStore().getXapi()
const { t } = useI18n()
const { isHostHalted } = useHostMetricsStore().subscribe()

return {
run: host => xapi.host.destroy(host.$ref),

validate: (isRunning, host) => {
if (host === undefined) {
throw new JobError(t('job:host-forget:missing-host'))
}

if (!isHostHalted(host)) {
throw new JobError(t('job:host-forget:bad-power-state'))
}

if (isRunning) {
throw new JobRunningError(t('job:host-forget:in-progress'))
}
},
}
})
Loading