|
| 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 com.cloud.network.GuestVlan; |
| 20 | +import com.cloud.user.Account; |
| 21 | +import com.cloud.utils.Pair; |
| 22 | +import org.apache.cloudstack.api.*; |
| 23 | +import org.apache.cloudstack.api.response.*; |
| 24 | +import org.apache.log4j.Logger; |
| 25 | + |
| 26 | +import java.util.ArrayList; |
| 27 | +import java.util.List; |
| 28 | + |
| 29 | + |
| 30 | +@APICommand(name = "listDedicatedGuestVlanRanges", description="Lists dedicated guest vlan ranges", responseObject=GuestVlanRangeResponse.class) |
| 31 | +public class ListDedicatedGuestVlanRangesCmd extends BaseListCmd { |
| 32 | + public static final Logger s_logger = Logger.getLogger(ListDedicatedGuestVlanRangesCmd.class.getName()); |
| 33 | + |
| 34 | + private static final String s_name = "listdedicatedguestvlanrangesresponse"; |
| 35 | + |
| 36 | + ///////////////////////////////////////////////////// |
| 37 | + //////////////// API parameters ///////////////////// |
| 38 | + ///////////////////////////////////////////////////// |
| 39 | + |
| 40 | + @Parameter(name=ApiConstants.ID, type=CommandType.UUID, entityType=GuestVlanRangeResponse.class, |
| 41 | + description="list dedicated guest vlan ranges by id") |
| 42 | + private Long id; |
| 43 | + |
| 44 | + @Parameter(name=ApiConstants.ACCOUNT, type=CommandType.STRING, description="the account with which the guest VLAN range is associated. Must be used with the domainId parameter.") |
| 45 | + private String accountName; |
| 46 | + |
| 47 | + @Parameter(name=ApiConstants.PROJECT_ID, type=CommandType.UUID, entityType = ProjectResponse.class, |
| 48 | + description="project who will own the guest VLAN range") |
| 49 | + private Long projectId; |
| 50 | + |
| 51 | + @Parameter(name=ApiConstants.DOMAIN_ID, type=CommandType.UUID, entityType = DomainResponse.class, |
| 52 | + description="the domain ID with which the guest VLAN range is associated. If used with the account parameter, returns all guest VLAN ranges for that account in the specified domain.") |
| 53 | + private Long domainId; |
| 54 | + |
| 55 | + @Parameter(name=ApiConstants.GUEST_VLAN_RANGE, type=CommandType.STRING, description="the dedicated guest vlan range") |
| 56 | + private String guestVlanRange; |
| 57 | + |
| 58 | + @Parameter(name=ApiConstants.PHYSICAL_NETWORK_ID, type=CommandType.UUID, entityType = PhysicalNetworkResponse.class, |
| 59 | + description="physical network id of the guest VLAN range") |
| 60 | + private Long physicalNetworkId; |
| 61 | + |
| 62 | + @Parameter(name=ApiConstants.ZONE_ID, type=CommandType.UUID, entityType = ZoneResponse.class, |
| 63 | + description="zone of the guest VLAN range") |
| 64 | + private Long zoneId; |
| 65 | + |
| 66 | + ///////////////////////////////////////////////////// |
| 67 | + /////////////////// Accessors /////////////////////// |
| 68 | + ///////////////////////////////////////////////////// |
| 69 | + |
| 70 | + public Long getId() { |
| 71 | + return id; |
| 72 | + } |
| 73 | + |
| 74 | + public String getAccountName() { |
| 75 | + return accountName; |
| 76 | + } |
| 77 | + |
| 78 | + public Long getDomainId() { |
| 79 | + return domainId; |
| 80 | + } |
| 81 | + |
| 82 | + public Long getProjectId() { |
| 83 | + return projectId; |
| 84 | + } |
| 85 | + |
| 86 | + public String getGuestVlanRange() { |
| 87 | + return guestVlanRange; |
| 88 | + } |
| 89 | + |
| 90 | + public Long getPhysicalNetworkId() { |
| 91 | + return physicalNetworkId; |
| 92 | + } |
| 93 | + |
| 94 | + public Long getZoneId() { |
| 95 | + return zoneId; |
| 96 | + } |
| 97 | + |
| 98 | + |
| 99 | + ///////////////////////////////////////////////////// |
| 100 | + /////////////// API Implementation/////////////////// |
| 101 | + ///////////////////////////////////////////////////// |
| 102 | + |
| 103 | + @Override |
| 104 | + public String getCommandName() { |
| 105 | + return s_name; |
| 106 | + } |
| 107 | + |
| 108 | + @Override |
| 109 | + public long getEntityOwnerId() { |
| 110 | + return Account.ACCOUNT_ID_SYSTEM; |
| 111 | + } |
| 112 | + |
| 113 | + @Override |
| 114 | + public void execute(){ |
| 115 | + Pair<List<? extends GuestVlan>, Integer> vlans = _networkService.listDedicatedGuestVlanRanges(this); |
| 116 | + ListResponse<GuestVlanRangeResponse> response = new ListResponse<GuestVlanRangeResponse>(); |
| 117 | + List<GuestVlanRangeResponse> guestVlanResponses = new ArrayList<GuestVlanRangeResponse>(); |
| 118 | + for (GuestVlan vlan : vlans.first()) { |
| 119 | + GuestVlanRangeResponse guestVlanResponse = _responseGenerator.createDedicatedGuestVlanRangeResponse(vlan); |
| 120 | + guestVlanResponse.setObjectName("dedicatedguestvlanrange"); |
| 121 | + guestVlanResponses.add(guestVlanResponse); |
| 122 | + } |
| 123 | + |
| 124 | + response.setResponses(guestVlanResponses, vlans.second()); |
| 125 | + response.setResponseName(getCommandName()); |
| 126 | + this.setResponseObject(response); |
| 127 | + } |
| 128 | + |
| 129 | +} |
0 commit comments