VPC: listPrivateGateways command is available for regular user too (he needs to know the gatewayId for the static route creation)

Conflicts:

	api/src/com/cloud/api/ResponseGenerator.java
	server/src/com/cloud/api/ApiResponseHelper.java
This commit is contained in:
Alena Prokharchyk 2012-06-29 15:16:52 -07:00
parent 1ee0c30935
commit b565f63e42
10 changed files with 121 additions and 11 deletions

View File

@ -23,7 +23,6 @@ import java.util.List;
import com.cloud.api.ApiConstants.HostDetails;
import com.cloud.api.ApiConstants.VMDetails;
import com.cloud.api.commands.QueryAsyncJobResultCmd;
import com.cloud.api.response.NetworkACLResponse;
import com.cloud.api.response.AccountResponse;
import com.cloud.api.response.AsyncJobResponse;
import com.cloud.api.response.CapacityResponse;
@ -46,6 +45,7 @@ import com.cloud.api.response.LBStickinessResponse;
import com.cloud.api.response.LDAPConfigResponse;
import com.cloud.api.response.ListResponse;
import com.cloud.api.response.LoadBalancerResponse;
import com.cloud.api.response.NetworkACLResponse;
import com.cloud.api.response.NetworkOfferingResponse;
import com.cloud.api.response.NetworkResponse;
import com.cloud.api.response.PhysicalNetworkResponse;
@ -120,10 +120,10 @@ import com.cloud.network.rules.StickinessPolicy;
import com.cloud.network.security.SecurityGroup;
import com.cloud.network.security.SecurityGroupRules;
import com.cloud.network.security.SecurityRule;
import com.cloud.network.vpc.PrivateGateway;
import com.cloud.network.vpc.StaticRoute;
import com.cloud.network.vpc.Vpc;
import com.cloud.network.vpc.VpcOffering;
import com.cloud.network.vpc.PrivateGateway;
import com.cloud.offering.DiskOffering;
import com.cloud.offering.NetworkOffering;
import com.cloud.offering.ServiceOffering;

View File

@ -18,7 +18,8 @@ import java.util.List;
import org.apache.log4j.Logger;
import com.cloud.api.ApiConstants;
import com.cloud.api.BaseListCmd;
import com.cloud.api.BaseCmd.CommandType;
import com.cloud.api.BaseListProjectAndAccountResourcesCmd;
import com.cloud.api.IdentityMapper;
import com.cloud.api.Implementation;
import com.cloud.api.Parameter;
@ -30,7 +31,7 @@ import com.cloud.network.vpc.PrivateGateway;
* @author Alena Prokharchyk
*/
@Implementation(description="List private gateways", responseObject=PrivateGatewayResponse.class)
public class ListPrivateGatewaysCmd extends BaseListCmd{
public class ListPrivateGatewaysCmd extends BaseListProjectAndAccountResourcesCmd{
public static final Logger s_logger = Logger.getLogger(ListPrivateGatewaysCmd.class.getName());
private static final String s_name = "listprivategatewaysresponse";
@ -38,6 +39,9 @@ public class ListPrivateGatewaysCmd extends BaseListCmd{
/////////////////////////////////////////////////////
//////////////// API parameters /////////////////////
/////////////////////////////////////////////////////
@IdentityMapper(entityTableName="static_routes")
@Parameter(name=ApiConstants.ID, type=CommandType.LONG, description="list private gateway by id")
private Long id;
@Parameter(name=ApiConstants.IP_ADDRESS, type=CommandType.STRING, description="list gateways by ip address")
private String ipAddress;
@ -65,6 +69,10 @@ public class ListPrivateGatewaysCmd extends BaseListCmd{
public Long getVpcId() {
return vpcId;
}
public Long getId() {
return id;
}
/////////////////////////////////////////////////////
/////////////// API Implementation///////////////////

View File

@ -21,7 +21,7 @@ import com.cloud.utils.IdentityProxy;
import com.google.gson.annotations.SerializedName;
@SuppressWarnings("unused")
public class PrivateGatewayResponse extends BaseResponse{
public class PrivateGatewayResponse extends BaseResponse implements ControlledEntityResponse{
@SerializedName(ApiConstants.ID) @Param(description="the id of the private gateway")
private IdentityProxy id = new IdentityProxy("vpc_gateways");
@ -50,6 +50,24 @@ public class PrivateGatewayResponse extends BaseResponse{
@SerializedName(ApiConstants.PHYSICAL_NETWORK_ID) @Param(description="the physical network id")
private IdentityProxy physicalNetworkId = new IdentityProxy("physical_network");
@SerializedName(ApiConstants.ACCOUNT)
@Param(description = "the account associated with the private gateway")
private String accountName;
@SerializedName(ApiConstants.PROJECT_ID) @Param(description="the project id of the private gateway")
private IdentityProxy projectId = new IdentityProxy("projects");
@SerializedName(ApiConstants.PROJECT) @Param(description="the project name of the private gateway")
private String projectName;
@SerializedName(ApiConstants.DOMAIN_ID)
@Param(description = "the ID of the domain associated with the private gateway")
private IdentityProxy domainId = new IdentityProxy("domain");
@SerializedName(ApiConstants.DOMAIN)
@Param(description = "the domain associated with the private gateway")
private String domainName;
public void setId(Long id) {
this.id.setValue(id);
@ -86,5 +104,30 @@ public class PrivateGatewayResponse extends BaseResponse{
public void setPhysicalNetworkId(Long physicalNetworkId) {
this.physicalNetworkId.setValue(physicalNetworkId);
}
@Override
public void setAccountName(String accountName) {
this.accountName = accountName;
}
@Override
public void setDomainId(Long domainId) {
this.domainId.setValue(domainId);
}
@Override
public void setDomainName(String domainName) {
this.domainName = domainName;
}
@Override
public void setProjectId(Long projectId) {
this.projectId.setValue(projectId);
}
@Override
public void setProjectName(String projectName) {
this.projectName = projectName;
}
}

View File

@ -12,12 +12,13 @@
// Automatically generated by addcopyright.py at 04/03/2012
package com.cloud.network.vpc;
import com.cloud.acl.ControlledEntity;
import com.cloud.api.Identity;
/**
* @author Alena Prokharchyk
*/
public interface VpcGateway extends Identity {
public interface VpcGateway extends Identity, ControlledEntity {
public enum Type {
Private,
Public,

View File

@ -354,7 +354,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;15
deletePrivateGateway=com.cloud.api.commands.DeletePrivateGatewayCmd;1
#### Network ACL commands

View File

@ -3587,6 +3587,10 @@ public class ApiResponseHelper implements ResponseGenerator {
response.setZoneName(zone.getName());
response.setAddress(result.getIp4Address());
response.setPhysicalNetworkId(result.getPhysicalNetworkId());
populateAccount(response, result.getAccountId());
populateDomain(response, result.getDomainId());
response.setObjectName("privategateway");
return response;

View File

@ -83,4 +83,14 @@ public class PrivateGatewayProfile implements PrivateGateway{
public long getPhysicalNetworkId() {
return physicalNetworkId;
}
@Override
public long getAccountId() {
return vpcGateway.getAccountId();
}
@Override
public long getDomainId() {
return vpcGateway.getDomainId();
}
}

View File

@ -73,6 +73,12 @@ public class VpcGatewayVO implements VpcGateway{
@Column(name="uuid")
private String uuid;
@Column(name = "account_id")
long accountId;
@Column(name = "domain_id")
long domainId;
protected VpcGatewayVO(){
this.uuid = UUID.randomUUID().toString();
}
@ -86,9 +92,12 @@ public class VpcGatewayVO implements VpcGateway{
* @param vlanTag TODO
* @param gateway TODO
* @param netmask TODO
* @param accountId TODO
* @param domainId TODO
* @param account_id
*/
public VpcGatewayVO(String ip4Address, Type type, Long vpcId, long zoneId, Long networkId, String vlanTag, String gateway, String netmask) {
public VpcGatewayVO(String ip4Address, Type type, Long vpcId, long zoneId, Long networkId, String vlanTag,
String gateway, String netmask, long accountId, long domainId) {
this.ip4Address = ip4Address;
this.type = type;
this.vpcId = vpcId;
@ -98,6 +107,8 @@ public class VpcGatewayVO implements VpcGateway{
this.gateway = gateway;
this.netmask = netmask;
this.uuid = UUID.randomUUID().toString();
this.accountId = accountId;
this.domainId = domainId;
}
@Override
@ -156,4 +167,14 @@ public class VpcGatewayVO implements VpcGateway{
public String getVlanTag() {
return vlanTag;
}
@Override
public long getAccountId() {
return accountId;
}
@Override
public long getDomainId() {
return domainId;
}
}

View File

@ -1057,7 +1057,7 @@ public class VpcManagerImpl implements VpcManager, Manager{
//2) create gateway entry
gatewayVO = new VpcGatewayVO(ipAddress, VpcGateway.Type.Private, vpcId, privateNtwk.getDataCenterId(),
privateNtwk.getId(), vlan, gateway, netmask);
privateNtwk.getId(), vlan, gateway, netmask, vpc.getAccountId(), vpc.getDomainId());
_vpcGatewayDao.persist(gatewayVO);
s_logger.debug("Created vpc gateway entry " + gatewayVO);
@ -1149,9 +1149,25 @@ public class VpcManagerImpl implements VpcManager, Manager{
String ipAddress = cmd.getIpAddress();
String vlan = cmd.getVlan();
Long vpcId = cmd.getVpcId();
Long id = cmd.getId();
Boolean isRecursive = cmd.isRecursive();
Boolean listAll = cmd.listAll();
Long domainId = cmd.getDomainId();
String accountName = cmd.getAccountName();
Account caller = UserContext.current().getCaller();
List<Long> permittedAccounts = new ArrayList<Long>();
Filter searchFilter = new Filter(VpcGatewayVO.class, "id", false, cmd.getStartIndex(), cmd.getPageSizeVal());
Ternary<Long, Boolean, ListProjectResourcesCriteria> domainIdRecursiveListProject = new Ternary<Long, Boolean,
ListProjectResourcesCriteria>(domainId, isRecursive, null);
_accountMgr.buildACLSearchParameters(caller, null, accountName, null, permittedAccounts, domainIdRecursiveListProject,
listAll, false);
domainId = domainIdRecursiveListProject.first();
isRecursive = domainIdRecursiveListProject.second();
ListProjectResourcesCriteria listProjectResourcesCriteria = domainIdRecursiveListProject.third();
SearchBuilder<VpcGatewayVO> sb = _vpcGatewayDao.createSearchBuilder();
_accountMgr.buildACLSearchBuilder(sb, domainId, isRecursive, permittedAccounts, listProjectResourcesCriteria);
if (vlan != null) {
SearchBuilder<NetworkVO> ntwkSearch = _ntwkDao.createSearchBuilder();
@ -1159,8 +1175,12 @@ public class VpcManagerImpl implements VpcManager, Manager{
sb.join("networkSearch", ntwkSearch, sb.entity().getNetworkId(), ntwkSearch.entity().getId(), JoinBuilder.JoinType.INNER);
}
SearchCriteria<VpcGatewayVO> sc = sb.create();
_accountMgr.buildACLSearchCriteria(sc, domainId, isRecursive, permittedAccounts, listProjectResourcesCriteria);
if (id != null) {
sc.addAnd("id", Op.EQ, id);
}
if (ipAddress != null) {
sc.addAnd("ip4Address", Op.EQ, ipAddress);
@ -1334,7 +1354,6 @@ public class VpcManagerImpl implements VpcManager, Manager{
Boolean isRecursive = cmd.isRecursive();
Boolean listAll = cmd.listAll();
String accountName = cmd.getAccountName();
Account caller = UserContext.current().getCaller();
List<Long> permittedAccounts = new ArrayList<Long>();

View File

@ -2258,11 +2258,15 @@ CREATE TABLE `cloud`.`vpc_gateways` (
`vpc_id` bigint unsigned NOT NULL COMMENT 'id of the vpc the gateway belongs to',
`zone_id` bigint unsigned NOT NULL COMMENT 'id of the zone the gateway belongs to',
`created` datetime COMMENT 'date created',
`account_id` bigint unsigned NOT NULL COMMENT 'owner id',
`domain_id` bigint unsigned NOT NULL COMMENT 'domain id',
`removed` datetime COMMENT 'date removed if not null',
PRIMARY KEY (`id`),
CONSTRAINT `fk_vpc_gateways__network_id` FOREIGN KEY `fk_vpc_gateways__network_id`(`network_id`) REFERENCES `networks`(`id`),
CONSTRAINT `fk_vpc_gateways__vpc_id` FOREIGN KEY `fk_vpc_gateways__vpc_id`(`vpc_id`) REFERENCES `vpc`(`id`),
CONSTRAINT `fk_vpc_gateways__zone_id` FOREIGN KEY `fk_vpc_gateways__zone_id`(`zone_id`) REFERENCES `data_center`(`id`),
CONSTRAINT `fk_vpc_gateways__account_id` FOREIGN KEY(`account_id`) REFERENCES `account`(`id`) ON DELETE CASCADE,
CONSTRAINT `fk_vpc_gateways__domain_id` FOREIGN KEY(`domain_id`) REFERENCES `domain`(`id`) ON DELETE CASCADE,
CONSTRAINT `uc_vpc_gateways__uuid` UNIQUE (`uuid`),
INDEX `i_vpc_gateways__removed`(`removed`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;