You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by bh...@apache.org on 2012/12/04 11:02:56 UTC
[23/55] [abbrv] git commit: api_refactor: refactor network apis
api_refactor: refactor network apis
- Fix refactored apis in commands*.in
- Fix comments etc.
- Expand tabs, remove trailing whitespace
- Fix trailing whitespaces for all *.java
Signed-off-by: Rohit Yadav <bh...@apache.org>
Project: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/commit/47ae62e4
Tree: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/tree/47ae62e4
Diff: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/diff/47ae62e4
Branch: refs/heads/api_refactoring
Commit: 47ae62e44a5ddf813230eeaa6f92b9fb2dd662d4
Parents: 5e0501d
Author: Rohit Yadav <bh...@apache.org>
Authored: Mon Dec 3 22:47:07 2012 -0800
Committer: Rohit Yadav <bh...@apache.org>
Committed: Mon Dec 3 22:47:07 2012 -0800
----------------------------------------------------------------------
.../cloud/api/commands/CreateNetworkACLCmd.java | 328 ---------------
.../com/cloud/api/commands/CreateNetworkCmd.java | 234 ----------
.../cloud/api/commands/DeleteNetworkACLCmd.java | 121 ------
.../com/cloud/api/commands/DeleteNetworkCmd.java | 108 -----
.../com/cloud/api/commands/ListNetworkACLsCmd.java | 94 ----
.../api/commands/ListNetworkOfferingsCmd.java | 191 ---------
.../com/cloud/api/commands/ListNetworksCmd.java | 164 -------
.../api/commands/ListVirtualRouterElementsCmd.java | 1 +
.../com/cloud/api/commands/RestartNetworkCmd.java | 130 ------
.../com/cloud/api/commands/UpdateNetworkCmd.java | 152 -------
.../cloud/configuration/ConfigurationService.java | 2 +-
api/src/com/cloud/network/NetworkService.java | 6 +-
.../cloud/network/firewall/NetworkACLService.java | 2 +-
.../user/network/command/CreateNetworkACLCmd.java | 328 +++++++++++++++
.../api/user/network/command/CreateNetworkCmd.java | 234 ++++++++++
.../user/network/command/DeleteNetworkACLCmd.java | 121 ++++++
.../api/user/network/command/DeleteNetworkCmd.java | 109 +++++
.../user/network/command/ListNetworkACLsCmd.java | 94 ++++
.../network/command/ListNetworkOfferingsCmd.java | 191 +++++++++
.../api/user/network/command/ListNetworksCmd.java | 164 +++++++
.../user/network/command/RestartNetworkCmd.java | 130 ++++++
.../api/user/network/command/UpdateNetworkCmd.java | 152 +++++++
client/tomcatconf/commands.properties.in | 18 +-
.../configuration/ConfigurationManagerImpl.java | 2 +-
.../src/com/cloud/network/NetworkManagerImpl.java | 6 +-
.../cloud/network/vpc/NetworkACLManagerImpl.java | 2 +-
.../com/cloud/network/MockNetworkManagerImpl.java | 6 +-
.../cloud/vpc/MockConfigurationManagerImpl.java | 2 +-
.../test/com/cloud/vpc/MockNetworkManagerImpl.java | 6 +-
29 files changed, 1550 insertions(+), 1548 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/47ae62e4/api/src/com/cloud/api/commands/CreateNetworkACLCmd.java
----------------------------------------------------------------------
diff --git a/api/src/com/cloud/api/commands/CreateNetworkACLCmd.java b/api/src/com/cloud/api/commands/CreateNetworkACLCmd.java
deleted file mode 100644
index 09e2922..0000000
--- a/api/src/com/cloud/api/commands/CreateNetworkACLCmd.java
+++ /dev/null
@@ -1,328 +0,0 @@
-// Licensed to the Apache Software Foundation (ASF) under one
-// or more contributor license agreements. See the NOTICE file
-// distributed with this work for additional information
-// regarding copyright ownership. The ASF licenses this file
-// to you under the Apache License, Version 2.0 (the
-// "License"); you may not use this file except in compliance
-// with 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.
-package com.cloud.api.commands;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.apache.log4j.Logger;
-
-import org.apache.cloudstack.api.ApiConstants;
-import org.apache.cloudstack.api.BaseAsyncCmd;
-import org.apache.cloudstack.api.BaseAsyncCreateCmd;
-import org.apache.cloudstack.api.BaseCmd;
-import org.apache.cloudstack.api.IdentityMapper;
-import org.apache.cloudstack.api.Implementation;
-import org.apache.cloudstack.api.Parameter;
-import org.apache.cloudstack.api.ServerApiException;
-import com.cloud.api.response.NetworkACLResponse;
-import com.cloud.async.AsyncJob;
-import com.cloud.event.EventTypes;
-import com.cloud.exception.InvalidParameterValueException;
-import com.cloud.exception.NetworkRuleConflictException;
-import com.cloud.exception.ResourceUnavailableException;
-import com.cloud.network.Network;
-import com.cloud.network.rules.FirewallRule;
-import com.cloud.network.vpc.Vpc;
-import com.cloud.user.Account;
-import com.cloud.user.UserContext;
-import com.cloud.utils.net.NetUtils;
-
-@Implementation(description = "Creates a ACL rule the given network (the network has to belong to VPC)",
-responseObject = NetworkACLResponse.class)
-public class CreateNetworkACLCmd extends BaseAsyncCreateCmd implements FirewallRule {
- public static final Logger s_logger = Logger.getLogger(CreateNetworkACLCmd.class.getName());
-
- private static final String s_name = "createnetworkaclresponse";
-
- // ///////////////////////////////////////////////////
- // ////////////// API parameters /////////////////////
- // ///////////////////////////////////////////////////
-
- @Parameter(name = ApiConstants.PROTOCOL, type = CommandType.STRING, required = true, description =
- "the protocol for the ACL rule. Valid values are TCP/UDP/ICMP.")
- private String protocol;
-
- @Parameter(name = ApiConstants.START_PORT, type = CommandType.INTEGER, description = "the starting port of ACL")
- private Integer publicStartPort;
-
- @Parameter(name = ApiConstants.END_PORT, type = CommandType.INTEGER, description = "the ending port of ACL")
- private Integer publicEndPort;
-
- @Parameter(name = ApiConstants.CIDR_LIST, type = CommandType.LIST, collectionType = CommandType.STRING,
- description = "the cidr list to allow traffic from/to")
- private List<String> cidrlist;
-
- @Parameter(name = ApiConstants.ICMP_TYPE, type = CommandType.INTEGER, description = "type of the icmp message being sent")
- private Integer icmpType;
-
- @Parameter(name = ApiConstants.ICMP_CODE, type = CommandType.INTEGER, description = "error code for this icmp message")
- private Integer icmpCode;
-
- @IdentityMapper(entityTableName="networks")
- @Parameter(name=ApiConstants.NETWORK_ID, type=CommandType.LONG, required=true,
- description="The network of the vm the ACL will be created for")
- private Long networkId;
-
- @Parameter(name=ApiConstants.TRAFFIC_TYPE, type=CommandType.STRING, description="the traffic type for the ACL," +
- "can be Ingress or Egress, defaulted to Ingress if not specified")
- private String trafficType;
-
- // ///////////////////////////////////////////////////
- // ///////////////// Accessors ///////////////////////
- // ///////////////////////////////////////////////////
-
- public String getEntityTable() {
- return "firewall_rules";
- }
-
- public Long getIpAddressId() {
- return null;
- }
-
- @Override
- public String getProtocol() {
- return protocol.trim();
- }
-
- public List<String> getSourceCidrList() {
- if (cidrlist != null) {
- return cidrlist;
- } else {
- List<String> oneCidrList = new ArrayList<String>();
- oneCidrList.add(NetUtils.ALL_CIDRS);
- return oneCidrList;
- }
- }
-
- public long getVpcId() {
- Network network = _networkService.getNetwork(getNetworkId());
- if (network == null) {
- throw new InvalidParameterValueException("Invalid networkId is given");
- }
-
- Long vpcId = network.getVpcId();
- if (vpcId == null) {
- throw new InvalidParameterValueException("Can create network ACL only for the network belonging to the VPC");
- }
-
- return vpcId;
- }
-
- @Override
- public FirewallRule.TrafficType getTrafficType() {
- if (trafficType == null) {
- return FirewallRule.TrafficType.Ingress;
- }
- for (FirewallRule.TrafficType type : FirewallRule.TrafficType.values()) {
- if (type.toString().equalsIgnoreCase(trafficType)) {
- return type;
- }
- }
- throw new InvalidParameterValueException("Invalid traffic type " + trafficType);
- }
-
- // ///////////////////////////////////////////////////
- // ///////////// API Implementation///////////////////
- // ///////////////////////////////////////////////////
-
- @Override
- public String getCommandName() {
- return s_name;
- }
-
- public void setSourceCidrList(List<String> cidrs){
- cidrlist = cidrs;
- }
-
- @Override
- public void execute() throws ResourceUnavailableException {
- UserContext callerContext = UserContext.current();
- boolean success = false;
- FirewallRule rule = _networkACLService.getNetworkACL(getEntityId());
- try {
- UserContext.current().setEventDetails("Rule Id: " + getEntityId());
- success = _networkACLService.applyNetworkACLs(rule.getNetworkId(), callerContext.getCaller());
-
- // State is different after the rule is applied, so get new object here
- NetworkACLResponse aclResponse = new NetworkACLResponse();
- if (rule != null) {
- aclResponse = _responseGenerator.createNetworkACLResponse(rule);
- setResponseObject(aclResponse);
- }
- aclResponse.setResponseName(getCommandName());
- } finally {
- if (!success || rule == null) {
- _networkACLService.revokeNetworkACL(getEntityId(), true);
- throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to create network ACL");
- }
- }
- }
-
- @Override
- public long getId() {
- throw new UnsupportedOperationException("database id can only provided by VO objects");
- }
-
- @Override
- public String getXid() {
- // FIXME: We should allow for end user to specify Xid.
- return null;
- }
-
- @Override
- public Long getSourceIpAddressId() {
- return null;
- }
-
- @Override
- public Integer getSourcePortStart() {
- if (publicStartPort != null) {
- return publicStartPort.intValue();
- }
- return null;
- }
-
- @Override
- public Integer getSourcePortEnd() {
- if (publicEndPort == null) {
- if (publicStartPort != null) {
- return publicStartPort.intValue();
- }
- } else {
- return publicEndPort.intValue();
- }
-
- return null;
- }
-
- @Override
- public Purpose getPurpose() {
- return Purpose.Firewall;
- }
-
- @Override
- public State getState() {
- throw new UnsupportedOperationException("Should never call me to find the state");
- }
-
- @Override
- public long getNetworkId() {
- return networkId;
- }
-
- @Override
- public long getEntityOwnerId() {
- Vpc vpc = _vpcService.getVpc(getVpcId());
- if (vpc == null) {
- throw new InvalidParameterValueException("Invalid vpcId is given");
- }
-
- Account account = _accountService.getAccount(vpc.getAccountId());
- return account.getId();
- }
-
- @Override
- public long getDomainId() {
- Vpc vpc = _vpcService.getVpc(getVpcId());
- return vpc.getDomainId();
- }
-
- @Override
- public void create() {
- if (getSourceCidrList() != null) {
- for (String cidr: getSourceCidrList()){
- if (!NetUtils.isValidCIDR(cidr)){
- throw new ServerApiException(BaseCmd.PARAM_ERROR, "Source cidrs formatting error " + cidr);
- }
- }
- }
-
- try {
- FirewallRule result = _networkACLService.createNetworkACL(this);
- setEntityId(result.getId());
- } catch (NetworkRuleConflictException ex) {
- s_logger.info("Network rule conflict: " + ex.getMessage());
- s_logger.trace("Network Rule Conflict: ", ex);
- throw new ServerApiException(BaseCmd.NETWORK_RULE_CONFLICT_ERROR, ex.getMessage());
- }
- }
-
- @Override
- public String getEventType() {
- return EventTypes.EVENT_FIREWALL_OPEN;
- }
-
- @Override
- public String getEventDescription() {
- Network network = _networkService.getNetwork(networkId);
- return ("Createing Network ACL for Netowrk: " + network + " for protocol:" + this.getProtocol());
- }
-
- @Override
- public long getAccountId() {
- Vpc vpc = _vpcService.getVpc(getVpcId());
- return vpc.getAccountId();
- }
-
- @Override
- public String getSyncObjType() {
- return BaseAsyncCmd.networkSyncObject;
- }
-
- @Override
- public Long getSyncObjId() {
- return getNetworkId();
- }
-
- @Override
- public Integer getIcmpCode() {
- if (icmpCode != null) {
- return icmpCode;
- } else if (protocol.equalsIgnoreCase(NetUtils.ICMP_PROTO)) {
- return -1;
- }
- return null;
- }
-
- @Override
- public Integer getIcmpType() {
- if (icmpType != null) {
- return icmpType;
- } else if (protocol.equalsIgnoreCase(NetUtils.ICMP_PROTO)) {
- return -1;
-
- }
- return null;
- }
-
- @Override
- public Long getRelated() {
- return null;
- }
-
- @Override
- public FirewallRuleType getType() {
- return FirewallRuleType.User;
- }
-
- @Override
- public AsyncJob.Type getInstanceType() {
- return AsyncJob.Type.FirewallRule;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/47ae62e4/api/src/com/cloud/api/commands/CreateNetworkCmd.java
----------------------------------------------------------------------
diff --git a/api/src/com/cloud/api/commands/CreateNetworkCmd.java b/api/src/com/cloud/api/commands/CreateNetworkCmd.java
deleted file mode 100644
index 53b19bb..0000000
--- a/api/src/com/cloud/api/commands/CreateNetworkCmd.java
+++ /dev/null
@@ -1,234 +0,0 @@
-// Licensed to the Apache Software Foundation (ASF) under one
-// or more contributor license agreements. See the NOTICE file
-// distributed with this work for additional information
-// regarding copyright ownership. The ASF licenses this file
-// to you under the Apache License, Version 2.0 (the
-// "License"); you may not use this file except in compliance
-// with 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.
-package com.cloud.api.commands;
-
-import org.apache.log4j.Logger;
-
-import org.apache.cloudstack.api.ApiConstants;
-import org.apache.cloudstack.api.BaseCmd;
-import org.apache.cloudstack.api.IdentityMapper;
-import org.apache.cloudstack.api.Implementation;
-import org.apache.cloudstack.api.Parameter;
-import org.apache.cloudstack.api.ServerApiException;
-import com.cloud.api.response.NetworkResponse;
-import com.cloud.exception.ConcurrentOperationException;
-import com.cloud.exception.InsufficientCapacityException;
-import com.cloud.exception.InvalidParameterValueException;
-import com.cloud.exception.ResourceAllocationException;
-import com.cloud.network.Network;
-import com.cloud.network.Network.GuestType;
-import com.cloud.offering.NetworkOffering;
-import com.cloud.user.UserContext;
-
-@Implementation(description="Creates a network", responseObject=NetworkResponse.class)
-public class CreateNetworkCmd extends BaseCmd {
- public static final Logger s_logger = Logger.getLogger(CreateNetworkCmd.class.getName());
-
- private static final String s_name = "createnetworkresponse";
-
- /////////////////////////////////////////////////////
- //////////////// API parameters /////////////////////
- /////////////////////////////////////////////////////
-
- @Parameter(name=ApiConstants.NAME, type=CommandType.STRING, required=true, description="the name of the network")
- private String name;
-
- @Parameter(name=ApiConstants.DISPLAY_TEXT, type=CommandType.STRING, required=true, description="the display text of the network")
- private String displayText;
-
- @IdentityMapper(entityTableName="network_offerings")
- @Parameter(name=ApiConstants.NETWORK_OFFERING_ID, type=CommandType.LONG, required=true, description="the network offering id")
- private Long networkOfferingId;
-
- @IdentityMapper(entityTableName="data_center")
- @Parameter(name=ApiConstants.ZONE_ID, type=CommandType.LONG, required=true, description="the Zone ID for the network")
- private Long zoneId;
-
- @IdentityMapper(entityTableName="physical_network")
- @Parameter(name=ApiConstants.PHYSICAL_NETWORK_ID, type=CommandType.LONG, description="the Physical Network ID the network belongs to")
- private Long physicalNetworkId;
-
- @Parameter(name=ApiConstants.GATEWAY, type=CommandType.STRING, description="the gateway of the network. Required " +
- "for Shared networks and Isolated networks when it belongs to VPC")
- private String gateway;
-
- @Parameter(name=ApiConstants.NETMASK, type=CommandType.STRING, description="the netmask of the network. Required " +
- "for Shared networks and Isolated networks when it belongs to VPC")
- private String netmask;
-
- @Parameter(name=ApiConstants.START_IP, type=CommandType.STRING, description="the beginning IP address in the network IP range")
- private String startIp;
-
- @Parameter(name=ApiConstants.END_IP, type=CommandType.STRING, description="the ending IP address in the network IP" +
- " range. If not specified, will be defaulted to startIP")
- private String endIp;
-
- @Parameter(name=ApiConstants.VLAN, type=CommandType.STRING, description="the ID or VID of the network")
- private String vlan;
-
- @Parameter(name=ApiConstants.NETWORK_DOMAIN, type=CommandType.STRING, description="network domain")
- private String networkDomain;
-
- @Parameter(name=ApiConstants.ACL_TYPE, type=CommandType.STRING, description="Access control type; supported values" +
- " are account and domain. In 3.0 all shared networks should have aclType=Domain, and all Isolated networks" +
- " - Account. Account means that only the account owner can use the network, domain - all accouns in the domain can use the network")
- private String aclType;
-
- @Parameter(name=ApiConstants.ACCOUNT, type=CommandType.STRING, description="account who will own the network")
- private String accountName;
-
- @IdentityMapper(entityTableName="projects")
- @Parameter(name=ApiConstants.PROJECT_ID, type=CommandType.LONG, description="an optional project for the ssh key")
- private Long projectId;
-
- @IdentityMapper(entityTableName="domain")
- @Parameter(name=ApiConstants.DOMAIN_ID, type=CommandType.LONG, description="domain ID of the account owning a network")
- private Long domainId;
-
- @Parameter(name=ApiConstants.SUBDOMAIN_ACCESS, type=CommandType.BOOLEAN, description="Defines whether to allow" +
- " subdomains to use networks dedicated to their parent domain(s). Should be used with aclType=Domain, defaulted to allow.subdomain.network.access global config if not specified")
- private Boolean subdomainAccess;
-
- @IdentityMapper(entityTableName="vpc")
- @Parameter(name=ApiConstants.VPC_ID, type=CommandType.LONG, description="the VPC network belongs to")
- private Long vpcId;
-
-
- /////////////////////////////////////////////////////
- /////////////////// Accessors ///////////////////////
- /////////////////////////////////////////////////////
- public Long getNetworkOfferingId() {
- return networkOfferingId;
- }
-
- public String getGateway() {
- return gateway;
- }
-
- public String getVlan() {
- return vlan;
- }
-
- public String getAccountName() {
- return accountName;
- }
-
- public Long getDomainId() {
- return domainId;
- }
-
- public String getNetmask() {
- return netmask;
- }
-
- public String getStartIp() {
- return startIp;
- }
-
- public String getEndIp() {
- return endIp;
- }
-
- public String getNetworkName() {
- return name;
- }
-
- public String getDisplayText() {
- return displayText;
- }
-
- public String getNetworkDomain() {
- return networkDomain;
- }
-
- public Long getProjectId() {
- return projectId;
- }
-
- public String getAclType() {
- return aclType;
- }
-
- public Boolean getSubdomainAccess() {
- return subdomainAccess;
- }
-
- public Long getVpcId() {
- return vpcId;
- }
-
- public Long getZoneId() {
- Long physicalNetworkId = getPhysicalNetworkId();
-
- if (physicalNetworkId == null && zoneId == null) {
- throw new InvalidParameterValueException("Zone id is required");
- }
-
- return zoneId;
- }
-
- public Long getPhysicalNetworkId() {
- NetworkOffering offering = _configService.getNetworkOffering(networkOfferingId);
- if (offering == null) {
- throw new InvalidParameterValueException("Unable to find network offering by id " + networkOfferingId);
- }
-
- if (physicalNetworkId != null) {
- if (offering.getGuestType() == GuestType.Shared) {
- return physicalNetworkId;
- } else {
- throw new InvalidParameterValueException("Physical network id can be specified for networks of guest ip type " + GuestType.Shared + " only.");
- }
- } else {
- if (zoneId == null) {
- throw new InvalidParameterValueException("ZoneId is required as physicalNetworkId is null");
- }
- return _networkService.findPhysicalNetworkId(zoneId, offering.getTags(), offering.getTrafficType());
- }
- }
-
- /////////////////////////////////////////////////////
- /////////////// API Implementation///////////////////
- /////////////////////////////////////////////////////
- @Override
- public String getCommandName() {
- return s_name;
- }
-
- @Override
- public long getEntityOwnerId() {
- Long accountId = finalyzeAccountId(accountName, domainId, projectId, true);
- if (accountId == null) {
- return UserContext.current().getCaller().getId();
- }
-
- return accountId;
- }
-
- @Override
- // an exception thrown by createNetwork() will be caught by the dispatcher.
- public void execute() throws InsufficientCapacityException, ConcurrentOperationException, ResourceAllocationException{
- Network result = _networkService.createGuestNetwork(this);
- if (result != null) {
- NetworkResponse response = _responseGenerator.createNetworkResponse(result);
- response.setResponseName(getCommandName());
- this.setResponseObject(response);
- }else {
- throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to create network");
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/47ae62e4/api/src/com/cloud/api/commands/DeleteNetworkACLCmd.java
----------------------------------------------------------------------
diff --git a/api/src/com/cloud/api/commands/DeleteNetworkACLCmd.java b/api/src/com/cloud/api/commands/DeleteNetworkACLCmd.java
deleted file mode 100644
index 1cd1e33..0000000
--- a/api/src/com/cloud/api/commands/DeleteNetworkACLCmd.java
+++ /dev/null
@@ -1,121 +0,0 @@
-// Licensed to the Apache Software Foundation (ASF) under one
-// or more contributor license agreements. See the NOTICE file
-// distributed with this work for additional information
-// regarding copyright ownership. The ASF licenses this file
-// to you under the Apache License, Version 2.0 (the
-// "License"); you may not use this file except in compliance
-// with 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.
-package com.cloud.api.commands;
-
-import org.apache.log4j.Logger;
-
-import org.apache.cloudstack.api.ApiConstants;
-import org.apache.cloudstack.api.BaseAsyncCmd;
-import org.apache.cloudstack.api.BaseCmd;
-import org.apache.cloudstack.api.IdentityMapper;
-import org.apache.cloudstack.api.Implementation;
-import org.apache.cloudstack.api.Parameter;
-import org.apache.cloudstack.api.ServerApiException;
-import com.cloud.api.response.SuccessResponse;
-import com.cloud.async.AsyncJob;
-import com.cloud.event.EventTypes;
-import com.cloud.exception.InvalidParameterValueException;
-import com.cloud.exception.ResourceUnavailableException;
-import com.cloud.network.rules.FirewallRule;
-import com.cloud.user.UserContext;
-
-@Implementation(description="Deletes a Network ACL", responseObject=SuccessResponse.class)
-public class DeleteNetworkACLCmd extends BaseAsyncCmd {
- public static final Logger s_logger = Logger.getLogger(DeleteNetworkACLCmd.class.getName());
- private static final String s_name = "deletenetworkaclresponse";
-
- /////////////////////////////////////////////////////
- //////////////// API parameters /////////////////////
- /////////////////////////////////////////////////////
-
- @IdentityMapper(entityTableName="firewall_rules")
- @Parameter(name=ApiConstants.ID, type=CommandType.LONG, required=true, description="the ID of the network ACL")
- private Long id;
-
- // unexposed parameter needed for events logging
- @IdentityMapper(entityTableName="account")
- @Parameter(name=ApiConstants.ACCOUNT_ID, type=CommandType.LONG, expose=false)
- private Long ownerId;
- /////////////////////////////////////////////////////
- /////////////////// Accessors ///////////////////////
- /////////////////////////////////////////////////////
-
- public Long getId() {
- return id;
- }
-
- /////////////////////////////////////////////////////
- /////////////// API Implementation///////////////////
- /////////////////////////////////////////////////////
- @Override
- public String getCommandName() {
- return s_name;
- }
-
- @Override
- public String getEventType() {
- return EventTypes.EVENT_FIREWALL_CLOSE;
- }
-
- @Override
- public String getEventDescription() {
- return ("Deleting Network ACL id=" + id);
- }
-
- @Override
- public long getEntityOwnerId() {
- if (ownerId == null) {
- FirewallRule rule = _networkACLService.getNetworkACL(id);
- if (rule == null) {
- throw new InvalidParameterValueException("Unable to find network ACL by id=" + id);
- } else {
- ownerId = rule.getAccountId();
- }
- }
- return ownerId;
- }
-
- @Override
- public void execute() throws ResourceUnavailableException {
- UserContext.current().setEventDetails("Network ACL Id: " + id);
- boolean result = _networkACLService.revokeNetworkACL(id, true);
-
- if (result) {
- SuccessResponse response = new SuccessResponse(getCommandName());
- this.setResponseObject(response);
- } else {
- throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to delete network ACL");
- }
- }
-
-
- @Override
- public String getSyncObjType() {
- return BaseAsyncCmd.networkSyncObject;
- }
-
- @Override
- public Long getSyncObjId() {
- return _firewallService.getFirewallRule(id).getNetworkId();
- }
-
- @Override
- public AsyncJob.Type getInstanceType() {
- return AsyncJob.Type.FirewallRule;
- }
-}
-
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/47ae62e4/api/src/com/cloud/api/commands/DeleteNetworkCmd.java
----------------------------------------------------------------------
diff --git a/api/src/com/cloud/api/commands/DeleteNetworkCmd.java b/api/src/com/cloud/api/commands/DeleteNetworkCmd.java
deleted file mode 100644
index 692fffe..0000000
--- a/api/src/com/cloud/api/commands/DeleteNetworkCmd.java
+++ /dev/null
@@ -1,108 +0,0 @@
-// Licensed to the Apache Software Foundation (ASF) under one
-// or more contributor license agreements. See the NOTICE file
-// distributed with this work for additional information
-// regarding copyright ownership. The ASF licenses this file
-// to you under the Apache License, Version 2.0 (the
-// "License"); you may not use this file except in compliance
-// with 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.
-package com.cloud.api.commands;
-
-import org.apache.log4j.Logger;
-
-import org.apache.cloudstack.api.ApiConstants;
-import org.apache.cloudstack.api.BaseAsyncCmd;
-import org.apache.cloudstack.api.BaseCmd;
-import org.apache.cloudstack.api.IdentityMapper;
-import org.apache.cloudstack.api.Implementation;
-import org.apache.cloudstack.api.Parameter;
-import org.apache.cloudstack.api.ServerApiException;
-import com.cloud.api.response.SuccessResponse;
-import com.cloud.event.EventTypes;
-import com.cloud.exception.InvalidParameterValueException;
-import com.cloud.network.Network;
-import com.cloud.user.UserContext;
-
-@Implementation(description="Deletes a network", responseObject=SuccessResponse.class)
-public class DeleteNetworkCmd extends BaseAsyncCmd{
- public static final Logger s_logger = Logger.getLogger(DeleteNetworkOfferingCmd.class.getName());
- private static final String s_name = "deletenetworkresponse";
-
- /////////////////////////////////////////////////////
- //////////////// API parameters /////////////////////
- /////////////////////////////////////////////////////
-
- @IdentityMapper(entityTableName="networks")
- @Parameter(name=ApiConstants.ID, type=CommandType.LONG, required=true, description="the ID of the network")
- private Long id;
-
-
- /////////////////////////////////////////////////////
- /////////////////// Accessors ///////////////////////
- /////////////////////////////////////////////////////
-
- public Long getId() {
- return id;
- }
-
-
- /////////////////////////////////////////////////////
- /////////////// API Implementation///////////////////
- /////////////////////////////////////////////////////
-
- @Override
- public String getCommandName() {
- return s_name;
- }
-
- @Override
- public void execute(){
- UserContext.current().setEventDetails("Network Id: " + id);
- boolean result = _networkService.deleteNetwork(id);
- if (result) {
- SuccessResponse response = new SuccessResponse(getCommandName());
- this.setResponseObject(response);
- } else {
- throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to delete network");
- }
- }
-
-
- @Override
- public String getSyncObjType() {
- return BaseAsyncCmd.networkSyncObject;
- }
-
- @Override
- public Long getSyncObjId() {
- return id;
- }
-
- @Override
- public String getEventType() {
- return EventTypes.EVENT_NETWORK_DELETE;
- }
-
- @Override
- public String getEventDescription() {
- return "Deleting network: " + id;
- }
-
- @Override
- public long getEntityOwnerId() {
- Network network = _networkService.getNetwork(id);
- if (network == null) {
- throw new InvalidParameterValueException("Networkd id=" + id + " doesn't exist");
- } else {
- return _networkService.getNetwork(id).getAccountId();
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/47ae62e4/api/src/com/cloud/api/commands/ListNetworkACLsCmd.java
----------------------------------------------------------------------
diff --git a/api/src/com/cloud/api/commands/ListNetworkACLsCmd.java b/api/src/com/cloud/api/commands/ListNetworkACLsCmd.java
deleted file mode 100644
index c75e318..0000000
--- a/api/src/com/cloud/api/commands/ListNetworkACLsCmd.java
+++ /dev/null
@@ -1,94 +0,0 @@
-// Licensed to the Apache Software Foundation (ASF) under one
-// or more contributor license agreements. See the NOTICE file
-// distributed with this work for additional information
-// regarding copyright ownership. The ASF licenses this file
-// to you under the Apache License, Version 2.0 (the
-// "License"); you may not use this file except in compliance
-// with 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.
-package com.cloud.api.commands;
-
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.apache.log4j.Logger;
-
-import org.apache.cloudstack.api.ApiConstants;
-import org.apache.cloudstack.api.BaseListTaggedResourcesCmd;
-import org.apache.cloudstack.api.IdentityMapper;
-import org.apache.cloudstack.api.Implementation;
-import org.apache.cloudstack.api.Parameter;
-import com.cloud.api.response.ListResponse;
-import com.cloud.api.response.NetworkACLResponse;
-import com.cloud.network.rules.FirewallRule;
-import com.cloud.utils.Pair;
-
-@Implementation(description="Lists all network ACLs", responseObject=NetworkACLResponse.class)
-public class ListNetworkACLsCmd extends BaseListTaggedResourcesCmd {
- public static final Logger s_logger = Logger.getLogger(ListNetworkACLsCmd.class.getName());
-
- private static final String s_name = "listnetworkaclsresponse";
-
- /////////////////////////////////////////////////////
- //////////////// API parameters /////////////////////
- /////////////////////////////////////////////////////
- @IdentityMapper(entityTableName="firewall_rules")
- @Parameter(name=ApiConstants.ID, type=CommandType.LONG, description="Lists network ACL with the specified ID.")
- private Long id;
-
- @IdentityMapper(entityTableName="networks")
- @Parameter(name=ApiConstants.NETWORK_ID, type=CommandType.LONG, description="list network ACLs by network Id")
- private Long networkId;
-
- @Parameter(name=ApiConstants.TRAFFIC_TYPE, type=CommandType.STRING, description="list network ACLs by traffic type - Ingress or Egress")
- private String trafficType;
-
- /////////////////////////////////////////////////////
- /////////////////// Accessors ///////////////////////
- /////////////////////////////////////////////////////
-
- public Long getNetworkId() {
- return networkId;
- }
-
- public Long getId() {
- return id;
- }
-
- public String getTrafficType() {
- return trafficType;
- }
-
- /////////////////////////////////////////////////////
- /////////////// API Implementation///////////////////
- /////////////////////////////////////////////////////
-
- @Override
- public String getCommandName() {
- return s_name;
- }
-
- @Override
- public void execute(){
- Pair<List<? extends FirewallRule>,Integer> result = _networkACLService.listNetworkACLs(this);
- ListResponse<NetworkACLResponse> response = new ListResponse<NetworkACLResponse>();
- List<NetworkACLResponse> aclResponses = new ArrayList<NetworkACLResponse>();
-
- for (FirewallRule acl : result.first()) {
- NetworkACLResponse ruleData = _responseGenerator.createNetworkACLResponse(acl);
- aclResponses.add(ruleData);
- }
- response.setResponses(aclResponses, result.second());
- response.setResponseName(getCommandName());
- this.setResponseObject(response);
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/47ae62e4/api/src/com/cloud/api/commands/ListNetworkOfferingsCmd.java
----------------------------------------------------------------------
diff --git a/api/src/com/cloud/api/commands/ListNetworkOfferingsCmd.java b/api/src/com/cloud/api/commands/ListNetworkOfferingsCmd.java
deleted file mode 100644
index 9f6f94d..0000000
--- a/api/src/com/cloud/api/commands/ListNetworkOfferingsCmd.java
+++ /dev/null
@@ -1,191 +0,0 @@
-// Licensed to the Apache Software Foundation (ASF) under one
-// or more contributor license agreements. See the NOTICE file
-// distributed with this work for additional information
-// regarding copyright ownership. The ASF licenses this file
-// to you under the Apache License, Version 2.0 (the
-// "License"); you may not use this file except in compliance
-// with 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.
-package com.cloud.api.commands;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.apache.log4j.Logger;
-
-import org.apache.cloudstack.api.ApiConstants;
-import org.apache.cloudstack.api.BaseListCmd;
-import org.apache.cloudstack.api.IdentityMapper;
-import org.apache.cloudstack.api.Implementation;
-import org.apache.cloudstack.api.Parameter;
-import com.cloud.api.response.ListResponse;
-import com.cloud.api.response.NetworkOfferingResponse;
-import com.cloud.offering.NetworkOffering;
-
-
-@Implementation(description="Lists all available network offerings.", responseObject=NetworkOfferingResponse.class)
-public class ListNetworkOfferingsCmd extends BaseListCmd {
- public static final Logger s_logger = Logger.getLogger(ListNetworkOfferingsCmd.class.getName());
- private static final String _name = "listnetworkofferingsresponse";
-
- /////////////////////////////////////////////////////
- //////////////// API parameters /////////////////////
- /////////////////////////////////////////////////////
- @IdentityMapper(entityTableName="network_offerings")
- @Parameter(name=ApiConstants.ID, type=CommandType.LONG, description="list network offerings by id")
- private Long id;
-
- @Parameter(name=ApiConstants.NAME, type=CommandType.STRING, description="list network offerings by name")
- private String networkOfferingName;
-
- @Parameter(name=ApiConstants.DISPLAY_TEXT, type=CommandType.STRING, description="list network offerings by display text")
- private String displayText;
-
- @Parameter(name=ApiConstants.TRAFFIC_TYPE, type=CommandType.STRING, description="list by traffic type")
- private String trafficType;
-
- @Parameter(name=ApiConstants.IS_DEFAULT, type=CommandType.BOOLEAN, description="true if need to list only default network offerings. Default value is false")
- private Boolean isDefault;
-
- @Parameter(name=ApiConstants.SPECIFY_VLAN, type=CommandType.BOOLEAN, description="the tags for the network offering.")
- private Boolean specifyVlan;
-
- @Parameter(name=ApiConstants.AVAILABILITY, type=CommandType.STRING, description="the availability of network offering. Default value is Required")
- private String availability;
-
- @IdentityMapper(entityTableName="data_center")
- @Parameter(name=ApiConstants.ZONE_ID, type=CommandType.LONG, description="list netowrk offerings available for network creation in specific zone")
- private Long zoneId;
-
- @Parameter(name=ApiConstants.STATE, type=CommandType.STRING, description="list network offerings by state")
- private String state;
-
- @IdentityMapper(entityTableName="networks")
- @Parameter(name=ApiConstants.NETWORK_ID, type=CommandType.LONG, description="the ID of the network. Pass this in if you want to see the available network offering that a network can be changed to.")
- private Long networkId;
-
- @Parameter(name=ApiConstants.GUEST_IP_TYPE, type=CommandType.STRING, description="list network offerings by guest type: Shared or Isolated")
- private String guestIpType;
-
- @Parameter(name=ApiConstants.SUPPORTED_SERVICES, type=CommandType.LIST, collectionType=CommandType.STRING, description="list network offerings supporting certain services")
- private List<String> supportedServices;
-
- @Parameter(name=ApiConstants.SOURCE_NAT_SUPPORTED, type=CommandType.BOOLEAN, description="true if need to list only netwok offerings where source nat is supported, false otherwise")
- private Boolean sourceNatSupported;
-
- @Parameter(name=ApiConstants.SPECIFY_IP_RANGES, type=CommandType.BOOLEAN, description="true if need to list only network offerings which support specifying ip ranges")
- private Boolean specifyIpRanges;
-
- @Parameter(name=ApiConstants.TAGS, type=CommandType.STRING, description="list network offerings by tags", length=4096)
- private String tags;
-
- @Parameter(name=ApiConstants.IS_TAGGED, type=CommandType.BOOLEAN, description="true if offering has tags specified")
- private Boolean isTagged;
-
- @Parameter(name=ApiConstants.FOR_VPC, type=CommandType.BOOLEAN, description="the network offering can be used" +
- " only for network creation inside the VPC")
- private Boolean forVpc;
-
- /////////////////////////////////////////////////////
- /////////////////// Accessors ///////////////////////
- /////////////////////////////////////////////////////
-
- public String getNetworkOfferingName() {
- return networkOfferingName;
- }
-
- public String getDisplayText() {
- return displayText;
- }
-
- public String getTrafficType() {
- return trafficType;
- }
-
- public Long getId() {
- return id;
- }
-
- public Boolean getIsDefault() {
- return isDefault;
- }
-
- public Boolean getSpecifyVlan() {
- return specifyVlan;
- }
-
- public String getAvailability() {
- return availability;
- }
-
- public Long getZoneId() {
- return zoneId;
- }
-
- public String getState() {
- return state;
- }
-
- public Long getNetworkId() {
- return networkId;
- }
-
- public String getGuestIpType() {
- return guestIpType;
- }
-
- public List<String> getSupportedServices() {
- return supportedServices;
- }
-
- public Boolean getSourceNatSupported() {
- return sourceNatSupported;
- }
-
- public Boolean getSpecifyIpRanges() {
- return specifyIpRanges;
- }
-
- public String getTags() {
- return tags;
- }
-
- public Boolean isTagged() {
- return isTagged;
- }
-
- public Boolean getForVpc() {
- return forVpc;
- }
-
- /////////////////////////////////////////////////////
- /////////////// API Implementation///////////////////
- /////////////////////////////////////////////////////
- @Override
- public String getCommandName() {
- return _name;
- }
-
- @Override
- public void execute(){
- List<? extends NetworkOffering> offerings = _configService.searchForNetworkOfferings(this);
- ListResponse<NetworkOfferingResponse> response = new ListResponse<NetworkOfferingResponse>();
- List<NetworkOfferingResponse> offeringResponses = new ArrayList<NetworkOfferingResponse>();
- for (NetworkOffering offering : offerings) {
- NetworkOfferingResponse offeringResponse = _responseGenerator.createNetworkOfferingResponse(offering);
- offeringResponses.add(offeringResponse);
- }
-
- response.setResponses(offeringResponses);
- response.setResponseName(getCommandName());
- this.setResponseObject(response);
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/47ae62e4/api/src/com/cloud/api/commands/ListNetworksCmd.java
----------------------------------------------------------------------
diff --git a/api/src/com/cloud/api/commands/ListNetworksCmd.java b/api/src/com/cloud/api/commands/ListNetworksCmd.java
deleted file mode 100644
index 4dcb22d..0000000
--- a/api/src/com/cloud/api/commands/ListNetworksCmd.java
+++ /dev/null
@@ -1,164 +0,0 @@
-// Licensed to the Apache Software Foundation (ASF) under one
-// or more contributor license agreements. See the NOTICE file
-// distributed with this work for additional information
-// regarding copyright ownership. The ASF licenses this file
-// to you under the Apache License, Version 2.0 (the
-// "License"); you may not use this file except in compliance
-// with 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.
-package com.cloud.api.commands;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.apache.log4j.Logger;
-
-import org.apache.cloudstack.api.ApiConstants;
-import org.apache.cloudstack.api.BaseListTaggedResourcesCmd;
-import org.apache.cloudstack.api.IdentityMapper;
-import org.apache.cloudstack.api.Implementation;
-import org.apache.cloudstack.api.Parameter;
-import com.cloud.api.response.ListResponse;
-import com.cloud.api.response.NetworkResponse;
-import com.cloud.network.Network;
-
-
-@Implementation(description="Lists all available networks.", responseObject=NetworkResponse.class)
-public class ListNetworksCmd extends BaseListTaggedResourcesCmd {
- public static final Logger s_logger = Logger.getLogger(ListNetworksCmd.class.getName());
- private static final String _name = "listnetworksresponse";
-
- /////////////////////////////////////////////////////
- //////////////// API parameters /////////////////////
- /////////////////////////////////////////////////////
- @IdentityMapper(entityTableName="networks")
- @Parameter(name=ApiConstants.ID, type=CommandType.LONG, description="list networks by id")
- private Long id;
-
- @IdentityMapper(entityTableName="data_center")
- @Parameter(name=ApiConstants.ZONE_ID, type=CommandType.LONG, description="the Zone ID of the network")
- private Long zoneId;
-
- @Parameter(name=ApiConstants.TYPE, type=CommandType.STRING, description="the type of the network. Supported values are: Isolated and Shared")
- private String guestIpType;
-
- @Parameter(name=ApiConstants.IS_SYSTEM, type=CommandType.BOOLEAN, description="true if network is system, false otherwise")
- private Boolean isSystem;
-
- @Parameter(name=ApiConstants.ACL_TYPE, type=CommandType.STRING, description="list networks by ACL (access control list) type. Supported values are Account and Domain")
- private String aclType;
-
- @Parameter(name=ApiConstants.TRAFFIC_TYPE, type=CommandType.STRING, description="type of the traffic")
- private String trafficType;
-
- @IdentityMapper(entityTableName="physical_network")
- @Parameter(name=ApiConstants.PHYSICAL_NETWORK_ID, type=CommandType.LONG, description="list networks by physical network id")
- private Long physicalNetworkId;
-
- @Parameter(name=ApiConstants.SUPPORTED_SERVICES, type=CommandType.LIST, collectionType=CommandType.STRING, description="list networks supporting certain services")
- private List<String> supportedServices;
-
- @Parameter(name=ApiConstants.RESTART_REQUIRED, type=CommandType.BOOLEAN, description="list networks by restartRequired")
-
- private Boolean restartRequired;
-
- @Parameter(name=ApiConstants.SPECIFY_IP_RANGES, type=CommandType.BOOLEAN, description="true if need to list only networks which support specifying ip ranges")
- private Boolean specifyIpRanges;
-
- @IdentityMapper(entityTableName="vpc")
- @Parameter(name=ApiConstants.VPC_ID, type=CommandType.LONG, description="List networks by VPC")
- private Long vpcId;
-
- @Parameter(name=ApiConstants.CAN_USE_FOR_DEPLOY, type=CommandType.BOOLEAN, description="list networks available for vm deployment")
- private Boolean canUseForDeploy;
-
- @Parameter(name=ApiConstants.FOR_VPC, type=CommandType.BOOLEAN, description="the network belongs to vpc")
- private Boolean forVpc;
-
- /////////////////////////////////////////////////////
- /////////////////// Accessors ///////////////////////
- /////////////////////////////////////////////////////
-
- public Long getId() {
- return id;
- }
-
- public Long getZoneId() {
- return zoneId;
- }
-
- public String getGuestIpType() {
- return guestIpType;
- }
-
- public Boolean getIsSystem() {
- return isSystem;
- }
-
- public String getAclType() {
- return aclType;
- }
-
- public String getTrafficType() {
- return trafficType;
- }
-
- public Long getPhysicalNetworkId() {
- return physicalNetworkId;
- }
-
- public List<String> getSupportedServices() {
- return supportedServices;
- }
-
- public Boolean getRestartRequired() {
- return restartRequired;
- }
-
- public Boolean getSpecifyIpRanges() {
- return specifyIpRanges;
- }
-
- public Long getVpcId() {
- return vpcId;
- }
-
- public Boolean canUseForDeploy() {
- return canUseForDeploy;
- }
-
- public Boolean getForVpc() {
- return forVpc;
- }
-
- /////////////////////////////////////////////////////
- /////////////// API Implementation///////////////////
- /////////////////////////////////////////////////////
- @Override
- public String getCommandName() {
- return _name;
- }
-
- @Override
- public void execute(){
- List<? extends Network> networks = _networkService.searchForNetworks(this);
- ListResponse<NetworkResponse> response = new ListResponse<NetworkResponse>();
- List<NetworkResponse> networkResponses = new ArrayList<NetworkResponse>();
- for (Network network : networks) {
- NetworkResponse networkResponse = _responseGenerator.createNetworkResponse(network);
- networkResponses.add(networkResponse);
- }
-
- response.setResponses(networkResponses);
- response.setResponseName(getCommandName());
- this.setResponseObject(response);
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/47ae62e4/api/src/com/cloud/api/commands/ListVirtualRouterElementsCmd.java
----------------------------------------------------------------------
diff --git a/api/src/com/cloud/api/commands/ListVirtualRouterElementsCmd.java b/api/src/com/cloud/api/commands/ListVirtualRouterElementsCmd.java
index 3a8cc97..aa24467 100644
--- a/api/src/com/cloud/api/commands/ListVirtualRouterElementsCmd.java
+++ b/api/src/com/cloud/api/commands/ListVirtualRouterElementsCmd.java
@@ -19,6 +19,7 @@ package com.cloud.api.commands;
import java.util.ArrayList;
import java.util.List;
+import org.apache.cloudstack.api.user.network.command.ListNetworkOfferingsCmd;
import org.apache.log4j.Logger;
import org.apache.cloudstack.api.ApiConstants;
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/47ae62e4/api/src/com/cloud/api/commands/RestartNetworkCmd.java
----------------------------------------------------------------------
diff --git a/api/src/com/cloud/api/commands/RestartNetworkCmd.java b/api/src/com/cloud/api/commands/RestartNetworkCmd.java
deleted file mode 100644
index d7d124d..0000000
--- a/api/src/com/cloud/api/commands/RestartNetworkCmd.java
+++ /dev/null
@@ -1,130 +0,0 @@
-// Licensed to the Apache Software Foundation (ASF) under one
-// or more contributor license agreements. See the NOTICE file
-// distributed with this work for additional information
-// regarding copyright ownership. The ASF licenses this file
-// to you under the Apache License, Version 2.0 (the
-// "License"); you may not use this file except in compliance
-// with 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.
-package com.cloud.api.commands;
-
-import org.apache.log4j.Logger;
-
-import org.apache.cloudstack.api.ApiConstants;
-import org.apache.cloudstack.api.BaseAsyncCmd;
-import org.apache.cloudstack.api.BaseCmd;
-import org.apache.cloudstack.api.IdentityMapper;
-import org.apache.cloudstack.api.Implementation;
-import org.apache.cloudstack.api.Parameter;
-import org.apache.cloudstack.api.ServerApiException;
-import com.cloud.api.response.IPAddressResponse;
-import com.cloud.api.response.SuccessResponse;
-import com.cloud.event.EventTypes;
-import com.cloud.exception.ConcurrentOperationException;
-import com.cloud.exception.InsufficientCapacityException;
-import com.cloud.exception.InvalidParameterValueException;
-import com.cloud.exception.ResourceAllocationException;
-import com.cloud.exception.ResourceUnavailableException;
-import com.cloud.network.Network;
-
-@Implementation(description="Restarts the network; includes 1) restarting network elements - virtual routers, dhcp servers 2) reapplying all public ips 3) reapplying loadBalancing/portForwarding rules", responseObject=IPAddressResponse.class)
-public class RestartNetworkCmd extends BaseAsyncCmd {
- public static final Logger s_logger = Logger.getLogger(RestartNetworkCmd.class.getName());
- private static final String s_name = "restartnetworkresponse";
-
- /////////////////////////////////////////////////////
- //////////////// API parameters /////////////////////
- /////////////////////////////////////////////////////
-
-
- @IdentityMapper(entityTableName="networks")
- @Parameter(name=ApiConstants.ID, type=CommandType.LONG, required=true, description="The id of the network to restart.")
- private Long id;
-
- @Parameter(name=ApiConstants.CLEANUP, type=CommandType.BOOLEAN, required=false, description="If cleanup old network elements")
- private Boolean cleanup;
-
-
- /////////////////////////////////////////////////////
- /////////////////// Accessors ///////////////////////
- /////////////////////////////////////////////////////
-
- public Long getNetworkId() {
- Network network = _networkService.getNetwork(id);
- if (network == null) {
- throw new InvalidParameterValueException("Unable to find network by id " + id);
- } else {
- return network.getId();
- }
- }
-
- public Boolean getCleanup() {
- if (cleanup != null) {
- return cleanup;
- }
- return true;
- }
-
-
- /////////////////////////////////////////////////////
- /////////////// API Implementation///////////////////
- /////////////////////////////////////////////////////
-
-
- @Override
- public String getCommandName() {
- return s_name;
- }
-
- public static String getResultObjectName() {
- return "addressinfo";
- }
-
- @Override
- public void execute() throws ResourceUnavailableException, ResourceAllocationException, ConcurrentOperationException, InsufficientCapacityException {
- boolean result = _networkService.restartNetwork(this, getCleanup());
- if (result) {
- SuccessResponse response = new SuccessResponse(getCommandName());
- this.setResponseObject(response);
- } else {
- throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to restart network");
- }
- }
-
- @Override
- public String getSyncObjType() {
- return BaseAsyncCmd.networkSyncObject;
- }
-
- @Override
- public Long getSyncObjId() {
- return id;
- }
-
- public String getEventDescription() {
- return "Restarting network: " + getNetworkId();
- }
-
- @Override
- public String getEventType() {
- return EventTypes.EVENT_NETWORK_RESTART;
- }
-
- @Override
- public long getEntityOwnerId() {
- Network network = _networkService.getNetwork(id);
- if (network == null) {
- throw new InvalidParameterValueException("Networkd id=" + id + " doesn't exist");
- } else {
- return _networkService.getNetwork(id).getAccountId();
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/47ae62e4/api/src/com/cloud/api/commands/UpdateNetworkCmd.java
----------------------------------------------------------------------
diff --git a/api/src/com/cloud/api/commands/UpdateNetworkCmd.java b/api/src/com/cloud/api/commands/UpdateNetworkCmd.java
deleted file mode 100644
index b5bb48e..0000000
--- a/api/src/com/cloud/api/commands/UpdateNetworkCmd.java
+++ /dev/null
@@ -1,152 +0,0 @@
-// Licensed to the Apache Software Foundation (ASF) under one
-// or more contributor license agreements. See the NOTICE file
-// distributed with this work for additional information
-// regarding copyright ownership. The ASF licenses this file
-// to you under the Apache License, Version 2.0 (the
-// "License"); you may not use this file except in compliance
-// with 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.
-package com.cloud.api.commands;
-
-import org.apache.log4j.Logger;
-
-import org.apache.cloudstack.api.ApiConstants;
-import org.apache.cloudstack.api.BaseAsyncCmd;
-import org.apache.cloudstack.api.BaseCmd;
-import org.apache.cloudstack.api.IdentityMapper;
-import org.apache.cloudstack.api.Implementation;
-import org.apache.cloudstack.api.Parameter;
-import org.apache.cloudstack.api.ServerApiException;
-import com.cloud.api.response.NetworkResponse;
-import com.cloud.event.EventTypes;
-import com.cloud.exception.ConcurrentOperationException;
-import com.cloud.exception.InsufficientCapacityException;
-import com.cloud.exception.InvalidParameterValueException;
-import com.cloud.network.Network;
-import com.cloud.user.Account;
-import com.cloud.user.User;
-import com.cloud.user.UserContext;
-
-@Implementation(description="Updates a network", responseObject=NetworkResponse.class)
-public class UpdateNetworkCmd extends BaseAsyncCmd {
- public static final Logger s_logger = Logger.getLogger(UpdateNetworkCmd.class.getName());
-
- private static final String s_name = "updatenetworkresponse";
-
- /////////////////////////////////////////////////////
- //////////////// API parameters /////////////////////
- /////////////////////////////////////////////////////
- @IdentityMapper(entityTableName="networks")
- @Parameter(name=ApiConstants.ID, type=CommandType.LONG, required=true, description="the ID of the network")
- private Long id;
-
- @Parameter(name=ApiConstants.NAME, type=CommandType.STRING, description="the new name for the network")
- private String name;
-
- @Parameter(name=ApiConstants.DISPLAY_TEXT, type=CommandType.STRING, description="the new display text for the network")
- private String displayText;
-
- @Parameter(name=ApiConstants.NETWORK_DOMAIN, type=CommandType.STRING, description="network domain")
- private String networkDomain;
-
- @Parameter(name=ApiConstants.CHANGE_CIDR, type=CommandType.BOOLEAN, description="Force update even if cidr type is different")
- private Boolean changeCidr;
-
- @IdentityMapper(entityTableName="network_offerings")
- @Parameter(name=ApiConstants.NETWORK_OFFERING_ID, type=CommandType.LONG, description="network offering ID")
- private Long networkOfferingId;
-
- /////////////////////////////////////////////////////
- /////////////////// Accessors ///////////////////////
- /////////////////////////////////////////////////////
-
- public Long getId() {
- return id;
- }
-
- public String getNetworkName() {
- return name;
- }
-
- public String getDisplayText() {
- return displayText;
- }
-
- private String getNetworkDomain() {
- return networkDomain;
- }
-
- private Long getNetworkOfferingId() {
- return networkOfferingId;
- }
-
- public Boolean getChangeCidr() {
- if (changeCidr != null) {
- return changeCidr;
- }
- return false;
- }
- /////////////////////////////////////////////////////
- /////////////// API Implementation///////////////////
- /////////////////////////////////////////////////////
-
- @Override
- public String getCommandName() {
- return s_name;
- }
-
- @Override
- public long getEntityOwnerId() {
- Network network = _networkService.getNetwork(id);
- if (network == null) {
- throw new InvalidParameterValueException("Networkd id=" + id + " doesn't exist");
- } else {
- return _networkService.getNetwork(id).getAccountId();
- }
- }
-
- @Override
- public void execute() throws InsufficientCapacityException, ConcurrentOperationException{
- User callerUser = _accountService.getActiveUser(UserContext.current().getCallerUserId());
- Account callerAccount = _accountService.getActiveAccountById(callerUser.getAccountId());
- Network network = _networkService.getNetwork(id);
- if (network == null) {
- throw new InvalidParameterValueException("Couldn't find network by id");
- }
-
- Network result = null;
- if (network.getVpcId() != null) {
- result = _vpcService.updateVpcGuestNetwork(getId(), getNetworkName(), getDisplayText(), callerAccount,
- callerUser, getNetworkDomain(), getNetworkOfferingId(), getChangeCidr());
- } else {
- result = _networkService.updateGuestNetwork(getId(), getNetworkName(), getDisplayText(), callerAccount,
- callerUser, getNetworkDomain(), getNetworkOfferingId(), getChangeCidr());
- }
-
- if (result != null) {
- NetworkResponse response = _responseGenerator.createNetworkResponse(result);
- response.setResponseName(getCommandName());
- this.setResponseObject(response);
- } else {
- throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to update network");
- }
- }
-
- @Override
- public String getEventDescription() {
- return "Updating network: " + getId();
- }
-
- @Override
- public String getEventType() {
- return EventTypes.EVENT_NETWORK_UPDATE;
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/47ae62e4/api/src/com/cloud/configuration/ConfigurationService.java
----------------------------------------------------------------------
diff --git a/api/src/com/cloud/configuration/ConfigurationService.java b/api/src/com/cloud/configuration/ConfigurationService.java
index c4ed278..098d280 100644
--- a/api/src/com/cloud/configuration/ConfigurationService.java
+++ b/api/src/com/cloud/configuration/ConfigurationService.java
@@ -33,7 +33,7 @@ import com.cloud.api.commands.DeleteVlanIpRangeCmd;
import com.cloud.api.commands.DeleteZoneCmd;
import com.cloud.api.commands.LDAPConfigCmd;
import com.cloud.api.commands.LDAPRemoveCmd;
-import com.cloud.api.commands.ListNetworkOfferingsCmd;
+import org.apache.cloudstack.api.user.network.command.ListNetworkOfferingsCmd;
import com.cloud.api.commands.UpdateCfgCmd;
import com.cloud.api.commands.UpdateDiskOfferingCmd;
import com.cloud.api.commands.UpdateNetworkOfferingCmd;
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/47ae62e4/api/src/com/cloud/network/NetworkService.java
----------------------------------------------------------------------
diff --git a/api/src/com/cloud/network/NetworkService.java b/api/src/com/cloud/network/NetworkService.java
index 1cefbb8..b71b867 100755
--- a/api/src/com/cloud/network/NetworkService.java
+++ b/api/src/com/cloud/network/NetworkService.java
@@ -20,10 +20,10 @@ import java.util.List;
import java.util.Map;
import java.util.Set;
-import com.cloud.api.commands.CreateNetworkCmd;
-import com.cloud.api.commands.ListNetworksCmd;
+import org.apache.cloudstack.api.user.network.command.CreateNetworkCmd;
+import org.apache.cloudstack.api.user.network.command.ListNetworksCmd;
import com.cloud.api.commands.ListTrafficTypeImplementorsCmd;
-import com.cloud.api.commands.RestartNetworkCmd;
+import org.apache.cloudstack.api.user.network.command.RestartNetworkCmd;
import com.cloud.exception.ConcurrentOperationException;
import com.cloud.exception.InsufficientAddressCapacityException;
import com.cloud.exception.InsufficientCapacityException;
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/47ae62e4/api/src/com/cloud/network/firewall/NetworkACLService.java
----------------------------------------------------------------------
diff --git a/api/src/com/cloud/network/firewall/NetworkACLService.java b/api/src/com/cloud/network/firewall/NetworkACLService.java
index 2c84a20..4c0f06c 100644
--- a/api/src/com/cloud/network/firewall/NetworkACLService.java
+++ b/api/src/com/cloud/network/firewall/NetworkACLService.java
@@ -19,7 +19,7 @@ package com.cloud.network.firewall;
import java.util.List;
-import com.cloud.api.commands.ListNetworkACLsCmd;
+import org.apache.cloudstack.api.user.network.command.ListNetworkACLsCmd;
import com.cloud.exception.NetworkRuleConflictException;
import com.cloud.exception.ResourceUnavailableException;
import com.cloud.network.rules.FirewallRule;
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/47ae62e4/api/src/org/apache/cloudstack/api/user/network/command/CreateNetworkACLCmd.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/api/user/network/command/CreateNetworkACLCmd.java b/api/src/org/apache/cloudstack/api/user/network/command/CreateNetworkACLCmd.java
new file mode 100644
index 0000000..89d5c85
--- /dev/null
+++ b/api/src/org/apache/cloudstack/api/user/network/command/CreateNetworkACLCmd.java
@@ -0,0 +1,328 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with 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.
+package org.apache.cloudstack.api.user.network.command;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.log4j.Logger;
+
+import org.apache.cloudstack.api.ApiConstants;
+import org.apache.cloudstack.api.BaseAsyncCmd;
+import org.apache.cloudstack.api.BaseAsyncCreateCmd;
+import org.apache.cloudstack.api.BaseCmd;
+import org.apache.cloudstack.api.IdentityMapper;
+import org.apache.cloudstack.api.Implementation;
+import org.apache.cloudstack.api.Parameter;
+import org.apache.cloudstack.api.ServerApiException;
+import com.cloud.api.response.NetworkACLResponse;
+import com.cloud.async.AsyncJob;
+import com.cloud.event.EventTypes;
+import com.cloud.exception.InvalidParameterValueException;
+import com.cloud.exception.NetworkRuleConflictException;
+import com.cloud.exception.ResourceUnavailableException;
+import com.cloud.network.Network;
+import com.cloud.network.rules.FirewallRule;
+import com.cloud.network.vpc.Vpc;
+import com.cloud.user.Account;
+import com.cloud.user.UserContext;
+import com.cloud.utils.net.NetUtils;
+
+@Implementation(description = "Creates a ACL rule the given network (the network has to belong to VPC)",
+responseObject = NetworkACLResponse.class)
+public class CreateNetworkACLCmd extends BaseAsyncCreateCmd implements FirewallRule {
+ public static final Logger s_logger = Logger.getLogger(CreateNetworkACLCmd.class.getName());
+
+ private static final String s_name = "createnetworkaclresponse";
+
+ // ///////////////////////////////////////////////////
+ // ////////////// API parameters /////////////////////
+ // ///////////////////////////////////////////////////
+
+ @Parameter(name = ApiConstants.PROTOCOL, type = CommandType.STRING, required = true, description =
+ "the protocol for the ACL rule. Valid values are TCP/UDP/ICMP.")
+ private String protocol;
+
+ @Parameter(name = ApiConstants.START_PORT, type = CommandType.INTEGER, description = "the starting port of ACL")
+ private Integer publicStartPort;
+
+ @Parameter(name = ApiConstants.END_PORT, type = CommandType.INTEGER, description = "the ending port of ACL")
+ private Integer publicEndPort;
+
+ @Parameter(name = ApiConstants.CIDR_LIST, type = CommandType.LIST, collectionType = CommandType.STRING,
+ description = "the cidr list to allow traffic from/to")
+ private List<String> cidrlist;
+
+ @Parameter(name = ApiConstants.ICMP_TYPE, type = CommandType.INTEGER, description = "type of the icmp message being sent")
+ private Integer icmpType;
+
+ @Parameter(name = ApiConstants.ICMP_CODE, type = CommandType.INTEGER, description = "error code for this icmp message")
+ private Integer icmpCode;
+
+ @IdentityMapper(entityTableName="networks")
+ @Parameter(name=ApiConstants.NETWORK_ID, type=CommandType.LONG, required=true,
+ description="The network of the vm the ACL will be created for")
+ private Long networkId;
+
+ @Parameter(name=ApiConstants.TRAFFIC_TYPE, type=CommandType.STRING, description="the traffic type for the ACL," +
+ "can be Ingress or Egress, defaulted to Ingress if not specified")
+ private String trafficType;
+
+ // ///////////////////////////////////////////////////
+ // ///////////////// Accessors ///////////////////////
+ // ///////////////////////////////////////////////////
+
+ public String getEntityTable() {
+ return "firewall_rules";
+ }
+
+ public Long getIpAddressId() {
+ return null;
+ }
+
+ @Override
+ public String getProtocol() {
+ return protocol.trim();
+ }
+
+ public List<String> getSourceCidrList() {
+ if (cidrlist != null) {
+ return cidrlist;
+ } else {
+ List<String> oneCidrList = new ArrayList<String>();
+ oneCidrList.add(NetUtils.ALL_CIDRS);
+ return oneCidrList;
+ }
+ }
+
+ public long getVpcId() {
+ Network network = _networkService.getNetwork(getNetworkId());
+ if (network == null) {
+ throw new InvalidParameterValueException("Invalid networkId is given");
+ }
+
+ Long vpcId = network.getVpcId();
+ if (vpcId == null) {
+ throw new InvalidParameterValueException("Can create network ACL only for the network belonging to the VPC");
+ }
+
+ return vpcId;
+ }
+
+ @Override
+ public FirewallRule.TrafficType getTrafficType() {
+ if (trafficType == null) {
+ return FirewallRule.TrafficType.Ingress;
+ }
+ for (FirewallRule.TrafficType type : FirewallRule.TrafficType.values()) {
+ if (type.toString().equalsIgnoreCase(trafficType)) {
+ return type;
+ }
+ }
+ throw new InvalidParameterValueException("Invalid traffic type " + trafficType);
+ }
+
+ // ///////////////////////////////////////////////////
+ // ///////////// API Implementation///////////////////
+ // ///////////////////////////////////////////////////
+
+ @Override
+ public String getCommandName() {
+ return s_name;
+ }
+
+ public void setSourceCidrList(List<String> cidrs){
+ cidrlist = cidrs;
+ }
+
+ @Override
+ public void execute() throws ResourceUnavailableException {
+ UserContext callerContext = UserContext.current();
+ boolean success = false;
+ FirewallRule rule = _networkACLService.getNetworkACL(getEntityId());
+ try {
+ UserContext.current().setEventDetails("Rule Id: " + getEntityId());
+ success = _networkACLService.applyNetworkACLs(rule.getNetworkId(), callerContext.getCaller());
+
+ // State is different after the rule is applied, so get new object here
+ NetworkACLResponse aclResponse = new NetworkACLResponse();
+ if (rule != null) {
+ aclResponse = _responseGenerator.createNetworkACLResponse(rule);
+ setResponseObject(aclResponse);
+ }
+ aclResponse.setResponseName(getCommandName());
+ } finally {
+ if (!success || rule == null) {
+ _networkACLService.revokeNetworkACL(getEntityId(), true);
+ throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to create network ACL");
+ }
+ }
+ }
+
+ @Override
+ public long getId() {
+ throw new UnsupportedOperationException("database id can only provided by VO objects");
+ }
+
+ @Override
+ public String getXid() {
+ // FIXME: We should allow for end user to specify Xid.
+ return null;
+ }
+
+ @Override
+ public Long getSourceIpAddressId() {
+ return null;
+ }
+
+ @Override
+ public Integer getSourcePortStart() {
+ if (publicStartPort != null) {
+ return publicStartPort.intValue();
+ }
+ return null;
+ }
+
+ @Override
+ public Integer getSourcePortEnd() {
+ if (publicEndPort == null) {
+ if (publicStartPort != null) {
+ return publicStartPort.intValue();
+ }
+ } else {
+ return publicEndPort.intValue();
+ }
+
+ return null;
+ }
+
+ @Override
+ public Purpose getPurpose() {
+ return Purpose.Firewall;
+ }
+
+ @Override
+ public State getState() {
+ throw new UnsupportedOperationException("Should never call me to find the state");
+ }
+
+ @Override
+ public long getNetworkId() {
+ return networkId;
+ }
+
+ @Override
+ public long getEntityOwnerId() {
+ Vpc vpc = _vpcService.getVpc(getVpcId());
+ if (vpc == null) {
+ throw new InvalidParameterValueException("Invalid vpcId is given");
+ }
+
+ Account account = _accountService.getAccount(vpc.getAccountId());
+ return account.getId();
+ }
+
+ @Override
+ public long getDomainId() {
+ Vpc vpc = _vpcService.getVpc(getVpcId());
+ return vpc.getDomainId();
+ }
+
+ @Override
+ public void create() {
+ if (getSourceCidrList() != null) {
+ for (String cidr: getSourceCidrList()){
+ if (!NetUtils.isValidCIDR(cidr)){
+ throw new ServerApiException(BaseCmd.PARAM_ERROR, "Source cidrs formatting error " + cidr);
+ }
+ }
+ }
+
+ try {
+ FirewallRule result = _networkACLService.createNetworkACL(this);
+ setEntityId(result.getId());
+ } catch (NetworkRuleConflictException ex) {
+ s_logger.info("Network rule conflict: " + ex.getMessage());
+ s_logger.trace("Network Rule Conflict: ", ex);
+ throw new ServerApiException(BaseCmd.NETWORK_RULE_CONFLICT_ERROR, ex.getMessage());
+ }
+ }
+
+ @Override
+ public String getEventType() {
+ return EventTypes.EVENT_FIREWALL_OPEN;
+ }
+
+ @Override
+ public String getEventDescription() {
+ Network network = _networkService.getNetwork(networkId);
+ return ("Createing Network ACL for Netowrk: " + network + " for protocol:" + this.getProtocol());
+ }
+
+ @Override
+ public long getAccountId() {
+ Vpc vpc = _vpcService.getVpc(getVpcId());
+ return vpc.getAccountId();
+ }
+
+ @Override
+ public String getSyncObjType() {
+ return BaseAsyncCmd.networkSyncObject;
+ }
+
+ @Override
+ public Long getSyncObjId() {
+ return getNetworkId();
+ }
+
+ @Override
+ public Integer getIcmpCode() {
+ if (icmpCode != null) {
+ return icmpCode;
+ } else if (protocol.equalsIgnoreCase(NetUtils.ICMP_PROTO)) {
+ return -1;
+ }
+ return null;
+ }
+
+ @Override
+ public Integer getIcmpType() {
+ if (icmpType != null) {
+ return icmpType;
+ } else if (protocol.equalsIgnoreCase(NetUtils.ICMP_PROTO)) {
+ return -1;
+
+ }
+ return null;
+ }
+
+ @Override
+ public Long getRelated() {
+ return null;
+ }
+
+ @Override
+ public FirewallRuleType getType() {
+ return FirewallRuleType.User;
+ }
+
+ @Override
+ public AsyncJob.Type getInstanceType() {
+ return AsyncJob.Type.FirewallRule;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/47ae62e4/api/src/org/apache/cloudstack/api/user/network/command/CreateNetworkCmd.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/api/user/network/command/CreateNetworkCmd.java b/api/src/org/apache/cloudstack/api/user/network/command/CreateNetworkCmd.java
new file mode 100644
index 0000000..cfa71dd
--- /dev/null
+++ b/api/src/org/apache/cloudstack/api/user/network/command/CreateNetworkCmd.java
@@ -0,0 +1,234 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with 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.
+package org.apache.cloudstack.api.user.network.command;
+
+import org.apache.log4j.Logger;
+
+import org.apache.cloudstack.api.ApiConstants;
+import org.apache.cloudstack.api.BaseCmd;
+import org.apache.cloudstack.api.IdentityMapper;
+import org.apache.cloudstack.api.Implementation;
+import org.apache.cloudstack.api.Parameter;
+import org.apache.cloudstack.api.ServerApiException;
+import com.cloud.api.response.NetworkResponse;
+import com.cloud.exception.ConcurrentOperationException;
+import com.cloud.exception.InsufficientCapacityException;
+import com.cloud.exception.InvalidParameterValueException;
+import com.cloud.exception.ResourceAllocationException;
+import com.cloud.network.Network;
+import com.cloud.network.Network.GuestType;
+import com.cloud.offering.NetworkOffering;
+import com.cloud.user.UserContext;
+
+@Implementation(description="Creates a network", responseObject=NetworkResponse.class)
+public class CreateNetworkCmd extends BaseCmd {
+ public static final Logger s_logger = Logger.getLogger(CreateNetworkCmd.class.getName());
+
+ private static final String s_name = "createnetworkresponse";
+
+ /////////////////////////////////////////////////////
+ //////////////// API parameters /////////////////////
+ /////////////////////////////////////////////////////
+
+ @Parameter(name=ApiConstants.NAME, type=CommandType.STRING, required=true, description="the name of the network")
+ private String name;
+
+ @Parameter(name=ApiConstants.DISPLAY_TEXT, type=CommandType.STRING, required=true, description="the display text of the network")
+ private String displayText;
+
+ @IdentityMapper(entityTableName="network_offerings")
+ @Parameter(name=ApiConstants.NETWORK_OFFERING_ID, type=CommandType.LONG, required=true, description="the network offering id")
+ private Long networkOfferingId;
+
+ @IdentityMapper(entityTableName="data_center")
+ @Parameter(name=ApiConstants.ZONE_ID, type=CommandType.LONG, required=true, description="the Zone ID for the network")
+ private Long zoneId;
+
+ @IdentityMapper(entityTableName="physical_network")
+ @Parameter(name=ApiConstants.PHYSICAL_NETWORK_ID, type=CommandType.LONG, description="the Physical Network ID the network belongs to")
+ private Long physicalNetworkId;
+
+ @Parameter(name=ApiConstants.GATEWAY, type=CommandType.STRING, description="the gateway of the network. Required " +
+ "for Shared networks and Isolated networks when it belongs to VPC")
+ private String gateway;
+
+ @Parameter(name=ApiConstants.NETMASK, type=CommandType.STRING, description="the netmask of the network. Required " +
+ "for Shared networks and Isolated networks when it belongs to VPC")
+ private String netmask;
+
+ @Parameter(name=ApiConstants.START_IP, type=CommandType.STRING, description="the beginning IP address in the network IP range")
+ private String startIp;
+
+ @Parameter(name=ApiConstants.END_IP, type=CommandType.STRING, description="the ending IP address in the network IP" +
+ " range. If not specified, will be defaulted to startIP")
+ private String endIp;
+
+ @Parameter(name=ApiConstants.VLAN, type=CommandType.STRING, description="the ID or VID of the network")
+ private String vlan;
+
+ @Parameter(name=ApiConstants.NETWORK_DOMAIN, type=CommandType.STRING, description="network domain")
+ private String networkDomain;
+
+ @Parameter(name=ApiConstants.ACL_TYPE, type=CommandType.STRING, description="Access control type; supported values" +
+ " are account and domain. In 3.0 all shared networks should have aclType=Domain, and all Isolated networks" +
+ " - Account. Account means that only the account owner can use the network, domain - all accouns in the domain can use the network")
+ private String aclType;
+
+ @Parameter(name=ApiConstants.ACCOUNT, type=CommandType.STRING, description="account who will own the network")
+ private String accountName;
+
+ @IdentityMapper(entityTableName="projects")
+ @Parameter(name=ApiConstants.PROJECT_ID, type=CommandType.LONG, description="an optional project for the ssh key")
+ private Long projectId;
+
+ @IdentityMapper(entityTableName="domain")
+ @Parameter(name=ApiConstants.DOMAIN_ID, type=CommandType.LONG, description="domain ID of the account owning a network")
+ private Long domainId;
+
+ @Parameter(name=ApiConstants.SUBDOMAIN_ACCESS, type=CommandType.BOOLEAN, description="Defines whether to allow" +
+ " subdomains to use networks dedicated to their parent domain(s). Should be used with aclType=Domain, defaulted to allow.subdomain.network.access global config if not specified")
+ private Boolean subdomainAccess;
+
+ @IdentityMapper(entityTableName="vpc")
+ @Parameter(name=ApiConstants.VPC_ID, type=CommandType.LONG, description="the VPC network belongs to")
+ private Long vpcId;
+
+
+ /////////////////////////////////////////////////////
+ /////////////////// Accessors ///////////////////////
+ /////////////////////////////////////////////////////
+ public Long getNetworkOfferingId() {
+ return networkOfferingId;
+ }
+
+ public String getGateway() {
+ return gateway;
+ }
+
+ public String getVlan() {
+ return vlan;
+ }
+
+ public String getAccountName() {
+ return accountName;
+ }
+
+ public Long getDomainId() {
+ return domainId;
+ }
+
+ public String getNetmask() {
+ return netmask;
+ }
+
+ public String getStartIp() {
+ return startIp;
+ }
+
+ public String getEndIp() {
+ return endIp;
+ }
+
+ public String getNetworkName() {
+ return name;
+ }
+
+ public String getDisplayText() {
+ return displayText;
+ }
+
+ public String getNetworkDomain() {
+ return networkDomain;
+ }
+
+ public Long getProjectId() {
+ return projectId;
+ }
+
+ public String getAclType() {
+ return aclType;
+ }
+
+ public Boolean getSubdomainAccess() {
+ return subdomainAccess;
+ }
+
+ public Long getVpcId() {
+ return vpcId;
+ }
+
+ public Long getZoneId() {
+ Long physicalNetworkId = getPhysicalNetworkId();
+
+ if (physicalNetworkId == null && zoneId == null) {
+ throw new InvalidParameterValueException("Zone id is required");
+ }
+
+ return zoneId;
+ }
+
+ public Long getPhysicalNetworkId() {
+ NetworkOffering offering = _configService.getNetworkOffering(networkOfferingId);
+ if (offering == null) {
+ throw new InvalidParameterValueException("Unable to find network offering by id " + networkOfferingId);
+ }
+
+ if (physicalNetworkId != null) {
+ if (offering.getGuestType() == GuestType.Shared) {
+ return physicalNetworkId;
+ } else {
+ throw new InvalidParameterValueException("Physical network id can be specified for networks of guest ip type " + GuestType.Shared + " only.");
+ }
+ } else {
+ if (zoneId == null) {
+ throw new InvalidParameterValueException("ZoneId is required as physicalNetworkId is null");
+ }
+ return _networkService.findPhysicalNetworkId(zoneId, offering.getTags(), offering.getTrafficType());
+ }
+ }
+
+ /////////////////////////////////////////////////////
+ /////////////// API Implementation///////////////////
+ /////////////////////////////////////////////////////
+ @Override
+ public String getCommandName() {
+ return s_name;
+ }
+
+ @Override
+ public long getEntityOwnerId() {
+ Long accountId = finalyzeAccountId(accountName, domainId, projectId, true);
+ if (accountId == null) {
+ return UserContext.current().getCaller().getId();
+ }
+
+ return accountId;
+ }
+
+ @Override
+ // an exception thrown by createNetwork() will be caught by the dispatcher.
+ public void execute() throws InsufficientCapacityException, ConcurrentOperationException, ResourceAllocationException{
+ Network result = _networkService.createGuestNetwork(this);
+ if (result != null) {
+ NetworkResponse response = _responseGenerator.createNetworkResponse(result);
+ response.setResponseName(getCommandName());
+ this.setResponseObject(response);
+ }else {
+ throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to create network");
+ }
+ }
+}