From d23db14d7a24979d3707ebd10fff860ce69d3f1f Mon Sep 17 00:00:00 2001 From: Nancy <42977925+mantis-toboggan-md@users.noreply.github.com> Date: Wed, 16 Oct 2024 14:49:05 -0700 Subject: [PATCH] update vsphere machine config to use new networks endpoint (#12263) * 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 --- shell/components/form/ArrayList.vue | 10 +- shell/machine-config/vmwarevsphere.vue | 228 ++++++++++++++----------- 2 files changed, 140 insertions(+), 98 deletions(-) diff --git a/shell/components/form/ArrayList.vue b/shell/components/form/ArrayList.vue index aea41aed334..e48b76fb05f 100644 --- a/shell/components/form/ArrayList.vue +++ b/shell/components/form/ArrayList.vue @@ -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) { diff --git a/shell/machine-config/vmwarevsphere.vue b/shell/machine-config/vmwarevsphere.vue index 7025dcbee97..e7f4b5ce786 100644 --- a/shell/machine-config/vmwarevsphere.vue +++ b/shell/machine-config/vmwarevsphere.vue @@ -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(); }; /** @@ -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: {}, }; }, @@ -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; }, @@ -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); } @@ -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() { @@ -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; + } + } }; @@ -1132,68 +1160,78 @@ export default {