|
18 | 18 |
|
19 | 19 | import java.util.ArrayList; |
20 | 20 | import java.util.List; |
21 | | - |
| 21 | +import com.cloud.vm.NicSecondaryIp; |
| 22 | +import org.apache.cloudstack.api.response.NicSecondaryIpResponse; |
22 | 23 | import org.apache.cloudstack.acl.RoleType; |
23 | 24 | import org.apache.cloudstack.api.APICommand; |
24 | 25 | import org.apache.cloudstack.api.ApiCommandJobType; |
@@ -122,22 +123,45 @@ public static String getResultObjectName() { |
122 | 123 | public void execute() throws ResourceUnavailableException, ResourceAllocationException, ConcurrentOperationException, InsufficientCapacityException { |
123 | 124 |
|
124 | 125 | try { |
125 | | - List<? extends Nic> results = _networkService.listNics(this); |
126 | | - ListResponse<NicResponse> response = new ListResponse<NicResponse>(); |
127 | | - List<NicResponse> resList = null; |
128 | | - if (results != null) { |
129 | | - resList = new ArrayList<NicResponse>(results.size()); |
130 | | - for (Nic r : results) { |
131 | | - NicResponse resp = _responseGenerator.createNicResponse(r); |
132 | | - resp.setObjectName("nic"); |
133 | | - resList.add(resp); |
| 126 | + if (this.getKeyword() != null && !this.getKeyword().isEmpty() && this.getNicId() != null) { |
| 127 | + List<? extends NicSecondaryIp> results = _networkService.listVmNicSecondaryIps(this); |
| 128 | + ListResponse<NicSecondaryIpResponse> response = new ListResponse<NicSecondaryIpResponse>(); |
| 129 | + List<NicSecondaryIpResponse> resList = new ArrayList<NicSecondaryIpResponse>(); |
| 130 | + NicSecondaryIpResponse res = new NicSecondaryIpResponse(); |
| 131 | + List<NicSecondaryIpResponse> res_List = new ArrayList<NicSecondaryIpResponse>(); |
| 132 | + if (results != null) { |
| 133 | + for (NicSecondaryIp r : results) { |
| 134 | + NicSecondaryIpResponse ipRes = _responseGenerator.createSecondaryIPToNicResponse(r); |
| 135 | + resList.add(ipRes); |
| 136 | + res.setSecondaryIpsList(resList); |
| 137 | + res.setObjectName("nic"); |
| 138 | + } |
| 139 | + |
| 140 | + res_List.add(res); |
| 141 | + response.setResponses(res_List); |
| 142 | + } |
| 143 | + response.setResponses(res_List); |
| 144 | + response.setResponseName(getCommandName()); |
| 145 | + this.setResponseObject(response); |
| 146 | + |
| 147 | + } else { |
| 148 | + List<? extends Nic> results = _networkService.listNics(this); |
| 149 | + ListResponse<NicResponse> response = new ListResponse<NicResponse>(); |
| 150 | + List<NicResponse> resList = null; |
| 151 | + if (results != null) { |
| 152 | + resList = new ArrayList<NicResponse>(results.size()); |
| 153 | + for (Nic r : results) { |
| 154 | + NicResponse resp = _responseGenerator.createNicResponse(r); |
| 155 | + resp.setObjectName("nic"); |
| 156 | + resList.add(resp); |
| 157 | + } |
| 158 | + response.setResponses(resList); |
134 | 159 | } |
| 160 | + |
135 | 161 | response.setResponses(resList); |
| 162 | + response.setResponseName(getCommandName()); |
| 163 | + this.setResponseObject(response); |
136 | 164 | } |
137 | | - response.setResponses(resList); |
138 | | - response.setResponseName(getCommandName()); |
139 | | - this.setResponseObject(response); |
140 | | - |
141 | 165 | } catch (Exception e) { |
142 | 166 | s_logger.warn("Failed to list secondary ip address per nic "); |
143 | 167 | throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, e.getMessage()); |
|
0 commit comments