Skip to content

Commit ee94ae5

Browse files
authored
Enhance VPC Network Tier form to auto-populate Gateway, and Netmask (#10617)
1 parent 3afab9a commit ee94ae5

File tree

3 files changed

+67
-6
lines changed

3 files changed

+67
-6
lines changed

Diff for: ui/public/locales/en.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -576,9 +576,9 @@
576576
"label.create.template": "Create Template",
577577
"label.create.tier.aclid.description": "The ACL associated with the Network Tier.",
578578
"label.create.tier.externalid.description": "ID of the Network in an external system.",
579-
"label.create.tier.gateway.description": "The Network Tier's gateway in the super CIDR range, not overlapping with the CIDR of other Network Tiers in this VPC.",
579+
"label.create.tier.gateway.description": "Gateway IP must be within VPC CIDR ({value})",
580580
"label.create.tier.name.description": "A unique name for the Network Tier.",
581-
"label.create.tier.netmask.description": "The Network Tier's netmask. For example 255.255.255.0",
581+
"label.create.tier.netmask.description": "Network Tier's netmask must be more restrictive than {value}",
582582
"label.create.tier.networkofferingid.description": "The Network offering for the Network Tier.",
583583
"label.create.tungsten.routing.policy": "Create Tungsten-Fabric routing policy",
584584
"label.create.user": "Create User",

Diff for: ui/src/utils/network.js

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
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.
17+
18+
// Parsing CIDR into Gateway,Netmask Placeholders
19+
20+
export function getNetmaskFromCidr (cidr) {
21+
if (!cidr?.includes('/')) return undefined
22+
const [, maskBits] = cidr.split('/')
23+
const subnetMasks = {
24+
8: '255.0.0.0',
25+
9: '255.128.0.0',
26+
10: '255.192.0.0',
27+
11: '255.224.0.0',
28+
12: '255.240.0.0',
29+
13: '255.248.0.0',
30+
14: '255.252.0.0',
31+
15: '255.254.0.0',
32+
16: '255.255.0.0',
33+
17: '255.255.128.0',
34+
18: '255.255.192.0',
35+
19: '255.255.224.0',
36+
20: '255.255.240.0',
37+
21: '255.255.248.0',
38+
22: '255.255.252.0',
39+
23: '255.255.254.0',
40+
24: '255.255.255.0',
41+
25: '255.255.255.128',
42+
26: '255.255.255.192',
43+
27: '255.255.255.224',
44+
28: '255.255.255.240',
45+
29: '255.255.255.248',
46+
30: '255.255.255.252',
47+
31: '255.255.255.254',
48+
32: '255.255.255.255'
49+
}
50+
return subnetMasks[+maskBits] || '255.255.255.0'
51+
}

Diff for: ui/src/views/network/VpcTiersTab.vue

+14-4
Original file line numberDiff line numberDiff line change
@@ -223,18 +223,18 @@
223223
</a-form-item>
224224
<a-form-item ref="gateway" name="gateway" :colon="false">
225225
<template #label>
226-
<tooltip-label :title="$t('label.gateway')" :tooltip="$t('label.create.tier.gateway.description')"/>
226+
<tooltip-label :title="$t('label.gateway')" :tooltip="gatewayPlaceholder"/>
227227
</template>
228228
<a-input
229-
:placeholder="$t('label.create.tier.gateway.description')"
229+
:placeholder="gatewayPlaceholder"
230230
v-model:value="form.gateway"></a-input>
231231
</a-form-item>
232232
<a-form-item ref="netmask" name="netmask" :colon="false">
233233
<template #label>
234-
<tooltip-label :title="$t('label.netmask')" :tooltip="$t('label.create.tier.netmask.description')"/>
234+
<tooltip-label :title="$t('label.netmask')" :tooltip="netmaskPlaceholder"/>
235235
</template>
236236
<a-input
237-
:placeholder="$t('label.create.tier.netmask.description')"
237+
:placeholder="netmaskPlaceholder"
238238
v-model:value="form.netmask"></a-input>
239239
</a-form-item>
240240
<a-form-item ref="externalId" name="externalId" :colon="false">
@@ -344,6 +344,7 @@ import { api } from '@/api'
344344
import { mixinForm } from '@/utils/mixin'
345345
import Status from '@/components/widgets/Status'
346346
import TooltipLabel from '@/components/widgets/TooltipLabel'
347+
import { getNetmaskFromCidr } from '@/utils/network'
347348
348349
export default {
349350
name: 'VpcTiersTab',
@@ -381,6 +382,8 @@ export default {
381382
selectedNetworkOffering: {},
382383
privateMtuMax: 1500,
383384
errorPrivateMtu: '',
385+
gatewayPlaceholder: '',
386+
netmaskPlaceholder: '',
384387
algorithms: {
385388
Source: 'source',
386389
'Round-robin': 'roundrobin',
@@ -617,6 +620,13 @@ export default {
617620
this.initForm()
618621
this.fetchNetworkAclList()
619622
this.fetchNetworkOfferings()
623+
const cidr = this.resource.cidr
624+
const netmask = getNetmaskFromCidr(cidr)
625+
if (netmask) {
626+
this.gatewayPlaceholder = this.$t('label.create.tier.gateway.description', { value: cidr })
627+
this.netmaskPlaceholder = this.$t('label.create.tier.netmask.description', { value: netmask })
628+
}
629+
620630
this.showCreateNetworkModal = true
621631
this.rules = {
622632
name: [{ required: true, message: this.$t('label.required') }],

0 commit comments

Comments
 (0)