|
| 1 | +// Copyright 2012 Citrix Systems, Inc. Licensed under the |
| 2 | +// Apache License, Version 2.0 (the "License"); you may not use this |
| 3 | +// file except in compliance with the License. Citrix Systems, Inc. |
| 4 | +// reserves all rights not expressly granted by the License. |
| 5 | +// You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 |
| 6 | +// Unless required by applicable law or agreed to in writing, software |
| 7 | +// distributed under the License is distributed on an "AS IS" BASIS, |
| 8 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 9 | +// See the License for the specific language governing permissions and |
| 10 | +// limitations under the License. |
| 11 | +// |
| 12 | +// Automatically generated by addcopyright.py at 04/03/2012 |
| 13 | +package com.cloud.api.commands; |
| 14 | + |
| 15 | +import org.apache.log4j.Logger; |
| 16 | + |
| 17 | +import com.cloud.api.ApiConstants; |
| 18 | +import com.cloud.api.BaseAsyncCreateCmd; |
| 19 | +import com.cloud.api.BaseCmd; |
| 20 | +import com.cloud.api.IdentityMapper; |
| 21 | +import com.cloud.api.Implementation; |
| 22 | +import com.cloud.api.Parameter; |
| 23 | +import com.cloud.api.ServerApiException; |
| 24 | +import com.cloud.api.response.PrivateGatewayResponse; |
| 25 | +import com.cloud.event.EventTypes; |
| 26 | +import com.cloud.exception.ConcurrentOperationException; |
| 27 | +import com.cloud.exception.InsufficientCapacityException; |
| 28 | +import com.cloud.exception.ResourceAllocationException; |
| 29 | +import com.cloud.exception.ResourceUnavailableException; |
| 30 | +import com.cloud.network.vpc.PrivateGateway; |
| 31 | +import com.cloud.user.Account; |
| 32 | + |
| 33 | +/** |
| 34 | + * @author Alena Prokharchyk |
| 35 | + */ |
| 36 | +@Implementation(description="Creates a private gateway", responseObject=PrivateGatewayResponse.class) |
| 37 | +public class CreatePrivateGatewayCmd extends BaseAsyncCreateCmd { |
| 38 | + public static final Logger s_logger = Logger.getLogger(CreatePrivateGatewayCmd.class.getName()); |
| 39 | + |
| 40 | + private static final String s_name = "createprivategatewayresponse"; |
| 41 | + |
| 42 | + ///////////////////////////////////////////////////// |
| 43 | + //////////////// API parameters ///////////////////// |
| 44 | + ///////////////////////////////////////////////////// |
| 45 | + |
| 46 | + @IdentityMapper(entityTableName="physical_network") |
| 47 | + @Parameter(name=ApiConstants.PHYSICAL_NETWORK_ID, type=CommandType.LONG, description="the Physical Network ID the network belongs to") |
| 48 | + private Long physicalNetworkId; |
| 49 | + |
| 50 | + @Parameter(name=ApiConstants.GATEWAY, type=CommandType.STRING, required=true, description="the gateway of the Private gateway") |
| 51 | + private String gateway; |
| 52 | + |
| 53 | + @Parameter(name=ApiConstants.NETMASK, type=CommandType.STRING, required=true, description="the netmask of the Private gateway") |
| 54 | + private String netmask; |
| 55 | + |
| 56 | + @Parameter(name=ApiConstants.IP_ADDRESS, type=CommandType.STRING, required=true, description="the IP address of the Private gateaway") |
| 57 | + private String ipAddress; |
| 58 | + |
| 59 | + @Parameter(name=ApiConstants.VLAN, type=CommandType.STRING, required=true, description="the Vlan for the private gateway") |
| 60 | + private String vlan; |
| 61 | + |
| 62 | + @IdentityMapper(entityTableName="vpc") |
| 63 | + @Parameter(name=ApiConstants.VPC_ID, type=CommandType.LONG, required=true, description="the VPC network belongs to") |
| 64 | + private Long vpcId; |
| 65 | + |
| 66 | + ///////////////////////////////////////////////////// |
| 67 | + /////////////////// Accessors /////////////////////// |
| 68 | + ///////////////////////////////////////////////////// |
| 69 | + |
| 70 | + public String getGateway() { |
| 71 | + return gateway; |
| 72 | + } |
| 73 | + |
| 74 | + public String getVlan() { |
| 75 | + return vlan; |
| 76 | + } |
| 77 | + |
| 78 | + public String getNetmask() { |
| 79 | + return netmask; |
| 80 | + } |
| 81 | + |
| 82 | + public String getStartIp() { |
| 83 | + return ipAddress; |
| 84 | + } |
| 85 | + |
| 86 | + public Long getPhysicalNetworkId() { |
| 87 | + return physicalNetworkId; |
| 88 | + } |
| 89 | + |
| 90 | + public Long getVpcId() { |
| 91 | + return vpcId; |
| 92 | + } |
| 93 | + |
| 94 | + ///////////////////////////////////////////////////// |
| 95 | + /////////////// API Implementation/////////////////// |
| 96 | + ///////////////////////////////////////////////////// |
| 97 | + @Override |
| 98 | + public String getCommandName() { |
| 99 | + return s_name; |
| 100 | + } |
| 101 | + |
| 102 | + |
| 103 | + @Override |
| 104 | + public void create() throws ResourceAllocationException { |
| 105 | + PrivateGateway result = null; |
| 106 | + try { |
| 107 | + result = _vpcService.createVpcPrivateGateway(getVpcId(), getPhysicalNetworkId(), |
| 108 | + getVlan(), getStartIp(), getGateway(), getNetmask(), getEntityOwnerId()); |
| 109 | + } catch (InsufficientCapacityException ex){ |
| 110 | + s_logger.info(ex); |
| 111 | + s_logger.trace(ex); |
| 112 | + throw new ServerApiException(BaseCmd.INSUFFICIENT_CAPACITY_ERROR, ex.getMessage()); |
| 113 | + } catch (ConcurrentOperationException ex) { |
| 114 | + s_logger.warn("Exception: ", ex); |
| 115 | + throw new ServerApiException(BaseCmd.INTERNAL_ERROR, ex.getMessage()); |
| 116 | + } |
| 117 | + |
| 118 | + if (result != null) { |
| 119 | + this.setEntityId(result.getId()); |
| 120 | + } else { |
| 121 | + throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to create private gateway"); |
| 122 | + } |
| 123 | + } |
| 124 | + |
| 125 | + @Override |
| 126 | + public void execute() throws InsufficientCapacityException, ConcurrentOperationException, |
| 127 | + ResourceAllocationException, ResourceUnavailableException { |
| 128 | + PrivateGateway result = _vpcService.applyVpcGateway(getEntityId()); |
| 129 | + if (result != null) { |
| 130 | + PrivateGatewayResponse response = _responseGenerator.createPrivateGatewayResponseResponse(result); |
| 131 | + response.setResponseName(getCommandName()); |
| 132 | + this.setResponseObject(response); |
| 133 | + } else { |
| 134 | + throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to create private gateway"); |
| 135 | + } |
| 136 | + } |
| 137 | + |
| 138 | + @Override |
| 139 | + public long getEntityOwnerId() { |
| 140 | + return Account.ACCOUNT_ID_SYSTEM; |
| 141 | + } |
| 142 | + |
| 143 | + @Override |
| 144 | + public String getEventType() { |
| 145 | + return EventTypes.EVENT_PRIVATE_GATEWAY_CREATE; |
| 146 | + } |
| 147 | + |
| 148 | + @Override |
| 149 | + public String getEventDescription() { |
| 150 | + return "creating private gateway"; |
| 151 | + |
| 152 | + } |
| 153 | + |
| 154 | + @Override |
| 155 | + public String getEntityTable() { |
| 156 | + return "vpc_gateways"; |
| 157 | + } |
| 158 | +} |
0 commit comments