Skip to content

Commit

Permalink
update vsphere machine config to use new networks endpoint (#12263)
Browse files Browse the repository at this point in the history
* update vsphere machine config to use new networks endpoint

* update vapp options to reference network name not moid

* vapp wip

* clear out vapp config when switching to custom
  • Loading branch information
mantis-toboggan-md authored Oct 16, 2024
1 parent 614826f commit d23db14
Show file tree
Hide file tree
Showing 2 changed files with 140 additions and 98 deletions.
10 changes: 7 additions & 3 deletions shell/components/form/ArrayList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -138,10 +138,14 @@ export default {
}
},
watch: {
value() {
this.lastUpdateWasFromValue = true;
this.rows = (this.value || []).map((v) => ({ value: v }));
value: {
deep: true,
handler() {
this.lastUpdateWasFromValue = true;
this.rows = (this.value || []).map((v) => ({ value: v }));
}
},
rows: {
deep: true,
handler(newValue, oldValue) {
Expand Down
228 changes: 133 additions & 95 deletions shell/machine-config/vmwarevsphere.vue
Original file line number Diff line number Diff line change
Expand Up @@ -64,48 +64,26 @@ const networksToVappProperties = (networks) => {
}
return networks.reduce(networkToVappProperties, [
`guestinfo.dns.servers=\${dns:${ networks[0] }}`,
`guestinfo.dns.domains=\${searchPath:${ networks[0] }}`
`guestinfo.dns.servers=\${dns:${ nameOnly(networks[0]) }}`,
`guestinfo.dns.domains=\${searchPath:${ nameOnly(networks[0]) }}`
]);
};
const networkToVappProperties = (props, network, i) => {
const n = i.toString();
const networkName = nameOnly(network);
props.push(
`guestinfo.interface.${ n }.ip.0.address=ip:${ network }`,
`guestinfo.interface.${ n }.ip.0.netmask=\${netmask:${ network }}`,
`guestinfo.interface.${ n }.route.0.gateway=\${gateway:${ network }}`
`guestinfo.interface.${ n }.ip.0.address=ip:${ networkName }`,
`guestinfo.interface.${ n }.ip.0.netmask=\${netmask:${ networkName }}`,
`guestinfo.interface.${ n }.route.0.gateway=\${gateway:${ networkName }}`
);
return props;
};
const getInitialVappMode = (c) => {
const vappProperty = c.vappProperty || [];
if (
!c.vappIpprotocol &&
!c.vappIpallocationpolicy &&
!c.vappTransport &&
vappProperty.length === 0
) {
return VAPP_MODE.DISABLED;
}
const d = getDefaultVappOptions(c.network || []);
if (
c.vappIpprotocol === d.vappIpprotocol &&
c.vappIpallocationpolicy === d.vappIpallocationpolicy &&
c.vappTransport === d.vappTransport &&
vappProperty.length === d.vappProperty.length &&
vappProperty.join() === d.vappProperty.join()
) {
return VAPP_MODE.AUTO;
}
return VAPP_MODE.MANUAL;
const nameOnly = (network) => {
return network.split('/').pop();
};
/**
Expand Down Expand Up @@ -266,9 +244,10 @@ export default {
haveAttributes: null,
haveTemplates: null,
vAppOptions,
vappMode: getInitialVappMode(this.value),
osOptions: OS_OPTIONS,
validationErrors: {},
vappMode: VAPP_MODE.DISABLED,
osOptions: OS_OPTIONS,
validationErrors: {},
};
},
Expand All @@ -288,6 +267,21 @@ export default {
...createOptionHelpers('attributeKeys'),
...createOptionHelpers('networks'),
networkNames() {
const { network = [] } = this.value;
return network.reduce((names, id) => {
// previously this form used network names instead of ids -- need to account for both possibilities
const name = this.networks.find((nw) => nw.value === id || nw.name === id)?.name;
if (name && !names.includes(name)) {
names.push(name);
}
return names;
}, []);
},
isDisabled() {
return this.disabled || this.mode === _VIEW;
},
Expand Down Expand Up @@ -390,13 +384,14 @@ export default {
},
vappMode(value) {
if (value === VAPP_MODE.AUTO) {
const defaultVappOptions = getDefaultVappOptions(this.value.network || []);
const defaultVappOptions = getDefaultVappOptions(this.networkNames || []);
return this.updateVappOptions(defaultVappOptions);
} else {
this.updateVappOptions(INITIAL_VAPP_OPTIONS);
}
this.updateVappOptions(INITIAL_VAPP_OPTIONS);
},
validationErrors(value) {
this.$emit('error', value);
}
Expand Down Expand Up @@ -546,12 +541,17 @@ export default {
async loadNetworks() {
set(this, 'networksResults', null);
const options = await this.requestOptions('networks', this.value.datacenter);
const content = this.mapPathOptionsToContent(options);
const options = await this.requestOptions('networks-extended', this.value.datacenter);
const content = options.map((opt) => {
return {
label: `${ opt.name } (${ opt.moid })`, value: opt.moid, name: opt.name
};
});
this.resetValueIfNecessary('network', content, options, true);
set(this, 'networksResults', content);
this.vappMode = this.getInitialVappMode(this.value);
},
async loadContentLibraries() {
Expand Down Expand Up @@ -724,6 +724,34 @@ export default {
this.validationErrors = Object.assign({}, this.validationErrors, { [this.poolId]: this.validationErrors[this.poolId].filter((x) => x === key) }) ;
}
},
getInitialVappMode(c) {
const vappProperty = c.vappProperty || [];
if (
!c.vappIpprotocol &&
!c.vappIpallocationpolicy &&
!c.vappTransport &&
vappProperty.length === 0
) {
return VAPP_MODE.DISABLED;
}
const d = getDefaultVappOptions(this.networkNames || []);
if (
c.vappIpprotocol === d.vappIpprotocol &&
c.vappIpallocationpolicy === d.vappIpallocationpolicy &&
c.vappTransport === d.vappTransport &&
vappProperty.length === d.vappProperty.length &&
vappProperty.join() === d.vappProperty.join()
) {
return VAPP_MODE.AUTO;
}
return VAPP_MODE.MANUAL;
}
}
};
</script>
Expand Down Expand Up @@ -1132,68 +1160,78 @@ export default {
</template>
<template #body>
<div>
<div class="row mb-10">
<div class="col span-6">
<RadioGroup
v-model:value="vappMode"
name="restoreMode"
:label="t('cluster.machineConfig.vsphere.vAppOptions.restoreType')"
:options="vAppOptions"
:disabled="isDisabled"
/>
</div>
</div>
<div
v-if="showManual"
class="row mb-10"
v-if="networksLoading"
class="row flex-justify-center"
>
<div class="col span-4">
<LabeledInput
v-model:value="value.vappTransport"
:mode="mode"
:label="t('cluster.machineConfig.vsphere.vAppOptions.transport.label')"
:tooltip="t('cluster.machineConfig.vsphere.vAppOptions.transport.tooltip')"
:placeholder="t('cluster.machineConfig.vsphere.vAppOptions.transport.placeholder')"
:disabled="isDisabled"
/>
</div>
<div class="col span-4">
<LabeledInput
v-model:value="value.vappIpprotocol"
:mode="mode"
:label="t('cluster.machineConfig.vsphere.vAppOptions.protocol.label')"
:tooltip="t('cluster.machineConfig.vsphere.vAppOptions.protocol.tooltip')"
:placeholder="t('cluster.machineConfig.vsphere.vAppOptions.protocol.placeholder')"
:disabled="isDisabled"
/>
<i
class="icon icon-spinner icon-spin"
/>
</div>
<template v-else>
<div class="row mb-10">
<div class="col span-6">
<RadioGroup
v-model:value="vappMode"
name="restoreMode"
:label="t('cluster.machineConfig.vsphere.vAppOptions.restoreType')"
:options="vAppOptions"
:disabled="isDisabled"
/>
</div>
</div>
<div class="col span-4">
<LabeledInput
v-model:value="value.vappIpallocationpolicy"
:mode="mode"
:label="t('cluster.machineConfig.vsphere.vAppOptions.allocation.label')"
:tooltip="t('cluster.machineConfig.vsphere.vAppOptions.allocation.tooltip')"
:placeholder="t('cluster.machineConfig.vsphere.vAppOptions.allocation.placeholder')"
:disabled="isDisabled"
/>
<div
v-if="showManual"
class="row mb-10"
>
<div class="col span-4">
<LabeledInput
v-model:value="value.vappTransport"
:mode="mode"
:label="t('cluster.machineConfig.vsphere.vAppOptions.transport.label')"
:tooltip="t('cluster.machineConfig.vsphere.vAppOptions.transport.tooltip')"
:placeholder="t('cluster.machineConfig.vsphere.vAppOptions.transport.placeholder')"
:disabled="isDisabled"
/>
</div>
<div class="col span-4">
<LabeledInput
v-model:value="value.vappIpprotocol"
:mode="mode"
:label="t('cluster.machineConfig.vsphere.vAppOptions.protocol.label')"
:tooltip="t('cluster.machineConfig.vsphere.vAppOptions.protocol.tooltip')"
:placeholder="t('cluster.machineConfig.vsphere.vAppOptions.protocol.placeholder')"
:disabled="isDisabled"
/>
</div>
<div class="col span-4">
<LabeledInput
v-model:value="value.vappIpallocationpolicy"
:mode="mode"
:label="t('cluster.machineConfig.vsphere.vAppOptions.allocation.label')"
:tooltip="t('cluster.machineConfig.vsphere.vAppOptions.allocation.tooltip')"
:placeholder="t('cluster.machineConfig.vsphere.vAppOptions.allocation.placeholder')"
:disabled="isDisabled"
/>
</div>
</div>
</div>
<div
v-if="showManual"
class="row"
>
<div class="col span-12">
<KeyValue
v-model:value="vappProperty"
:title="t('cluster.machineConfig.vsphere.vAppOptions.properties.label')"
:key-placeholder="t('cluster.machineConfig.vsphere.vAppOptions.properties.keyPlaceholder')"
:value-placeholder="t('cluster.machineConfig.vsphere.vAppOptions.properties.valuePlaceholder')"
:add-label="t('cluster.machineConfig.vsphere.vAppOptions.properties.add')"
:read-allowed="false"
:disabled="isDisabled"
/>
<div
v-if="showManual"
class="row"
>
<div class="col span-12">
<KeyValue
v-model:value="vappProperty"
:title="t('cluster.machineConfig.vsphere.vAppOptions.properties.label')"
:key-placeholder="t('cluster.machineConfig.vsphere.vAppOptions.properties.keyPlaceholder')"
:value-placeholder="t('cluster.machineConfig.vsphere.vAppOptions.properties.valuePlaceholder')"
:add-label="t('cluster.machineConfig.vsphere.vAppOptions.properties.add')"
:read-allowed="false"
:disabled="isDisabled"
/>
</div>
</div>
</div>
</template>
</div>
</template>
</Card>
Expand Down

0 comments on commit d23db14

Please sign in to comment.