| 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.Date; |
| 24 | import java.util.Map; |
| 25 | |
| 26 | /** |
| 27 | * A server is a virtual machine instance in the OpenStack Nova system. Flavor and image are |
| 28 | * requisite elements when creating a server. |
| 29 | * |
| 30 | * @author Adrian Cole |
| 31 | */ |
| 32 | public class Server extends Resource { |
| 33 | private int id; |
| 34 | private String name; |
| 35 | |
| 36 | private Map<String, String> metadata = Maps.newHashMap(); |
| 37 | |
| 38 | private Addresses addresses; |
| 39 | private String adminPass; |
| 40 | private String flavorRef; |
| 41 | private String hostId; |
| 42 | private String imageRef; |
| 43 | private String affinityId; |
| 44 | |
| 45 | private Date created; |
| 46 | private Date updated; |
| 47 | |
| 48 | public Date getCreated() { |
| 49 | return created; |
| 50 | } |
| 51 | |
| 52 | public Date getUpdated() { |
| 53 | return updated; |
| 54 | } |
| 55 | |
| 56 | |
| 57 | private Integer progress; |
| 58 | private ServerStatus status; |
| 59 | |
| 60 | public Server() { |
| 61 | } |
| 62 | |
| 63 | public Server(int id, String name) { |
| 64 | this.id = id; |
| 65 | this.name = name; |
| 66 | } |
| 67 | |
| 68 | public String getAffinityId() { |
| 69 | return affinityId; |
| 70 | } |
| 71 | |
| 72 | public void setAffinityId(String affinityId) { |
| 73 | this.affinityId = affinityId; |
| 74 | } |
| 75 | |
| 76 | public void setMetadata(Map<String, String> metadata) { |
| 77 | this.metadata = metadata; |
| 78 | } |
| 79 | |
| 80 | public Map<String, String> getMetadata() { |
| 81 | return metadata; |
| 82 | } |
| 83 | |
| 84 | public void setAddresses(Addresses addresses) { |
| 85 | this.addresses = addresses; |
| 86 | } |
| 87 | |
| 88 | public Addresses getAddresses() { |
| 89 | return addresses; |
| 90 | } |
| 91 | |
| 92 | public void setAdminPass(String adminPass) { |
| 93 | this.adminPass = adminPass; |
| 94 | } |
| 95 | |
| 96 | public String getAdminPass() { |
| 97 | return adminPass; |
| 98 | } |
| 99 | |
| 100 | public void setFlavorRef(String flavorRef) { |
| 101 | this.flavorRef = flavorRef; |
| 102 | } |
| 103 | |
| 104 | public String getFlavorRef() { |
| 105 | return flavorRef; |
| 106 | } |
| 107 | |
| 108 | public void setHostId(String hostId) { |
| 109 | this.hostId = hostId; |
| 110 | } |
| 111 | |
| 112 | /** |
| 113 | * The OpenStack Nova provisioning algorithm has an anti-affinity property that attempts to spread |
| 114 | * out customer VMs across hosts. Under certain situations, VMs from the same customer may be |
| 115 | * placed on the same host. hostId represents the host your cloud server runs on and can be used |
| 116 | * to determine this scenario if it's relevant to your application. |
| 117 | * <p/> |
| 118 | * Note: hostId is unique PER ACCOUNT and is not globally unique. |
| 119 | */ |
| 120 | public String getHostId() { |
| 121 | return hostId; |
| 122 | } |
| 123 | |
| 124 | public int getId() { |
| 125 | return id; |
| 126 | } |
| 127 | |
| 128 | public void setImageRef(String imageRef) { |
| 129 | this.imageRef = imageRef; |
| 130 | } |
| 131 | |
| 132 | public String getImageRef() { |
| 133 | return imageRef; |
| 134 | } |
| 135 | |
| 136 | public String getName() { |
| 137 | return name; |
| 138 | } |
| 139 | |
| 140 | public void setProgress(Integer progress) { |
| 141 | this.progress = progress; |
| 142 | } |
| 143 | |
| 144 | public Integer getProgress() { |
| 145 | return progress; |
| 146 | } |
| 147 | |
| 148 | public void setStatus(ServerStatus status) { |
| 149 | this.status = status; |
| 150 | } |
| 151 | |
| 152 | /** |
| 153 | * Servers contain a status attribute that can be used as an indication of the current server |
| 154 | * state. Servers with an ACTIVE status are available for use. |
| 155 | */ |
| 156 | public ServerStatus getStatus() { |
| 157 | return status; |
| 158 | } |
| 159 | |
| 160 | @Override |
| 161 | public int hashCode() { |
| 162 | final int prime = 31; |
| 163 | int result = 1; |
| 164 | result = prime * result + ((addresses == null) ? 0 : addresses.hashCode()); |
| 165 | result = prime * result + ((adminPass == null) ? 0 : adminPass.hashCode()); |
| 166 | result = prime * result + ((flavorRef == null) ? 0 : flavorRef.hashCode()); |
| 167 | result = prime * result + ((hostId == null) ? 0 : hostId.hashCode()); |
| 168 | result = prime * result + id; |
| 169 | result = prime * result + ((imageRef == null) ? 0 : imageRef.hashCode()); |
| 170 | result = prime * result + ((metadata == null) ? 0 : metadata.hashCode()); |
| 171 | result = prime * result + ((name == null) ? 0 : name.hashCode()); |
| 172 | return result; |
| 173 | } |
| 174 | |
| 175 | @Override |
| 176 | public boolean equals(Object obj) { |
| 177 | if (this == obj) |
| 178 | return true; |
| 179 | if (obj == null) |
| 180 | return false; |
| 181 | if (getClass() != obj.getClass()) |
| 182 | return false; |
| 183 | Server other = (Server) obj; |
| 184 | if (addresses == null) { |
| 185 | if (other.addresses != null) |
| 186 | return false; |
| 187 | } else if (!addresses.equals(other.addresses)) |
| 188 | return false; |
| 189 | if (adminPass == null) { |
| 190 | if (other.adminPass != null) |
| 191 | return false; |
| 192 | } else if (!adminPass.equals(other.adminPass)) |
| 193 | return false; |
| 194 | if (flavorRef == null) { |
| 195 | if (other.flavorRef != null) |
| 196 | return false; |
| 197 | } else if (!flavorRef.equals(other.flavorRef)) |
| 198 | return false; |
| 199 | if (hostId == null) { |
| 200 | if (other.hostId != null) |
| 201 | return false; |
| 202 | } else if (!hostId.equals(other.hostId)) |
| 203 | return false; |
| 204 | if (id != other.id) |
| 205 | return false; |
| 206 | if (imageRef == null) { |
| 207 | if (other.imageRef != null) |
| 208 | return false; |
| 209 | } else if (!imageRef.equals(other.imageRef)) |
| 210 | return false; |
| 211 | if (metadata == null) { |
| 212 | if (other.metadata != null) |
| 213 | return false; |
| 214 | } else if (!metadata.equals(other.metadata)) |
| 215 | return false; |
| 216 | if (name == null) { |
| 217 | if (other.name != null) |
| 218 | return false; |
| 219 | } else if (!name.equals(other.name)) |
| 220 | return false; |
| 221 | return true; |
| 222 | } |
| 223 | |
| 224 | public void setName(String name) { |
| 225 | this.name = name; |
| 226 | } |
| 227 | |
| 228 | @Override |
| 229 | public String toString() { |
| 230 | return "Server [addresses=" + addresses + ", adminPass=" + adminPass + ", flavorRef=" |
| 231 | + flavorRef + ", hostId=" + hostId + ", id=" + id + ", imageRef=" + imageRef |
| 232 | + ", metadata=" + metadata + ", name=" + name + "]"; |
| 233 | } |
| 234 | |
| 235 | } |