| 1 | /** |
| 2 | * Licensed to jclouds, Inc. (jclouds) under one or more |
| 3 | * contributor license agreements. See the NOTICE file |
| 4 | * distributed with this work for additional information |
| 5 | * regarding copyright ownership. jclouds 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 | package org.jclouds.gogrid.options; |
| 20 | |
| 21 | import static com.google.common.base.Preconditions.checkNotNull; |
| 22 | import static com.google.common.base.Preconditions.checkState; |
| 23 | import static org.jclouds.gogrid.reference.GoGridQueryParams.DATACENTER_KEY; |
| 24 | import static org.jclouds.gogrid.reference.GoGridQueryParams.IP_STATE_KEY; |
| 25 | import static org.jclouds.gogrid.reference.GoGridQueryParams.IP_TYPE_KEY; |
| 26 | |
| 27 | import org.jclouds.gogrid.domain.IpState; |
| 28 | import org.jclouds.gogrid.domain.IpType; |
| 29 | import org.jclouds.http.options.BaseHttpRequestOptions; |
| 30 | |
| 31 | /** |
| 32 | * @author Oleksiy Yarmula |
| 33 | */ |
| 34 | public class GetIpListOptions extends BaseHttpRequestOptions { |
| 35 | |
| 36 | public static final GetIpListOptions NONE = new GetIpListOptions(); |
| 37 | |
| 38 | public GetIpListOptions onlyAssigned() { |
| 39 | checkState(!queryParameters.containsKey(IP_STATE_KEY), |
| 40 | "Can't have multiple values for whether IP is assigned"); |
| 41 | queryParameters.put(IP_STATE_KEY, IpState.ASSIGNED.toString()); |
| 42 | return this; |
| 43 | } |
| 44 | |
| 45 | public GetIpListOptions onlyUnassigned() { |
| 46 | checkState(!queryParameters.containsKey(IP_STATE_KEY), |
| 47 | "Can't have multiple values for whether IP is assigned"); |
| 48 | queryParameters.put(IP_STATE_KEY, IpState.UNASSIGNED.toString()); |
| 49 | return this; |
| 50 | } |
| 51 | |
| 52 | public GetIpListOptions onlyWithType(IpType type) { |
| 53 | checkState(!queryParameters.containsKey(IP_TYPE_KEY), |
| 54 | "Can't have multiple values for ip type limit"); |
| 55 | queryParameters.put(IP_TYPE_KEY, type.toString()); |
| 56 | return this; |
| 57 | } |
| 58 | |
| 59 | public GetIpListOptions inDatacenter(String datacenterId) { |
| 60 | checkState(!queryParameters.containsKey(DATACENTER_KEY), "Can't have duplicate datacenter id"); |
| 61 | queryParameters.put(DATACENTER_KEY, datacenterId); |
| 62 | return this; |
| 63 | } |
| 64 | |
| 65 | public static class Builder { |
| 66 | |
| 67 | public GetIpListOptions inDatacenter(String datacenterId) { |
| 68 | return new GetIpListOptions().inDatacenter(checkNotNull(datacenterId)); |
| 69 | } |
| 70 | |
| 71 | public GetIpListOptions create() { |
| 72 | return new GetIpListOptions(); |
| 73 | } |
| 74 | |
| 75 | public GetIpListOptions limitToType(IpType type) { |
| 76 | return new GetIpListOptions().onlyWithType(type); |
| 77 | } |
| 78 | |
| 79 | public GetIpListOptions unassignedPublicIps() { |
| 80 | return new GetIpListOptions().onlyWithType(IpType.PUBLIC).onlyUnassigned(); |
| 81 | } |
| 82 | } |
| 83 | |
| 84 | } |