Skip to content

Commit 0416f87

Browse files
abh1sardhslove
authored andcommitted
UI: make a newly added Network the default one (apache#9708)
* 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
1 parent 4715dc6 commit 0416f87

File tree

2 files changed

+31
-2
lines changed

2 files changed

+31
-2
lines changed

ui/public/locales/en.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1395,6 +1395,7 @@
13951395
"label.maintenance": "Maintenance",
13961396
"label.majorsequence": "Major Sequence",
13971397
"label.make": "Make",
1398+
"label.make.default": "Make default",
13981399
"label.make.project.owner": "Make Account project owner",
13991400
"label.make.user.project.owner": "Make User project owner",
14001401
"label.makeredundant": "Make redundant",

ui/src/views/network/NicsTab.vue

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,11 @@
118118
</a-select>
119119
<p class="modal-form__label">{{ $t('label.publicip') }}:</p>
120120
<a-input v-model:value="addNetworkData.ip"></a-input>
121+
<br>
122+
<a-checkbox v-model:checked="addNetworkData.makedefault">
123+
{{ $t('label.make.default') }}
124+
</a-checkbox>
125+
<br>
121126
</div>
122127

123128
<div :span="24" class="action-button">
@@ -260,13 +265,15 @@ export default {
260265
data () {
261266
return {
262267
vm: {},
268+
nic: {},
263269
showAddNetworkModal: false,
264270
showUpdateIpModal: false,
265271
showSecondaryIpModal: false,
266272
addNetworkData: {
267273
allNetworks: [],
268274
network: '',
269-
ip: ''
275+
ip: '',
276+
makedefault: false
270277
},
271278
loadingNic: false,
272279
editIpAddressNic: '',
@@ -344,6 +351,7 @@ export default {
344351
this.showSecondaryIpModal = false
345352
this.addNetworkData.network = ''
346353
this.addNetworkData.ip = ''
354+
this.addNetworkData.makedefault = false
347355
this.editIpAddressValue = ''
348356
this.newSecondaryIp = ''
349357
},
@@ -380,7 +388,19 @@ export default {
380388
this.$pollJob({
381389
jobId: response.addnictovirtualmachineresponse.jobid,
382390
successMessage: this.$t('message.success.add.network'),
383-
successMethod: () => {
391+
successMethod: async () => {
392+
if (this.addNetworkData.makedefault) {
393+
try {
394+
this.nic = await this.getNic(params.networkid, params.virtualmachineid)
395+
if (this.nic) {
396+
this.setAsDefault(this.nic)
397+
} else {
398+
this.$notifyError('NIC data not found.')
399+
}
400+
} catch (error) {
401+
this.$notifyError('Failed to fetch NIC data.')
402+
}
403+
}
384404
this.loadingNic = false
385405
this.closeModals()
386406
},
@@ -402,6 +422,14 @@ export default {
402422
this.loadingNic = false
403423
})
404424
},
425+
getNic (networkid, virtualmachineid) {
426+
const params = {}
427+
params.virtualmachineid = virtualmachineid
428+
params.networkid = networkid
429+
return api('listNics', params).then(response => {
430+
return response.listnicsresponse.nic[0]
431+
})
432+
},
405433
setAsDefault (item) {
406434
this.loadingNic = true
407435
api('updateDefaultNicForVirtualMachine', {

0 commit comments

Comments
 (0)