Skip to content

Commit

Permalink
improve srs list and default sr
Browse files Browse the repository at this point in the history
  • Loading branch information
J0ris-K committed Feb 11, 2025
1 parent 4bdd880 commit bdef50b
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 22 deletions.
4 changes: 2 additions & 2 deletions @xen-orchestra/lite/src/libs/xen-api/xen-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -379,10 +379,10 @@ export default class XenApi {
)
},

clone: (vmRefsToClone: VmRefsWithNameLabel) => {
clone: (vmRefsToClone: VmRefsWithNameLabel): Promise<XenApiVm['$ref'][]> => {
const vmRefs = Object.keys(vmRefsToClone) as XenApiVm['$ref'][]

return Promise.all(vmRefs.map(vmRef => this.call('VM.clone', [vmRef, vmRefsToClone[vmRef]])))
return Promise.all(vmRefs.map(vmRef => this.call<XenApiVm['$ref']>('VM.clone', [vmRef, vmRefsToClone[vmRef]])))
},

provision: (vmRefs: VmRefs) => {
Expand Down
2 changes: 1 addition & 1 deletion @xen-orchestra/lite/src/types/new-vm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ export interface Disk {
name_label: string
name_description: string
size: number
SR: string
SR: string | undefined
}

export interface NetworkInterface {
Expand Down
32 changes: 13 additions & 19 deletions @xen-orchestra/lite/src/views/new-vm/NewVmView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@
<tr v-for="(disk, index) in newVmState.existingDisks" :key="index">
<td>
<FormSelect v-model="disk.SR">
<option v-for="sr in srs" :key="sr.uuid" :value="sr.name_label">
<option v-for="sr in getFilteredSrs" :key="sr.uuid" :value="sr.name_label">
{{ sr.name_label }}
</option>
</FormSelect>
Expand Down Expand Up @@ -229,7 +229,7 @@
<tr v-for="(disk, index) in newVmState.VDIs" :key="index">
<td>
<FormSelect v-model="disk.SR">
<option v-for="sr in srs" :key="sr.uuid" :value="sr.name_label">
<option v-for="sr in getFilteredSrs" :key="sr.uuid" :value="sr.name_label">
{{ sr.name_label }}
</option>
</FormSelect>
Expand Down Expand Up @@ -389,8 +389,8 @@ const addStorageEntry = () => {
newVmState.existingDisks.push({
name_label: (newVmState.vm_name || 'disk') + '_' + generateRandomString(4),
name_description: 'Created by XO',
size: '',
SR: getOpaqueRefSr(pool?.value?.default_SR)?.name_label || '',
size: 0,
SR: pool.value ? getOpaqueRefSr(pool.value.default_SR)?.name_label || '' : '',
})
}
}
Expand All @@ -410,19 +410,13 @@ const isDiskTemplate = (template: XenApiVm) => {
return template && template.VBDs.length !== 0 && template.name_label !== 'Other install media'
}
const getDefaultSr = (template: XenApiVm) => {
if (pool.value !== undefined) {
return pool.value.default_SR
}
if (template === undefined) {
return
}
const defaultSr = pool.value?.default_SR || ''
const getDefaultSr = computed(() => {
return pool && pool.value ? getOpaqueRefSr(pool.value?.default_SR)?.name_label : ''
})
return srs.value.filter(sr => sr.uuid === defaultSr.uuid && sr.content_type !== 'iso' && sr.physical_size > 0)
}
const getFilteredSrs = computed(() => {
return srs.value.filter(sr => sr.content_type !== 'iso' && sr.physical_size > 0)
})
const getVDis = (template: XenApiVm) => {
const VdisArray = [] as Disk[]
Expand All @@ -442,7 +436,7 @@ const getVDis = (template: XenApiVm) => {
name_label: (newVmState.vm_name || 'disk') + '_' + generateRandomString(4),
name_description: 'Created by XO',
size: byteFormatter(Number(size)),
SR: getOpaqueRefSr(getDefaultSr(template))?.name_label,
SR: getDefaultSr.value,
})
return VdisArray
Expand All @@ -464,7 +458,7 @@ const getExistingDisks = (template: XenApiVm) => {
name_label: vdi.name_label,
name_description: vdi.name_description,
size: byteFormatter(vdi.virtual_size),
SR: vdi.SR ? getOpaqueRefSr(vdi.SR)?.name_label : getDefaultSr(template),
SR: vdi.SR ? getOpaqueRefSr(vdi.SR)?.name_label : getDefaultSr.value,
})
}
})
Expand Down Expand Up @@ -633,7 +627,7 @@ const createVM = async () => {
console.log('VIFS: =>', data.value.VIFs)
const vmRef = await xapi.vm.clone({ [templateRef]: newVmName })
console.log('Clone réussi, référence VM:', vmRef)
console.log('Clone réussi, référence VM :', vmRef)
await Promise.all([
xapi.vm.setNameLabel(vmRef, data.value.name_label),
Expand Down

0 comments on commit bdef50b

Please sign in to comment.