Skip to content

Commit 34bed7a

Browse files
committed
Fix project-based network filtering in unmanaged instance import
1 parent 27bce46 commit 34bed7a

File tree

2 files changed

+559
-395
lines changed

2 files changed

+559
-395
lines changed

ui/src/views/compute/wizard/MultiNetworkSelection.vue

Lines changed: 66 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,22 @@
1-
// Licensed to the Apache Software Foundation (ASF) under one
2-
// or more contributor license agreements. See the NOTICE file
3-
// distributed with this work for additional information
4-
// regarding copyright ownership. The ASF licenses this file
5-
// to you under the Apache License, Version 2.0 (the
6-
// "License"); you may not use this file except in compliance
7-
// with the License. You may obtain a copy of the License at
8-
//
9-
// http://www.apache.org/licenses/LICENSE-2.0
10-
//
11-
// Unless required by applicable law or agreed to in writing,
12-
// software distributed under the License is distributed on an
13-
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14-
// KIND, either express or implied. See the License for the
15-
// specific language governing permissions and limitations
16-
// under the License.
1+
// Licensed to the Apache Software Foundation (ASF) under one // or more contributor license agreements. See the NOTICE
2+
file // distributed with this work for additional information // regarding copyright ownership. The ASF licenses this
3+
file // to you under the Apache License, Version 2.0 (the // "License"); you may not use this file except in compliance
4+
// with the License. You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // //
5+
Unless required by applicable law or agreed to in writing, // software distributed under the License is distributed on
6+
an // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the
7+
// specific language governing permissions and limitations // under the License.
178

189
<template>
1910
<div>
2011
<a-table
2112
:loading="loading"
2213
:columns="columns"
2314
:dataSource="tableSource"
24-
:rowKey="record => record.id"
15+
:rowKey="(record) => record.id"
2516
:pagination="false"
2617
:rowSelection="rowSelection"
27-
:scroll="{ y: 225 }" >
28-
18+
:scroll="{ y: 225 }"
19+
>
2920
<template #bodyCell="{ column, record }">
3021
<template v-if="column.key === 'name'">
3122
<span>{{ record.displaytext || record.name }}</span>
@@ -48,16 +39,20 @@
4839
style="width: 100%"
4940
v-if="validNetworks[record.id] && validNetworks[record.id].length > 0"
5041
:defaultValue="getDefaultNetwork(record)"
51-
@change="val => handleNetworkChange(record, val)"
42+
@change="(val) => handleNetworkChange(record, val)"
5243
showSearch
5344
optionFilterProp="label"
54-
:filterOption="(input, option) => {
55-
return option.label.toLowerCase().indexOf(input.toLowerCase()) >= 0
56-
}" >
45+
:filterOption="
46+
(input, option) => {
47+
return option.label.toLowerCase().indexOf(input.toLowerCase()) >= 0
48+
}
49+
"
50+
>
5751
<a-select-option
5852
v-for="network in hypervisor !== 'KVM' ? validNetworks[record.id] : networks"
5953
:key="network.id"
60-
:label="network.displaytext + (network.broadcasturi ? ' (' + network.broadcasturi + ')' : '')">
54+
:label="network.displaytext + (network.broadcasturi ? ' (' + network.broadcasturi + ')' : '')"
55+
>
6156
<div>{{ network.displaytext + (network.broadcasturi ? ' (' + network.broadcasturi + ')' : '') }}</div>
6257
</a-select-option>
6358
</a-select>
@@ -72,8 +67,9 @@
7267
:checkBoxLabel="$t('label.auto.assign.random.ip')"
7368
:defaultCheckBoxValue="true"
7469
:reversed="true"
75-
:visible="(indexNum > 0 && ipAddressesEnabled[record.id])"
76-
@handle-checkinputpair-change="setIpAddress" />
70+
:visible="indexNum > 0 && ipAddressesEnabled[record.id]"
71+
@handle-checkinputpair-change="setIpAddress"
72+
/>
7773
</template>
7874
</template>
7975
</a-table>
@@ -107,6 +103,10 @@ export default {
107103
type: String,
108104
default: ''
109105
},
106+
projectid: {
107+
type: String,
108+
default: ''
109+
},
110110
selectionEnabled: {
111111
type: Boolean,
112112
default: true
@@ -158,7 +158,7 @@ export default {
158158
},
159159
computed: {
160160
tableSource () {
161-
return this.items.map(item => {
161+
return this.items.map((item) => {
162162
var nic = { ...item, disabled: this.validNetworks[item.id] && this.validNetworks[item.id].length === 0 }
163163
nic.name = item.displaytext || item.name
164164
return nic
@@ -169,7 +169,7 @@ export default {
169169
return {
170170
type: 'checkbox',
171171
selectedRowKeys: this.selectedRowKeys,
172-
getCheckboxProps: record => ({
172+
getCheckboxProps: (record) => ({
173173
props: {
174174
disabled: record.disabled
175175
}
@@ -201,6 +201,9 @@ export default {
201201
this.fetchNetworks()
202202
}
203203
}, 750)
204+
},
205+
projectid () {
206+
this.fetchNetworks()
204207
}
205208
},
206209
created () {
@@ -221,28 +224,37 @@ export default {
221224
params.domainid = this.domainid
222225
params.account = this.account
223226
}
224-
getAPI('listNetworks', params).then(response => {
225-
this.networks = response.listnetworksresponse.network || []
226-
}).catch(() => {
227-
this.networks = []
228-
}).finally(() => {
229-
this.orderNetworks()
230-
this.loading = false
231-
})
227+
if (this.projectid) {
228+
params.projectid = this.projectid
229+
}
230+
getAPI('listNetworks', params)
231+
.then((response) => {
232+
this.networks = response.listnetworksresponse.network || []
233+
})
234+
.catch(() => {
235+
this.networks = []
236+
})
237+
.finally(() => {
238+
this.orderNetworks()
239+
this.loading = false
240+
})
232241
},
233242
orderNetworks () {
234243
this.loading = true
235244
this.validNetworks = {}
236245
for (const item of this.items) {
237246
this.validNetworks[item.id] = this.networks
238247
if (this.filterUnimplementedNetworks) {
239-
this.validNetworks[item.id] = this.validNetworks[item.id].filter(x => (x.state === 'Implemented' || (x.state === 'Setup' && ['Shared', 'L2'].includes(x.type))))
248+
this.validNetworks[item.id] = this.validNetworks[item.id].filter(
249+
(x) => x.state === 'Implemented' || (x.state === 'Setup' && ['Shared', 'L2'].includes(x.type))
250+
)
240251
}
241252
if (this.filterMatchKey) {
242-
const filtered = this.networks.filter(x => x[this.filterMatchKey] === item[this.filterMatchKey])
253+
const filtered = this.networks.filter((x) => x[this.filterMatchKey] === item[this.filterMatchKey])
243254
if (this.hypervisor === 'KVM') {
244255
this.unableToMatch = filtered.length === 0
245-
this.validNetworks[item.id] = filtered.length === 0 ? this.networks : filtered.concat(this.networks.filter(x => filtered.includes(x)))
256+
this.validNetworks[item.id] =
257+
filtered.length === 0 ? this.networks : filtered.concat(this.networks.filter((x) => filtered.includes(x)))
246258
} else {
247259
this.validNetworks[item.id] = filtered
248260
}
@@ -253,7 +265,7 @@ export default {
253265
},
254266
setIpAddressEnabled (nic, network) {
255267
this.ipAddressesEnabled[nic.id] = network && network.type !== 'L2'
256-
this.ipAddresses[nic.id] = (!network || network.type === 'L2') ? null : 'auto'
268+
this.ipAddresses[nic.id] = !network || network.type === 'L2' ? null : 'auto'
257269
this.values[nic.id] = network ? network.id : null
258270
this.indexNum = (this.indexNum % 2) + 1
259271
},
@@ -267,7 +279,7 @@ export default {
267279
for (const item of this.items) {
268280
let network = null
269281
if (item.vlanid && item.vlanid !== -1) {
270-
const matched = this.validNetworks[item.id].filter(x => Number(x.vlan) === item.vlanid)
282+
const matched = this.validNetworks[item.id].filter((x) => Number(x.vlan) === item.vlanid)
271283
if (matched.length > 0) {
272284
network = matched[0]
273285
}
@@ -276,16 +288,22 @@ export default {
276288
network = this.validNetworks[item.id]?.[0] || null
277289
}
278290
this.values[item.id] = network ? network.id : ''
279-
this.ipAddresses[item.id] = (!network || network.type === 'L2') ? null : 'auto'
291+
this.ipAddresses[item.id] = !network || network.type === 'L2' ? null : 'auto'
280292
this.setIpAddressEnabled(item, network)
281293
}
282294
this.sendValuesTimed()
283295
},
284296
handleNetworkChange (nic, networkId) {
285297
if (this.hypervisor === 'KVM') {
286-
this.setIpAddressEnabled(nic, _.find(this.networks, (option) => option.id === networkId))
298+
this.setIpAddressEnabled(
299+
nic,
300+
_.find(this.networks, (option) => option.id === networkId)
301+
)
287302
} else {
288-
this.setIpAddressEnabled(nic, _.find(this.validNetworks[nic.id], (option) => option.id === networkId))
303+
this.setIpAddressEnabled(
304+
nic,
305+
_.find(this.validNetworks[nic.id], (option) => option.id === networkId)
306+
)
289307
}
290308
this.sendValuesTimed()
291309
},
@@ -301,7 +319,7 @@ export default {
301319
sendValues () {
302320
const data = {}
303321
if (this.selectionEnabled) {
304-
this.selectedRowKeys.map(x => {
322+
this.selectedRowKeys.map((x) => {
305323
var d = { network: this.values[x] }
306324
if (this.ipAddresses[x]) {
307325
d.ipAddress = this.ipAddresses[x]
@@ -324,7 +342,7 @@ export default {
324342
</script>
325343
326344
<style lang="less" scoped>
327-
.ant-table-wrapper {
328-
margin: 2rem 0;
329-
}
345+
.ant-table-wrapper {
346+
margin: 2rem 0;
347+
}
330348
</style>

0 commit comments

Comments
 (0)