Skip to content

Commit 592bf9e

Browse files
Imvedanshdhslove
authored andcommitted
Enhance VPC Network Tier form to auto-populate Gateway, and Netmask (apache#10617)
1 parent 8e4c790 commit 592bf9e

File tree

3 files changed

+67
-6
lines changed

3 files changed

+67
-6
lines changed

ui/public/locales/en.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -657,9 +657,9 @@
657657
"label.create.template": "Create Template",
658658
"label.create.tier.aclid.description": "The ACL associated with the Network Tier.",
659659
"label.create.tier.externalid.description": "ID of the Network in an external system.",
660-
"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.",
660+
"label.create.tier.gateway.description": "Gateway IP must be within VPC CIDR ({value})",
661661
"label.create.tier.name.description": "A unique name for the Network Tier.",
662-
"label.create.tier.netmask.description": "The Network Tier's netmask. For example 255.255.255.0",
662+
"label.create.tier.netmask.description": "Network Tier's netmask must be more restrictive than {value}",
663663
"label.create.tier.networkofferingid.description": "The Network offering for the Network Tier.",
664664
"label.create.tungsten.routing.policy": "Create Tungsten-Fabric routing policy",
665665
"label.create.user": "Create User",

ui/src/utils/network.js

Lines changed: 51 additions & 0 deletions
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+
}

ui/src/views/network/VpcTiersTab.vue

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -242,18 +242,18 @@
242242
</a-form-item>
243243
<a-form-item ref="gateway" name="gateway" :colon="false">
244244
<template #label>
245-
<tooltip-label :title="$t('label.gateway')" :tooltip="$t('label.create.tier.gateway.description')"/>
245+
<tooltip-label :title="$t('label.gateway')" :tooltip="gatewayPlaceholder"/>
246246
</template>
247247
<a-input
248-
:placeholder="$t('label.create.tier.gateway.description')"
248+
:placeholder="gatewayPlaceholder"
249249
v-model:value="form.gateway"></a-input>
250250
</a-form-item>
251251
<a-form-item ref="netmask" name="netmask" :colon="false">
252252
<template #label>
253-
<tooltip-label :title="$t('label.netmask')" :tooltip="$t('label.create.tier.netmask.description')"/>
253+
<tooltip-label :title="$t('label.netmask')" :tooltip="netmaskPlaceholder"/>
254254
</template>
255255
<a-input
256-
:placeholder="$t('label.create.tier.netmask.description')"
256+
:placeholder="netmaskPlaceholder"
257257
v-model:value="form.netmask"></a-input>
258258
</a-form-item>
259259
<a-form-item ref="externalId" name="externalId" :colon="false">
@@ -363,6 +363,7 @@ import { api } from '@/api'
363363
import { mixinForm } from '@/utils/mixin'
364364
import Status from '@/components/widgets/Status'
365365
import TooltipLabel from '@/components/widgets/TooltipLabel'
366+
import { getNetmaskFromCidr } from '@/utils/network'
366367
367368
export default {
368369
name: 'VpcTiersTab',
@@ -400,6 +401,8 @@ export default {
400401
selectedNetworkOffering: {},
401402
privateMtuMax: 1500,
402403
errorPrivateMtu: '',
404+
gatewayPlaceholder: '',
405+
netmaskPlaceholder: '',
403406
algorithms: {
404407
Source: 'source',
405408
'Round-robin': 'roundrobin',
@@ -696,6 +699,13 @@ export default {
696699
this.initForm()
697700
this.fetchNetworkAclList()
698701
this.fetchNetworkOfferings()
702+
const cidr = this.resource.cidr
703+
const netmask = getNetmaskFromCidr(cidr)
704+
if (netmask) {
705+
this.gatewayPlaceholder = this.$t('label.create.tier.gateway.description', { value: cidr })
706+
this.netmaskPlaceholder = this.$t('label.create.tier.netmask.description', { value: netmask })
707+
}
708+
699709
this.showCreateNetworkModal = true
700710
this.rules = {
701711
name: [{ required: true, message: this.$t('label.required') }],

0 commit comments

Comments
 (0)