| 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.openstack.nova.domain; |
| 20 | |
| 21 | import com.google.common.collect.Maps; |
| 22 | |
| 23 | import java.util.Collections; |
| 24 | import java.util.Date; |
| 25 | import java.util.Map; |
| 26 | |
| 27 | /** |
| 28 | * An image is a collection of files used to create or rebuild a server. Rackspace provides a number |
| 29 | * of pre-built OS images by default. You may also create custom images from cloud servers you have |
| 30 | * launched. These custom images are useful for backup purposes or for producing gold server images |
| 31 | * if you plan to deploy a particular server configuration frequently. |
| 32 | * |
| 33 | * @author Adrian Cole |
| 34 | */ |
| 35 | public class Image extends Resource { |
| 36 | |
| 37 | private int id; |
| 38 | private String name; |
| 39 | private Integer progress; |
| 40 | private String serverRef; |
| 41 | private ImageStatus status; |
| 42 | private Map<String, String> metadata = Maps.newHashMap(); |
| 43 | |
| 44 | private Date created; |
| 45 | private Date updated; |
| 46 | |
| 47 | public Date getCreated() { |
| 48 | return created; |
| 49 | } |
| 50 | |
| 51 | public Date getUpdated() { |
| 52 | return updated; |
| 53 | } |
| 54 | |
| 55 | |
| 56 | public Image() { |
| 57 | } |
| 58 | |
| 59 | public Image(int id, String name) { |
| 60 | this.id = id; |
| 61 | this.name = name; |
| 62 | } |
| 63 | |
| 64 | |
| 65 | public void setId(int id) { |
| 66 | this.id = id; |
| 67 | } |
| 68 | |
| 69 | public int getId() { |
| 70 | return id; |
| 71 | } |
| 72 | |
| 73 | public void setName(String name) { |
| 74 | this.name = name; |
| 75 | } |
| 76 | |
| 77 | public String getName() { |
| 78 | return name; |
| 79 | } |
| 80 | |
| 81 | public void setProgress(Integer progress) { |
| 82 | this.progress = progress; |
| 83 | } |
| 84 | |
| 85 | public Integer getProgress() { |
| 86 | return progress; |
| 87 | } |
| 88 | |
| 89 | public void setServerRef(String serverRef) { |
| 90 | this.serverRef = serverRef; |
| 91 | } |
| 92 | |
| 93 | public String getServerRef() { |
| 94 | return serverRef; |
| 95 | } |
| 96 | |
| 97 | public void setStatus(ImageStatus status) { |
| 98 | this.status = status; |
| 99 | } |
| 100 | |
| 101 | public ImageStatus getStatus() { |
| 102 | return status; |
| 103 | } |
| 104 | |
| 105 | |
| 106 | public Map<String, String> getMetadata() { |
| 107 | return Collections.unmodifiableMap(metadata); |
| 108 | } |
| 109 | |
| 110 | public void setMetadata(Map<String, String> metadata) { |
| 111 | this.metadata = Maps.newHashMap(metadata); |
| 112 | } |
| 113 | |
| 114 | /** |
| 115 | * note that this ignores some fields |
| 116 | */ |
| 117 | @Override |
| 118 | public int hashCode() { |
| 119 | final int prime = 31; |
| 120 | int result = 1; |
| 121 | result = prime * result + id; |
| 122 | result = prime * result + ((name == null) ? 0 : name.hashCode()); |
| 123 | result = prime * result + ((serverRef == null) ? 0 : serverRef.hashCode()); |
| 124 | return result; |
| 125 | } |
| 126 | |
| 127 | /** |
| 128 | * note that this ignores some fields |
| 129 | */ |
| 130 | @Override |
| 131 | public boolean equals(Object obj) { |
| 132 | if (this == obj) |
| 133 | return true; |
| 134 | if (obj == null) |
| 135 | return false; |
| 136 | if (getClass() != obj.getClass()) |
| 137 | return false; |
| 138 | Image other = (Image) obj; |
| 139 | if (id != other.id) |
| 140 | return false; |
| 141 | if (name == null) { |
| 142 | if (other.name != null) |
| 143 | return false; |
| 144 | } else if (!name.equals(other.name)) |
| 145 | return false; |
| 146 | return true; |
| 147 | } |
| 148 | |
| 149 | @Override |
| 150 | public String toString() { |
| 151 | return "Image [created=" + getCreated() + ", id=" + id + ", name=" + name + ", serverRef=" |
| 152 | + serverRef + "]"; |
| 153 | } |
| 154 | |
| 155 | } |