diff --git a/api/src/com/cloud/api/ResponseGenerator.java b/api/src/com/cloud/api/ResponseGenerator.java index 002f12c5c1e..9e6ab8e6b3a 100755 --- a/api/src/com/cloud/api/ResponseGenerator.java +++ b/api/src/com/cloud/api/ResponseGenerator.java @@ -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; diff --git a/api/src/com/cloud/api/commands/ListPrivateGatewaysCmd.java b/api/src/com/cloud/api/commands/ListPrivateGatewaysCmd.java index 6b217757fbb..67ff27deee8 100644 --- a/api/src/com/cloud/api/commands/ListPrivateGatewaysCmd.java +++ b/api/src/com/cloud/api/commands/ListPrivateGatewaysCmd.java @@ -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/////////////////// diff --git a/api/src/com/cloud/api/response/PrivateGatewayResponse.java b/api/src/com/cloud/api/response/PrivateGatewayResponse.java index 621442ab711..52f1b0b887a 100644 --- a/api/src/com/cloud/api/response/PrivateGatewayResponse.java +++ b/api/src/com/cloud/api/response/PrivateGatewayResponse.java @@ -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; + } } diff --git a/api/src/com/cloud/network/vpc/VpcGateway.java b/api/src/com/cloud/network/vpc/VpcGateway.java index 1ebaffc6734..cde9a04ae08 100644 --- a/api/src/com/cloud/network/vpc/VpcGateway.java +++ b/api/src/com/cloud/network/vpc/VpcGateway.java @@ -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, diff --git a/client/tomcatconf/commands.properties.in b/client/tomcatconf/commands.properties.in index 58a09d043de..e17c3c98510 100755 --- a/client/tomcatconf/commands.properties.in +++ b/client/tomcatconf/commands.properties.in @@ -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 diff --git a/server/src/com/cloud/api/ApiResponseHelper.java b/server/src/com/cloud/api/ApiResponseHelper.java index 9a1b8e573e7..2f41764b036 100755 --- a/server/src/com/cloud/api/ApiResponseHelper.java +++ b/server/src/com/cloud/api/ApiResponseHelper.java @@ -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; diff --git a/server/src/com/cloud/network/vpc/PrivateGatewayProfile.java b/server/src/com/cloud/network/vpc/PrivateGatewayProfile.java index 0ec3883f4e8..62e7e22eef2 100644 --- a/server/src/com/cloud/network/vpc/PrivateGatewayProfile.java +++ b/server/src/com/cloud/network/vpc/PrivateGatewayProfile.java @@ -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(); + } } diff --git a/server/src/com/cloud/network/vpc/VpcGatewayVO.java b/server/src/com/cloud/network/vpc/VpcGatewayVO.java index 58a283ce773..2178be327ad 100644 --- a/server/src/com/cloud/network/vpc/VpcGatewayVO.java +++ b/server/src/com/cloud/network/vpc/VpcGatewayVO.java @@ -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; + } } diff --git a/server/src/com/cloud/network/vpc/VpcManagerImpl.java b/server/src/com/cloud/network/vpc/VpcManagerImpl.java index 43b1e2a984f..989e1bc9e44 100644 --- a/server/src/com/cloud/network/vpc/VpcManagerImpl.java +++ b/server/src/com/cloud/network/vpc/VpcManagerImpl.java @@ -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 permittedAccounts = new ArrayList(); Filter searchFilter = new Filter(VpcGatewayVO.class, "id", false, cmd.getStartIndex(), cmd.getPageSizeVal()); + Ternary domainIdRecursiveListProject = new Ternary(domainId, isRecursive, null); + _accountMgr.buildACLSearchParameters(caller, null, accountName, null, permittedAccounts, domainIdRecursiveListProject, + listAll, false); + domainId = domainIdRecursiveListProject.first(); + isRecursive = domainIdRecursiveListProject.second(); + ListProjectResourcesCriteria listProjectResourcesCriteria = domainIdRecursiveListProject.third(); + SearchBuilder sb = _vpcGatewayDao.createSearchBuilder(); + _accountMgr.buildACLSearchBuilder(sb, domainId, isRecursive, permittedAccounts, listProjectResourcesCriteria); if (vlan != null) { SearchBuilder 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 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 permittedAccounts = new ArrayList(); diff --git a/setup/db/create-schema.sql b/setup/db/create-schema.sql index ec70a153795..dfa50e5f974 100755 --- a/setup/db/create-schema.sql +++ b/setup/db/create-schema.sql @@ -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;