From 7a9713f7c71579e6f39338278bd303806f6a6a6c Mon Sep 17 00:00:00 2001 From: abh1sar Date: Thu, 19 Sep 2024 13:49:33 +0530 Subject: [PATCH 1/2] UI: Checkbox to make a newly added Network the default one in the Instance's Network tab --- ui/public/locales/en.json | 1 + ui/src/views/network/NicsTab.vue | 41 ++++++++++++++++++++++++++++---- 2 files changed, 38 insertions(+), 4 deletions(-) diff --git a/ui/public/locales/en.json b/ui/public/locales/en.json index eb1be420b2ed..f14d065c0ef9 100644 --- a/ui/public/locales/en.json +++ b/ui/public/locales/en.json @@ -1365,6 +1365,7 @@ "label.maintenance": "Maintenance", "label.majorsequence": "Major Sequence", "label.make": "Make", +"label.make.default": "Make default", "label.make.project.owner": "Make Account project owner", "label.make.user.project.owner": "Make User project owner", "label.makeredundant": "Make redundant", diff --git a/ui/src/views/network/NicsTab.vue b/ui/src/views/network/NicsTab.vue index 6346ae4d4ab8..b50152ff673b 100644 --- a/ui/src/views/network/NicsTab.vue +++ b/ui/src/views/network/NicsTab.vue @@ -106,6 +106,11 @@ +
+ + {{ $t('label.make.default') }} + +
@@ -248,13 +253,15 @@ export default { data () { return { vm: {}, + nic: {}, showAddNetworkModal: false, showUpdateIpModal: false, showSecondaryIpModal: false, addNetworkData: { allNetworks: [], network: '', - ip: '' + ip: '', + makedefault: false }, loadingNic: false, editIpAddressNic: '', @@ -332,6 +339,7 @@ export default { this.showSecondaryIpModal = false this.addNetworkData.network = '' this.addNetworkData.ip = '' + this.addNetworkData.makedefault = false this.editIpAddressValue = '' this.newSecondaryIp = '' }, @@ -368,9 +376,26 @@ export default { this.$pollJob({ jobId: response.addnictovirtualmachineresponse.jobid, successMessage: this.$t('message.success.add.network'), - successMethod: () => { - this.loadingNic = false - this.closeModals() + successMethod: async () => { + if (this.addNetworkData.makedefault) { + try { + this.nic = await this.getNic(params.networkid, params.virtualmachineid) + if (this.nic) { + this.setAsDefault(this.nic) + } else { + this.$notifyError('NIC data not found.') + this.loadingNic = false + this.closeModals() + } + } catch (error) { + this.$notifyError('Failed to fetch NIC data.') + this.loadingNic = false + this.closeModals() + } + } else { + this.loadingNic = false + this.closeModals() + } }, errorMessage: this.$t('message.add.network.failed'), errorMethod: () => { @@ -390,6 +415,14 @@ export default { this.loadingNic = false }) }, + getNic (networkid, virtualmachineid) { + const params = {} + params.virtualmachineid = virtualmachineid + params.networkid = networkid + return api('listNics', params).then(response => { + return response.listnicsresponse.nic[0] + }) + }, setAsDefault (item) { this.loadingNic = true api('updateDefaultNicForVirtualMachine', { From 02be6a2e48e906d5256ab683747d62709bb73a52 Mon Sep 17 00:00:00 2001 From: abh1sar Date: Thu, 19 Sep 2024 16:59:00 +0530 Subject: [PATCH 2/2] Fixed an issue that was causing exit from network tab after add-network --- ui/src/views/network/NicsTab.vue | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/ui/src/views/network/NicsTab.vue b/ui/src/views/network/NicsTab.vue index b50152ff673b..eb0fd818cfa5 100644 --- a/ui/src/views/network/NicsTab.vue +++ b/ui/src/views/network/NicsTab.vue @@ -384,18 +384,13 @@ export default { this.setAsDefault(this.nic) } else { this.$notifyError('NIC data not found.') - this.loadingNic = false - this.closeModals() } } catch (error) { this.$notifyError('Failed to fetch NIC data.') - this.loadingNic = false - this.closeModals() } - } else { - this.loadingNic = false - this.closeModals() } + this.loadingNic = false + this.closeModals() }, errorMessage: this.$t('message.add.network.failed'), errorMethod: () => {