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.compute.domain; |
20 | |
21 | import static com.google.common.base.Preconditions.checkNotNull; |
22 | |
23 | import java.net.URI; |
24 | import java.util.Map; |
25 | |
26 | import org.jclouds.javax.annotation.Nullable; |
27 | |
28 | import org.jclouds.compute.domain.internal.ImageImpl; |
29 | import org.jclouds.domain.Credentials; |
30 | import org.jclouds.domain.Location; |
31 | |
32 | /** |
33 | * @author Adrian Cole |
34 | */ |
35 | public class ImageBuilder extends ComputeMetadataBuilder { |
36 | private OperatingSystem operatingSystem; |
37 | private String version; |
38 | private String description; |
39 | @Nullable |
40 | private String adminPassword; |
41 | private Credentials defaultCredentials; |
42 | |
43 | public ImageBuilder() { |
44 | super(ComputeType.IMAGE); |
45 | } |
46 | |
47 | public ImageBuilder operatingSystem(OperatingSystem operatingSystem) { |
48 | this.operatingSystem = checkNotNull(operatingSystem, "operatingSystem"); |
49 | return this; |
50 | } |
51 | |
52 | public ImageBuilder version(@Nullable String version) { |
53 | this.version = version; |
54 | return this; |
55 | } |
56 | |
57 | public ImageBuilder description(String description) { |
58 | this.description = checkNotNull(description, "description"); |
59 | return this; |
60 | } |
61 | |
62 | public ImageBuilder adminPassword(@Nullable String adminPassword) { |
63 | this.adminPassword = adminPassword; |
64 | return this; |
65 | } |
66 | |
67 | public ImageBuilder defaultCredentials(@Nullable Credentials defaultCredentials) { |
68 | this.defaultCredentials = defaultCredentials; |
69 | return this; |
70 | } |
71 | |
72 | @Override |
73 | public ImageBuilder id(String id) { |
74 | return ImageBuilder.class.cast(super.id(id)); |
75 | } |
76 | |
77 | public ImageBuilder tags(Iterable<String> tags) { |
78 | return ImageBuilder.class.cast(super.tags(tags)); |
79 | } |
80 | |
81 | @Override |
82 | public ImageBuilder ids(String id) { |
83 | return ImageBuilder.class.cast(super.ids(id)); |
84 | } |
85 | |
86 | @Override |
87 | public ImageBuilder providerId(String providerId) { |
88 | return ImageBuilder.class.cast(super.providerId(providerId)); |
89 | } |
90 | |
91 | @Override |
92 | public ImageBuilder name(String name) { |
93 | return ImageBuilder.class.cast(super.name(name)); |
94 | } |
95 | |
96 | @Override |
97 | public ImageBuilder location(Location location) { |
98 | return ImageBuilder.class.cast(super.location(location)); |
99 | } |
100 | |
101 | @Override |
102 | public ImageBuilder uri(URI uri) { |
103 | return ImageBuilder.class.cast(super.uri(uri)); |
104 | } |
105 | |
106 | @Override |
107 | public ImageBuilder userMetadata(Map<String, String> userMetadata) { |
108 | return ImageBuilder.class.cast(super.userMetadata(userMetadata)); |
109 | } |
110 | |
111 | @Override |
112 | public Image build() { |
113 | return new ImageImpl(providerId, name, id, location, uri, userMetadata, tags, operatingSystem, description, version, |
114 | adminPassword, defaultCredentials); |
115 | } |
116 | |
117 | public static ImageBuilder fromImage(Image image) { |
118 | return new ImageBuilder().providerId(image.getProviderId()).name(image.getName()).id(image.getId()).location( |
119 | image.getLocation()).uri(image.getUri()).userMetadata(image.getUserMetadata()).tags(image.getTags()).version( |
120 | image.getVersion()).description(image.getDescription()).operatingSystem(image.getOperatingSystem()) |
121 | .adminPassword(image.getAdminPassword()).defaultCredentials(image.getDefaultCredentials()); |
122 | } |
123 | |
124 | } |