Jian Li | 073f1ba | 2021-02-28 03:50:15 +0900 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2021-present Open Networking Foundation |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | package org.onosproject.kubevirtnetworking.web; |
| 17 | |
| 18 | import org.onosproject.kubevirtnetworking.api.KubevirtFloatingIp; |
| 19 | import org.onosproject.kubevirtnetworking.api.KubevirtRouterService; |
| 20 | import org.onosproject.rest.AbstractWebResource; |
| 21 | import org.slf4j.Logger; |
| 22 | import org.slf4j.LoggerFactory; |
| 23 | |
| 24 | import javax.ws.rs.GET; |
| 25 | import javax.ws.rs.Path; |
| 26 | import javax.ws.rs.Produces; |
| 27 | import javax.ws.rs.core.MediaType; |
| 28 | import javax.ws.rs.core.Response; |
| 29 | |
| 30 | /** |
| 31 | * Handles REST API call for kubevirt floating IPs. |
| 32 | */ |
Jian Li | 1c10cf2 | 2021-03-05 01:32:04 +0900 | [diff] [blame] | 33 | @Path("floating-ip") |
Jian Li | 073f1ba | 2021-02-28 03:50:15 +0900 | [diff] [blame] | 34 | public class KubevirtFloatingIpsWebResource extends AbstractWebResource { |
| 35 | |
| 36 | protected final Logger log = LoggerFactory.getLogger(getClass()); |
| 37 | |
Jian Li | 1c10cf2 | 2021-03-05 01:32:04 +0900 | [diff] [blame] | 38 | private static final String FLOATING_IPS = "floating-ips"; |
| 39 | |
Jian Li | 073f1ba | 2021-02-28 03:50:15 +0900 | [diff] [blame] | 40 | /** |
| 41 | * Returns set of all floating IPs. |
| 42 | * |
| 43 | * @return 200 OK with set of all floating IPs |
| 44 | * @onos.rsModel KubevirtFloatingIps |
| 45 | */ |
| 46 | @GET |
| 47 | @Produces(MediaType.APPLICATION_JSON) |
| 48 | public Response getFloatingIps() { |
| 49 | KubevirtRouterService service = get(KubevirtRouterService.class); |
| 50 | final Iterable<KubevirtFloatingIp> fips = service.floatingIps(); |
Jian Li | 1c10cf2 | 2021-03-05 01:32:04 +0900 | [diff] [blame] | 51 | return ok(encodeArray(KubevirtFloatingIp.class, FLOATING_IPS, fips)).build(); |
Jian Li | 073f1ba | 2021-02-28 03:50:15 +0900 | [diff] [blame] | 52 | } |
| 53 | } |