Skip to content

Commit 219978a

Browse files
committed
Create network using physical network id
1 parent 0d7ddb5 commit 219978a

35 files changed

Lines changed: 182 additions & 163 deletions

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

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import com.cloud.api.response.NetworkResponse;
3131
import com.cloud.exception.ConcurrentOperationException;
3232
import com.cloud.exception.InsufficientCapacityException;
33+
import com.cloud.exception.InvalidParameterValueException;
3334
import com.cloud.network.Network;
3435
import com.cloud.user.UserContext;
3536

@@ -52,7 +53,7 @@ public class CreateNetworkCmd extends BaseCmd {
5253
@Parameter(name=ApiConstants.NETWORK_OFFERING_ID, type=CommandType.LONG, required=true, description="the network offering id")
5354
private Long networkOfferingId;
5455

55-
@Parameter(name=ApiConstants.ZONE_ID, type=CommandType.LONG, required=true, description="the Zone ID for the network")
56+
@Parameter(name=ApiConstants.ZONE_ID, type=CommandType.LONG, description="the Zone ID for the network")
5657
private Long zoneId;
5758

5859
@Parameter(name=ApiConstants.GATEWAY, type=CommandType.STRING, description="the gateway of the network")
@@ -90,6 +91,9 @@ public class CreateNetworkCmd extends BaseCmd {
9091

9192
@Parameter(name=ApiConstants.TAGS, type=CommandType.LIST, collectionType=CommandType.STRING, description="Tag the network")
9293
private List<String> tags;
94+
95+
@Parameter(name=ApiConstants.PHYSICAL_NETWORK_ID, type=CommandType.LONG, description="the Physical Network ID the network belongs to")
96+
private Long physicalNetworkId;
9397

9498
/////////////////////////////////////////////////////
9599
/////////////////// Accessors ///////////////////////
@@ -102,10 +106,6 @@ public List<String> getTags() {
102106
return tags;
103107
}
104108

105-
public Long getZoneId() {
106-
return zoneId;
107-
}
108-
109109
public String getGateway() {
110110
return gateway;
111111
}
@@ -158,6 +158,16 @@ public Boolean getIsShared() {
158158
return isShared == null ? false : isShared;
159159
}
160160

161+
public Long getPhysicalNetworkId() {
162+
if (physicalNetworkId != null) {
163+
return physicalNetworkId;
164+
} else if (zoneId != null) {
165+
return _networkService.translateZoneToPhysicalNetwork(zoneId);
166+
} else {
167+
throw new InvalidParameterValueException("Either zoneId or physicalNetworkId have to be specified");
168+
}
169+
}
170+
161171
/////////////////////////////////////////////////////
162172
/////////////// API Implementation///////////////////
163173
/////////////////////////////////////////////////////

api/src/com/cloud/api/commands/ListNetworksCmd.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,9 @@ public class ListNetworksCmd extends BaseListCmd {
6969

7070
@Parameter(name=ApiConstants.PROJECT_ID, type=CommandType.LONG, description="list networks by project id")
7171
private Long projectId;
72+
73+
@Parameter(name=ApiConstants.PHYSICAL_NETWORK_ID, type=CommandType.LONG, description="list networks by physical network id")
74+
private Long physicalNetworkId;
7275

7376
/////////////////////////////////////////////////////
7477
/////////////////// Accessors ///////////////////////
@@ -114,6 +117,10 @@ public Long getProjectId() {
114117
return projectId;
115118
}
116119

120+
public Long getPhysicalNetworkId() {
121+
return physicalNetworkId;
122+
}
123+
117124
/////////////////////////////////////////////////////
118125
/////////////// API Implementation///////////////////
119126
/////////////////////////////////////////////////////

api/src/com/cloud/api/response/NetworkResponse.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,10 @@ public class NetworkResponse extends BaseResponse implements ControlledEntityRes
125125

126126
@SerializedName(ApiConstants.TAGS) @Param(description="comma separated tag")
127127
private String tags;
128+
129+
@SerializedName(ApiConstants.PHYSICAL_NETWORK_ID) @Param(description="the physical network id")
130+
private Long physicalNetworkId;
131+
128132

129133
public void setId(Long id) {
130134
this.id = id;
@@ -268,7 +272,9 @@ public void setProjectId(Long projectId) {
268272
public void setProjectName(String projectName) {
269273
this.projectName = projectName;
270274
}
271-
272-
275+
276+
public void setPhysicalNetworkId(Long physicalNetworkId) {
277+
this.physicalNetworkId = physicalNetworkId;
278+
}
273279

274280
}

api/src/com/cloud/deploy/DataCenterDeployment.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,19 +25,21 @@ public class DataCenterDeployment implements DeploymentPlan {
2525
Long _clusterId;
2626
Long _poolId;
2727
Long _hostId;
28+
Long _physicalNetworkId;
2829
ExcludeList _avoids = null;
2930
boolean _recreateDisks;
3031

3132
public DataCenterDeployment(long dataCenterId) {
32-
this(dataCenterId, null, null, null, null);
33+
this(dataCenterId, null, null, null, null, null);
3334
}
3435

35-
public DataCenterDeployment(long dataCenterId, Long podId, Long clusterId, Long hostId, Long poolId) {
36+
public DataCenterDeployment(long dataCenterId, Long podId, Long clusterId, Long hostId, Long poolId, Long physicalNetworkId) {
3637
_dcId = dataCenterId;
3738
_podId = podId;
3839
_clusterId = clusterId;
3940
_hostId = hostId;
4041
_poolId = poolId;
42+
_physicalNetworkId = physicalNetworkId;
4143
}
4244

4345
@Override
@@ -74,4 +76,9 @@ public ExcludeList getAvoids() {
7476
public void setAvoids(ExcludeList avoids) {
7577
_avoids = avoids;
7678
}
79+
80+
@Override
81+
public Long getPhysicalNetworkId() {
82+
return _physicalNetworkId;
83+
}
7784
}

api/src/com/cloud/deploy/DeploymentPlan.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,4 +63,6 @@ public interface DeploymentPlan {
6363
* the ExcludeList to avoid for deployment
6464
*/
6565
public ExcludeList getAvoids();
66+
67+
Long getPhysicalNetworkId();
6668
}

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
*/
4040
public interface Network extends ControlledEntity {
4141

42+
@Deprecated
4243
public enum GuestIpType {
4344
Virtual,
4445
Direct,
@@ -252,6 +253,7 @@ private State(String description) {
252253

253254
URI getBroadcastUri();
254255

256+
@Deprecated
255257
GuestIpType getGuestType();
256258

257259
String getDisplayText();
@@ -270,5 +272,5 @@ private State(String description) {
270272

271273
boolean getIsShared();
272274

273-
long getPhysicalNetworkId();
275+
Long getPhysicalNetworkId();
274276
}

api/src/com/cloud/network/NetworkProfile.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,10 @@ public class NetworkProfile implements Network {
5050
private boolean isSecurityGroupEnabled;
5151
private List<String> tags;
5252
private Network.Type type;
53+
@Deprecated
5354
private GuestIpType guestIpType;
5455
private boolean isShared;
55-
private long physicalNetworkId;
56+
private Long physicalNetworkId;
5657

5758
public NetworkProfile(Network network) {
5859
this.id = network.getId();
@@ -216,7 +217,7 @@ public boolean getIsShared() {
216217
}
217218

218219
@Override
219-
public long getPhysicalNetworkId() {
220+
public Long getPhysicalNetworkId() {
220221
return physicalNetworkId;
221222
}
222223
}

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,4 +117,6 @@ public interface NetworkService {
117117
PhysicalNetworkServiceProvider getPhysicalNetworkServiceProvider(Long providerId);
118118

119119
PhysicalNetworkServiceProvider getCreatedPhysicalNetworkServiceProvider(Long providerId);
120+
121+
long translateZoneToPhysicalNetwork(long zoneId);
120122
}

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@
1818
package com.cloud.offering;
1919

2020
import com.cloud.network.Network.GuestIpType;
21-
import com.cloud.network.Network.Provider;
22-
import com.cloud.network.Network.Service;
2321
import com.cloud.network.Network.Type;
2422
import com.cloud.network.Networks.TrafficType;
2523

@@ -91,6 +89,7 @@ public enum State {
9189

9290
boolean isSharedSourceNatService();
9391

92+
@Deprecated
9493
GuestIpType getGuestType();
9594

9695
String getUniqueName();

server/src/com/cloud/agent/manager/allocator/impl/RecreateHostAllocator.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ public List<Host> allocateTo(VirtualMachineProfile<? extends VirtualMachine> vm,
130130
}
131131
continue;
132132
}
133-
DataCenterDeployment newPlan = new DataCenterDeployment(plan.getDataCenterId(), p.getPod().getId(), clusterId, null, null);
133+
DataCenterDeployment newPlan = new DataCenterDeployment(plan.getDataCenterId(), p.getPod().getId(), clusterId, null, null, null);
134134
hosts = super.allocateTo(vm, newPlan, type, avoid, returnUpTo);
135135
if (hosts != null && !hosts.isEmpty()) {
136136
return hosts;

0 commit comments

Comments
 (0)