From e774c88b3420780f849e3265a854a07391cde922 Mon Sep 17 00:00:00 2001 From: Nancy Butler <42977925+mantis-toboggan-md@users.noreply.github.com> Date: Tue, 15 Oct 2024 15:39:56 -0700 Subject: [PATCH] update vapp options to reference network name not moid --- shell/machine-config/vmwarevsphere.vue | 217 ++++++++++++++----------- 1 file changed, 125 insertions(+), 92 deletions(-) diff --git a/shell/machine-config/vmwarevsphere.vue b/shell/machine-config/vmwarevsphere.vue index 85a827358b..575adbd89a 100644 --- a/shell/machine-config/vmwarevsphere.vue +++ b/shell/machine-config/vmwarevsphere.vue @@ -81,33 +81,6 @@ const networkToVappProperties = (props, network, i) => { 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; -}; - /** * passing 'datacenter' yields * @@ -266,9 +239,11 @@ export default { haveAttributes: null, haveTemplates: null, vAppOptions, - vappMode: getInitialVappMode(this.value), - osOptions: OS_OPTIONS, - validationErrors: {}, + // vappMode: getInitialVappMode(this.value), + vappMode: VAPP_MODE.DISABLED, + + osOptions: OS_OPTIONS, + validationErrors: {}, }; }, @@ -288,6 +263,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; }, @@ -388,14 +378,16 @@ export default { set(this.value, 'boot2dockerUrl', boot2dockerUrl); }, - vappMode(value) { + vappMode(value, old) { if (value === VAPP_MODE.AUTO) { - const defaultVappOptions = getDefaultVappOptions(this.value.network || []); + // const defaultVappOptions = getDefaultVappOptions(this.value.network || []); + + const defaultVappOptions = getDefaultVappOptions(this.networkNames || []); return this.updateVappOptions(defaultVappOptions); + } else if (value === VAPP_MODE.DISABLED) { + this.updateVappOptions(INITIAL_VAPP_OPTIONS); } - - this.updateVappOptions(INITIAL_VAPP_OPTIONS); }, validationErrors(value) { this.$emit('error', value); @@ -548,12 +540,15 @@ export default { const options = await this.requestOptions('networks-extended', this.value.datacenter); const content = options.map((opt) => { - return { label: `${ opt.name } (${ opt.moid })`, value: opt.moid }; + 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() { @@ -726,6 +721,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; + } + } }; @@ -1134,68 +1157,78 @@ export default {