From f3a474bb9ef2dfe71d1605776f1696345c718206 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Jo=C3=A3o=20Jandre?=
<48719461+JoaoJandre@users.noreply.github.com>
Date: Tue, 3 Dec 2024 03:44:08 -0300
Subject: [PATCH] UI: make a newly added Network the default one (#9708)
(#10022)
* UI: Checkbox to make a newly added Network the default one in the Instance's Network tab
* Fixed an issue that was causing exit from network tab after add-network
Co-authored-by: Abhisar Sinha <63767682+abh1sar@users.noreply.github.com>
---
ui/public/locales/en.json | 1 +
ui/src/views/network/NicsTab.vue | 32 ++++++++++++++++++++++++++++++--
2 files changed, 31 insertions(+), 2 deletions(-)
diff --git a/ui/public/locales/en.json b/ui/public/locales/en.json
index e2f637bd410..76334d2b504 100644
--- a/ui/public/locales/en.json
+++ b/ui/public/locales/en.json
@@ -1368,6 +1368,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 6346ae4d4ab..eb0fd818cfa 100644
--- a/ui/src/views/network/NicsTab.vue
+++ b/ui/src/views/network/NicsTab.vue
@@ -106,6 +106,11 @@
{{ $t('label.publicip') }}:
+
+
+ {{ $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,7 +376,19 @@ export default {
this.$pollJob({
jobId: response.addnictovirtualmachineresponse.jobid,
successMessage: this.$t('message.success.add.network'),
- successMethod: () => {
+ 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.')
+ }
+ } catch (error) {
+ this.$notifyError('Failed to fetch NIC data.')
+ }
+ }
this.loadingNic = false
this.closeModals()
},
@@ -390,6 +410,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', {