1 | /** |
2 | * |
3 | * Copyright (C) 2011 Cloud Conscious, LLC. <info@cloudconscious.com> |
4 | * |
5 | * ==================================================================== |
6 | * Licensed under the Apache License, Version 2.0 (the "License"); |
7 | * you may not use this file except in compliance with the License. |
8 | * 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, software |
13 | * distributed under the License is distributed on an "AS IS" BASIS, |
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
15 | * See the License for the specific language governing permissions and |
16 | * limitations under the License. |
17 | * ==================================================================== |
18 | */ |
19 | package org.jclouds.cloudservers.options; |
20 | |
21 | import static com.google.common.base.Preconditions.checkArgument; |
22 | |
23 | import java.util.Map; |
24 | |
25 | import org.jclouds.http.HttpRequest; |
26 | import org.jclouds.rest.binders.BindToJsonPayload; |
27 | |
28 | import com.google.common.collect.ImmutableMap; |
29 | import com.google.common.collect.Maps; |
30 | |
31 | /** |
32 | * |
33 | * |
34 | * @author Adrian Cole |
35 | * |
36 | */ |
37 | public class RebuildServerOptions extends BindToJsonPayload { |
38 | Integer imageId; |
39 | |
40 | @Override |
41 | public <R extends HttpRequest> R bindToRequest(R request, Map<String, String> postParams) { |
42 | Map<String, Integer> image = Maps.newHashMap(); |
43 | if (imageId != null) |
44 | image.put("imageId", imageId); |
45 | return super.bindToRequest(request, ImmutableMap.of("rebuild", image)); |
46 | } |
47 | |
48 | @Override |
49 | public <R extends HttpRequest> R bindToRequest(R request, Object toBind) { |
50 | throw new IllegalStateException("RebuildServer is a POST operation"); |
51 | } |
52 | |
53 | /** |
54 | * |
55 | * @param id |
56 | * of the image to rebuild the server with. |
57 | */ |
58 | public RebuildServerOptions withImage(int id) { |
59 | checkArgument(id > 0, "server id must be a positive number"); |
60 | this.imageId = id; |
61 | return this; |
62 | } |
63 | |
64 | public static class Builder { |
65 | |
66 | /** |
67 | * @see RebuildServerOptions#withImage(int) |
68 | */ |
69 | public static RebuildServerOptions withImage(int id) { |
70 | RebuildServerOptions options = new RebuildServerOptions(); |
71 | return options.withImage(id); |
72 | } |
73 | } |
74 | } |