Issue 158: Added operating system and password to virtual guest

This commit is contained in:
Jason King 2011-09-28 16:59:09 +01:00
parent c24ba815cf
commit fd3cb496fd
3 changed files with 305 additions and 4 deletions

View File

@ -0,0 +1,137 @@
/**
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.jclouds.softlayer.domain;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Sets;
import java.util.Set;
import static com.google.common.base.Preconditions.checkNotNull;
/**
* Extends the SoftLayer_Software_Component data type to include operating system specific properties.
*
* @author Jason King
* @see <a href=
* "http://sldn.softlayer.com/reference/datatypes/SoftLayer_Software_Component_OperatingSystem"
* />
*/
public class OperatingSystem implements Comparable<OperatingSystem> {
// There are other properties
public static Builder builder() {
return new Builder();
}
public static class Builder {
private int id = -1;
private Set<Password> passwords = Sets.newLinkedHashSet();
public Builder id(int id) {
this.id = id;
return this;
}
public Builder password(Password password) {
this.passwords.add(checkNotNull(password, "password"));
return this;
}
public Builder passwords(Iterable<Password> passwords) {
this.passwords = ImmutableSet.<Password> copyOf(checkNotNull(passwords, "passwords"));
return this;
}
public OperatingSystem build() {
return new OperatingSystem(id, passwords);
}
public static Builder fromOperatingSystem(OperatingSystem in) {
return OperatingSystem.builder()
.id(in.getId())
.passwords(in.getPasswords());
}
}
private int id = -1;
private Set<Password> passwords = Sets.newLinkedHashSet();
// for deserializer
OperatingSystem() {
}
public OperatingSystem(int id,Iterable<Password> passwords) {
this.id = id;
this.passwords = ImmutableSet.<Password> copyOf(checkNotNull(passwords, "passwords"));
}
@Override
public int compareTo(OperatingSystem arg0) {
return new Integer(id).compareTo(arg0.getId());
}
/**
* @return An ID number identifying this Software Component (Software Installation)
*/
public int getId() {
return id;
}
/**
*
* @return Username/Password pairs used for access to this Software Installation.
*/
public Set<Password> getPasswords() {
return passwords;
}
public Builder toBuilder() {
return Builder.fromOperatingSystem(this);
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + (id ^ (id >>> 32));
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
OperatingSystem other = (OperatingSystem) obj;
if (id != other.id)
return false;
return true;
}
@Override
public String toString() {
return "OperatingSystem [id=" + id + ", passwords=" + passwords + "]";
}
}

View File

@ -0,0 +1,141 @@
/**
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.jclouds.softlayer.domain;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.base.Strings.emptyToNull;
/**
*
* Contains a password for a specific software component instance
*
* @author Jason King
* @see <a href= "http://sldn.softlayer.com/reference/datatypes/SoftLayer_Software_Component_Password"
* />
*/
public class Password implements Comparable<Password> {
public static Builder builder() {
return new Builder();
}
public static class Builder {
private int id = -1;
private String username;
private String password;
public Builder id(int id) {
this.id = id;
return this;
}
public Builder username(String username) {
this.username = username;
return this;
}
public Builder password(String password) {
this.password = password;
return this;
}
public Password build() {
return new Password(id, username, password);
}
public static Builder fromPassword(Password in) {
return Password.builder().id(in.getId())
.username(in.getUsername())
.password(in.getPassword());
}
}
private int id = -1;
private String username;
private String password;
// for deserializer
Password() {
}
public Password(int id, String username, String password) {
this.id = id;
this.username = checkNotNull(emptyToNull(username),"username cannot be null or empty:"+username);
this.password = password;
}
@Override
public int compareTo(Password arg0) {
return new Integer(id).compareTo(arg0.getId());
}
/**
* @return An id number for this specific username/password pair.
*/
public int getId() {
return id;
}
/**
* @return The username part of the username/password pair.
*/
public String getUsername() {
return username;
}
/**
* @return The password part of the username/password pair.
*/
public String getPassword() {
return password;
}
public Builder toBuilder() {
return Builder.fromPassword(this);
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + (id ^ (id >>> 32));
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
Password other = (Password) obj;
if (id != other.id)
return false;
return true;
}
@Override
public String toString() {
return "Password [id=" + id + ", username=" + username + ", password=**********]";
}
}

View File

@ -64,6 +64,7 @@ public class VirtualGuest implements Comparable<VirtualGuest> {
private String primaryBackendIpAddress;
private String primaryIpAddress;
private BillingItemVirtualGuest billingItem;
private OperatingSystem operatingSystem;
public Builder id(int id) {
this.id = id;
@ -170,12 +171,17 @@ public class VirtualGuest implements Comparable<VirtualGuest> {
return this;
}
public Builder operatingSystem(OperatingSystem operatingSystem) {
this.operatingSystem = operatingSystem;
return this;
}
public VirtualGuest build() {
return new VirtualGuest(accountId, createDate, dedicatedAccountHostOnly, domain,
fullyQualifiedDomainName, hostname, id, lastVerifiedDate, maxCpu,
maxCpuUnits, maxMemory, metricPollDate, modifyDate, notes,
privateNetworkOnly, startCpus, statusId, uuid, primaryBackendIpAddress,
primaryIpAddress,billingItem);
primaryIpAddress,billingItem,operatingSystem);
}
public static Builder fromVirtualGuest(VirtualGuest in) {
@ -200,7 +206,9 @@ public class VirtualGuest implements Comparable<VirtualGuest> {
.uuid(in.getUuid())
.primaryBackendIpAddress(in.getPrimaryBackendIpAddress())
.primaryIpAddress(in.getPrimaryIpAddress())
.billingItem(in.getBillingItem());
.billingItem(in.getBillingItem())
.operatingSystem(in.getOperatingSystem());
}
}
@ -252,6 +260,7 @@ public class VirtualGuest implements Comparable<VirtualGuest> {
private String primaryIpAddress;
private BillingItemVirtualGuest billingItem;
private OperatingSystem operatingSystem;
// for deserializer
VirtualGuest() {
@ -262,7 +271,7 @@ public class VirtualGuest implements Comparable<VirtualGuest> {
String fullyQualifiedDomainName, String hostname, int id, Date lastVerifiedDate, int maxCpu,
String maxCpuUnits, int maxMemory, Date metricPollDate, Date modifyDate, String notes,
boolean privateNetworkOnly, int startCpus, int statusId, String uuid, String primaryBackendIpAddress,
String primaryIpAddress,BillingItemVirtualGuest billingItem) {
String primaryIpAddress,BillingItemVirtualGuest billingItem, OperatingSystem operatingSystem) {
this.accountId = accountId;
this.createDate = createDate;
this.dedicatedAccountHostOnly = dedicatedAccountHostOnly;
@ -284,6 +293,7 @@ public class VirtualGuest implements Comparable<VirtualGuest> {
this.primaryBackendIpAddress = primaryBackendIpAddress;
this.primaryIpAddress = primaryIpAddress;
this.billingItem = billingItem;
this.operatingSystem = operatingSystem;
}
@Override
@ -441,6 +451,13 @@ public class VirtualGuest implements Comparable<VirtualGuest> {
return billingItem;
}
/**
* @return A guest's operating system.
*/
public OperatingSystem getOperatingSystem() {
return operatingSystem;
}
@Override
public int hashCode() {
final int prime = 31;
@ -466,6 +483,7 @@ public class VirtualGuest implements Comparable<VirtualGuest> {
result = prime * result + statusId;
result = prime * result + ((uuid == null) ? 0 : uuid.hashCode());
result = prime * result + ((billingItem == null) ? 0 : billingItem.hashCode());
result = prime * result + ((operatingSystem == null) ? 0 : operatingSystem.hashCode());
return result;
}
@ -559,6 +577,11 @@ public class VirtualGuest implements Comparable<VirtualGuest> {
return false;
} else if (!billingItem.equals(other.billingItem))
return false;
if (operatingSystem == null) {
if (other.operatingSystem != null)
return false;
} else if (!operatingSystem.equals(other.operatingSystem))
return false;
return true;
}
@ -571,7 +594,7 @@ public class VirtualGuest implements Comparable<VirtualGuest> {
+ ", metricPollDate=" + metricPollDate + ", modifyDate=" + modifyDate + ", notes=" + notes
+ ", primaryBackendIpAddress=" + primaryBackendIpAddress + ", primaryIpAddress=" + primaryIpAddress
+ ", privateNetworkOnly=" + privateNetworkOnly + ", startCpus=" + startCpus + ", statusId=" + statusId
+ ", uuid=" + uuid + ", billingItem="+billingItem+"]";
+ ", uuid=" + uuid + ", billingItem="+billingItem+", operatingSystem="+operatingSystem+"]";
}
}