|
| 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 java.util.List; |
| 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.BaseCmd; |
| 25 | +import org.apache.cloudstack.api.Parameter; |
| 26 | +import org.apache.cloudstack.api.ServerApiException; |
| 27 | +import org.apache.cloudstack.api.response.NetworkOfferingResponse; |
| 28 | + |
| 29 | +import com.cloud.offering.NetworkOffering; |
| 30 | + |
| 31 | +@APICommand(name = "cloneNetworkOffering", |
| 32 | + description = "Clones a network offering. All parameters are copied from the source offering unless explicitly overridden. " + |
| 33 | + "Use 'addServices' and 'dropServices' to modify the service list without respecifying everything.", |
| 34 | + responseObject = NetworkOfferingResponse.class, |
| 35 | + requestHasSensitiveInfo = false, |
| 36 | + responseHasSensitiveInfo = false, |
| 37 | + since = "4.23.0") |
| 38 | +public class CloneNetworkOfferingCmd extends CreateNetworkOfferingCmd { |
| 39 | + |
| 40 | + ///////////////////////////////////////////////////// |
| 41 | + //////////////// API parameters ///////////////////// |
| 42 | + ///////////////////////////////////////////////////// |
| 43 | + |
| 44 | + @Parameter(name = ApiConstants.SOURCE_OFFERING_ID, |
| 45 | + type = BaseCmd.CommandType.UUID, |
| 46 | + entityType = NetworkOfferingResponse.class, |
| 47 | + required = true, |
| 48 | + description = "The ID of the network offering to clone") |
| 49 | + private Long sourceOfferingId; |
| 50 | + |
| 51 | + @Parameter(name = "addservices", |
| 52 | + type = CommandType.LIST, |
| 53 | + collectionType = CommandType.STRING, |
| 54 | + description = "Services to add to the cloned offering (in addition to source offering services). " + |
| 55 | + "If specified along with 'supportedservices', this parameter is ignored.") |
| 56 | + private List<String> addServices; |
| 57 | + |
| 58 | + @Parameter(name = "dropservices", |
| 59 | + type = CommandType.LIST, |
| 60 | + collectionType = CommandType.STRING, |
| 61 | + description = "Services to remove from the cloned offering (that exist in source offering). " + |
| 62 | + "If specified along with 'supportedservices', this parameter is ignored.") |
| 63 | + private List<String> dropServices; |
| 64 | + |
| 65 | + ///////////////////////////////////////////////////// |
| 66 | + /////////////////// Accessors /////////////////////// |
| 67 | + ///////////////////////////////////////////////////// |
| 68 | + |
| 69 | + public Long getSourceOfferingId() { |
| 70 | + return sourceOfferingId; |
| 71 | + } |
| 72 | + |
| 73 | + public List<String> getAddServices() { |
| 74 | + return addServices; |
| 75 | + } |
| 76 | + |
| 77 | + public List<String> getDropServices() { |
| 78 | + return dropServices; |
| 79 | + } |
| 80 | + |
| 81 | + ///////////////////////////////////////////////////// |
| 82 | + /////////////// API Implementation/////////////////// |
| 83 | + ///////////////////////////////////////////////////// |
| 84 | + |
| 85 | + @Override |
| 86 | + public void execute() { |
| 87 | + NetworkOffering result = _configService.cloneNetworkOffering(this); |
| 88 | + if (result != null) { |
| 89 | + NetworkOfferingResponse response = _responseGenerator.createNetworkOfferingResponse(result); |
| 90 | + response.setResponseName(getCommandName()); |
| 91 | + this.setResponseObject(response); |
| 92 | + } else { |
| 93 | + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to clone network offering"); |
| 94 | + } |
| 95 | + } |
| 96 | +} |
| 97 | + |
0 commit comments