Skip to content

Commit f4060c3

Browse files
author
Alena Prokharchyk
committed
1) Added new element - VpcVirtualRouterElement. Extends VirtualRouter + has plug/unplug nics support
2) Added services api support for plugging/unplugging the nics to VpcElement Conflicts: api/src/com/cloud/network/NetworkService.java core/src/com/cloud/vm/VMInstanceVO.java server/src/com/cloud/network/NetworkManagerImpl.java server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java server/test/com/cloud/network/MockNetworkManagerImpl.java
1 parent c12ba9c commit f4060c3

37 files changed

Lines changed: 1048 additions & 265 deletions

‎api/src/com/cloud/api/ApiConstants.java‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -359,6 +359,7 @@ public class ApiConstants {
359359
public static final String ADD_VSM_FLAG = "addvsmflag";
360360
public static final String VPC_OFF_ID = "vpcofferingid";
361361
public static final String NETWORK = "network";
362+
public static final String VPC_ID = "vpcid";
362363

363364
public enum HostDetails {
364365
all, capacity, events, stats, min;

‎api/src/com/cloud/api/commands/CreateNetworkCmd.java‎

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -62,16 +62,19 @@ public class CreateNetworkCmd extends BaseCmd {
6262
@Parameter(name=ApiConstants.PHYSICAL_NETWORK_ID, type=CommandType.LONG, description="the Physical Network ID the network belongs to")
6363
private Long physicalNetworkId;
6464

65-
@Parameter(name=ApiConstants.GATEWAY, type=CommandType.STRING, description="the gateway of the network")
65+
@Parameter(name=ApiConstants.GATEWAY, type=CommandType.STRING, description="the gateway of the network. Required " +
66+
"for Shared networks and Isolated networks when it belongs to VPC")
6667
private String gateway;
6768

68-
@Parameter(name=ApiConstants.NETMASK, type=CommandType.STRING, description="the netmask of the network")
69+
@Parameter(name=ApiConstants.NETMASK, type=CommandType.STRING, description="the netmask of the network. Required " +
70+
"for Shared networks and Isolated networks when it belongs to VPC")
6971
private String netmask;
7072

7173
@Parameter(name=ApiConstants.START_IP, type=CommandType.STRING, description="the beginning IP address in the network IP range")
7274
private String startIp;
7375

74-
@Parameter(name=ApiConstants.END_IP, type=CommandType.STRING, description="the ending IP address in the network IP range. If not specified, will be defaulted to startIP")
76+
@Parameter(name=ApiConstants.END_IP, type=CommandType.STRING, description="the ending IP address in the network IP" +
77+
" range. If not specified, will be defaulted to startIP")
7578
private String endIp;
7679

7780
@Parameter(name=ApiConstants.VLAN, type=CommandType.STRING, description="the ID or VID of the network")
@@ -80,7 +83,9 @@ public class CreateNetworkCmd extends BaseCmd {
8083
@Parameter(name=ApiConstants.NETWORK_DOMAIN, type=CommandType.STRING, description="network domain")
8184
private String networkDomain;
8285

83-
@Parameter(name=ApiConstants.ACL_TYPE, type=CommandType.STRING, description="Access control type; supported values are account and domain. In 3.0 all shared networks should have aclType=Domain, and all Isolated networks - Account. Account means that only the account owner can use the network, domain - all accouns in the domain can use the network")
86+
@Parameter(name=ApiConstants.ACL_TYPE, type=CommandType.STRING, description="Access control type; supported values" +
87+
" are account and domain. In 3.0 all shared networks should have aclType=Domain, and all Isolated networks" +
88+
" - Account. Account means that only the account owner can use the network, domain - all accouns in the domain can use the network")
8489
private String aclType;
8590

8691
@Parameter(name=ApiConstants.ACCOUNT, type=CommandType.STRING, description="account who will own the network")
@@ -94,9 +99,13 @@ public class CreateNetworkCmd extends BaseCmd {
9499
@Parameter(name=ApiConstants.DOMAIN_ID, type=CommandType.LONG, description="domain ID of the account owning a network")
95100
private Long domainId;
96101

97-
@Parameter(name=ApiConstants.SUBDOMAIN_ACCESS, type=CommandType.BOOLEAN, description="Defines whether to allow subdomains to use networks dedicated to their parent domain(s). Should be used with aclType=Domain, defaulted to allow.subdomain.network.access global config if not specified")
102+
@Parameter(name=ApiConstants.SUBDOMAIN_ACCESS, type=CommandType.BOOLEAN, description="Defines whether to allow" +
103+
" subdomains to use networks dedicated to their parent domain(s). Should be used with aclType=Domain, defaulted to allow.subdomain.network.access global config if not specified")
98104
private Boolean subdomainAccess;
99105

106+
@IdentityMapper(entityTableName="vpc")
107+
@Parameter(name=ApiConstants.VPC_ID, type=CommandType.LONG, description="the VPC network belongs to")
108+
private Long vpcId;
100109

101110

102111
/////////////////////////////////////////////////////
@@ -158,7 +167,11 @@ public Boolean getSubdomainAccess() {
158167
return subdomainAccess;
159168
}
160169

161-
public Long getZoneId() {
170+
public Long getVpcId() {
171+
return vpcId;
172+
}
173+
174+
public Long getZoneId() {
162175
Long physicalNetworkId = getPhysicalNetworkId();
163176

164177
if (physicalNetworkId == null && zoneId == null) {
@@ -209,7 +222,7 @@ public long getEntityOwnerId() {
209222
@Override
210223
// an exception thrown by createNetwork() will be caught by the dispatcher.
211224
public void execute() throws InsufficientCapacityException, ConcurrentOperationException, ResourceAllocationException{
212-
Network result = _networkService.createNetwork(this);
225+
Network result = _networkService.createGuestNetwork(this);
213226
if (result != null) {
214227
NetworkResponse response = _responseGenerator.createNetworkResponse(result);
215228
response.setResponseName(getCommandName());

‎api/src/com/cloud/api/commands/CreateVPCCmd.java‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,9 @@ public class CreateVPCCmd extends BaseAsyncCreateCmd{
6969
@Parameter(name=ApiConstants.VPC_OFF_ID, type=CommandType.LONG, required=true, description="the ID of the VPC offering")
7070
private Long vpcOffering;
7171

72+
@Parameter(name=ApiConstants.NETWORK_DOMAIN, type=CommandType.STRING, description="network domain")
73+
private String networkDomain;
74+
7275
/////////////////////////////////////////////////////
7376
/////////////////// Accessors ///////////////////////
7477
/////////////////////////////////////////////////////
@@ -100,10 +103,15 @@ public String getDisplayText() {
100103
public Long getVpcOffering() {
101104
return vpcOffering;
102105
}
106+
107+
public String getNetworkDomain() {
108+
return networkDomain;
109+
}
103110

104111
@Override
105112
public void create() throws ResourceAllocationException {
106-
Vpc vpc = _vpcService.createVpc(getZoneId(), getVpcOffering(), getEntityOwnerId(), getVpcName(), getDisplayText(), getCidr());
113+
Vpc vpc = _vpcService.createVpc(getZoneId(), getVpcOffering(), getEntityOwnerId(), getVpcName(), getDisplayText(),
114+
getCidr(), getNetworkDomain());
107115
if (vpc != null) {
108116
this.setEntityId(vpc.getId());
109117
} else {

‎api/src/com/cloud/api/commands/UpdateNetworkOfferingCmd.java‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@ public class UpdateNetworkOfferingCmd extends BaseCmd {
4747
@Parameter(name=ApiConstants.DISPLAY_TEXT, type=CommandType.STRING, description="the display text of the network offering")
4848
private String displayText;
4949

50-
@Parameter(name=ApiConstants.AVAILABILITY, type=CommandType.STRING, description="the availability of network offering. Default value is Required for Guest Virtual network offering; Optional for Guest Direct network offering")
50+
@Parameter(name=ApiConstants.AVAILABILITY, type=CommandType.STRING, description="the availability of network offering." +
51+
" Default value is Required for Guest Virtual network offering; Optional for Guest Direct network offering")
5152
private String availability;
5253

5354
@Parameter(name=ApiConstants.SORT_KEY, type=CommandType.INTEGER, description="sort key of the network offering, integer")

‎api/src/com/cloud/network/Network.java‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,11 @@ public static class Service {
4545
public static final Service Dhcp = new Service("Dhcp");
4646
public static final Service Dns = new Service("Dns", Capability.AllowDnsSuffixModification);
4747
public static final Service Gateway = new Service("Gateway");
48-
public static final Service Firewall = new Service("Firewall", Capability.SupportedProtocols, Capability.MultipleIps, Capability.TrafficStatistics);
49-
public static final Service Lb = new Service("Lb", Capability.SupportedLBAlgorithms, Capability.SupportedLBIsolation, Capability.SupportedProtocols, Capability.TrafficStatistics, Capability.LoadBalancingSupportedIps, Capability.SupportedStickinessMethods, Capability.ElasticLb);
48+
public static final Service Firewall = new Service("Firewall", Capability.SupportedProtocols,
49+
Capability.MultipleIps, Capability.TrafficStatistics);
50+
public static final Service Lb = new Service("Lb", Capability.SupportedLBAlgorithms, Capability.SupportedLBIsolation,
51+
Capability.SupportedProtocols, Capability.TrafficStatistics, Capability.LoadBalancingSupportedIps,
52+
Capability.SupportedStickinessMethods, Capability.ElasticLb);
5053
public static final Service UserData = new Service("UserData");
5154
public static final Service SourceNat = new Service("SourceNat", Capability.SupportedSourceNatTypes, Capability.RedundantRouter);
5255
public static final Service StaticNat = new Service("StaticNat", Capability.ElasticIp);
@@ -113,6 +116,7 @@ public static class Provider {
113116
public static final Provider ExternalGateWay = new Provider("ExternalGateWay", true);
114117
public static final Provider ElasticLoadBalancerVm = new Provider("ElasticLoadBalancerVm", false);
115118
public static final Provider SecurityGroupProvider = new Provider("SecurityGroupProvider", false);
119+
public static final Provider VPCVirtualRouter = new Provider("VpcVirtualRouter", false);
116120
public static final Provider None = new Provider("None", false);
117121

118122
private String name;

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

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,15 @@
3636
import com.cloud.user.Account;
3737
import com.cloud.user.User;
3838
import com.cloud.utils.Pair;
39+
import com.cloud.vm.VirtualMachine;
3940

4041
public interface NetworkService {
4142

4243
List<? extends Network> getIsolatedNetworksOwnedByAccountInZone(long zoneId, Account owner);
4344

4445
IpAddress allocateIP(long networkId, Account ipOwner) throws ResourceAllocationException, InsufficientAddressCapacityException, ConcurrentOperationException;
46+
IpAddress allocateIP(long networkId, Account ipOwner, boolean isSystem) throws ResourceAllocationException,
47+
InsufficientAddressCapacityException, ConcurrentOperationException;
4548

4649
/**
4750
* Associates a public IP address for a router.
@@ -52,17 +55,20 @@ public interface NetworkService {
5255
* @throws ResourceAllocationException
5356
* , InsufficientCapacityException
5457
*/
55-
IpAddress associateIP(long ipId) throws ResourceAllocationException, InsufficientAddressCapacityException, ConcurrentOperationException, ResourceUnavailableException;
58+
IpAddress associateIP(long ipId) throws ResourceAllocationException, InsufficientAddressCapacityException,
59+
ConcurrentOperationException, ResourceUnavailableException;
5660

5761
boolean disassociateIpAddress(long ipAddressId) throws InsufficientAddressCapacityException;
5862

59-
Network createNetwork(CreateNetworkCmd cmd) throws InsufficientCapacityException, ConcurrentOperationException, ResourceAllocationException;
63+
Network createGuestNetwork(CreateNetworkCmd cmd) throws InsufficientCapacityException, ConcurrentOperationException,
64+
ResourceAllocationException;
6065

6166
List<? extends Network> searchForNetworks(ListNetworksCmd cmd);
6267

6368
boolean deleteNetwork(long networkId);
6469

65-
boolean restartNetwork(RestartNetworkCmd cmd, boolean cleanup) throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException;
70+
boolean restartNetwork(RestartNetworkCmd cmd, boolean cleanup) throws ConcurrentOperationException,
71+
ResourceUnavailableException, InsufficientCapacityException;
6672

6773
int getActiveNicsInNetwork(long networkId);
6874

@@ -78,29 +84,35 @@ public interface NetworkService {
7884

7985
Long getDedicatedNetworkDomain(long networkId);
8086

81-
Network updateGuestNetwork(long networkId, String name, String displayText, Account callerAccount, User callerUser, String domainSuffix, Long networkOfferingId, Boolean changeCidr);
87+
Network updateGuestNetwork(long networkId, String name, String displayText, Account callerAccount, User callerUser,
88+
String domainSuffix, Long networkOfferingId, Boolean changeCidr);
8289

8390
Integer getNetworkRate(long networkId, Long vmId);
8491

8592
Network getSystemNetworkByZoneAndTrafficType(long zoneId, TrafficType trafficType);
8693

8794
Map<Service, Set<Provider>> getNetworkOfferingServiceProvidersMap(long networkOfferingId);
8895

89-
PhysicalNetwork createPhysicalNetwork(Long zoneId, String vnetRange, String networkSpeed, List<String> isolationMethods, String broadcastDomainRange, Long domainId, List<String> tags, String name);
96+
PhysicalNetwork createPhysicalNetwork(Long zoneId, String vnetRange, String networkSpeed,
97+
List<String> isolationMethods, String broadcastDomainRange, Long domainId, List<String> tags, String name);
9098

91-
List<? extends PhysicalNetwork> searchPhysicalNetworks(Long id, Long zoneId, String keyword, Long startIndex, Long pageSize, String name);
99+
List<? extends PhysicalNetwork> searchPhysicalNetworks(Long id, Long zoneId, String keyword,
100+
Long startIndex, Long pageSize, String name);
92101

93-
PhysicalNetwork updatePhysicalNetwork(Long id, String networkSpeed, List<String> tags, String newVnetRangeString, String state);
102+
PhysicalNetwork updatePhysicalNetwork(Long id, String networkSpeed, List<String> tags,
103+
String newVnetRangeString, String state);
94104

95105
boolean deletePhysicalNetwork(Long id);
96106

97107
List<? extends Service> listNetworkServices(String providerName);
98108

99109
List<? extends Provider> listSupportedNetworkServiceProviders(String serviceName);
100110

101-
PhysicalNetworkServiceProvider addProviderToPhysicalNetwork(Long physicalNetworkId, String providerName, Long destinationPhysicalNetworkId, List<String> enabledServices);
111+
PhysicalNetworkServiceProvider addProviderToPhysicalNetwork(Long physicalNetworkId, String providerName,
112+
Long destinationPhysicalNetworkId, List<String> enabledServices);
102113

103-
List<? extends PhysicalNetworkServiceProvider> listNetworkServiceProviders(Long physicalNetworkId, String name, String state, Long startIndex, Long pageSize);
114+
List<? extends PhysicalNetworkServiceProvider> listNetworkServiceProviders(Long physicalNetworkId, String name,
115+
String state, Long startIndex, Long pageSize);
104116

105117
PhysicalNetworkServiceProvider updateNetworkServiceProvider(Long id, String state, List<String> enabledServices);
106118

@@ -116,7 +128,8 @@ public interface NetworkService {
116128

117129
long findPhysicalNetworkId(long zoneId, String tag, TrafficType trafficType);
118130

119-
PhysicalNetworkTrafficType addTrafficTypeToPhysicalNetwork(Long physicalNetworkId, String trafficType, String xenLabel, String kvmLabel, String vmwareLabel, String simulatorLabel, String vlan);
131+
PhysicalNetworkTrafficType addTrafficTypeToPhysicalNetwork(Long physicalNetworkId, String trafficType,
132+
String xenLabel, String kvmLabel, String vmwareLabel, String simulatorLabel, String vlan);
120133

121134
PhysicalNetworkTrafficType getPhysicalNetworkTrafficType(Long id);
122135

@@ -135,5 +148,11 @@ public interface NetworkService {
135148
List<? extends Network> getIsolatedNetworksWithSourceNATOwnedByAccountInZone(long zoneId, Account owner);
136149

137150
List<? extends Network> listNetworksByVpc(long vpcId);
151+
152+
boolean addVmToNetwork(VirtualMachine vm, Network network);
153+
154+
boolean removeVmFromNetwork(VirtualMachine vm, Network network);
155+
156+
boolean isVmPartOfNetwork(long vmId, long ntwkId);
138157

139158
}

‎api/src/com/cloud/network/element/VpcProvider.java‎

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,12 @@
1717
import com.cloud.exception.InsufficientCapacityException;
1818
import com.cloud.exception.InsufficientNetworkCapacityException;
1919
import com.cloud.exception.ResourceUnavailableException;
20+
import com.cloud.network.Network;
2021
import com.cloud.network.vpc.Vpc;
22+
import com.cloud.vm.NicProfile;
2123
import com.cloud.vm.ReservationContext;
24+
import com.cloud.vm.VirtualMachine;
25+
import com.cloud.vm.VirtualMachineProfile;
2226

2327
/**
2428
* @author Alena Prokharchyk
@@ -31,5 +35,33 @@ public interface VpcProvider extends NetworkElement{
3135
*/
3236
boolean startVpc(Vpc vpc, DeployDestination dest, ReservationContext context)
3337
throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException;
38+
39+
/**
40+
* Prepare for a nic to be plugged into the network.
41+
* @param network
42+
* @param nic
43+
* @param vm
44+
* @param context
45+
* @return
46+
* @throws ConcurrentOperationException
47+
* @throws ResourceUnavailableException
48+
* @throws InsufficientNetworkCapacityException
49+
*/
50+
boolean plugNic(Network network, NicProfile nic, VirtualMachineProfile<? extends VirtualMachine> vm,
51+
ReservationContext context) throws ConcurrentOperationException,
52+
ResourceUnavailableException, InsufficientCapacityException;
53+
54+
/**
55+
* A nic is unplugged from this network.
56+
* @param network
57+
* @param nic
58+
* @param vm
59+
* @param context
60+
* @return
61+
* @throws ConcurrentOperationException
62+
* @throws ResourceUnavailableException
63+
*/
64+
boolean unplugNic(Network network, NicProfile nic, VirtualMachineProfile<? extends VirtualMachine> vm,
65+
ReservationContext context) throws ConcurrentOperationException, ResourceUnavailableException;
3466

3567
}

‎api/src/com/cloud/network/vpc/VpcService.java‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,10 @@ List<? extends VpcOffering> listVpcOfferings(Long id, String name, String displa
6363
* @param vpcName
6464
* @param displayText
6565
* @param cidr
66+
* @param networkDomain TODO
6667
* @return
6768
*/
68-
public Vpc createVpc(long zoneId, long vpcOffId, long vpcOwnerId, String vpcName, String displayText, String cidr);
69+
public Vpc createVpc(long zoneId, long vpcOffId, long vpcOwnerId, String vpcName, String displayText, String cidr, String networkDomain);
6970

7071
/**
7172
* @param vpcId

‎api/src/com/cloud/offering/NetworkOffering.java‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ public enum State {
4646
public final static String DefaultSharedNetworkOffering = "DefaultSharedNetworkOffering";
4747
public final static String DefaultIsolatedNetworkOffering = "DefaultIsolatedNetworkOffering";
4848
public final static String DefaultSharedEIPandELBNetworkOffering = "DefaultSharedNetscalerEIPandELBNetworkOffering";
49+
public final static String DefaultIsolatedNetworkOfferingForVpcNetworks = "DefaultIsolatedNetworkOfferingForVpcNetworks";
50+
4951

5052
long getId();
5153

‎api/src/com/cloud/vm/NicProfile.java‎

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -234,13 +234,6 @@ public NicProfile(Nic nic, Network network, URI broadcastUri, URI isolationUri,
234234
}
235235
}
236236

237-
public NicProfile(long id, BroadcastDomainType type, Mode mode, long vmId) {
238-
this.id = id;
239-
this.broadcastType = type;
240-
this.mode = mode;
241-
this.vmId = vmId;
242-
}
243-
244237
public NicProfile(ReservationStrategy strategy, String ip4Address, String macAddress, String gateway, String netmask) {
245238
this.format = AddressFormat.Ip4;
246239
this.ip4Address = ip4Address;

0 commit comments

Comments
 (0)