Skip to content

Commit 1a23217

Browse files
author
Alena Prokharchyk
committed
VPC: implementation for Add/delete/list StaticRoute. Agent implementation is yet to be done
1 parent ce876e2 commit 1a23217

20 files changed

Lines changed: 572 additions & 47 deletions
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// Copyright 2012 Citrix Systems, Inc. Licensed under the
2+
// Apache License, Version 2.0 (the "License"); you may not use this
3+
// file except in compliance with the License. Citrix Systems, Inc.
4+
// reserves all rights not expressly granted by the License.
5+
// You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
6+
// Unless required by applicable law or agreed to in writing, software
7+
// distributed under the License is distributed on an "AS IS" BASIS,
8+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
9+
// See the License for the specific language governing permissions and
10+
// limitations under the License.
11+
//
12+
// Automatically generated by addcopyright.py at 04/03/2012
13+
package com.cloud.agent.api.routing;
14+
15+
import com.cloud.agent.api.Answer;
16+
17+
/**
18+
* @author Alena Prokharchyk
19+
*/
20+
public class SetStaticRouteAnswer extends Answer{
21+
String[] results;
22+
23+
protected SetStaticRouteAnswer() {
24+
}
25+
26+
public SetStaticRouteAnswer(SetStaticRouteCommand cmd, boolean success, String[] results) {
27+
super(cmd, success, null);
28+
assert (cmd.getStaticRoutes().length == results.length) : "Static routes and their results should be the same length";
29+
this.results = results;
30+
}
31+
32+
public String[] getResults() {
33+
return results;
34+
}
35+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// Copyright 2012 Citrix Systems, Inc. Licensed under the
2+
// Apache License, Version 2.0 (the "License"); you may not use this
3+
// file except in compliance with the License. Citrix Systems, Inc.
4+
// reserves all rights not expressly granted by the License.
5+
// You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
6+
// Unless required by applicable law or agreed to in writing, software
7+
// distributed under the License is distributed on an "AS IS" BASIS,
8+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
9+
// See the License for the specific language governing permissions and
10+
// limitations under the License.
11+
//
12+
// Automatically generated by addcopyright.py at 04/03/2012
13+
package com.cloud.agent.api.routing;
14+
15+
import java.util.List;
16+
17+
import com.cloud.network.vpc.StaticRouteProfile;
18+
19+
/**
20+
* @author Alena Prokharchyk
21+
*/
22+
public class SetStaticRouteCommand extends NetworkElementCommand{
23+
StaticRouteProfile[] staticRoutes;
24+
25+
protected SetStaticRouteCommand() {
26+
}
27+
28+
public SetStaticRouteCommand(List<StaticRouteProfile> staticRoutes) {
29+
this.staticRoutes = staticRoutes.toArray(new StaticRouteProfile[staticRoutes.size()]);
30+
}
31+
32+
public StaticRouteProfile[] getStaticRoutes() {
33+
return staticRoutes;
34+
}
35+
}

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import com.cloud.exception.InvalidParameterValueException;
2929
import com.cloud.exception.NetworkRuleConflictException;
3030
import com.cloud.exception.ResourceAllocationException;
31+
import com.cloud.exception.ResourceUnavailableException;
3132
import com.cloud.network.vpc.PrivateGateway;
3233
import com.cloud.network.vpc.StaticRoute;
3334
import com.cloud.user.UserContext;
@@ -91,7 +92,7 @@ public String getEventDescription() {
9192
}
9293

9394
@Override
94-
public void execute() {
95+
public void execute() throws ResourceUnavailableException {
9596
boolean success = false;
9697
StaticRoute route = _entityMgr.findById(StaticRoute.class, getEntityId());
9798
try {

‎api/src/com/cloud/api/response/StaticRouteResponse.java‎

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
* @author Alena Prokharchyk
2222
*/
2323
@SuppressWarnings("unused")
24-
public class StaticRouteResponse extends BaseResponse{
24+
public class StaticRouteResponse extends BaseResponse implements ControlledEntityResponse{
2525
@SerializedName(ApiConstants.ID) @Param(description="the ID of static route")
2626
private IdentityProxy id = new IdentityProxy("static_routes");
2727

@@ -36,6 +36,24 @@ public class StaticRouteResponse extends BaseResponse{
3636

3737
@SerializedName(ApiConstants.CIDR) @Param(description="static route CIDR")
3838
private String cidr;
39+
40+
@SerializedName(ApiConstants.ACCOUNT)
41+
@Param(description = "the account associated with the static route")
42+
private String accountName;
43+
44+
@SerializedName(ApiConstants.PROJECT_ID) @Param(description="the project id of the static route")
45+
private IdentityProxy projectId = new IdentityProxy("projects");
46+
47+
@SerializedName(ApiConstants.PROJECT) @Param(description="the project name of the static route")
48+
private String projectName;
49+
50+
@SerializedName(ApiConstants.DOMAIN_ID)
51+
@Param(description = "the ID of the domain associated with the static route")
52+
private IdentityProxy domainId = new IdentityProxy("domain");
53+
54+
@SerializedName(ApiConstants.DOMAIN)
55+
@Param(description = "the domain associated with the static route")
56+
private String domainName;
3957

4058
public void setId(Long id) {
4159
this.id.setValue(id);
@@ -56,4 +74,29 @@ public void setGatewayId(Long gatewayId) {
5674
public void setCidr(String cidr) {
5775
this.cidr = cidr;
5876
}
77+
78+
@Override
79+
public void setAccountName(String accountName) {
80+
this.accountName = accountName;
81+
}
82+
83+
@Override
84+
public void setDomainId(Long domainId) {
85+
this.domainId.setValue(domainId);
86+
}
87+
88+
@Override
89+
public void setDomainName(String domainName) {
90+
this.domainName = domainName;
91+
}
92+
93+
@Override
94+
public void setProjectId(Long projectId) {
95+
this.projectId.setValue(projectId);
96+
}
97+
98+
@Override
99+
public void setProjectName(String projectName) {
100+
this.projectName = projectName;
101+
}
59102
}

‎api/src/com/cloud/api/response/VolumeResponse.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -292,5 +292,5 @@ public void setProjectId(Long projectId) {
292292
@Override
293293
public void setProjectName(String projectName) {
294294
this.projectName = projectName;
295-
}
295+
}
296296
}

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
// Automatically generated by addcopyright.py at 04/03/2012
1313
package com.cloud.network.element;
1414

15+
1516
import java.util.List;
1617

1718
import com.cloud.deploy.DeployDestination;
@@ -20,7 +21,7 @@
2021
import com.cloud.exception.InsufficientNetworkCapacityException;
2122
import com.cloud.exception.ResourceUnavailableException;
2223
import com.cloud.network.vpc.PrivateGateway;
23-
import com.cloud.network.vpc.StaticRoute;
24+
import com.cloud.network.vpc.StaticRouteProfile;
2425
import com.cloud.network.vpc.Vpc;
2526
import com.cloud.vm.ReservationContext;
2627

@@ -48,5 +49,5 @@ boolean implementVpc(Vpc vpc, DeployDestination dest, ReservationContext context
4849

4950
boolean deletePrivateGateway(PrivateGateway privateGateway) throws ConcurrentOperationException, ResourceUnavailableException;
5051

51-
boolean applyStaticRoutes(Vpc vpc, List<? extends StaticRoute> routes) throws ResourceUnavailableException;
52+
boolean applyStaticRoutes(Vpc vpc, List<StaticRouteProfile> routes) throws ResourceUnavailableException;
5253
}
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
// Copyright 2012 Citrix Systems, Inc. Licensed under the
2+
// Apache License, Version 2.0 (the "License"); you may not use this
3+
// file except in compliance with the License. Citrix Systems, Inc.
4+
// reserves all rights not expressly granted by the License.
5+
// You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
6+
// Unless required by applicable law or agreed to in writing, software
7+
// distributed under the License is distributed on an "AS IS" BASIS,
8+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
9+
// See the License for the specific language governing permissions and
10+
// limitations under the License.
11+
//
12+
// Automatically generated by addcopyright.py at 04/03/2012
13+
package com.cloud.network.vpc;
14+
15+
/**
16+
* @author Alena Prokharchyk
17+
*/
18+
public class StaticRouteProfile implements StaticRoute{
19+
private long id;
20+
private String cidr;
21+
private long accountId;
22+
private long domainId;
23+
private long gatewayId;
24+
private StaticRoute.State state;
25+
private long vpcId;
26+
String vlanTag;
27+
String gateway;
28+
String netmask;
29+
String ipAddress;
30+
31+
32+
public StaticRouteProfile(StaticRoute staticRoute, PrivateGateway gateway) {
33+
this.id = staticRoute.getId();
34+
this.cidr = staticRoute.getCidr();
35+
this.accountId = staticRoute.getAccountId();
36+
this.domainId = staticRoute.getDomainId();
37+
this.gatewayId = staticRoute.getVpcGatewayId();
38+
this.state = staticRoute.getState();
39+
this.vpcId = staticRoute.getVpcId();
40+
this.vlanTag = gateway.getVlanTag();
41+
this.gateway = gateway.getGateway();
42+
this.netmask = gateway.getNetmask();
43+
this.ipAddress = gateway.getIp4Address();
44+
}
45+
46+
@Override
47+
public long getAccountId() {
48+
return accountId;
49+
}
50+
51+
@Override
52+
public long getDomainId() {
53+
return domainId;
54+
}
55+
56+
@Override
57+
public long getVpcGatewayId() {
58+
return gatewayId;
59+
}
60+
61+
@Override
62+
public String getCidr() {
63+
return cidr;
64+
}
65+
66+
@Override
67+
public State getState() {
68+
return state;
69+
}
70+
71+
@Override
72+
public Long getVpcId() {
73+
return vpcId;
74+
}
75+
76+
@Override
77+
public long getId() {
78+
return id;
79+
}
80+
81+
public String getVlanTag() {
82+
return vlanTag;
83+
}
84+
85+
public String getIp4Address() {
86+
return ipAddress;
87+
}
88+
89+
public String getGateway() {
90+
return gateway;
91+
}
92+
93+
public String getNetmask() {
94+
return netmask;
95+
}
96+
97+
}

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -189,14 +189,16 @@ public PrivateGateway createVpcPrivateGateway(long vpcId, Long physicalNetworkId
189189
/**
190190
* @param vpcId
191191
* @return
192+
* @throws ResourceUnavailableException
192193
*/
193-
public boolean applyStaticRoutes(long vpcId);
194+
public boolean applyStaticRoutes(long vpcId) throws ResourceUnavailableException;
194195

195196
/**
196197
* @param routeId
197198
* @return TODO
199+
* @throws ResourceUnavailableException
198200
*/
199-
public boolean revokeStaticRoute(long routeId);
201+
public boolean revokeStaticRoute(long routeId) throws ResourceUnavailableException;
200202

201203
/**
202204
* @param gatewayId

‎core/src/com/cloud/hypervisor/xen/resource/CitrixResourceBase.java‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,8 @@
156156
import com.cloud.agent.api.routing.SetSourceNatCommand;
157157
import com.cloud.agent.api.routing.SetStaticNatRulesAnswer;
158158
import com.cloud.agent.api.routing.SetStaticNatRulesCommand;
159+
import com.cloud.agent.api.routing.SetStaticRouteAnswer;
160+
import com.cloud.agent.api.routing.SetStaticRouteCommand;
159161
import com.cloud.agent.api.routing.VmDataCommand;
160162
import com.cloud.agent.api.routing.VpnUsersCfgCommand;
161163
import com.cloud.agent.api.storage.CopyVolumeAnswer;
@@ -542,12 +544,13 @@ public Answer executeRequest(Command cmd) {
542544
return execute((SetNetworkACLCommand) cmd);
543545
} else if (clazz == SetPortForwardingRulesVpcCommand.class) {
544546
return execute((SetPortForwardingRulesVpcCommand) cmd);
547+
} else if (clazz == SetStaticRouteCommand.class) {
548+
return execute((SetStaticRouteCommand) cmd);
545549
} else {
546550
return Answer.createUnsupportedCommandAnswer(cmd);
547551
}
548552
}
549553

550-
551554
protected XsLocalNetwork getNativeNetworkForTraffic(Connection conn, TrafficType type, String name) throws XenAPIException, XmlRpcException {
552555
if (name != null) {
553556
if (s_logger.isDebugEnabled()) {
@@ -7125,4 +7128,10 @@ protected SetPortForwardingRulesAnswer execute(SetPortForwardingRulesVpcCommand
71257128
//TODO - add implementation
71267129
return null;
71277130
}
7131+
7132+
7133+
private SetStaticRouteAnswer execute(SetStaticRouteCommand cmd) {
7134+
// TODO Auto-generated method stub
7135+
return null;
7136+
}
71287137
}

‎server/src/com/cloud/api/ApiResponseHelper.java‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3563,6 +3563,8 @@ public StaticRouteResponse createStaticRouteResponse(StaticRoute result) {
35633563
stateToSet = "Deleting";
35643564
}
35653565
response.setState(stateToSet);
3566+
populateAccount(response, result.getAccountId());
3567+
populateDomain(response, result.getDomainId());
35663568
response.setObjectName("staticroute");
35673569

35683570
return response;

0 commit comments

Comments
 (0)