Skip to content

Commit 030458a

Browse files
author
Alena Prokharchyk
committed
VPC: implemented add/delete Private gateway
Conflicts: client/tomcatconf/commands.properties.in server/src/com/cloud/api/ApiResponseHelper.java server/src/com/cloud/dc/DataCenterVO.java server/src/com/cloud/network/NetworkManagerImpl.java
1 parent 3001109 commit 030458a

39 files changed

Lines changed: 1393 additions & 106 deletions

api/src/com/cloud/agent/api/routing/SetSourceNatCommand.java

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,23 +13,20 @@
1313
package com.cloud.agent.api.routing;
1414

1515
import com.cloud.agent.api.to.IpAddressTO;
16-
import com.cloud.agent.api.to.NicTO;
1716

1817
/**
1918
* @author Alena Prokharchyk
2019
*/
2120
public class SetSourceNatCommand extends NetworkElementCommand{
2221
IpAddressTO ipAddress;
2322
boolean add;
24-
NicTO nic;
25-
23+
2624
protected SetSourceNatCommand() {
2725
}
2826

29-
public SetSourceNatCommand(IpAddressTO ip, boolean add, NicTO nic) {
27+
public SetSourceNatCommand(IpAddressTO ip, boolean add) {
3028
this.ipAddress = ip;
3129
this.add = add;
32-
this.nic = nic;
3330
}
3431

3532
@Override
@@ -41,7 +38,4 @@ public IpAddressTO getIpAddress() {
4138
return ipAddress;
4239
}
4340

44-
public NicTO getNic() {
45-
return nic;
46-
}
4741
}

api/src/com/cloud/agent/api/to/IpAddressTO.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818

1919
import com.cloud.network.Networks.TrafficType;
2020

21-
2221
public class IpAddressTO {
2322

2423
private long accountId;

api/src/com/cloud/api/ResponseGenerator.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
import com.cloud.api.response.NetworkResponse;
5151
import com.cloud.api.response.PhysicalNetworkResponse;
5252
import com.cloud.api.response.PodResponse;
53+
import com.cloud.api.response.PrivateGatewayResponse;
5354
import com.cloud.api.response.ProjectAccountResponse;
5455
import com.cloud.api.response.ProjectInvitationResponse;
5556
import com.cloud.api.response.ProjectResponse;
@@ -113,6 +114,7 @@
113114
import com.cloud.network.security.SecurityRule;
114115
import com.cloud.network.vpc.Vpc;
115116
import com.cloud.network.vpc.VpcOffering;
117+
import com.cloud.network.vpc.PrivateGateway;
116118
import com.cloud.offering.DiskOffering;
117119
import com.cloud.offering.NetworkOffering;
118120
import com.cloud.offering.ServiceOffering;
@@ -304,4 +306,10 @@ public interface ResponseGenerator {
304306
* @return
305307
*/
306308
NetworkACLResponse createNetworkACLResponse(NetworkACL networkACL);
309+
310+
/**
311+
* @param result
312+
* @return
313+
*/
314+
PrivateGatewayResponse createPrivateGatewayResponseResponse(PrivateGateway result);
307315
}
Lines changed: 158 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,158 @@
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.api.commands;
14+
15+
import org.apache.log4j.Logger;
16+
17+
import com.cloud.api.ApiConstants;
18+
import com.cloud.api.BaseAsyncCreateCmd;
19+
import com.cloud.api.BaseCmd;
20+
import com.cloud.api.IdentityMapper;
21+
import com.cloud.api.Implementation;
22+
import com.cloud.api.Parameter;
23+
import com.cloud.api.ServerApiException;
24+
import com.cloud.api.response.PrivateGatewayResponse;
25+
import com.cloud.event.EventTypes;
26+
import com.cloud.exception.ConcurrentOperationException;
27+
import com.cloud.exception.InsufficientCapacityException;
28+
import com.cloud.exception.ResourceAllocationException;
29+
import com.cloud.exception.ResourceUnavailableException;
30+
import com.cloud.network.vpc.PrivateGateway;
31+
import com.cloud.user.Account;
32+
33+
/**
34+
* @author Alena Prokharchyk
35+
*/
36+
@Implementation(description="Creates a private gateway", responseObject=PrivateGatewayResponse.class)
37+
public class CreatePrivateGatewayCmd extends BaseAsyncCreateCmd {
38+
public static final Logger s_logger = Logger.getLogger(CreatePrivateGatewayCmd.class.getName());
39+
40+
private static final String s_name = "createprivategatewayresponse";
41+
42+
/////////////////////////////////////////////////////
43+
//////////////// API parameters /////////////////////
44+
/////////////////////////////////////////////////////
45+
46+
@IdentityMapper(entityTableName="physical_network")
47+
@Parameter(name=ApiConstants.PHYSICAL_NETWORK_ID, type=CommandType.LONG, description="the Physical Network ID the network belongs to")
48+
private Long physicalNetworkId;
49+
50+
@Parameter(name=ApiConstants.GATEWAY, type=CommandType.STRING, required=true, description="the gateway of the Private gateway")
51+
private String gateway;
52+
53+
@Parameter(name=ApiConstants.NETMASK, type=CommandType.STRING, required=true, description="the netmask of the Private gateway")
54+
private String netmask;
55+
56+
@Parameter(name=ApiConstants.IP_ADDRESS, type=CommandType.STRING, required=true, description="the IP address of the Private gateaway")
57+
private String ipAddress;
58+
59+
@Parameter(name=ApiConstants.VLAN, type=CommandType.STRING, required=true, description="the Vlan for the private gateway")
60+
private String vlan;
61+
62+
@IdentityMapper(entityTableName="vpc")
63+
@Parameter(name=ApiConstants.VPC_ID, type=CommandType.LONG, required=true, description="the VPC network belongs to")
64+
private Long vpcId;
65+
66+
/////////////////////////////////////////////////////
67+
/////////////////// Accessors ///////////////////////
68+
/////////////////////////////////////////////////////
69+
70+
public String getGateway() {
71+
return gateway;
72+
}
73+
74+
public String getVlan() {
75+
return vlan;
76+
}
77+
78+
public String getNetmask() {
79+
return netmask;
80+
}
81+
82+
public String getStartIp() {
83+
return ipAddress;
84+
}
85+
86+
public Long getPhysicalNetworkId() {
87+
return physicalNetworkId;
88+
}
89+
90+
public Long getVpcId() {
91+
return vpcId;
92+
}
93+
94+
/////////////////////////////////////////////////////
95+
/////////////// API Implementation///////////////////
96+
/////////////////////////////////////////////////////
97+
@Override
98+
public String getCommandName() {
99+
return s_name;
100+
}
101+
102+
103+
@Override
104+
public void create() throws ResourceAllocationException {
105+
PrivateGateway result = null;
106+
try {
107+
result = _vpcService.createVpcPrivateGateway(getVpcId(), getPhysicalNetworkId(),
108+
getVlan(), getStartIp(), getGateway(), getNetmask(), getEntityOwnerId());
109+
} catch (InsufficientCapacityException ex){
110+
s_logger.info(ex);
111+
s_logger.trace(ex);
112+
throw new ServerApiException(BaseCmd.INSUFFICIENT_CAPACITY_ERROR, ex.getMessage());
113+
} catch (ConcurrentOperationException ex) {
114+
s_logger.warn("Exception: ", ex);
115+
throw new ServerApiException(BaseCmd.INTERNAL_ERROR, ex.getMessage());
116+
}
117+
118+
if (result != null) {
119+
this.setEntityId(result.getId());
120+
} else {
121+
throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to create private gateway");
122+
}
123+
}
124+
125+
@Override
126+
public void execute() throws InsufficientCapacityException, ConcurrentOperationException,
127+
ResourceAllocationException, ResourceUnavailableException {
128+
PrivateGateway result = _vpcService.applyVpcGateway(getEntityId());
129+
if (result != null) {
130+
PrivateGatewayResponse response = _responseGenerator.createPrivateGatewayResponseResponse(result);
131+
response.setResponseName(getCommandName());
132+
this.setResponseObject(response);
133+
} else {
134+
throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to create private gateway");
135+
}
136+
}
137+
138+
@Override
139+
public long getEntityOwnerId() {
140+
return Account.ACCOUNT_ID_SYSTEM;
141+
}
142+
143+
@Override
144+
public String getEventType() {
145+
return EventTypes.EVENT_PRIVATE_GATEWAY_CREATE;
146+
}
147+
148+
@Override
149+
public String getEventDescription() {
150+
return "creating private gateway";
151+
152+
}
153+
154+
@Override
155+
public String getEntityTable() {
156+
return "vpc_gateways";
157+
}
158+
}
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
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.api.commands;
14+
15+
import org.apache.log4j.Logger;
16+
17+
import com.cloud.api.ApiConstants;
18+
import com.cloud.api.BaseAsyncCmd;
19+
import com.cloud.api.BaseCmd;
20+
import com.cloud.api.IdentityMapper;
21+
import com.cloud.api.Implementation;
22+
import com.cloud.api.Parameter;
23+
import com.cloud.api.ServerApiException;
24+
import com.cloud.api.response.SuccessResponse;
25+
import com.cloud.async.AsyncJob;
26+
import com.cloud.event.EventTypes;
27+
import com.cloud.exception.ConcurrentOperationException;
28+
import com.cloud.exception.InvalidParameterValueException;
29+
import com.cloud.exception.ResourceUnavailableException;
30+
import com.cloud.network.vpc.VpcGateway;
31+
import com.cloud.user.Account;
32+
import com.cloud.user.UserContext;
33+
34+
/**
35+
* @author Alena Prokharchyk
36+
*/
37+
@Implementation(description="Deletes a Private gateway", responseObject=SuccessResponse.class)
38+
public class DeletePrivateGatewayCmd extends BaseAsyncCmd {
39+
public static final Logger s_logger = Logger.getLogger(DeletePrivateGatewayCmd.class.getName());
40+
private static final String s_name = "deleteprivategatewayresponse";
41+
42+
/////////////////////////////////////////////////////
43+
//////////////// API parameters /////////////////////
44+
/////////////////////////////////////////////////////
45+
46+
@IdentityMapper(entityTableName="vpc_gateways")
47+
@Parameter(name=ApiConstants.ID, type=CommandType.LONG, required=true, description="the ID of the private gateway")
48+
private Long id;
49+
50+
/////////////////////////////////////////////////////
51+
/////////////////// Accessors ///////////////////////
52+
/////////////////////////////////////////////////////
53+
54+
public Long getId() {
55+
return id;
56+
}
57+
58+
/////////////////////////////////////////////////////
59+
/////////////// API Implementation///////////////////
60+
/////////////////////////////////////////////////////
61+
@Override
62+
public String getCommandName() {
63+
return s_name;
64+
}
65+
66+
@Override
67+
public String getEventType() {
68+
return EventTypes.EVENT_PRIVATE_GATEWAY_DELETE;
69+
}
70+
71+
@Override
72+
public String getEventDescription() {
73+
return ("Deleting private gateway id=" + id);
74+
}
75+
76+
@Override
77+
public long getEntityOwnerId() {
78+
return Account.ACCOUNT_ID_SYSTEM;
79+
}
80+
81+
@Override
82+
public void execute() throws ResourceUnavailableException, ConcurrentOperationException {
83+
UserContext.current().setEventDetails("Network ACL Id: " + id);
84+
boolean result = _vpcService.deleteVpcPrivateGateway(id);
85+
if (result) {
86+
SuccessResponse response = new SuccessResponse(getCommandName());
87+
this.setResponseObject(response);
88+
} else {
89+
throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to delete private gateway");
90+
}
91+
}
92+
93+
94+
@Override
95+
public String getSyncObjType() {
96+
return BaseAsyncCmd.networkSyncObject;
97+
}
98+
99+
@Override
100+
public Long getSyncObjId() {
101+
VpcGateway gateway = _vpcService.getVpcPrivateGateway(getId());
102+
if (gateway == null) {
103+
throw new InvalidParameterValueException("Invalid private gateway id");
104+
}
105+
return gateway.getVpcId();
106+
}
107+
108+
@Override
109+
public AsyncJob.Type getInstanceType() {
110+
return AsyncJob.Type.Vpc;
111+
}
112+
113+
}

0 commit comments

Comments
 (0)