|
| 1 | +// Licensed to the Apache Software Foundation (ASF) under one |
| 2 | +// or more contributor license agreements. See the NOTICE file |
| 3 | +// distributed with this work for additional information |
| 4 | +// regarding copyright ownership. The ASF licenses this file |
| 5 | +// to you under the Apache License, Version 2.0 (the |
| 6 | +// "License"); you may not use this file except in compliance |
| 7 | +// with the License. You may obtain a copy of the License at |
| 8 | +// |
| 9 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | +// |
| 11 | +// Unless required by applicable law or agreed to in writing, |
| 12 | +// software distributed under the License is distributed on an |
| 13 | +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 14 | +// KIND, either express or implied. See the License for the |
| 15 | +// specific language governing permissions and limitations |
| 16 | +// under the License. |
| 17 | +package org.apache.cloudstack.api.command.admin.network; |
| 18 | + |
| 19 | +import org.apache.log4j.Logger; |
| 20 | + |
| 21 | +import org.apache.cloudstack.api.APICommand; |
| 22 | +import org.apache.cloudstack.api.ApiConstants; |
| 23 | +import org.apache.cloudstack.api.ApiErrorCode; |
| 24 | +import org.apache.cloudstack.api.Parameter; |
| 25 | +import org.apache.cloudstack.api.ResponseObject.ResponseView; |
| 26 | +import org.apache.cloudstack.api.ServerApiException; |
| 27 | +import org.apache.cloudstack.api.command.user.network.CreateNetworkCmd; |
| 28 | +import org.apache.cloudstack.api.response.NetworkResponse; |
| 29 | + |
| 30 | +import com.cloud.exception.ConcurrentOperationException; |
| 31 | +import com.cloud.exception.InsufficientCapacityException; |
| 32 | +import com.cloud.exception.ResourceAllocationException; |
| 33 | +import com.cloud.network.Network; |
| 34 | + |
| 35 | +@APICommand(name = "createNetwork", description = "Creates a network", responseObject = NetworkResponse.class, responseView = ResponseView.Full) |
| 36 | +public class CreateNetworkCmdByAdmin extends CreateNetworkCmd { |
| 37 | + public static final Logger s_logger = Logger.getLogger(CreateNetworkCmdByAdmin.class.getName()); |
| 38 | + |
| 39 | + @Parameter(name=ApiConstants.VLAN, type=CommandType.STRING, description="the ID or VID of the network") |
| 40 | + private String vlan; |
| 41 | + |
| 42 | + ///////////////////////////////////////////////////// |
| 43 | + /////////////////// Accessors /////////////////////// |
| 44 | + ///////////////////////////////////////////////////// |
| 45 | + |
| 46 | + public String getVlan() { |
| 47 | + return vlan; |
| 48 | + } |
| 49 | + |
| 50 | + ///////////////////////////////////////////////////// |
| 51 | + /////////////// API Implementation/////////////////// |
| 52 | + ///////////////////////////////////////////////////// |
| 53 | + |
| 54 | + @Override |
| 55 | + // an exception thrown by createNetwork() will be caught by the dispatcher. |
| 56 | + public void execute() throws InsufficientCapacityException, ConcurrentOperationException, ResourceAllocationException{ |
| 57 | + Network result = _networkService.createGuestNetwork(this); |
| 58 | + if (result != null) { |
| 59 | + NetworkResponse response = _responseGenerator.createNetworkResponse(ResponseView.Full, result); |
| 60 | + response.setResponseName(getCommandName()); |
| 61 | + setResponseObject(response); |
| 62 | + }else { |
| 63 | + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to create network"); |
| 64 | + } |
| 65 | + } |
| 66 | +} |
0 commit comments