Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions api/src/main/java/com/cloud/network/Network.java
Original file line number Diff line number Diff line change
Expand Up @@ -510,4 +510,6 @@ public void setIp6Address(String ip6Address) {
Integer getPrivateMtu();

Integer getNetworkCidrSize();

boolean getKeepMacAddressOnPublicNic();
}
5 changes: 5 additions & 0 deletions api/src/main/java/com/cloud/network/NetworkProfile.java
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,11 @@ public Integer getNetworkCidrSize() {
return networkCidrSize;
}

@Override
public boolean getKeepMacAddressOnPublicNic() {
return true;
}

@Override
public String toString() {
return String.format("NetworkProfile %s",
Expand Down
2 changes: 2 additions & 0 deletions api/src/main/java/com/cloud/network/vpc/Vpc.java
Original file line number Diff line number Diff line change
Expand Up @@ -107,4 +107,6 @@ public enum State {
String getIp6Dns2();

boolean useRouterIpAsResolver();

boolean getKeepMacAddressOnPublicNic();
}
4 changes: 2 additions & 2 deletions api/src/main/java/com/cloud/network/vpc/VpcService.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public interface VpcService {
*/
Vpc createVpc(long zoneId, long vpcOffId, long vpcOwnerId, String vpcName, String displayText, String cidr, String networkDomain,
String ip4Dns1, String ip4Dns2, String ip6Dns1, String ip6Dns2, Boolean displayVpc, Integer publicMtu, Integer cidrSize,
Long asNumber, List<Long> bgpPeerIds, Boolean useVrIpResolver) throws ResourceAllocationException;
Long asNumber, List<Long> bgpPeerIds, Boolean useVrIpResolver, boolean keepMacAddressOnPublicNic) throws ResourceAllocationException;

/**
* Persists VPC record in the database
Expand Down Expand Up @@ -104,7 +104,7 @@ Vpc createVpc(long zoneId, long vpcOffId, long vpcOwnerId, String vpcName, Strin
* @throws ResourceUnavailableException if during restart some resources may not be available
* @throws InsufficientCapacityException if for instance no address space, compute or storage is sufficiently available
*/
Vpc updateVpc(long vpcId, String vpcName, String displayText, String customId, Boolean displayVpc, Integer mtu, String sourceNatIp) throws ResourceUnavailableException, InsufficientCapacityException;
Vpc updateVpc(long vpcId, String vpcName, String displayText, String customId, Boolean displayVpc, Integer mtu, String sourceNatIp, Boolean keepMacAddressOnPublicNic) throws ResourceUnavailableException, InsufficientCapacityException;

/**
* Lists VPC(s) based on the parameters passed to the API call
Expand Down
7 changes: 7 additions & 0 deletions api/src/main/java/org/apache/cloudstack/api/ApiConstants.java
Original file line number Diff line number Diff line change
Expand Up @@ -1348,6 +1348,13 @@ public class ApiConstants {
public static final String OBJECT_STORAGE_LIMIT = "objectstoragelimit";
public static final String OBJECT_STORAGE_TOTAL = "objectstoragetotal";

public static final String KEEP_MAC_ADDRESS_ON_PUBLIC_NIC = "keepmacaddressonpublicnic";

public static final String PARAMETER_DESCRIPTION_KEEP_MAC_ADDRESS_ON_PUBLIC_NIC =
"Indicates whether to use the same MAC address for the public NIC of VRs on the same network. If \"true\", when creating redundant routers or recreating" +
" a VR, CloudStack will use the same MAC address for the public NIC of all VRs. Otherwise, if \"false\", new public NICs will always have " +
" a new MAC address.";

public static final String PARAMETER_DESCRIPTION_ACTIVATION_RULE = "Quota tariff's activation rule. It can receive a JS script that results in either " +
"a boolean or a numeric value: if it results in a boolean value, the tariff value will be applied according to the result; if it results in a numeric value, the " +
"numeric value will be applied; if the result is neither a boolean nor a numeric value, the tariff will not be applied. If the rule is not informed, the tariff " +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,11 @@ public class CreateNetworkCmd extends BaseCmd implements UserCmd {
@Parameter(name=ApiConstants.AS_NUMBER, type=CommandType.LONG, since = "4.20.0", description="the AS Number of the network")
private Long asNumber;

@Parameter(name = ApiConstants.KEEP_MAC_ADDRESS_ON_PUBLIC_NIC,
description = ApiConstants.PARAMETER_DESCRIPTION_KEEP_MAC_ADDRESS_ON_PUBLIC_NIC,
type = CommandType.BOOLEAN, since = "4.23.0", authorized = {RoleType.Admin})
private Boolean keepMacAddressOnPublicNic;

/////////////////////////////////////////////////////
/////////////////// Accessors ///////////////////////
/////////////////////////////////////////////////////
Expand Down Expand Up @@ -286,6 +291,10 @@ public String getSourceNatIP() {
return sourceNatIP;
}

public Boolean getKeepMacAddressOnPublicNic() {
return keepMacAddressOnPublicNic;
}

@Override
public boolean isDisplay() {
if(displayNetwork == null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,11 @@ public class UpdateNetworkCmd extends BaseAsyncCustomIdCmd implements UserCmd {
@Parameter(name = ApiConstants.SOURCE_NAT_IP, type = CommandType.STRING, description = "IPV4 address to be assigned to the public interface of the network router. This address must already be acquired for this network", since = "4.19")
private String sourceNatIP;

@Parameter(name = ApiConstants.KEEP_MAC_ADDRESS_ON_PUBLIC_NIC,
description = ApiConstants.PARAMETER_DESCRIPTION_KEEP_MAC_ADDRESS_ON_PUBLIC_NIC,
type = CommandType.BOOLEAN, since = "4.23.0", authorized = {RoleType.Admin})
private Boolean keepMacAddressOnPublicNic;

/////////////////////////////////////////////////////
/////////////////// Accessors ///////////////////////
/////////////////////////////////////////////////////
Expand Down Expand Up @@ -186,6 +191,10 @@ public String getSourceNatIP() {
return sourceNatIP;
}

public Boolean getKeepMacAddressOnPublicNic() {
return keepMacAddressOnPublicNic;
}

/////////////////////////////////////////////////////
/////////////// API Implementation///////////////////
/////////////////////////////////////////////////////
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,11 @@ public class CreateVPCCmd extends BaseAsyncCreateCmd implements UserCmd {
description="(optional) for NSX based VPCs: when set to true, use the VR IP as nameserver, otherwise use DNS1 and DNS2")
private Boolean useVrIpResolver;

@Parameter(name = ApiConstants.KEEP_MAC_ADDRESS_ON_PUBLIC_NIC,
description = ApiConstants.PARAMETER_DESCRIPTION_KEEP_MAC_ADDRESS_ON_PUBLIC_NIC,
type = CommandType.BOOLEAN, since = "4.23.0", authorized = {RoleType.Admin})
private boolean keepMacAddressOnPublicNic = true;

// ///////////////////////////////////////////////////
// ///////////////// Accessors ///////////////////////
// ///////////////////////////////////////////////////
Expand Down Expand Up @@ -214,6 +219,10 @@ public boolean getUseVrIpResolver() {
return BooleanUtils.toBoolean(useVrIpResolver);
}

public boolean getKeepMacAddressOnPublicNic() {
return keepMacAddressOnPublicNic;
}

/////////////////////////////////////////////////////
/////////////// API Implementation///////////////////
/////////////////////////////////////////////////////
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,15 @@ public class UpdateVPCCmd extends BaseAsyncCustomIdCmd implements UserCmd {
since = "4.19")
private String sourceNatIP;

@Parameter(name = ApiConstants.KEEP_MAC_ADDRESS_ON_PUBLIC_NIC,
description = ApiConstants.PARAMETER_DESCRIPTION_KEEP_MAC_ADDRESS_ON_PUBLIC_NIC,
type = CommandType.BOOLEAN, since = "4.23.0", authorized = {RoleType.Admin})
private Boolean keepMacAddressOnPublicNic;

public Boolean getKeepMacAddressOnPublicNic() {
return keepMacAddressOnPublicNic;
}

/////////////////////////////////////////////////////
/////////////////// Accessors ///////////////////////
/////////////////////////////////////////////////////
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,10 @@ public class NetworkResponse extends BaseResponseWithAssociatedNetwork implement
@Param(description = "The BGP peers for the network", since = "4.20.0")
private Set<BgpPeerResponse> bgpPeers;

@SerializedName(ApiConstants.KEEP_MAC_ADDRESS_ON_PUBLIC_NIC)
@Param(description = ApiConstants.PARAMETER_DESCRIPTION_KEEP_MAC_ADDRESS_ON_PUBLIC_NIC, since = "4.23.0")
private Boolean keepMacAddressOnPublicNic;

public NetworkResponse() {}

public Boolean getDisplayNetwork() {
Expand Down Expand Up @@ -702,4 +706,8 @@ public void setIpv6Dns1(String ipv6Dns1) {
public void setIpv6Dns2(String ipv6Dns2) {
this.ipv6Dns2 = ipv6Dns2;
}

public void setKeepMacAddressOnPublicNic(Boolean keepMacAddressOnPublicNic) {
this.keepMacAddressOnPublicNic = keepMacAddressOnPublicNic;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,10 @@ public class VpcResponse extends BaseResponseWithAnnotations implements Controll
@Param(description = "The BGP peers for the VPC", since = "4.20.0")
private Set<BgpPeerResponse> bgpPeers;

@SerializedName(ApiConstants.KEEP_MAC_ADDRESS_ON_PUBLIC_NIC)
@Param(description = ApiConstants.PARAMETER_DESCRIPTION_KEEP_MAC_ADDRESS_ON_PUBLIC_NIC, since = "4.23.0")
private Boolean keepMacAddressOnPublicNic;

public void setId(final String id) {
this.id = id;
}
Expand Down Expand Up @@ -366,4 +370,8 @@ public void addBgpPeer(BgpPeerResponse bgpPeer) {
}
this.bgpPeers.add(bgpPeer);
}

public void setKeepMacAddressOnPublicNic(Boolean keepMacAddressOnPublicNic) {
this.keepMacAddressOnPublicNic = keepMacAddressOnPublicNic;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public void testExecute() throws ResourceUnavailableException, InsufficientCapac
responseGenerator = Mockito.mock(ResponseGenerator.class);
cmd._responseGenerator = responseGenerator;
Mockito.verify(_vpcService, Mockito.times(0)).updateVpc(Mockito.anyLong(), Mockito.anyString(), Mockito.anyString(),
Mockito.anyString(), Mockito.anyBoolean(), Mockito.anyInt(), Mockito.anyString());
Mockito.anyString(), Mockito.anyBoolean(), Mockito.anyInt(), Mockito.anyString(), Mockito.anyBoolean());

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,11 @@ Network createGuestNetwork(long networkOfferingId, String name, String displayTe
Boolean displayNetworkEnabled, String isolatedPvlan, Network.PVlanType isolatedPvlanType, String externalId, String routerIp, String routerIpv6,
String ip4Dns1, String ip4Dns2, String ip6Dns1, String ip6Dns2, Pair<Integer, Integer> vrIfaceMTUs, Integer networkCidrSize) throws ConcurrentOperationException, InsufficientCapacityException, ResourceAllocationException;

Network createGuestNetwork(long networkOfferingId, String name, String displayText, String gateway, String cidr, String vlanId, boolean bypassVlanOverlapCheck, String networkDomain, Account owner,
Long domainId, PhysicalNetwork physicalNetwork, long zoneId, ACLType aclType, Boolean subdomainAccess, Long vpcId, String ip6Gateway, String ip6Cidr,
Boolean displayNetworkEnabled, String isolatedPvlan, Network.PVlanType isolatedPvlanType, String externalId, String routerIp, String routerIpv6,
String ip4Dns1, String ip4Dns2, String ip6Dns1, String ip6Dns2, Pair<Integer, Integer> vrIfaceMTUs, Integer networkCidrSize, Boolean keepMacAddressOnPublicNic) throws ConcurrentOperationException, InsufficientCapacityException, ResourceAllocationException;

UserDataServiceProvider getPasswordResetProvider(Network network);

UserDataServiceProvider getSSHKeyResetProvider(Network network);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -858,6 +858,7 @@ private static NetworkVO getNetworkVO(long id, final NetworkOffering offering, f
vpcId, offering.isRedundantRouter(), predefined.getExternalId());
vo.setDisplayNetwork(isDisplayNetworkEnabled == null || isDisplayNetworkEnabled);
vo.setStrechedL2Network(offering.isSupportingStrechedL2());
vo.setKeepMacAddressOnPublicNic(predefined.getKeepMacAddressOnPublicNic());
return vo;
}

Expand Down Expand Up @@ -2719,7 +2720,7 @@ public Network createPrivateNetwork(final long networkOfferingId, final String n
return createGuestNetwork(networkOfferingId, name, displayText, gateway, cidr, vlanId,
bypassVlanOverlapCheck, null, owner, null, pNtwk, pNtwk.getDataCenterId(), ACLType.Account, null,
vpcId, null, null, true, null, null, null, true, null, null,
null, null, null, null, null, null);
null, null, null, null, null, null, null);
}

@Override
Expand All @@ -2730,10 +2731,25 @@ public Network createGuestNetwork(final long networkOfferingId, final String nam
final Boolean isDisplayNetworkEnabled, final String isolatedPvlan, Network.PVlanType isolatedPvlanType, String externalId,
String routerIp, String routerIpv6, String ip4Dns1, String ip4Dns2, String ip6Dns1, String ip6Dns2,
Pair<Integer, Integer> vrIfaceMTUs, Integer networkCidrSize) throws ConcurrentOperationException, InsufficientCapacityException, ResourceAllocationException {
return createGuestNetwork(networkOfferingId, name, displayText, gateway, cidr, vlanId, bypassVlanOverlapCheck,
networkDomain, owner, domainId, pNtwk, zoneId, aclType, subdomainAccess, vpcId, ip6Gateway, ip6Cidr,
isDisplayNetworkEnabled, isolatedPvlan, isolatedPvlanType, externalId, false, routerIp, routerIpv6,
ip4Dns1, ip4Dns2, ip6Dns1, ip6Dns2, vrIfaceMTUs, networkCidrSize, true);
}

@Override
@DB
public Network createGuestNetwork(final long networkOfferingId, final String name, final String displayText, final String gateway, final String cidr, String vlanId,
boolean bypassVlanOverlapCheck, String networkDomain, final Account owner, final Long domainId, final PhysicalNetwork pNtwk,
final long zoneId, final ACLType aclType, Boolean subdomainAccess, final Long vpcId, final String ip6Gateway, final String ip6Cidr,
final Boolean isDisplayNetworkEnabled, final String isolatedPvlan, Network.PVlanType isolatedPvlanType, String externalId,
String routerIp, String routerIpv6, String ip4Dns1, String ip4Dns2, String ip6Dns1, String ip6Dns2,
Pair<Integer, Integer> vrIfaceMTUs, Integer networkCidrSize, Boolean keepMacAddressOnPublicNic) throws ConcurrentOperationException, InsufficientCapacityException, ResourceAllocationException {
// create Isolated/Shared/L2 network
return createGuestNetwork(networkOfferingId, name, displayText, gateway, cidr, vlanId, bypassVlanOverlapCheck,
networkDomain, owner, domainId, pNtwk, zoneId, aclType, subdomainAccess, vpcId, ip6Gateway, ip6Cidr,
isDisplayNetworkEnabled, isolatedPvlan, isolatedPvlanType, externalId, false, routerIp, routerIpv6, ip4Dns1, ip4Dns2, ip6Dns1, ip6Dns2, vrIfaceMTUs, networkCidrSize);
isDisplayNetworkEnabled, isolatedPvlan, isolatedPvlanType, externalId, false, routerIp, routerIpv6,
ip4Dns1, ip4Dns2, ip6Dns1, ip6Dns2, vrIfaceMTUs, networkCidrSize, keepMacAddressOnPublicNic);
}

@DB
Expand All @@ -2742,7 +2758,8 @@ private Network createGuestNetwork(final long networkOfferingId, final String na
final long zoneId, final ACLType aclType, Boolean subdomainAccess, final Long vpcId, final String ip6Gateway, final String ip6Cidr,
final Boolean isDisplayNetworkEnabled, final String isolatedPvlan, Network.PVlanType isolatedPvlanType, String externalId,
final Boolean isPrivateNetwork, String routerIp, String routerIpv6, final String ip4Dns1, final String ip4Dns2,
final String ip6Dns1, final String ip6Dns2, Pair<Integer, Integer> vrIfaceMTUs, Integer networkCidrSize) throws ConcurrentOperationException, InsufficientCapacityException, ResourceAllocationException {
final String ip6Dns1, final String ip6Dns2, Pair<Integer, Integer> vrIfaceMTUs, Integer networkCidrSize,
Boolean keepMacAddressOnPublicNic) throws ConcurrentOperationException, InsufficientCapacityException, ResourceAllocationException {

final NetworkOfferingVO ntwkOff = _networkOfferingDao.findById(networkOfferingId);
final DataCenterVO zone = _dcDao.findById(zoneId);
Expand Down Expand Up @@ -3095,6 +3112,7 @@ public Network doInTransaction(final TransactionStatus status) {
}
}
userNetwork.setNetworkCidrSize(networkCidrSize);
userNetwork.setKeepMacAddressOnPublicNic(keepMacAddressOnPublicNic);
final List<? extends Network> networks = setupNetwork(owner, ntwkOff, userNetwork, plan, name, displayText, true, domainId, aclType, subdomainAccessFinal, vpcId,
isDisplayNetworkEnabled);
Network network;
Expand Down
13 changes: 13 additions & 0 deletions engine/schema/src/main/java/com/cloud/network/dao/NetworkVO.java
Original file line number Diff line number Diff line change
Expand Up @@ -203,9 +203,13 @@ public class NetworkVO implements Network {
@Column(name = "private_mtu")
Integer privateMtu;

@Column(name = "keep_mac_address_on_public_nic")
private boolean keepMacAddressOnPublicNic = true;

@Transient
Integer networkCidrSize;


public NetworkVO() {
uuid = UUID.randomUUID().toString();
}
Expand Down Expand Up @@ -773,4 +777,13 @@ public Integer getNetworkCidrSize() {
public void setNetworkCidrSize(Integer networkCidrSize) {
this.networkCidrSize = networkCidrSize;
}

@Override
public boolean getKeepMacAddressOnPublicNic() {
return keepMacAddressOnPublicNic;
}

public void setKeepMacAddressOnPublicNic(boolean keepMacAddressOnPublicNic) {
this.keepMacAddressOnPublicNic = keepMacAddressOnPublicNic;
}
}
12 changes: 12 additions & 0 deletions engine/schema/src/main/java/com/cloud/network/vpc/VpcVO.java
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,9 @@ public class VpcVO implements Vpc {
@Column(name = "use_router_ip_resolver")
boolean useRouterIpResolver = false;

@Column(name = "keep_mac_address_on_public_nic")
private boolean keepMacAddressOnPublicNic = true;

@Transient
boolean rollingRestart = false;

Expand Down Expand Up @@ -321,4 +324,13 @@ public boolean useRouterIpAsResolver() {
public void setUseRouterIpResolver(boolean useRouterIpResolver) {
this.useRouterIpResolver = useRouterIpResolver;
}

@Override
public boolean getKeepMacAddressOnPublicNic() {
return keepMacAddressOnPublicNic;
}

public void setKeepMacAddressOnPublicNic(boolean keepMacAddressOnPublicNic) {
this.keepMacAddressOnPublicNic = keepMacAddressOnPublicNic;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -117,3 +117,7 @@ CALL `cloud`.`IDEMPOTENT_ADD_COLUMN`('cloud.vpc_offerings','conserve_mode', 'tin

--- Disable/enable NICs
CALL `cloud`.`IDEMPOTENT_ADD_COLUMN`('cloud.nics','enabled', 'TINYINT(1) NOT NULL DEFAULT 1 COMMENT ''Indicates whether the NIC is enabled or not'' ');

-- Add the 'keep_mac_address_on_public_nic' column to the 'cloud.networks' and 'cloud.vpc' tables
CALL `cloud`.`IDEMPOTENT_ADD_COLUMN`('cloud.networks', 'keep_mac_address_on_public_nic', 'TINYINT(1) NOT NULL DEFAULT 1');
CALL `cloud`.`IDEMPOTENT_ADD_COLUMN`('cloud.vpc', 'keep_mac_address_on_public_nic', 'TINYINT(1) NOT NULL DEFAULT 1');
8 changes: 8 additions & 0 deletions server/src/main/java/com/cloud/api/ApiResponseHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -2874,6 +2874,11 @@ public NetworkResponse createNetworkResponse(ResponseView view, Network network)
}
}

if (CallContext.current().getCallingAccount().getType() == Account.Type.ADMIN &&
network.getVpcId() == null && network.getGuestType() == Network.GuestType.Isolated) {
response.setKeepMacAddressOnPublicNic(network.getKeepMacAddressOnPublicNic());
}

response.setObjectName("network");
return response;
}
Expand Down Expand Up @@ -3637,6 +3642,9 @@ public VpcResponse createVpcResponse(ResponseView view, Vpc vpc) {
}
}

if (CallContext.current().getCallingAccount().getType() == Account.Type.ADMIN) {
response.setKeepMacAddressOnPublicNic(vpc.getKeepMacAddressOnPublicNic());
}
response.setObjectName("vpc");
return response;
}
Expand Down
Loading
Loading