Skip to content

Commit 873aaa3

Browse files
committed
Abstraction of logic and few minor fixes
1 parent 217789e commit 873aaa3

File tree

3 files changed

+56
-36
lines changed

3 files changed

+56
-36
lines changed

ui/public/locales/en.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -576,7 +576,7 @@
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": "Gateway in range of VPC CIDR ({value})",
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.",
581581
"label.create.tier.netmask.description": "The Network Tier's netmask. For example {value}",
582582
"label.create.tier.networkofferingid.description": "The Network offering for the Network Tier.",

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 Placehoolders
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: 4 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -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',
@@ -620,42 +621,10 @@ export default {
620621
this.fetchNetworkAclList()
621622
this.fetchNetworkOfferings()
622623
const cidr = this.resource.cidr
623-
if (cidr && cidr.includes('/')) {
624-
const [address, maskBits] = cidr.split('/')
625-
const prefix = Number(maskBits)
624+
if (cidr?.includes('/')) {
625+
const netmask = getNetmaskFromCidr(cidr)
626626
627-
const subnetMasks = {
628-
8: '255.0.0.0',
629-
9: '255.128.0.0',
630-
10: '255.192.0.0',
631-
11: '255.224.0.0',
632-
12: '255.240.0.0',
633-
13: '255.248.0.0',
634-
14: '255.252.0.0',
635-
15: '255.254.0.0',
636-
16: '255.255.0.0',
637-
17: '255.255.128.0',
638-
18: '255.255.192.0',
639-
19: '255.255.224.0',
640-
20: '255.255.240.0',
641-
21: '255.255.248.0',
642-
22: '255.255.252.0',
643-
23: '255.255.254.0',
644-
24: '255.255.255.0',
645-
25: '255.255.255.128',
646-
26: '255.255.255.192',
647-
27: '255.255.255.224',
648-
28: '255.255.255.240',
649-
29: '255.255.255.248',
650-
30: '255.255.255.252',
651-
31: '255.255.255.254',
652-
32: '255.255.255.255'
653-
}
654-
655-
const cidrValue = `${address}/${maskBits}`
656-
const netmask = subnetMasks[prefix] || '255.255.255.0'
657-
658-
this.gatewayPlaceholder = this.$t('label.create.tier.gateway.description', { value: cidrValue })
627+
this.gatewayPlaceholder = this.$t('label.create.tier.gateway.description', { value: cidr })
659628
this.netmaskPlaceholder = this.$t('label.create.tier.netmask.description', { value: netmask })
660629
}
661630

0 commit comments

Comments
 (0)