Skip to content

Commit 3fd969b

Browse files
committed
Fixes
1 parent 5ade2b3 commit 3fd969b

File tree

6 files changed

+71
-23
lines changed

6 files changed

+71
-23
lines changed

engine/schema/src/main/resources/META-INF/db/schema-42100to42200.sql

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,5 +87,3 @@ CALL `cloud`.`INSERT_EXTENSION_DETAIL_IF_NOT_EXISTS`('MaaS', 'orchestratorrequir
8787

8888
CALL `cloud`.`IDEMPOTENT_DROP_UNIQUE_KEY`('counter', 'uc_counter__provider__source__value');
8989
CALL `cloud`.`IDEMPOTENT_ADD_UNIQUE_KEY`('cloud.counter', 'uc_counter__provider__source__value__removed', '(provider, source, value, removed)');
90-
91-
CALL `cloud`.`IDEMPOTENT_ADD_COLUMN`('cloud.vpc_offerings','conserve_mode', 'tinyint(1) unsigned NULL DEFAULT 1');

engine/schema/src/main/resources/META-INF/db/schema-42210to42300.sql

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,3 +49,6 @@ CREATE TABLE IF NOT EXISTS `cloud`.`webhook_filter` (
4949
INDEX `i_webhook_filter__webhook_id`(`webhook_id`),
5050
CONSTRAINT `fk_webhook_filter__webhook_id` FOREIGN KEY(`webhook_id`) REFERENCES `webhook`(`id`) ON DELETE CASCADE
5151
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
52+
53+
CALL `cloud`.`IDEMPOTENT_ADD_COLUMN`('cloud.vpc_offerings','conserve_mode', 'tinyint(1) unsigned NULL DEFAULT 0');
54+
UPDATE `cloud`.`vpc_offerings` SET conserve_mode=1 WHERE name='Default VPC offering';

server/src/main/java/com/cloud/network/firewall/FirewallManagerImpl.java

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@
3030
import javax.inject.Inject;
3131
import javax.naming.ConfigurationException;
3232

33+
import com.cloud.network.vpc.VpcOfferingVO;
34+
import com.cloud.network.vpc.dao.VpcOfferingDao;
3335
import org.apache.commons.lang3.ObjectUtils;
3436
import org.springframework.stereotype.Component;
3537

@@ -159,6 +161,8 @@ public class FirewallManagerImpl extends ManagerBase implements FirewallService,
159161
IpAddressManager _ipAddrMgr;
160162
@Inject
161163
RoutedIpv4Manager routedIpv4Manager;
164+
@Inject
165+
VpcOfferingDao vpcOfferingDao;
162166

163167
private boolean _elbEnabled = false;
164168
static Boolean rulesContinueOnErrFlag = true;
@@ -400,6 +404,11 @@ public void detectRulesConflict(FirewallRule newRule) throws NetworkRuleConflict
400404
throw new InvalidParameterValueException("Unable to create firewall rule as cannot find network by id=" + newRule.getNetworkId());
401405
}
402406
boolean isNewRuleOnVpcNetwork = newRuleNetwork.getVpcId() != null;
407+
boolean isVpcConserveModeEnabled = false;
408+
if (isNewRuleOnVpcNetwork) {
409+
VpcOfferingVO vpcOffering = vpcOfferingDao.findById(newRuleNetwork.getVpcId());
410+
isVpcConserveModeEnabled = vpcOffering != null && vpcOffering.isConserveMode();
411+
}
403412

404413
for (FirewallRuleVO rule : rules) {
405414
if (rule.getId() == newRule.getId()) {
@@ -448,9 +457,15 @@ public void detectRulesConflict(FirewallRule newRule) throws NetworkRuleConflict
448457
}
449458
}
450459

451-
// Checking if the rule applied is to the same network that is passed in the rule. (except for VPC networks)
452-
if (!isNewRuleOnVpcNetwork && rule.getNetworkId() != newRule.getNetworkId() && rule.getState() != State.Revoke) {
453-
throw new NetworkRuleConflictException("New rule is for a different network than what's specified in rule " + rule.getXid());
460+
// Checking if the rule applied is to the same network that is passed in the rule.
461+
// (except for VPCs with conserve mode = true)
462+
if ((!isNewRuleOnVpcNetwork || !isVpcConserveModeEnabled)
463+
&& rule.getNetworkId() != newRule.getNetworkId() && rule.getState() != State.Revoke) {
464+
String errMsg = String.format("New rule is for a different network than what's specified in rule %s", rule.getXid());
465+
if (isNewRuleOnVpcNetwork) {
466+
errMsg += String.format(" - VPC id=%s is not using conserve mode", newRuleNetwork.getVpcId());
467+
}
468+
throw new NetworkRuleConflictException(errMsg);
454469
}
455470

456471
//Check for the ICMP protocol. This has to be done separately from other protocols as we need to check the ICMP codes and ICMP type also.

ui/src/views/network/LoadBalancing.vue

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@
9797
{{ $t('label.add') }}
9898
</a-button>
9999
</div>
100-
<div class="form__item" v-else-if="newRule.autoscale === 'yes' && ('vpcid' in this.resource)">
100+
<div class="form__item" v-else-if="newRule.autoscale === 'yes' && ('vpcid' in this.resource && !this.associatednetworkid)">
101101
<div class="form__label" style="white-space: nowrap;">{{ $t('label.select.tier') }}</div>
102102
<a-button :disabled="!('createLoadBalancerRule' in $store.getters.apis)" type="primary" @click="handleOpenAddNetworkModal">
103103
{{ $t('label.add') }}
@@ -487,10 +487,10 @@
487487
>
488488
<div @keyup.ctrl.enter="handleAddNewRule">
489489
<span
490-
v-if="'vpcid' in resource">
490+
v-if="'vpcid' in resource && (!('associatednetworkid' in resource) || this.vpcConserveMode)">
491491
<strong>{{ $t('label.select.tier') }} </strong>
492492
<a-select
493-
v-focus="'vpcid' in resource"
493+
v-focus="'vpcid' in resource && (!('associatednetworkid' in resource) || this.vpcConserveMode)"
494494
v-model:value="selectedTier"
495495
@change="fetchVirtualMachines()"
496496
:placeholder="$t('label.select.tier')"
@@ -1022,7 +1022,8 @@ export default {
10221022
urlpath: '/'
10231023
},
10241024
healthMonitorLoading: false,
1025-
isNetrisZone: false
1025+
isNetrisZone: false,
1026+
vpcConserveMode: false
10261027
}
10271028
},
10281029
computed: {
@@ -1079,10 +1080,24 @@ export default {
10791080
})
10801081
},
10811082
fetchData () {
1083+
this.fetchVpc()
10821084
this.fetchListTiers()
10831085
this.fetchLBRules()
10841086
this.fetchZone()
10851087
},
1088+
fetchVpc () {
1089+
if (!this.resource.vpcid) {
1090+
return
1091+
}
1092+
this.vpcConserveMode = false
1093+
getAPI('listVPCs', {
1094+
id: this.resource.vpcid
1095+
}).then(json => {
1096+
this.vpcConserveMode = json.listvpcsresponse?.vpc?.[0].vpcofferingconservemode || false
1097+
}).catch(error => {
1098+
this.$notifyError(error)
1099+
})
1100+
},
10861101
fetchListTiers () {
10871102
this.tiers.loading = true
10881103
@@ -1830,7 +1845,7 @@ export default {
18301845
18311846
getAPI('listNics', {
18321847
virtualmachineid: e.target.value,
1833-
networkid: ('vpcid' in this.resource) ? this.selectedTier : this.resource.associatednetworkid
1848+
networkid: ('vpcid' in this.resource && (!('associatednetworkid' in this.resource) || this.vpcConserveMode)) ? this.selectedTier : this.resource.associatednetworkid
18341849
}).then(response => {
18351850
if (!response || !response.listnicsresponse || !response.listnicsresponse.nic[0]) return
18361851
const newItem = []
@@ -1850,7 +1865,7 @@ export default {
18501865
this.vmCount = 0
18511866
this.vms = []
18521867
this.addVmModalLoading = true
1853-
const networkId = ('vpcid' in this.resource) ? this.selectedTier : this.resource.associatednetworkid
1868+
const networkId = ('vpcid' in this.resource && (!('associatednetworkid' in this.resource) || this.vpcConserveMode)) ? this.selectedTier : this.resource.associatednetworkid
18541869
if (!networkId) {
18551870
this.addVmModalLoading = false
18561871
return
@@ -1999,7 +2014,7 @@ export default {
19992014
}
20002015
20012016
const networkId = this.selectedTierForAutoScaling != null ? this.selectedTierForAutoScaling
2002-
: ('vpcid' in this.resource) ? this.selectedTier : this.resource.associatednetworkid
2017+
: ('vpcid' in this.resource && !('associatednetworkid' in this.resource)) ? this.selectedTier : this.resource.associatednetworkid
20032018
postAPI('createLoadBalancerRule', {
20042019
openfirewall: false,
20052020
networkid: networkId,

ui/src/views/network/PortForwarding.vue

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -216,10 +216,10 @@
216216
@cancel="closeModal">
217217
<div v-ctrl-enter="addRule">
218218
<span
219-
v-if="'vpcid' in resource">
219+
v-if="'vpcid' in resource && (!('associatednetworkid' in resource) || this.vpcConserveMode)">
220220
<strong>{{ $t('label.select.tier') }} </strong>
221221
<a-select
222-
:v-focus="'vpcid' in resource"
222+
:v-focus="'vpcid' in resource && (!('associatednetworkid' in resource) || this.vpcConserveMode)"
223223
v-model:value="selectedTier"
224224
@change="fetchVirtualMachines()"
225225
:placeholder="$t('label.select.tier')"
@@ -467,7 +467,8 @@ export default {
467467
vmPageSize: 10,
468468
vmCount: 0,
469469
searchQuery: null,
470-
cidrlist: ''
470+
cidrlist: '',
471+
vpcConserveMode: false
471472
}
472473
},
473474
computed: {
@@ -504,9 +505,23 @@ export default {
504505
})
505506
},
506507
fetchData () {
508+
this.fetchVpc()
507509
this.fetchListTiers()
508510
this.fetchPFRules()
509511
},
512+
fetchVpc () {
513+
if (!this.resource.vpcid) {
514+
return
515+
}
516+
this.vpcConserveMode = false
517+
getAPI('listVPCs', {
518+
id: this.resource.vpcid
519+
}).then(json => {
520+
this.vpcConserveMode = json.listvpcsresponse?.vpc?.[0].vpcofferingconservemode || false
521+
}).catch(error => {
522+
this.$notifyError(error)
523+
})
524+
},
510525
fetchListTiers () {
511526
this.selectedTier = null
512527
this.tiers.loading = true
@@ -627,7 +642,7 @@ export default {
627642
if (this.loading) return
628643
this.loading = true
629644
this.addVmModalVisible = false
630-
const networkId = ('vpcid' in this.resource) ? this.selectedTier : this.resource.associatednetworkid
645+
const networkId = ('vpcid' in this.resource && (!('associatednetworkid' in this.resource || this.vpcConserveMode))) ? this.selectedTier : this.resource.associatednetworkid
631646
postAPI('createPortForwardingRule', {
632647
...this.newRule,
633648
ipaddressid: this.resource.id,
@@ -785,7 +800,7 @@ export default {
785800
this.newRule.virtualmachineid = e.target.value
786801
getAPI('listNics', {
787802
virtualmachineid: e.target.value,
788-
networkId: ('vpcid' in this.resource) ? this.selectedTier : this.resource.associatednetworkid
803+
networkId: ('vpcid' in this.resource && (!('associatednetworkid' in this.resource) || this.vpcConserveMode)) ? this.selectedTier : this.resource.associatednetworkid
789804
}).then(response => {
790805
if (!response.listnicsresponse.nic || response.listnicsresponse.nic.length < 1) return
791806
const nic = response.listnicsresponse.nic[0]
@@ -805,7 +820,7 @@ export default {
805820
this.vmCount = 0
806821
this.vms = []
807822
this.addVmModalLoading = true
808-
const networkId = ('vpcid' in this.resource) ? this.selectedTier : this.resource.associatednetworkid
823+
const networkId = ('vpcid' in this.resource && (!('associatednetworkid' in this.resource) || this.vpcConserveMode)) ? this.selectedTier : this.resource.associatednetworkid
809824
if (!networkId) {
810825
this.addVmModalLoading = false
811826
return

ui/src/views/network/PublicIpResource.vue

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -147,13 +147,15 @@ export default {
147147
let tabs = this.$route.meta.tabs.filter(tab => tab.name !== 'firewall')
148148
149149
const network = await this.fetchNetwork()
150-
if ((network && network.networkofferingconservemode) || !network && this.resource.issourcenat) {
150+
if (network && network.networkofferingconservemode) {
151151
this.tabs = tabs
152152
return
153-
} else if (this.resource.issourcenat) {
154-
// VPC IPs with Source Nat have only VPN when conserve_mode = false
155-
this.tabs = this.defaultTabs.concat(this.$route.meta.tabs.filter(tab => tab.name === 'vpn'))
156-
return
153+
} else {
154+
// VPC IPs with source nat have only VPN when conserve mode = false
155+
if (this.resource.issourcenat) {
156+
this.tabs = this.defaultTabs.concat(this.$route.meta.tabs.filter(tab => tab.name === 'vpn'))
157+
return
158+
}
157159
}
158160
159161
this.portFWRuleCount = await this.fetchPortFWRule()

0 commit comments

Comments
 (0)