Skip to content

Commit db2e89a

Browse files
authored
UI: make a newly added Network the default one (#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 528fca2 commit db2e89a

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
@@ -1365,6 +1365,7 @@
13651365
"label.maintenance": "Maintenance",
13661366
"label.majorsequence": "Major Sequence",
13671367
"label.make": "Make",
1368+
"label.make.default": "Make default",
13681369
"label.make.project.owner": "Make Account project owner",
13691370
"label.make.user.project.owner": "Make User project owner",
13701371
"label.makeredundant": "Make redundant",

ui/src/views/network/NicsTab.vue

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,11 @@
106106
</a-select>
107107
<p class="modal-form__label">{{ $t('label.publicip') }}:</p>
108108
<a-input v-model:value="addNetworkData.ip"></a-input>
109+
<br>
110+
<a-checkbox v-model:checked="addNetworkData.makedefault">
111+
{{ $t('label.make.default') }}
112+
</a-checkbox>
113+
<br>
109114
</div>
110115

111116
<div :span="24" class="action-button">
@@ -248,13 +253,15 @@ export default {
248253
data () {
249254
return {
250255
vm: {},
256+
nic: {},
251257
showAddNetworkModal: false,
252258
showUpdateIpModal: false,
253259
showSecondaryIpModal: false,
254260
addNetworkData: {
255261
allNetworks: [],
256262
network: '',
257-
ip: ''
263+
ip: '',
264+
makedefault: false
258265
},
259266
loadingNic: false,
260267
editIpAddressNic: '',
@@ -332,6 +339,7 @@ export default {
332339
this.showSecondaryIpModal = false
333340
this.addNetworkData.network = ''
334341
this.addNetworkData.ip = ''
342+
this.addNetworkData.makedefault = false
335343
this.editIpAddressValue = ''
336344
this.newSecondaryIp = ''
337345
},
@@ -368,7 +376,19 @@ export default {
368376
this.$pollJob({
369377
jobId: response.addnictovirtualmachineresponse.jobid,
370378
successMessage: this.$t('message.success.add.network'),
371-
successMethod: () => {
379+
successMethod: async () => {
380+
if (this.addNetworkData.makedefault) {
381+
try {
382+
this.nic = await this.getNic(params.networkid, params.virtualmachineid)
383+
if (this.nic) {
384+
this.setAsDefault(this.nic)
385+
} else {
386+
this.$notifyError('NIC data not found.')
387+
}
388+
} catch (error) {
389+
this.$notifyError('Failed to fetch NIC data.')
390+
}
391+
}
372392
this.loadingNic = false
373393
this.closeModals()
374394
},
@@ -390,6 +410,14 @@ export default {
390410
this.loadingNic = false
391411
})
392412
},
413+
getNic (networkid, virtualmachineid) {
414+
const params = {}
415+
params.virtualmachineid = virtualmachineid
416+
params.networkid = networkid
417+
return api('listNics', params).then(response => {
418+
return response.listnicsresponse.nic[0]
419+
})
420+
},
393421
setAsDefault (item) {
394422
this.loadingNic = true
395423
api('updateDefaultNicForVirtualMachine', {

0 commit comments

Comments
 (0)