Skip to content

Commit d8cca73

Browse files
committed
resolve conflict with main
2 parents 7f5e2a7 + b744824 commit d8cca73

File tree

80 files changed

+11744
-1949
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

80 files changed

+11744
-1949
lines changed

.github/CODEOWNERS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,5 @@
2020

2121
.pre-commit-config.yaml @jbampton
2222
/.github/linters/ @jbampton
23+
24+
/plugins/network-elements/nsx/ @Pearl1594 @nvazquez

.github/workflows/ci.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ jobs:
146146
smoke/test_vm_snapshot_kvm
147147
smoke/test_vm_snapshots
148148
smoke/test_volumes
149+
smoke/test_vpc_conserve_mode
149150
smoke/test_vpc_ipv6
150151
smoke/test_vpc_redundant
151152
smoke/test_vpc_router_nics

api/src/main/java/com/cloud/configuration/ConfigurationService.java

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,18 @@
2424
import org.apache.cloudstack.api.ApiConstants;
2525
import org.apache.cloudstack.api.command.admin.config.ResetCfgCmd;
2626
import org.apache.cloudstack.api.command.admin.config.UpdateCfgCmd;
27+
import org.apache.cloudstack.api.command.admin.network.CloneNetworkOfferingCmd;
2728
import org.apache.cloudstack.api.command.admin.network.CreateGuestNetworkIpv6PrefixCmd;
2829
import org.apache.cloudstack.api.command.admin.network.CreateManagementNetworkIpRangeCmd;
29-
import org.apache.cloudstack.api.command.admin.network.CreateNetworkOfferingCmd;
3030
import org.apache.cloudstack.api.command.admin.network.DeleteGuestNetworkIpv6PrefixCmd;
3131
import org.apache.cloudstack.api.command.admin.network.DeleteManagementNetworkIpRangeCmd;
3232
import org.apache.cloudstack.api.command.admin.network.DeleteNetworkOfferingCmd;
3333
import org.apache.cloudstack.api.command.admin.network.ListGuestNetworkIpv6PrefixesCmd;
34+
import org.apache.cloudstack.api.command.admin.network.NetworkOfferingBaseCmd;
3435
import org.apache.cloudstack.api.command.admin.network.UpdateNetworkOfferingCmd;
3536
import org.apache.cloudstack.api.command.admin.network.UpdatePodManagementNetworkIpRangeCmd;
37+
import org.apache.cloudstack.api.command.admin.offering.CloneDiskOfferingCmd;
38+
import org.apache.cloudstack.api.command.admin.offering.CloneServiceOfferingCmd;
3639
import org.apache.cloudstack.api.command.admin.offering.CreateDiskOfferingCmd;
3740
import org.apache.cloudstack.api.command.admin.offering.CreateServiceOfferingCmd;
3841
import org.apache.cloudstack.api.command.admin.offering.DeleteDiskOfferingCmd;
@@ -105,6 +108,33 @@ public interface ConfigurationService {
105108
*/
106109
ServiceOffering createServiceOffering(CreateServiceOfferingCmd cmd);
107110

111+
/**
112+
* Clones a service offering with optional parameter overrides
113+
*
114+
* @param cmd
115+
* the command object that specifies the source offering ID and optional parameter overrides
116+
* @return the newly created service offering cloned from source, null otherwise
117+
*/
118+
ServiceOffering cloneServiceOffering(CloneServiceOfferingCmd cmd);
119+
120+
/**
121+
* Clones a disk offering with optional parameter overrides
122+
*
123+
* @param cmd
124+
* the command object that specifies the source offering ID and optional parameter overrides
125+
* @return the newly created disk offering cloned from source, null otherwise
126+
*/
127+
DiskOffering cloneDiskOffering(CloneDiskOfferingCmd cmd);
128+
129+
/**
130+
* Clones a network offering with optional parameter overrides
131+
*
132+
* @param cmd
133+
* the command object that specifies the source offering ID and optional parameter overrides
134+
* @return the newly created network offering cloned from source, null otherwise
135+
*/
136+
NetworkOffering cloneNetworkOffering(CloneNetworkOfferingCmd cmd);
137+
108138
/**
109139
* Updates a service offering
110140
*
@@ -282,7 +312,7 @@ Vlan updateVlanAndPublicIpRange(UpdateVlanIpRangeCmd cmd) throws ConcurrentOpera
282312

283313
boolean releasePublicIpRange(ReleasePublicIpRangeCmd cmd);
284314

285-
NetworkOffering createNetworkOffering(CreateNetworkOfferingCmd cmd);
315+
NetworkOffering createNetworkOffering(NetworkOfferingBaseCmd cmd);
286316

287317
NetworkOffering updateNetworkOffering(UpdateNetworkOfferingCmd cmd);
288318

api/src/main/java/com/cloud/event/EventTypes.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -378,11 +378,13 @@ public class EventTypes {
378378

379379
// Service Offerings
380380
public static final String EVENT_SERVICE_OFFERING_CREATE = "SERVICE.OFFERING.CREATE";
381+
public static final String EVENT_SERVICE_OFFERING_CLONE = "SERVICE.OFFERING.CLONE";
381382
public static final String EVENT_SERVICE_OFFERING_EDIT = "SERVICE.OFFERING.EDIT";
382383
public static final String EVENT_SERVICE_OFFERING_DELETE = "SERVICE.OFFERING.DELETE";
383384

384385
// Disk Offerings
385386
public static final String EVENT_DISK_OFFERING_CREATE = "DISK.OFFERING.CREATE";
387+
public static final String EVENT_DISK_OFFERING_CLONE = "DISK.OFFERING.CLONE";
386388
public static final String EVENT_DISK_OFFERING_EDIT = "DISK.OFFERING.EDIT";
387389
public static final String EVENT_DISK_OFFERING_DELETE = "DISK.OFFERING.DELETE";
388390

@@ -403,6 +405,7 @@ public class EventTypes {
403405

404406
// Network offerings
405407
public static final String EVENT_NETWORK_OFFERING_CREATE = "NETWORK.OFFERING.CREATE";
408+
public static final String EVENT_NETWORK_OFFERING_CLONE = "NETWORK.OFFERING.CLONE";
406409
public static final String EVENT_NETWORK_OFFERING_ASSIGN = "NETWORK.OFFERING.ASSIGN";
407410
public static final String EVENT_NETWORK_OFFERING_EDIT = "NETWORK.OFFERING.EDIT";
408411
public static final String EVENT_NETWORK_OFFERING_REMOVE = "NETWORK.OFFERING.REMOVE";
@@ -602,6 +605,7 @@ public class EventTypes {
602605

603606
// VPC offerings
604607
public static final String EVENT_VPC_OFFERING_CREATE = "VPC.OFFERING.CREATE";
608+
public static final String EVENT_VPC_OFFERING_CLONE = "VPC.OFFERING.CLONE";
605609
public static final String EVENT_VPC_OFFERING_UPDATE = "VPC.OFFERING.UPDATE";
606610
public static final String EVENT_VPC_OFFERING_DELETE = "VPC.OFFERING.DELETE";
607611

@@ -634,6 +638,7 @@ public class EventTypes {
634638

635639
// Backup and Recovery events
636640
public static final String EVENT_VM_BACKUP_IMPORT_OFFERING = "BACKUP.IMPORT.OFFERING";
641+
public static final String EVENT_VM_BACKUP_OFFERING_CLONE = "BACKUP.OFFERING.CLONE";
637642
public static final String EVENT_VM_BACKUP_OFFERING_ASSIGN = "BACKUP.OFFERING.ASSIGN";
638643
public static final String EVENT_VM_BACKUP_OFFERING_REMOVE = "BACKUP.OFFERING.REMOVE";
639644
public static final String EVENT_VM_BACKUP_CREATE = "BACKUP.CREATE";
@@ -1059,11 +1064,13 @@ public class EventTypes {
10591064

10601065
// Service Offerings
10611066
entityEventDetails.put(EVENT_SERVICE_OFFERING_CREATE, ServiceOffering.class);
1067+
entityEventDetails.put(EVENT_SERVICE_OFFERING_CLONE, ServiceOffering.class);
10621068
entityEventDetails.put(EVENT_SERVICE_OFFERING_EDIT, ServiceOffering.class);
10631069
entityEventDetails.put(EVENT_SERVICE_OFFERING_DELETE, ServiceOffering.class);
10641070

10651071
// Disk Offerings
10661072
entityEventDetails.put(EVENT_DISK_OFFERING_CREATE, DiskOffering.class);
1073+
entityEventDetails.put(EVENT_DISK_OFFERING_CLONE, DiskOffering.class);
10671074
entityEventDetails.put(EVENT_DISK_OFFERING_EDIT, DiskOffering.class);
10681075
entityEventDetails.put(EVENT_DISK_OFFERING_DELETE, DiskOffering.class);
10691076

@@ -1084,6 +1091,7 @@ public class EventTypes {
10841091

10851092
// Network offerings
10861093
entityEventDetails.put(EVENT_NETWORK_OFFERING_CREATE, NetworkOffering.class);
1094+
entityEventDetails.put(EVENT_NETWORK_OFFERING_CLONE, NetworkOffering.class);
10871095
entityEventDetails.put(EVENT_NETWORK_OFFERING_ASSIGN, NetworkOffering.class);
10881096
entityEventDetails.put(EVENT_NETWORK_OFFERING_EDIT, NetworkOffering.class);
10891097
entityEventDetails.put(EVENT_NETWORK_OFFERING_REMOVE, NetworkOffering.class);

api/src/main/java/com/cloud/network/NetworkService.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,4 +279,6 @@ Network createPrivateNetwork(String networkName, String displayText, long physic
279279
IpAddresses getIpAddressesFromIps(String ipAddress, String ip6Address, String macAddress);
280280

281281
String getNicVlanValueForExternalVm(NicTO nic);
282+
283+
Long getPreferredNetworkIdForPublicIpRuleAssignment(IpAddress ip, Long networkId);
282284
}

api/src/main/java/com/cloud/network/lb/LoadBalancingRulesService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ LoadBalancer createPublicLoadBalancerRule(String xId, String name, String descri
108108
/**
109109
* Assign a virtual machine or list of virtual machines, or Map of <vmId vmIp> to a load balancer.
110110
*/
111-
boolean assignToLoadBalancer(long lbRuleId, List<Long> vmIds, Map<Long, List<String>> vmIdIpMap, boolean isAutoScaleVM);
111+
boolean assignToLoadBalancer(long lbRuleId, List<Long> vmIds, Map<Long, List<String>> vmIdIpMap, Map<Long, Long> vmIdNetworkMap, boolean isAutoScaleVM);
112112

113113
boolean assignSSLCertToLoadBalancerRule(Long lbRuleId, String certName, String publicCert, String privateKey);
114114

api/src/main/java/com/cloud/network/vpc/VpcOffering.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,4 +84,6 @@ public enum State {
8484
NetworkOffering.RoutingMode getRoutingMode();
8585

8686
Boolean isSpecifyAsNumber();
87+
88+
boolean isConserveMode();
8789
}

api/src/main/java/com/cloud/network/vpc/VpcProvisioningService.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import java.util.List;
2121
import java.util.Map;
2222

23+
import org.apache.cloudstack.api.command.admin.vpc.CloneVPCOfferingCmd;
2324
import org.apache.cloudstack.api.command.admin.vpc.CreateVPCOfferingCmd;
2425
import org.apache.cloudstack.api.command.admin.vpc.UpdateVPCOfferingCmd;
2526
import org.apache.cloudstack.api.command.user.vpc.ListVPCOfferingsCmd;
@@ -34,12 +35,14 @@ public interface VpcProvisioningService {
3435

3536
VpcOffering createVpcOffering(CreateVPCOfferingCmd cmd);
3637

38+
VpcOffering cloneVPCOffering(CloneVPCOfferingCmd cmd);
39+
3740
VpcOffering createVpcOffering(String name, String displayText, List<String> supportedServices,
3841
Map<String, List<String>> serviceProviders,
3942
Map serviceCapabilitystList, NetUtils.InternetProtocol internetProtocol,
4043
Long serviceOfferingId, String externalProvider, NetworkOffering.NetworkMode networkMode,
4144
List<Long> domainIds, List<Long> zoneIds, VpcOffering.State state,
42-
NetworkOffering.RoutingMode routingMode, boolean specifyAsNumber);
45+
NetworkOffering.RoutingMode routingMode, boolean specifyAsNumber, boolean conserveMode);
4346

4447

4548
Pair<List<? extends VpcOffering>,Integer> listVpcOfferings(ListVPCOfferingsCmd cmd);

api/src/main/java/org/apache/cloudstack/api/ApiConstants.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -559,6 +559,7 @@ public class ApiConstants {
559559
public static final String USE_STORAGE_REPLICATION = "usestoragereplication";
560560

561561
public static final String SOURCE_CIDR_LIST = "sourcecidrlist";
562+
public static final String SOURCE_OFFERING_ID = "sourceofferingid";
562563
public static final String SOURCE_ZONE_ID = "sourcezoneid";
563564
public static final String SSL_VERIFICATION = "sslverification";
564565
public static final String START_ASN = "startasn";
@@ -986,6 +987,7 @@ public class ApiConstants {
986987
public static final String REGION_ID = "regionid";
987988
public static final String VPC_OFF_ID = "vpcofferingid";
988989
public static final String VPC_OFF_NAME = "vpcofferingname";
990+
public static final String VPC_OFFERING_CONSERVE_MODE = "vpcofferingconservemode";
989991
public static final String NETWORK = "network";
990992
public static final String VPC_ID = "vpcid";
991993
public static final String VPC_NAME = "vpcname";
Lines changed: 166 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,166 @@
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+
package org.apache.cloudstack.api.command.admin.backup;
18+
19+
import javax.inject.Inject;
20+
21+
import org.apache.cloudstack.acl.RoleType;
22+
import org.apache.cloudstack.api.APICommand;
23+
import org.apache.cloudstack.api.ApiConstants;
24+
import org.apache.cloudstack.api.ApiErrorCode;
25+
import org.apache.cloudstack.api.BaseAsyncCmd;
26+
import org.apache.cloudstack.api.BaseCmd;
27+
import org.apache.cloudstack.api.Parameter;
28+
import org.apache.cloudstack.api.ServerApiException;
29+
import org.apache.cloudstack.api.command.offering.DomainAndZoneIdResolver;
30+
import org.apache.cloudstack.api.response.BackupOfferingResponse;
31+
import org.apache.cloudstack.api.response.ZoneResponse;
32+
import org.apache.cloudstack.backup.BackupManager;
33+
import org.apache.cloudstack.backup.BackupOffering;
34+
import org.apache.cloudstack.context.CallContext;
35+
36+
import com.cloud.event.EventTypes;
37+
import com.cloud.exception.ConcurrentOperationException;
38+
import com.cloud.exception.InsufficientCapacityException;
39+
import com.cloud.exception.InvalidParameterValueException;
40+
import com.cloud.exception.NetworkRuleConflictException;
41+
import com.cloud.exception.ResourceAllocationException;
42+
import com.cloud.exception.ResourceUnavailableException;
43+
import com.cloud.utils.exception.CloudRuntimeException;
44+
45+
import java.util.Arrays;
46+
import java.util.List;
47+
import java.util.function.LongFunction;
48+
49+
@APICommand(name = "cloneBackupOffering",
50+
description = "Clones a backup offering from an existing offering",
51+
responseObject = BackupOfferingResponse.class, since = "4.23.0",
52+
authorized = {RoleType.Admin})
53+
public class CloneBackupOfferingCmd extends BaseAsyncCmd implements DomainAndZoneIdResolver {
54+
55+
@Inject
56+
protected BackupManager backupManager;
57+
58+
/////////////////////////////////////////////////////
59+
//////////////// API parameters /////////////////////
60+
////////////////////////////////////////////////////
61+
62+
@Parameter(name = ApiConstants.SOURCE_OFFERING_ID, type = BaseCmd.CommandType.UUID, entityType = BackupOfferingResponse.class,
63+
required = true, description = "The ID of the source backup offering to clone from")
64+
private Long sourceOfferingId;
65+
66+
@Parameter(name = ApiConstants.NAME, type = BaseCmd.CommandType.STRING, required = true,
67+
description = "The name of the cloned offering")
68+
private String name;
69+
70+
@Parameter(name = ApiConstants.DESCRIPTION, type = BaseCmd.CommandType.STRING, required = false,
71+
description = "The description of the cloned offering")
72+
private String description;
73+
74+
@Parameter(name = ApiConstants.EXTERNAL_ID, type = BaseCmd.CommandType.STRING, required = false,
75+
description = "The backup offering ID (from backup provider side)")
76+
private String externalId;
77+
78+
@Parameter(name = ApiConstants.ZONE_ID, type = BaseCmd.CommandType.UUID, entityType = ZoneResponse.class,
79+
description = "The zone ID", required = false)
80+
private Long zoneId;
81+
82+
@Parameter(name = ApiConstants.DOMAIN_ID,
83+
type = CommandType.STRING,
84+
description = "the ID of the containing domain(s) as comma separated string, public for public offerings",
85+
length = 4096)
86+
private String domainIds;
87+
88+
@Parameter(name = ApiConstants.ALLOW_USER_DRIVEN_BACKUPS, type = BaseCmd.CommandType.BOOLEAN,
89+
description = "Whether users are allowed to create adhoc backups and backup schedules", required = false)
90+
private Boolean userDrivenBackups;
91+
92+
/////////////////////////////////////////////////////
93+
/////////////////// Accessors ///////////////////////
94+
/////////////////////////////////////////////////////
95+
96+
public Long getSourceOfferingId() {
97+
return sourceOfferingId;
98+
}
99+
100+
public String getName() {
101+
return name;
102+
}
103+
104+
public String getExternalId() {
105+
return externalId;
106+
}
107+
108+
public Long getZoneId() {
109+
return zoneId;
110+
}
111+
112+
public String getDescription() {
113+
return description;
114+
}
115+
116+
public Boolean getUserDrivenBackups() {
117+
return userDrivenBackups;
118+
}
119+
120+
public List<Long> getDomainIds() {
121+
if (domainIds != null && !domainIds.isEmpty()) {
122+
return Arrays.asList(Arrays.stream(domainIds.split(",")).map(domainId -> Long.parseLong(domainId.trim())).toArray(Long[]::new));
123+
}
124+
LongFunction<List<Long>> defaultDomainsProvider = null;
125+
if (backupManager != null) {
126+
defaultDomainsProvider = backupManager::getBackupOfferingDomains;
127+
}
128+
return resolveDomainIds(domainIds, sourceOfferingId, defaultDomainsProvider, "backup offering");
129+
}
130+
131+
/////////////////////////////////////////////////////
132+
/////////////// API Implementation///////////////////
133+
/////////////////////////////////////////////////////
134+
135+
@Override
136+
public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException, ResourceAllocationException, NetworkRuleConflictException {
137+
try {
138+
BackupOffering policy = backupManager.cloneBackupOffering(this);
139+
if (policy == null) {
140+
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to clone backup offering");
141+
}
142+
BackupOfferingResponse response = _responseGenerator.createBackupOfferingResponse(policy);
143+
response.setResponseName(getCommandName());
144+
setResponseObject(response);
145+
} catch (InvalidParameterValueException e) {
146+
throw new ServerApiException(ApiErrorCode.PARAM_ERROR, e.getMessage());
147+
} catch (CloudRuntimeException e) {
148+
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, e.getMessage());
149+
}
150+
}
151+
152+
@Override
153+
public long getEntityOwnerId() {
154+
return CallContext.current().getCallingAccount().getId();
155+
}
156+
157+
@Override
158+
public String getEventType() {
159+
return EventTypes.EVENT_VM_BACKUP_OFFERING_CLONE;
160+
}
161+
162+
@Override
163+
public String getEventDescription() {
164+
return "Cloning backup offering: " + name + " from source offering: " + (sourceOfferingId == null ? "" : sourceOfferingId.toString());
165+
}
166+
}

0 commit comments

Comments
 (0)