|
| 1 | +// |
| 2 | +// Licensed to the Apache Software Foundation (ASF) under one |
| 3 | +// or more contributor license agreements. See the NOTICE file |
| 4 | +// distributed with this work for additional information |
| 5 | +// regarding copyright ownership. The ASF licenses this file |
| 6 | +// to you under the Apache License, Version 2.0 (the |
| 7 | +// "License"); you may not use this file except in compliance |
| 8 | +// with the License. You may obtain a copy of the License at |
| 9 | +// |
| 10 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | +// |
| 12 | +// Unless required by applicable law or agreed to in writing, |
| 13 | +// software distributed under the License is distributed on an |
| 14 | +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 15 | +// KIND, either express or implied. See the License for the |
| 16 | +// specific language governing permissions and limitations |
| 17 | +// under the License. |
| 18 | +// |
| 19 | + |
| 20 | +package com.cloud.api.commands; |
| 21 | + |
| 22 | +import com.cloud.api.response.NuageVspDomainTemplateResponse; |
| 23 | +import com.cloud.exception.ConcurrentOperationException; |
| 24 | +import com.cloud.exception.InsufficientCapacityException; |
| 25 | +import com.cloud.exception.InvalidParameterValueException; |
| 26 | +import com.cloud.exception.ResourceAllocationException; |
| 27 | +import com.cloud.exception.ResourceUnavailableException; |
| 28 | +import com.cloud.network.manager.NuageVspManager; |
| 29 | +import com.cloud.utils.exception.CloudRuntimeException; |
| 30 | +import org.apache.cloudstack.acl.RoleType; |
| 31 | +import org.apache.cloudstack.api.APICommand; |
| 32 | +import org.apache.cloudstack.api.ApiConstants; |
| 33 | +import org.apache.cloudstack.api.ApiErrorCode; |
| 34 | +import org.apache.cloudstack.api.BaseCmd; |
| 35 | +import org.apache.cloudstack.api.BaseResponse; |
| 36 | +import org.apache.cloudstack.api.Parameter; |
| 37 | +import org.apache.cloudstack.api.ServerApiException; |
| 38 | +import org.apache.cloudstack.api.response.DomainResponse; |
| 39 | +import org.apache.cloudstack.api.response.ListResponse; |
| 40 | +import org.apache.cloudstack.api.response.PhysicalNetworkResponse; |
| 41 | +import org.apache.cloudstack.api.response.ZoneResponse; |
| 42 | + |
| 43 | +import javax.inject.Inject; |
| 44 | +import java.util.List; |
| 45 | + |
| 46 | +@APICommand(name = ListNuageVspDomainTemplatesCmd.APINAME, responseObject = BaseResponse.class, description = "Lists Nuage VSP domain templates", since = "4.11", responseHasSensitiveInfo = false, authorized = {RoleType.Admin, RoleType.DomainAdmin, RoleType.User}) |
| 47 | +public class ListNuageVspDomainTemplatesCmd extends BaseCmd { |
| 48 | + static final String APINAME = "listNuageVspDomainTemplates"; |
| 49 | + |
| 50 | + @Inject |
| 51 | + private NuageVspManager _nuageVspManager; |
| 52 | + |
| 53 | + ///////////////////////////////////////////////////// |
| 54 | + //////////////// API parameters ///////////////////// |
| 55 | + ///////////////////////////////////////////////////// |
| 56 | + |
| 57 | + @Parameter(name = ApiConstants.DOMAIN_ID, type = CommandType.UUID, entityType = DomainResponse.class, |
| 58 | + description = "the domain ID") |
| 59 | + private Long domainId; |
| 60 | + |
| 61 | + @Parameter(name = ApiConstants.PHYSICAL_NETWORK_ID, type = CommandType.UUID, entityType = PhysicalNetworkResponse.class, |
| 62 | + description = "the physical network ID") |
| 63 | + private Long physicalNetworkId; |
| 64 | + |
| 65 | + @Parameter(name = ApiConstants.ZONE_ID, type = CommandType.UUID, entityType = ZoneResponse.class, |
| 66 | + description = "the zone ID") |
| 67 | + private Long zoneId; |
| 68 | + |
| 69 | + @Parameter(name = ApiConstants.KEYWORD, type = CommandType.STRING, |
| 70 | + description = "filters the domain templates which contain the keyword") |
| 71 | + private String keyword; |
| 72 | + |
| 73 | + ///////////////////////////////////////////////////// |
| 74 | + /////////////////// Accessors /////////////////////// |
| 75 | + ///////////////////////////////////////////////////// |
| 76 | + |
| 77 | + public String getKeyword() { |
| 78 | + return keyword; |
| 79 | + } |
| 80 | + |
| 81 | + public Long getDomainId() { |
| 82 | + return domainId; |
| 83 | + } |
| 84 | + |
| 85 | + public Long getPhysicalNetworkId() { |
| 86 | + return physicalNetworkId; |
| 87 | + } |
| 88 | + |
| 89 | + public Long getZoneId() { return zoneId; } |
| 90 | + |
| 91 | + ///////////////////////////////////////////////////// |
| 92 | + /////////////// API Implementation/////////////////// |
| 93 | + ///////////////////////////////////////////////////// |
| 94 | + |
| 95 | + @Override |
| 96 | + public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException, ResourceAllocationException { |
| 97 | + try { |
| 98 | + List<NuageVspDomainTemplateResponse> responses = _nuageVspManager.listNuageVspDomainTemplates(this); |
| 99 | + ListResponse<NuageVspDomainTemplateResponse> response = new ListResponse<>(); |
| 100 | + response.setResponses(responses); |
| 101 | + response.setResponseName(getCommandName()); |
| 102 | + this.setResponseObject(response); |
| 103 | + } catch (InvalidParameterValueException invalidParamExcp) { |
| 104 | + throw new ServerApiException(ApiErrorCode.PARAM_ERROR, invalidParamExcp.getMessage()); |
| 105 | + } catch (CloudRuntimeException e) { |
| 106 | + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, e.getMessage()); |
| 107 | + } |
| 108 | + } |
| 109 | + |
| 110 | + @Override |
| 111 | + public String getCommandName() { |
| 112 | + return APINAME.toLowerCase() + BaseCmd.RESPONSE_SUFFIX; |
| 113 | + } |
| 114 | + |
| 115 | + @Override public long getEntityOwnerId() { |
| 116 | + return 0; //not owned by anyone |
| 117 | + } |
| 118 | + |
| 119 | +} |
| 120 | + |
0 commit comments