Skip to content

Commit dc04e0b

Browse files
author
Alena Prokharchyk
committed
VPC: listPrivateGateways API implementation
1 parent 11de5d4 commit dc04e0b

4 files changed

Lines changed: 145 additions & 1 deletion

File tree

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
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 java.util.ArrayList;
16+
import java.util.List;
17+
18+
import org.apache.log4j.Logger;
19+
20+
import com.cloud.api.ApiConstants;
21+
import com.cloud.api.BaseListCmd;
22+
import com.cloud.api.IdentityMapper;
23+
import com.cloud.api.Parameter;
24+
import com.cloud.api.response.ListResponse;
25+
import com.cloud.api.response.PrivateGatewayResponse;
26+
import com.cloud.network.vpc.PrivateGateway;
27+
28+
/**
29+
* @author Alena Prokharchyk
30+
*/
31+
public class ListPrivateGatewaysCmd extends BaseListCmd{
32+
public static final Logger s_logger = Logger.getLogger(ListPrivateGatewaysCmd.class.getName());
33+
34+
private static final String s_name = "listprivategatewaysresponse";
35+
36+
/////////////////////////////////////////////////////
37+
//////////////// API parameters /////////////////////
38+
/////////////////////////////////////////////////////
39+
40+
@Parameter(name=ApiConstants.IP_ADDRESS, type=CommandType.STRING, description="list gateways by ip address")
41+
private String ipAddress;
42+
43+
@Parameter(name=ApiConstants.VLAN, type=CommandType.STRING, description="list gateways by vlan")
44+
private String vlan;
45+
46+
@IdentityMapper(entityTableName="vpc")
47+
@Parameter(name=ApiConstants.VPC_ID, type=CommandType.LONG, description="list gateways by vpc")
48+
private Long vpcId;
49+
50+
/////////////////////////////////////////////////////
51+
/////////////////// Accessors ///////////////////////
52+
/////////////////////////////////////////////////////
53+
54+
55+
public String getVlan() {
56+
return vlan;
57+
}
58+
59+
public String getIpAddress() {
60+
return ipAddress;
61+
}
62+
63+
public Long getVpcId() {
64+
return vpcId;
65+
}
66+
67+
/////////////////////////////////////////////////////
68+
/////////////// API Implementation///////////////////
69+
/////////////////////////////////////////////////////
70+
@Override
71+
public String getCommandName() {
72+
return s_name;
73+
}
74+
75+
@Override
76+
public void execute() {
77+
List<PrivateGateway> gateways = _vpcService.listPrivateGateway(this);
78+
ListResponse<PrivateGatewayResponse> response = new ListResponse<PrivateGatewayResponse>();
79+
List<PrivateGatewayResponse> projectResponses = new ArrayList<PrivateGatewayResponse>();
80+
for (PrivateGateway gateway : gateways) {
81+
PrivateGatewayResponse gatewayResponse = _responseGenerator.createPrivateGatewayResponseResponse(gateway);
82+
projectResponses.add(gatewayResponse);
83+
}
84+
response.setResponses(projectResponses);
85+
response.setResponseName(getCommandName());
86+
87+
this.setResponseObject(response);
88+
}
89+
}

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import java.util.Map;
1717
import java.util.Set;
1818

19+
import com.cloud.api.commands.ListPrivateGatewaysCmd;
1920
import com.cloud.exception.ConcurrentOperationException;
2021
import com.cloud.exception.InsufficientCapacityException;
2122
import com.cloud.exception.ResourceAllocationException;
@@ -171,4 +172,10 @@ public PrivateGateway createVpcPrivateGateway(long vpcId, Long physicalNetworkId
171172
*/
172173
boolean deleteVpcPrivateGateway(Long gatewayId) throws ConcurrentOperationException, ResourceUnavailableException;
173174

175+
/**
176+
* @param listPrivateGatewaysCmd
177+
* @return
178+
*/
179+
public List<PrivateGateway> listPrivateGateway(ListPrivateGatewaysCmd listPrivateGatewaysCmd);
180+
174181
}

‎client/tomcatconf/commands.properties.in‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,7 @@ listVPCOfferings=com.cloud.api.commands.ListVPCOfferingsCmd;15
353353

354354
#### Private gateway commands
355355
createPrivateGateway=com.cloud.api.commands.CreatePrivateGatewayCmd;1
356-
#listPrivateGateways=com.cloud.api.commands.ListPrivateGatewaysCmd;1
356+
listPrivateGateways=com.cloud.api.commands.ListPrivateGatewaysCmd;1
357357
deletePrivateGateway=com.cloud.api.commands.DeletePrivateGatewayCmd;1
358358

359359
####

‎server/src/com/cloud/network/vpc/VpcManagerImpl.java‎

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424

2525
import org.apache.log4j.Logger;
2626

27+
import com.cloud.api.commands.ListPrivateGatewaysCmd;
2728
import com.cloud.configuration.ConfigurationManager;
2829
import com.cloud.configuration.dao.ConfigurationDao;
2930
import com.cloud.dc.DataCenter;
@@ -43,6 +44,8 @@
4344
import com.cloud.network.Network.Provider;
4445
import com.cloud.network.Network.Service;
4546
import com.cloud.network.NetworkManager;
47+
import com.cloud.network.NetworkVO;
48+
import com.cloud.network.Networks.BroadcastDomainType;
4649
import com.cloud.network.Networks.TrafficType;
4750
import com.cloud.network.PhysicalNetwork;
4851
import com.cloud.network.dao.IPAddressDao;
@@ -66,8 +69,10 @@
6669
import com.cloud.utils.component.Manager;
6770
import com.cloud.utils.db.DB;
6871
import com.cloud.utils.db.Filter;
72+
import com.cloud.utils.db.JoinBuilder;
6973
import com.cloud.utils.db.SearchBuilder;
7074
import com.cloud.utils.db.SearchCriteria;
75+
import com.cloud.utils.db.SearchCriteria.Op;
7176
import com.cloud.utils.db.Transaction;
7277
import com.cloud.utils.net.NetUtils;
7378
import com.cloud.vm.DomainRouterVO;
@@ -930,6 +935,10 @@ public PrivateGateway getVpcPrivateGateway(long id) {
930935
if (gateway == null || gateway.getType() != VpcGateway.Type.Private) {
931936
return null;
932937
}
938+
return getPrivateGatewayProfile(gateway);
939+
}
940+
941+
protected PrivateGateway getPrivateGatewayProfile(VpcGateway gateway) {
933942
Network network = _ntwkMgr.getNetwork(gateway.getNetworkId());
934943
String vlanTag = network.getBroadcastUri().getHost();
935944
String netmask = NetUtils.getCidrNetmask(network.getCidr());
@@ -1050,4 +1059,43 @@ public boolean deletePrivateGateway(PrivateGateway gateway) {
10501059
txn.commit();
10511060
return true;
10521061
}
1062+
1063+
@Override
1064+
public List<PrivateGateway> listPrivateGateway(ListPrivateGatewaysCmd cmd) {
1065+
String ipAddress = cmd.getIpAddress();
1066+
String vlan = cmd.getVlan();
1067+
Long vpcId = cmd.getVpcId();
1068+
1069+
Filter searchFilter = new Filter(VpcGatewayVO.class, "id", false, cmd.getStartIndex(), cmd.getPageSizeVal());
1070+
SearchBuilder<VpcGatewayVO> sb = _vpcGatewayDao.createSearchBuilder();
1071+
1072+
if (vlan != null) {
1073+
SearchBuilder<NetworkVO> ntwkSearch = _ntwkDao.createSearchBuilder();
1074+
ntwkSearch.and("vlan", ntwkSearch.entity().getBroadcastUri(), SearchCriteria.Op.EQ);
1075+
sb.join("networkSearch", ntwkSearch, sb.entity().getNetworkId(), ntwkSearch.entity().getId(), JoinBuilder.JoinType.INNER);
1076+
}
1077+
1078+
1079+
SearchCriteria<VpcGatewayVO> sc = sb.create();
1080+
1081+
if (ipAddress != null) {
1082+
sc.addAnd("ip4Address", Op.EQ, ipAddress);
1083+
}
1084+
1085+
if (vpcId != null) {
1086+
sc.addAnd("vpcId", Op.EQ, vpcId);
1087+
}
1088+
1089+
if (vlan != null) {
1090+
sc.setJoinParameters("networkSearch", "vlan", BroadcastDomainType.Vlan.toUri(vlan));
1091+
}
1092+
1093+
List<VpcGatewayVO> vos = _vpcGatewayDao.search(sc, searchFilter);
1094+
List<PrivateGateway> privateGtws = new ArrayList<PrivateGateway>(vos.size());
1095+
for (VpcGateway vo : vos) {
1096+
privateGtws.add(getPrivateGatewayProfile(vo));
1097+
}
1098+
1099+
return privateGtws;
1100+
}
10531101
}

0 commit comments

Comments
 (0)