mirror of
https://github.com/apache/cloudstack.git
synced 2025-11-02 20:02:29 +01:00
VPC: listPrivateGateways API implementation
This commit is contained in:
parent
11de5d4fbe
commit
dc04e0b2e5
89
api/src/com/cloud/api/commands/ListPrivateGatewaysCmd.java
Normal file
89
api/src/com/cloud/api/commands/ListPrivateGatewaysCmd.java
Normal file
@ -0,0 +1,89 @@
|
||||
// Copyright 2012 Citrix Systems, Inc. Licensed under the
|
||||
// Apache License, Version 2.0 (the "License"); you may not use this
|
||||
// file except in compliance with the License. Citrix Systems, Inc.
|
||||
// reserves all rights not expressly granted by the License.
|
||||
// You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
// Automatically generated by addcopyright.py at 04/03/2012
|
||||
package com.cloud.api.commands;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import com.cloud.api.ApiConstants;
|
||||
import com.cloud.api.BaseListCmd;
|
||||
import com.cloud.api.IdentityMapper;
|
||||
import com.cloud.api.Parameter;
|
||||
import com.cloud.api.response.ListResponse;
|
||||
import com.cloud.api.response.PrivateGatewayResponse;
|
||||
import com.cloud.network.vpc.PrivateGateway;
|
||||
|
||||
/**
|
||||
* @author Alena Prokharchyk
|
||||
*/
|
||||
public class ListPrivateGatewaysCmd extends BaseListCmd{
|
||||
public static final Logger s_logger = Logger.getLogger(ListPrivateGatewaysCmd.class.getName());
|
||||
|
||||
private static final String s_name = "listprivategatewaysresponse";
|
||||
|
||||
/////////////////////////////////////////////////////
|
||||
//////////////// API parameters /////////////////////
|
||||
/////////////////////////////////////////////////////
|
||||
|
||||
@Parameter(name=ApiConstants.IP_ADDRESS, type=CommandType.STRING, description="list gateways by ip address")
|
||||
private String ipAddress;
|
||||
|
||||
@Parameter(name=ApiConstants.VLAN, type=CommandType.STRING, description="list gateways by vlan")
|
||||
private String vlan;
|
||||
|
||||
@IdentityMapper(entityTableName="vpc")
|
||||
@Parameter(name=ApiConstants.VPC_ID, type=CommandType.LONG, description="list gateways by vpc")
|
||||
private Long vpcId;
|
||||
|
||||
/////////////////////////////////////////////////////
|
||||
/////////////////// Accessors ///////////////////////
|
||||
/////////////////////////////////////////////////////
|
||||
|
||||
|
||||
public String getVlan() {
|
||||
return vlan;
|
||||
}
|
||||
|
||||
public String getIpAddress() {
|
||||
return ipAddress;
|
||||
}
|
||||
|
||||
public Long getVpcId() {
|
||||
return vpcId;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////
|
||||
/////////////// API Implementation///////////////////
|
||||
/////////////////////////////////////////////////////
|
||||
@Override
|
||||
public String getCommandName() {
|
||||
return s_name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute() {
|
||||
List<PrivateGateway> gateways = _vpcService.listPrivateGateway(this);
|
||||
ListResponse<PrivateGatewayResponse> response = new ListResponse<PrivateGatewayResponse>();
|
||||
List<PrivateGatewayResponse> projectResponses = new ArrayList<PrivateGatewayResponse>();
|
||||
for (PrivateGateway gateway : gateways) {
|
||||
PrivateGatewayResponse gatewayResponse = _responseGenerator.createPrivateGatewayResponseResponse(gateway);
|
||||
projectResponses.add(gatewayResponse);
|
||||
}
|
||||
response.setResponses(projectResponses);
|
||||
response.setResponseName(getCommandName());
|
||||
|
||||
this.setResponseObject(response);
|
||||
}
|
||||
}
|
||||
@ -16,6 +16,7 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import com.cloud.api.commands.ListPrivateGatewaysCmd;
|
||||
import com.cloud.exception.ConcurrentOperationException;
|
||||
import com.cloud.exception.InsufficientCapacityException;
|
||||
import com.cloud.exception.ResourceAllocationException;
|
||||
@ -171,4 +172,10 @@ public interface VpcService {
|
||||
*/
|
||||
boolean deleteVpcPrivateGateway(Long gatewayId) throws ConcurrentOperationException, ResourceUnavailableException;
|
||||
|
||||
/**
|
||||
* @param listPrivateGatewaysCmd
|
||||
* @return
|
||||
*/
|
||||
public List<PrivateGateway> listPrivateGateway(ListPrivateGatewaysCmd listPrivateGatewaysCmd);
|
||||
|
||||
}
|
||||
|
||||
@ -353,7 +353,7 @@ listVPCOfferings=com.cloud.api.commands.ListVPCOfferingsCmd;15
|
||||
|
||||
#### Private gateway commands
|
||||
createPrivateGateway=com.cloud.api.commands.CreatePrivateGatewayCmd;1
|
||||
#listPrivateGateways=com.cloud.api.commands.ListPrivateGatewaysCmd;1
|
||||
listPrivateGateways=com.cloud.api.commands.ListPrivateGatewaysCmd;1
|
||||
deletePrivateGateway=com.cloud.api.commands.DeletePrivateGatewayCmd;1
|
||||
|
||||
####
|
||||
|
||||
@ -24,6 +24,7 @@ import javax.naming.ConfigurationException;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import com.cloud.api.commands.ListPrivateGatewaysCmd;
|
||||
import com.cloud.configuration.ConfigurationManager;
|
||||
import com.cloud.configuration.dao.ConfigurationDao;
|
||||
import com.cloud.dc.DataCenter;
|
||||
@ -43,6 +44,8 @@ import com.cloud.network.Network.GuestType;
|
||||
import com.cloud.network.Network.Provider;
|
||||
import com.cloud.network.Network.Service;
|
||||
import com.cloud.network.NetworkManager;
|
||||
import com.cloud.network.NetworkVO;
|
||||
import com.cloud.network.Networks.BroadcastDomainType;
|
||||
import com.cloud.network.Networks.TrafficType;
|
||||
import com.cloud.network.PhysicalNetwork;
|
||||
import com.cloud.network.dao.IPAddressDao;
|
||||
@ -66,8 +69,10 @@ import com.cloud.utils.component.Inject;
|
||||
import com.cloud.utils.component.Manager;
|
||||
import com.cloud.utils.db.DB;
|
||||
import com.cloud.utils.db.Filter;
|
||||
import com.cloud.utils.db.JoinBuilder;
|
||||
import com.cloud.utils.db.SearchBuilder;
|
||||
import com.cloud.utils.db.SearchCriteria;
|
||||
import com.cloud.utils.db.SearchCriteria.Op;
|
||||
import com.cloud.utils.db.Transaction;
|
||||
import com.cloud.utils.net.NetUtils;
|
||||
import com.cloud.vm.DomainRouterVO;
|
||||
@ -930,6 +935,10 @@ public class VpcManagerImpl implements VpcManager, Manager{
|
||||
if (gateway == null || gateway.getType() != VpcGateway.Type.Private) {
|
||||
return null;
|
||||
}
|
||||
return getPrivateGatewayProfile(gateway);
|
||||
}
|
||||
|
||||
protected PrivateGateway getPrivateGatewayProfile(VpcGateway gateway) {
|
||||
Network network = _ntwkMgr.getNetwork(gateway.getNetworkId());
|
||||
String vlanTag = network.getBroadcastUri().getHost();
|
||||
String netmask = NetUtils.getCidrNetmask(network.getCidr());
|
||||
@ -1050,4 +1059,43 @@ public class VpcManagerImpl implements VpcManager, Manager{
|
||||
txn.commit();
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<PrivateGateway> listPrivateGateway(ListPrivateGatewaysCmd cmd) {
|
||||
String ipAddress = cmd.getIpAddress();
|
||||
String vlan = cmd.getVlan();
|
||||
Long vpcId = cmd.getVpcId();
|
||||
|
||||
Filter searchFilter = new Filter(VpcGatewayVO.class, "id", false, cmd.getStartIndex(), cmd.getPageSizeVal());
|
||||
SearchBuilder<VpcGatewayVO> sb = _vpcGatewayDao.createSearchBuilder();
|
||||
|
||||
if (vlan != null) {
|
||||
SearchBuilder<NetworkVO> ntwkSearch = _ntwkDao.createSearchBuilder();
|
||||
ntwkSearch.and("vlan", ntwkSearch.entity().getBroadcastUri(), SearchCriteria.Op.EQ);
|
||||
sb.join("networkSearch", ntwkSearch, sb.entity().getNetworkId(), ntwkSearch.entity().getId(), JoinBuilder.JoinType.INNER);
|
||||
}
|
||||
|
||||
|
||||
SearchCriteria<VpcGatewayVO> sc = sb.create();
|
||||
|
||||
if (ipAddress != null) {
|
||||
sc.addAnd("ip4Address", Op.EQ, ipAddress);
|
||||
}
|
||||
|
||||
if (vpcId != null) {
|
||||
sc.addAnd("vpcId", Op.EQ, vpcId);
|
||||
}
|
||||
|
||||
if (vlan != null) {
|
||||
sc.setJoinParameters("networkSearch", "vlan", BroadcastDomainType.Vlan.toUri(vlan));
|
||||
}
|
||||
|
||||
List<VpcGatewayVO> vos = _vpcGatewayDao.search(sc, searchFilter);
|
||||
List<PrivateGateway> privateGtws = new ArrayList<PrivateGateway>(vos.size());
|
||||
for (VpcGateway vo : vos) {
|
||||
privateGtws.add(getPrivateGatewayProfile(vo));
|
||||
}
|
||||
|
||||
return privateGtws;
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user