| 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.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 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 | @Override |
| 78 | public ImageBuilder ids(String id) { |
| 79 | return ImageBuilder.class.cast(super.ids(id)); |
| 80 | } |
| 81 | |
| 82 | @Override |
| 83 | public ImageBuilder providerId(String providerId) { |
| 84 | return ImageBuilder.class.cast(super.providerId(providerId)); |
| 85 | } |
| 86 | |
| 87 | @Override |
| 88 | public ImageBuilder name(String name) { |
| 89 | return ImageBuilder.class.cast(super.name(name)); |
| 90 | } |
| 91 | |
| 92 | @Override |
| 93 | public ImageBuilder location(Location location) { |
| 94 | return ImageBuilder.class.cast(super.location(location)); |
| 95 | } |
| 96 | |
| 97 | @Override |
| 98 | public ImageBuilder uri(URI uri) { |
| 99 | return ImageBuilder.class.cast(super.uri(uri)); |
| 100 | } |
| 101 | |
| 102 | @Override |
| 103 | public ImageBuilder userMetadata(Map<String, String> userMetadata) { |
| 104 | return ImageBuilder.class.cast(super.userMetadata(userMetadata)); |
| 105 | } |
| 106 | |
| 107 | @Override |
| 108 | public Image build() { |
| 109 | return new ImageImpl(providerId, name, id, location, uri, userMetadata, operatingSystem, description, version, |
| 110 | adminPassword, defaultCredentials); |
| 111 | } |
| 112 | |
| 113 | public static ImageBuilder fromImage(Image image) { |
| 114 | return new ImageBuilder().providerId(image.getProviderId()).name(image.getName()).id(image.getId()).location( |
| 115 | image.getLocation()).uri(image.getUri()).userMetadata(image.getUserMetadata()).version( |
| 116 | image.getVersion()).description(image.getDescription()).operatingSystem(image.getOperatingSystem()) |
| 117 | .adminPassword(image.getAdminPassword()).defaultCredentials(image.getDefaultCredentials()); |
| 118 | } |
| 119 | |
| 120 | } |