|
| 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 | + |
| 18 | +package org.apache.cloudstack.api.command.admin.network; |
| 19 | + |
| 20 | +import java.util.List; |
| 21 | + |
| 22 | +import javax.inject.Inject; |
| 23 | + |
| 24 | +import org.apache.cloudstack.acl.RoleType; |
| 25 | +import org.apache.cloudstack.api.APICommand; |
| 26 | +import org.apache.cloudstack.api.ApiConstants; |
| 27 | +import org.apache.cloudstack.api.BaseListCmd; |
| 28 | +import org.apache.cloudstack.api.Parameter; |
| 29 | +import org.apache.cloudstack.api.response.ListResponse; |
| 30 | +import org.apache.cloudstack.api.response.NetworkRateLimitResponse; |
| 31 | +import org.apache.cloudstack.api.response.NetworkResponse; |
| 32 | +import org.apache.cloudstack.api.response.VpcResponse; |
| 33 | +import org.apache.cloudstack.api.response.UserVmResponse; |
| 34 | +import org.apache.cloudstack.network.NetworkRateLimitService; |
| 35 | + |
| 36 | + |
| 37 | +@APICommand(name = "listNetworkRateLimits", |
| 38 | + description = "Lists the effective network rate limits on interfaces of Networks, VPCs, " + |
| 39 | + "Virtual Routers and Virtual Machines. Admin only.", |
| 40 | + responseObject = NetworkRateLimitResponse.class, |
| 41 | + authorized = {RoleType.Admin}, |
| 42 | + requestHasSensitiveInfo = false, |
| 43 | + responseHasSensitiveInfo = false, |
| 44 | + since = "4.21.0") |
| 45 | +public class ListNetworkRateLimitsCmd extends BaseListCmd { |
| 46 | + |
| 47 | + // ── Parameters ──────────────────────────────────────────────────────────── |
| 48 | + |
| 49 | + @Parameter(name = "type", |
| 50 | + type = CommandType.STRING, |
| 51 | + description = "Filter by resource type. Allowed values: vm, network, vpc, vr. " + |
| 52 | + "Leave empty to list all types.") |
| 53 | + private String type; |
| 54 | + |
| 55 | + @Parameter(name = ApiConstants.NETWORK_ID, |
| 56 | + type = CommandType.UUID, |
| 57 | + entityType = NetworkResponse.class, |
| 58 | + description = "UUID of a specific network to query (optional)") |
| 59 | + private Long networkId; |
| 60 | + |
| 61 | + @Parameter(name = ApiConstants.VPC_ID, |
| 62 | + type = CommandType.UUID, |
| 63 | + entityType = VpcResponse.class, |
| 64 | + description = "UUID of a specific VPC to query (optional)") |
| 65 | + private Long vpcId; |
| 66 | + |
| 67 | + @Parameter(name = ApiConstants.VIRTUAL_MACHINE_ID, |
| 68 | + type = CommandType.UUID, |
| 69 | + entityType = UserVmResponse.class, |
| 70 | + description = "UUID of a specific VM to query (optional)") |
| 71 | + private Long vmId; |
| 72 | + |
| 73 | + // ── Service ─────────────────────────────────────────────────────────────── |
| 74 | + |
| 75 | + @Inject |
| 76 | + NetworkRateLimitService networkRateLimitService; |
| 77 | + |
| 78 | + // ── Accessors ───────────────────────────────────────────────────────────── |
| 79 | + |
| 80 | + public String getType() { |
| 81 | + return type; |
| 82 | + } |
| 83 | + |
| 84 | + public Long getNetworkId() { |
| 85 | + return networkId; |
| 86 | + } |
| 87 | + |
| 88 | + public Long getVpcId() { |
| 89 | + return vpcId; |
| 90 | + } |
| 91 | + |
| 92 | + public Long getVmId() { |
| 93 | + return vmId; |
| 94 | + } |
| 95 | + |
| 96 | + // ── Execution ───────────────────────────────────────────────────────────── |
| 97 | + |
| 98 | + @Override |
| 99 | + public void execute() { |
| 100 | + List<NetworkRateLimitResponse> entries = networkRateLimitService.listNetworkRateLimits(this); |
| 101 | + ListResponse<NetworkRateLimitResponse> response = new ListResponse<>(); |
| 102 | + response.setResponses(entries, entries.size()); |
| 103 | + response.setResponseName(getCommandName()); |
| 104 | + setResponseObject(response); |
| 105 | + } |
| 106 | +} |
0 commit comments