mirror of https://github.com/apache/jclouds.git
added ip address functionality to cloudstack
This commit is contained in:
parent
ff1f46ca2c
commit
c2ef282acf
|
@ -19,6 +19,7 @@
|
|||
|
||||
package org.jclouds.cloudstack;
|
||||
|
||||
import org.jclouds.cloudstack.features.AddressAsyncClient;
|
||||
import org.jclouds.cloudstack.features.AsyncJobAsyncClient;
|
||||
import org.jclouds.cloudstack.features.NetworkAsyncClient;
|
||||
import org.jclouds.cloudstack.features.OfferingAsyncClient;
|
||||
|
@ -79,4 +80,10 @@ public interface CloudStackAsyncClient {
|
|||
*/
|
||||
@Delegate
|
||||
AsyncJobAsyncClient getAsyncJobClient();
|
||||
|
||||
/**
|
||||
* Provides asynchronous access to Address features.
|
||||
*/
|
||||
@Delegate
|
||||
AddressAsyncClient getAddressClient();
|
||||
}
|
||||
|
|
|
@ -21,6 +21,7 @@ package org.jclouds.cloudstack;
|
|||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.jclouds.cloudstack.features.AddressClient;
|
||||
import org.jclouds.cloudstack.features.AsyncJobClient;
|
||||
import org.jclouds.cloudstack.features.NetworkClient;
|
||||
import org.jclouds.cloudstack.features.OfferingClient;
|
||||
|
@ -82,4 +83,10 @@ public interface CloudStackClient {
|
|||
*/
|
||||
@Delegate
|
||||
AsyncJobClient getAsyncJobClient();
|
||||
|
||||
/**
|
||||
* Provides synchronous access to Address features.
|
||||
*/
|
||||
@Delegate
|
||||
AddressClient getAddressClient();
|
||||
}
|
||||
|
|
|
@ -23,6 +23,8 @@ import java.util.Map;
|
|||
|
||||
import org.jclouds.cloudstack.CloudStackAsyncClient;
|
||||
import org.jclouds.cloudstack.CloudStackClient;
|
||||
import org.jclouds.cloudstack.features.AddressAsyncClient;
|
||||
import org.jclouds.cloudstack.features.AddressClient;
|
||||
import org.jclouds.cloudstack.features.AsyncJobAsyncClient;
|
||||
import org.jclouds.cloudstack.features.AsyncJobClient;
|
||||
import org.jclouds.cloudstack.features.NetworkAsyncClient;
|
||||
|
@ -60,14 +62,15 @@ import com.google.common.collect.ImmutableMap;
|
|||
public class CloudStackRestClientModule extends RestClientModule<CloudStackClient, CloudStackAsyncClient> {
|
||||
|
||||
public static final Map<Class<?>, Class<?>> DELEGATE_MAP = ImmutableMap.<Class<?>, Class<?>> builder()//
|
||||
.put(ZoneClient.class, ZoneAsyncClient.class)//
|
||||
.put(TemplateClient.class, TemplateAsyncClient.class)//
|
||||
.put(OfferingClient.class, OfferingAsyncClient.class)//
|
||||
.put(NetworkClient.class, NetworkAsyncClient.class)//
|
||||
.put(VirtualMachineClient.class, VirtualMachineAsyncClient.class)//
|
||||
.put(SecurityGroupClient.class, SecurityGroupAsyncClient.class)//
|
||||
.put(AsyncJobClient.class, AsyncJobAsyncClient.class)//
|
||||
.build();
|
||||
.put(ZoneClient.class, ZoneAsyncClient.class)//
|
||||
.put(TemplateClient.class, TemplateAsyncClient.class)//
|
||||
.put(OfferingClient.class, OfferingAsyncClient.class)//
|
||||
.put(NetworkClient.class, NetworkAsyncClient.class)//
|
||||
.put(VirtualMachineClient.class, VirtualMachineAsyncClient.class)//
|
||||
.put(SecurityGroupClient.class, SecurityGroupAsyncClient.class)//
|
||||
.put(AsyncJobClient.class, AsyncJobAsyncClient.class)//
|
||||
.put(AddressClient.class, AddressAsyncClient.class)//
|
||||
.build();
|
||||
|
||||
public CloudStackRestClientModule() {
|
||||
super(CloudStackClient.class, CloudStackAsyncClient.class, DELEGATE_MAP);
|
||||
|
|
|
@ -0,0 +1,513 @@
|
|||
/**
|
||||
*
|
||||
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||
*
|
||||
* ====================================================================
|
||||
* Licensed 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.cloudstack.domain;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
import com.google.common.base.CaseFormat;
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
public class PublicIPAddress implements Comparable<PublicIPAddress> {
|
||||
|
||||
public static Builder builder() {
|
||||
return new Builder();
|
||||
}
|
||||
|
||||
public static class Builder {
|
||||
private long id;
|
||||
private String account;
|
||||
private Date allocated;
|
||||
private long associatedNetworkId;
|
||||
private String domain;
|
||||
private long domainId;
|
||||
private boolean usesVirtualNetwork;
|
||||
private String IPAddress;
|
||||
private boolean isSourceNAT;
|
||||
private boolean isStaticNAT;
|
||||
private long networkId;
|
||||
private State state;
|
||||
private String virtualMachineDisplayName;
|
||||
private long virtualMachineId;
|
||||
private String virtualMachineName;
|
||||
private long VLANId;
|
||||
private String VLANName;
|
||||
private long zoneId;
|
||||
private String zoneName;
|
||||
|
||||
public Builder id(long id) {
|
||||
this.id = id;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder account(String account) {
|
||||
this.account = account;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder allocated(Date allocated) {
|
||||
this.allocated = allocated;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder associatedNetworkId(long associatedNetworkId) {
|
||||
this.associatedNetworkId = associatedNetworkId;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder domain(String domain) {
|
||||
this.domain = domain;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder domainId(long domainId) {
|
||||
this.domainId = domainId;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder usesVirtualNetwork(boolean usesVirtualNetwork) {
|
||||
this.usesVirtualNetwork = usesVirtualNetwork;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder IPAddress(String IPAddress) {
|
||||
this.IPAddress = IPAddress;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder isSourceNAT(boolean isSourceNAT) {
|
||||
this.isSourceNAT = isSourceNAT;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder isStaticNAT(boolean isStaticNAT) {
|
||||
this.isStaticNAT = isStaticNAT;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder networkId(long networkId) {
|
||||
this.networkId = networkId;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder state(State state) {
|
||||
this.state = state;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder virtualMachineDisplayName(String virtualMachineDisplayName) {
|
||||
this.virtualMachineDisplayName = virtualMachineDisplayName;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder virtualMachineId(long virtualMachineId) {
|
||||
this.virtualMachineId = virtualMachineId;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder virtualMachineName(String virtualMachineName) {
|
||||
this.virtualMachineName = virtualMachineName;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder VLANId(long VLANId) {
|
||||
this.VLANId = VLANId;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder VLANName(String VLANName) {
|
||||
this.VLANName = VLANName;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder zoneId(long zoneId) {
|
||||
this.zoneId = zoneId;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder zoneName(String zoneName) {
|
||||
this.zoneName = zoneName;
|
||||
return this;
|
||||
}
|
||||
|
||||
public PublicIPAddress build() {
|
||||
return new PublicIPAddress(id, account, allocated, associatedNetworkId, domain, domainId, usesVirtualNetwork,
|
||||
IPAddress, isSourceNAT, isStaticNAT, networkId, state, virtualMachineDisplayName, virtualMachineId,
|
||||
virtualMachineName, VLANId, VLANName, zoneId, zoneName);
|
||||
}
|
||||
}
|
||||
|
||||
private long id;
|
||||
private String account;
|
||||
private Date allocated;
|
||||
@SerializedName("associatednetworkid")
|
||||
private long associatedNetworkId;
|
||||
private String domain;
|
||||
@SerializedName("domainid")
|
||||
private long domainId;
|
||||
@SerializedName("forvirtualnetwork")
|
||||
private boolean usesVirtualNetwork;
|
||||
@SerializedName("ipaddress")
|
||||
private String IPAddress;
|
||||
@SerializedName("issourcenat")
|
||||
private boolean isSourceNAT;
|
||||
@SerializedName("isstaticnat")
|
||||
private boolean isStaticNAT;
|
||||
@SerializedName("networkid")
|
||||
private long networkId;
|
||||
private State state;
|
||||
@SerializedName("virtualmachinedisplayname")
|
||||
private String virtualMachineDisplayName;
|
||||
@SerializedName("virtualmachineid")
|
||||
private long virtualMachineId;
|
||||
@SerializedName("virtualmachinename")
|
||||
private String virtualMachineName;
|
||||
@SerializedName("VLANid")
|
||||
private long VLANId;
|
||||
@SerializedName("VLANname")
|
||||
private String VLANName;
|
||||
@SerializedName("zoneid")
|
||||
private long zoneId;
|
||||
@SerializedName("zonename")
|
||||
private String zoneName;
|
||||
|
||||
public static enum State {
|
||||
ALLOCATING, ALLOCATED, RELEASING, UNRECOGNIZED;
|
||||
@Override
|
||||
public String toString() {
|
||||
return CaseFormat.UPPER_UNDERSCORE.to(CaseFormat.UPPER_CAMEL, name());
|
||||
}
|
||||
|
||||
public static State fromValue(String state) {
|
||||
try {
|
||||
return valueOf(CaseFormat.UPPER_CAMEL.to(CaseFormat.UPPER_UNDERSCORE, checkNotNull(state, "state")));
|
||||
} catch (IllegalArgumentException e) {
|
||||
return UNRECOGNIZED;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// for serialization
|
||||
PublicIPAddress() {
|
||||
|
||||
}
|
||||
|
||||
public PublicIPAddress(long id, String account, Date allocated, long associatedNetworkId, String domain,
|
||||
long domainId, boolean usesVirtualNetwork, String iPAddress, boolean isSourceNAT, boolean isStaticNAT,
|
||||
long networkId, State state, String virtualMachineDisplayName, long virtualMachineId,
|
||||
String virtualMachineName, long VLANId, String VLANName, long zoneId, String zoneName) {
|
||||
this.id = id;
|
||||
this.account = account;
|
||||
this.allocated = allocated;
|
||||
this.associatedNetworkId = associatedNetworkId;
|
||||
this.domain = domain;
|
||||
this.domainId = domainId;
|
||||
this.usesVirtualNetwork = usesVirtualNetwork;
|
||||
this.IPAddress = iPAddress;
|
||||
this.isSourceNAT = isSourceNAT;
|
||||
this.isStaticNAT = isStaticNAT;
|
||||
this.networkId = networkId;
|
||||
this.state = state;
|
||||
this.virtualMachineDisplayName = virtualMachineDisplayName;
|
||||
this.virtualMachineId = virtualMachineId;
|
||||
this.virtualMachineName = virtualMachineName;
|
||||
this.VLANId = VLANId;
|
||||
this.VLANName = VLANName;
|
||||
this.zoneId = zoneId;
|
||||
this.zoneName = zoneName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(PublicIPAddress arg0) {
|
||||
return new Long(id).compareTo(arg0.getId());
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return public IP address id
|
||||
*/
|
||||
public long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return the account the public IP address is associated with
|
||||
*/
|
||||
public String getAccount() {
|
||||
return account;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return date the public IP address was acquired
|
||||
*/
|
||||
public Date getAllocated() {
|
||||
return allocated;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return the ID of the Network associated with the IP address
|
||||
*/
|
||||
public long getAssociatedNetworkId() {
|
||||
return associatedNetworkId;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return the domain the public IP address is associated with
|
||||
*/
|
||||
public String getDomain() {
|
||||
return domain;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return the domain ID the public IP address is associated with
|
||||
*/
|
||||
public long getDomainId() {
|
||||
return domainId;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return uses virtual network
|
||||
*/
|
||||
public boolean usesVirtualNetwork() {
|
||||
return usesVirtualNetwork;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return public IP address
|
||||
*/
|
||||
public String getIPAddress() {
|
||||
return IPAddress;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return true if the IP address is a source nat address, false otherwise
|
||||
*/
|
||||
public boolean isSourceNAT() {
|
||||
return isSourceNAT;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return true if this ip is for static nat, false otherwise
|
||||
*/
|
||||
public boolean isStaticNAT() {
|
||||
return isStaticNAT;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return the ID of the Network where ip belongs to
|
||||
*/
|
||||
public long getNetworkId() {
|
||||
return networkId;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return State of the ip address. Can be: Allocating, Allocated and Releasing
|
||||
*/
|
||||
public State getState() {
|
||||
return state;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return virtual machine display name the ip address is assigned to (not null only for static
|
||||
* nat Ip)
|
||||
*/
|
||||
public String getVirtualMachineDisplayName() {
|
||||
return virtualMachineDisplayName;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return virtual machine id the ip address is assigned to (not null only for static nat Ip)
|
||||
*/
|
||||
public long getVirtualMachineId() {
|
||||
return virtualMachineId;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return virtual machine name the ip address is assigned to (not null only for static nat Ip)
|
||||
*/
|
||||
public String getVirtualMachineName() {
|
||||
return virtualMachineName;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return the ID of the VLAN associated with the IP address
|
||||
*/
|
||||
public long getVLANId() {
|
||||
return VLANId;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return the VLAN associated with the IP address
|
||||
*/
|
||||
public String getVLANName() {
|
||||
return VLANName;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return the ID of the zone the public IP address belongs to
|
||||
*/
|
||||
public long getZoneId() {
|
||||
return zoneId;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return the name of the zone the public IP address belongs to
|
||||
*/
|
||||
public String getZoneName() {
|
||||
return zoneName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
result = prime * result + ((IPAddress == null) ? 0 : IPAddress.hashCode());
|
||||
result = prime * result + (int) (VLANId ^ (VLANId >>> 32));
|
||||
result = prime * result + ((VLANName == null) ? 0 : VLANName.hashCode());
|
||||
result = prime * result + ((account == null) ? 0 : account.hashCode());
|
||||
result = prime * result + ((allocated == null) ? 0 : allocated.hashCode());
|
||||
result = prime * result + (int) (associatedNetworkId ^ (associatedNetworkId >>> 32));
|
||||
result = prime * result + ((domain == null) ? 0 : domain.hashCode());
|
||||
result = prime * result + (int) (domainId ^ (domainId >>> 32));
|
||||
result = prime * result + (int) (id ^ (id >>> 32));
|
||||
result = prime * result + (isSourceNAT ? 1231 : 1237);
|
||||
result = prime * result + (isStaticNAT ? 1231 : 1237);
|
||||
result = prime * result + (int) (networkId ^ (networkId >>> 32));
|
||||
result = prime * result + ((state == null) ? 0 : state.hashCode());
|
||||
result = prime * result + (usesVirtualNetwork ? 1231 : 1237);
|
||||
result = prime * result + ((virtualMachineDisplayName == null) ? 0 : virtualMachineDisplayName.hashCode());
|
||||
result = prime * result + (int) (virtualMachineId ^ (virtualMachineId >>> 32));
|
||||
result = prime * result + ((virtualMachineName == null) ? 0 : virtualMachineName.hashCode());
|
||||
result = prime * result + (int) (zoneId ^ (zoneId >>> 32));
|
||||
result = prime * result + ((zoneName == null) ? 0 : zoneName.hashCode());
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj)
|
||||
return true;
|
||||
if (obj == null)
|
||||
return false;
|
||||
if (getClass() != obj.getClass())
|
||||
return false;
|
||||
PublicIPAddress other = (PublicIPAddress) obj;
|
||||
if (IPAddress == null) {
|
||||
if (other.IPAddress != null)
|
||||
return false;
|
||||
} else if (!IPAddress.equals(other.IPAddress))
|
||||
return false;
|
||||
if (VLANId != other.VLANId)
|
||||
return false;
|
||||
if (VLANName == null) {
|
||||
if (other.VLANName != null)
|
||||
return false;
|
||||
} else if (!VLANName.equals(other.VLANName))
|
||||
return false;
|
||||
if (account == null) {
|
||||
if (other.account != null)
|
||||
return false;
|
||||
} else if (!account.equals(other.account))
|
||||
return false;
|
||||
if (allocated == null) {
|
||||
if (other.allocated != null)
|
||||
return false;
|
||||
} else if (!allocated.equals(other.allocated))
|
||||
return false;
|
||||
if (associatedNetworkId != other.associatedNetworkId)
|
||||
return false;
|
||||
if (domain == null) {
|
||||
if (other.domain != null)
|
||||
return false;
|
||||
} else if (!domain.equals(other.domain))
|
||||
return false;
|
||||
if (domainId != other.domainId)
|
||||
return false;
|
||||
if (id != other.id)
|
||||
return false;
|
||||
if (isSourceNAT != other.isSourceNAT)
|
||||
return false;
|
||||
if (isStaticNAT != other.isStaticNAT)
|
||||
return false;
|
||||
if (networkId != other.networkId)
|
||||
return false;
|
||||
if (state == null) {
|
||||
if (other.state != null)
|
||||
return false;
|
||||
} else if (!state.equals(other.state))
|
||||
return false;
|
||||
if (usesVirtualNetwork != other.usesVirtualNetwork)
|
||||
return false;
|
||||
if (virtualMachineDisplayName == null) {
|
||||
if (other.virtualMachineDisplayName != null)
|
||||
return false;
|
||||
} else if (!virtualMachineDisplayName.equals(other.virtualMachineDisplayName))
|
||||
return false;
|
||||
if (virtualMachineId != other.virtualMachineId)
|
||||
return false;
|
||||
if (virtualMachineName == null) {
|
||||
if (other.virtualMachineName != null)
|
||||
return false;
|
||||
} else if (!virtualMachineName.equals(other.virtualMachineName))
|
||||
return false;
|
||||
if (zoneId != other.zoneId)
|
||||
return false;
|
||||
if (zoneName == null) {
|
||||
if (other.zoneName != null)
|
||||
return false;
|
||||
} else if (!zoneName.equals(other.zoneName))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "[id=" + id + ", IPAddress=" + IPAddress + ", VLANId=" + VLANId + ", VLANName=" + VLANName + ", account="
|
||||
+ account + ", allocated=" + allocated + ", associatedNetworkId=" + associatedNetworkId + ", domain="
|
||||
+ domain + ", domainId=" + domainId + ", usesVirtualNetwork=" + usesVirtualNetwork + ", isSourceNAT="
|
||||
+ isSourceNAT + ", isStaticNAT=" + isStaticNAT + ", networkId=" + networkId + ", state=" + state
|
||||
+ ", virtualMachineDisplayName=" + virtualMachineDisplayName + ", virtualMachineId=" + virtualMachineId
|
||||
+ ", virtualMachineName=" + virtualMachineName + ", zoneId=" + zoneId + ", zoneName=" + zoneName + "]";
|
||||
}
|
||||
|
||||
}
|
|
@ -513,7 +513,7 @@ public class VirtualMachine implements Comparable<VirtualMachine> {
|
|||
/**
|
||||
* @return the virtual network for the service offering
|
||||
*/
|
||||
public boolean isUsesVirtualNetwork() {
|
||||
public boolean usesVirtualNetwork() {
|
||||
return usesVirtualNetwork;
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,94 @@
|
|||
/**
|
||||
*
|
||||
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||
*
|
||||
* ====================================================================
|
||||
* Licensed 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.cloudstack.features;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
import javax.ws.rs.Consumes;
|
||||
import javax.ws.rs.GET;
|
||||
import javax.ws.rs.QueryParam;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
|
||||
import org.jclouds.cloudstack.domain.AsyncCreateResponse;
|
||||
import org.jclouds.cloudstack.domain.PublicIPAddress;
|
||||
import org.jclouds.cloudstack.filters.QuerySigner;
|
||||
import org.jclouds.cloudstack.options.AssociateIPAddressOptions;
|
||||
import org.jclouds.cloudstack.options.ListPublicIPAddressesOptions;
|
||||
import org.jclouds.rest.annotations.ExceptionParser;
|
||||
import org.jclouds.rest.annotations.QueryParams;
|
||||
import org.jclouds.rest.annotations.RequestFilters;
|
||||
import org.jclouds.rest.annotations.Unwrap;
|
||||
import org.jclouds.rest.functions.ReturnEmptySetOnNotFoundOr404;
|
||||
import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404;
|
||||
import org.jclouds.rest.functions.ReturnVoidOnNotFoundOr404;
|
||||
|
||||
import com.google.common.util.concurrent.ListenableFuture;
|
||||
|
||||
/**
|
||||
* Provides asynchronous access to cloudstack via their REST API.
|
||||
* <p/>
|
||||
*
|
||||
* @see AddressClient
|
||||
* @see <a href="http://download.cloud.com/releases/2.2.0/api/TOC_User.html" />
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@RequestFilters(QuerySigner.class)
|
||||
@QueryParams(keys = "response", values = "json")
|
||||
public interface AddressAsyncClient {
|
||||
|
||||
/**
|
||||
* @see AddressClient#listPublicIPAddresses
|
||||
*/
|
||||
@GET
|
||||
@QueryParams(keys = "command", values = "listPublicIpAddresses")
|
||||
@Unwrap(depth = 2)
|
||||
@Consumes(MediaType.APPLICATION_JSON)
|
||||
@ExceptionParser(ReturnEmptySetOnNotFoundOr404.class)
|
||||
ListenableFuture<Set<PublicIPAddress>> listPublicIPAddresses(ListPublicIPAddressesOptions... options);
|
||||
|
||||
/**
|
||||
* @see AddressClient#getPublicIPAddress
|
||||
*/
|
||||
@GET
|
||||
@QueryParams(keys = "command", values = "listPublicIpAddresses")
|
||||
@Unwrap(depth = 3, edgeCollection = Set.class)
|
||||
@Consumes(MediaType.APPLICATION_JSON)
|
||||
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
|
||||
ListenableFuture<PublicIPAddress> getPublicIPAddress(@QueryParam("id") long id);
|
||||
|
||||
/**
|
||||
* @see AddressClient#associateIPAddress
|
||||
*/
|
||||
@GET
|
||||
@QueryParams(keys = "command", values = "associateIpAddress")
|
||||
@Unwrap
|
||||
@Consumes(MediaType.APPLICATION_JSON)
|
||||
ListenableFuture<AsyncCreateResponse> associateIPAddress(@QueryParam("zoneid") long zoneId,
|
||||
AssociateIPAddressOptions... options);
|
||||
|
||||
/**
|
||||
* @see AddressClient#disassociateIPAddress
|
||||
*/
|
||||
@GET
|
||||
@QueryParams(keys = "command", values = "disassociateIpAddress")
|
||||
@ExceptionParser(ReturnVoidOnNotFoundOr404.class)
|
||||
ListenableFuture<Void> disassociateIPAddress(@QueryParam("id") long id);
|
||||
|
||||
}
|
|
@ -0,0 +1,75 @@
|
|||
/**
|
||||
*
|
||||
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||
*
|
||||
* ====================================================================
|
||||
* Licensed 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.cloudstack.features;
|
||||
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.jclouds.cloudstack.domain.AsyncCreateResponse;
|
||||
import org.jclouds.cloudstack.domain.PublicIPAddress;
|
||||
import org.jclouds.cloudstack.options.AssociateIPAddressOptions;
|
||||
import org.jclouds.cloudstack.options.ListPublicIPAddressesOptions;
|
||||
import org.jclouds.concurrent.Timeout;
|
||||
|
||||
/**
|
||||
* Provides synchronous access to CloudStack IPAddress features.
|
||||
* <p/>
|
||||
*
|
||||
* @see IPAddressAsyncClient
|
||||
* @see <a href="http://download.cloud.com/releases/2.2.0/api/TOC_User.html" />
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@Timeout(duration = 60, timeUnit = TimeUnit.SECONDS)
|
||||
public interface AddressClient {
|
||||
/**
|
||||
* Lists IPAddresses
|
||||
*
|
||||
* @param options
|
||||
* if present, how to constrain the list.
|
||||
* @return IPAddresses matching query, or empty set, if no IPAddresses are found
|
||||
*/
|
||||
Set<PublicIPAddress> listPublicIPAddresses(ListPublicIPAddressesOptions... options);
|
||||
|
||||
/**
|
||||
* get a specific IPAddress by id
|
||||
*
|
||||
* @param id
|
||||
* IPAddress to get
|
||||
* @return IPAddress or null if not found
|
||||
*/
|
||||
PublicIPAddress getPublicIPAddress(long id);
|
||||
|
||||
/**
|
||||
* Acquires and associates a public IP to an account.
|
||||
*
|
||||
* @param zoneId
|
||||
* the ID of the availability zone you want to acquire an public IP address from
|
||||
* @return IPAddress
|
||||
*/
|
||||
AsyncCreateResponse associateIPAddress(long zoneId, AssociateIPAddressOptions... options);
|
||||
|
||||
/**
|
||||
* Disassociates an ip address from the account.
|
||||
*
|
||||
* @param id
|
||||
* the id of the public ip address to disassociate
|
||||
*/
|
||||
void disassociateIPAddress(long id);
|
||||
}
|
|
@ -0,0 +1,91 @@
|
|||
/**
|
||||
*
|
||||
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||
*
|
||||
* ====================================================================
|
||||
* Licensed 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.cloudstack.options;
|
||||
|
||||
import org.jclouds.http.options.BaseHttpRequestOptions;
|
||||
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
|
||||
/**
|
||||
* Options used to acquire and associate a public IP to an account.
|
||||
*
|
||||
* @see <a href="http://download.cloud.com/releases/2.2.0/api/user/associateIpAddress.html" />
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
public class AssociateIPAddressOptions extends BaseHttpRequestOptions {
|
||||
|
||||
public static final AssociateIPAddressOptions NONE = new AssociateIPAddressOptions();
|
||||
|
||||
/**
|
||||
* @param domainId
|
||||
* the ID of the domain to associate with this IP address
|
||||
*/
|
||||
public AssociateIPAddressOptions domainId(long domainId) {
|
||||
this.queryParameters.replaceValues("domainid", ImmutableSet.of(domainId + ""));
|
||||
return this;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param account
|
||||
* the account to associate with this IP address
|
||||
*/
|
||||
public AssociateIPAddressOptions account(String account) {
|
||||
this.queryParameters.replaceValues("account", ImmutableSet.of(account));
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param networkId
|
||||
* The network this ip address should be associated to.
|
||||
*/
|
||||
public AssociateIPAddressOptions networkId(long networkId) {
|
||||
this.queryParameters.replaceValues("networkid", ImmutableSet.of(networkId + ""));
|
||||
return this;
|
||||
|
||||
}
|
||||
|
||||
public static class Builder {
|
||||
|
||||
/**
|
||||
* @see AssociateIPAddressOptions#account
|
||||
*/
|
||||
public static AssociateIPAddressOptions account(String account) {
|
||||
AssociateIPAddressOptions options = new AssociateIPAddressOptions();
|
||||
return options.account(account);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see AssociateIPAddressOptions#domainId
|
||||
*/
|
||||
public static AssociateIPAddressOptions domainId(long id) {
|
||||
AssociateIPAddressOptions options = new AssociateIPAddressOptions();
|
||||
return options.domainId(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see AssociateIPAddressOptions#networkId
|
||||
*/
|
||||
public static AssociateIPAddressOptions networkId(long networkId) {
|
||||
AssociateIPAddressOptions options = new AssociateIPAddressOptions();
|
||||
return options.networkId(networkId);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,200 @@
|
|||
/**
|
||||
*
|
||||
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||
*
|
||||
* ====================================================================
|
||||
* Licensed 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.cloudstack.options;
|
||||
|
||||
import org.jclouds.http.options.BaseHttpRequestOptions;
|
||||
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
|
||||
/**
|
||||
* Options used to control what ip addresss information is returned
|
||||
*
|
||||
* @see <a href="http://download.cloud.com/releases/2.2.0/api/user/listIPAddresses.html" />
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
public class ListPublicIPAddressesOptions extends BaseHttpRequestOptions {
|
||||
|
||||
public static final ListPublicIPAddressesOptions NONE = new ListPublicIPAddressesOptions();
|
||||
|
||||
/**
|
||||
* @param id
|
||||
* lists ip address by id
|
||||
*/
|
||||
public ListPublicIPAddressesOptions id(long id) {
|
||||
this.queryParameters.replaceValues("id", ImmutableSet.of(id + ""));
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param domainId
|
||||
* lists all public IP addresses by domain ID. If used with the account parameter,
|
||||
* lists all public IP addresses by account for specified domain.
|
||||
*/
|
||||
public ListPublicIPAddressesOptions domainId(long domainId) {
|
||||
this.queryParameters.replaceValues("domainid", ImmutableSet.of(domainId + ""));
|
||||
return this;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param account
|
||||
* account id
|
||||
* @param domain
|
||||
* domain id
|
||||
*/
|
||||
public ListPublicIPAddressesOptions accountInDomain(String account, long domain) {
|
||||
this.queryParameters.replaceValues("account", ImmutableSet.of(account));
|
||||
return domainId(domain);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param allocatedOnly
|
||||
* limits search results to allocated public IP addresses
|
||||
*/
|
||||
public ListPublicIPAddressesOptions allocatedOnly(boolean allocatedOnly) {
|
||||
this.queryParameters.replaceValues("allocatedonly", ImmutableSet.of(allocatedOnly + ""));
|
||||
return this;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param networkId
|
||||
* list ip addresss by networkId.
|
||||
*/
|
||||
public ListPublicIPAddressesOptions networkId(long networkId) {
|
||||
this.queryParameters.replaceValues("networkid", ImmutableSet.of(networkId + ""));
|
||||
return this;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param VLANId
|
||||
* lists all public IP addresses by VLAN ID
|
||||
*/
|
||||
public ListPublicIPAddressesOptions VLANId(long VLANId) {
|
||||
this.queryParameters.replaceValues("vlanid", ImmutableSet.of(VLANId + ""));
|
||||
return this;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param IPAddress
|
||||
* lists the specified IP address
|
||||
*/
|
||||
public ListPublicIPAddressesOptions IPAddress(String IPAddress) {
|
||||
this.queryParameters.replaceValues("ipaddress", ImmutableSet.of(IPAddress));
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param zoneId
|
||||
* lists all public IP addresses by Zone ID
|
||||
*/
|
||||
public ListPublicIPAddressesOptions zoneId(long zoneId) {
|
||||
this.queryParameters.replaceValues("zoneid", ImmutableSet.of(zoneId + ""));
|
||||
return this;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param usesVirtualNetwork
|
||||
* the virtual network for the IP address
|
||||
*/
|
||||
public ListPublicIPAddressesOptions usesVirtualNetwork(boolean usesVirtualNetwork) {
|
||||
this.queryParameters.replaceValues("forvirtualnetwork", ImmutableSet.of(usesVirtualNetwork + ""));
|
||||
return this;
|
||||
}
|
||||
|
||||
public static class Builder {
|
||||
|
||||
/**
|
||||
* @see ListPublicIPAddressesOptions#accountInDomain
|
||||
*/
|
||||
public static ListPublicIPAddressesOptions accountInDomain(String account, long domain) {
|
||||
ListPublicIPAddressesOptions options = new ListPublicIPAddressesOptions();
|
||||
return options.accountInDomain(account, domain);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see ListPublicIPAddressesOptions#IPAddress
|
||||
*/
|
||||
public static ListPublicIPAddressesOptions IPAddress(String IPAddress) {
|
||||
ListPublicIPAddressesOptions options = new ListPublicIPAddressesOptions();
|
||||
return options.IPAddress(IPAddress);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see ListPublicIPAddressesOptions#domainId
|
||||
*/
|
||||
public static ListPublicIPAddressesOptions domainId(long id) {
|
||||
ListPublicIPAddressesOptions options = new ListPublicIPAddressesOptions();
|
||||
return options.domainId(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see ListPublicIPAddressesOptions#id
|
||||
*/
|
||||
public static ListPublicIPAddressesOptions id(long id) {
|
||||
ListPublicIPAddressesOptions options = new ListPublicIPAddressesOptions();
|
||||
return options.id(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see ListPublicIPAddressesOptions#allocatedOnly
|
||||
*/
|
||||
public static ListPublicIPAddressesOptions allocatedOnly(boolean allocatedOnly) {
|
||||
ListPublicIPAddressesOptions options = new ListPublicIPAddressesOptions();
|
||||
return options.allocatedOnly(allocatedOnly);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see ListPublicIPAddressesOptions#networkId
|
||||
*/
|
||||
public static ListPublicIPAddressesOptions networkId(long id) {
|
||||
ListPublicIPAddressesOptions options = new ListPublicIPAddressesOptions();
|
||||
return options.networkId(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see ListPublicIPAddressesOptions#VLANId
|
||||
*/
|
||||
public static ListPublicIPAddressesOptions VLANId(long id) {
|
||||
ListPublicIPAddressesOptions options = new ListPublicIPAddressesOptions();
|
||||
return options.VLANId(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see ListPublicIPAddressesOptions#zoneId
|
||||
*/
|
||||
public static ListPublicIPAddressesOptions zoneId(long id) {
|
||||
ListPublicIPAddressesOptions options = new ListPublicIPAddressesOptions();
|
||||
return options.zoneId(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see ListPublicIPAddressesOptions#usesVirtualNetwork
|
||||
*/
|
||||
public static ListPublicIPAddressesOptions usesVirtualNetwork(boolean usesVirtualNetwork) {
|
||||
ListPublicIPAddressesOptions options = new ListPublicIPAddressesOptions();
|
||||
return options.usesVirtualNetwork(usesVirtualNetwork);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -50,6 +50,7 @@ public class CloudStackAsyncClientTest extends BaseCloudStackAsyncClientTest<Clo
|
|||
assert syncClient.getVirtualMachineClient() != null;
|
||||
assert syncClient.getSecurityGroupClient() != null;
|
||||
assert syncClient.getAsyncJobClient() != null;
|
||||
assert syncClient.getAddressClient() != null;
|
||||
}
|
||||
|
||||
public void testAsync() throws SecurityException, NoSuchMethodException, InterruptedException, ExecutionException {
|
||||
|
@ -60,6 +61,7 @@ public class CloudStackAsyncClientTest extends BaseCloudStackAsyncClientTest<Clo
|
|||
assert asyncClient.getVirtualMachineClient() != null;
|
||||
assert asyncClient.getSecurityGroupClient() != null;
|
||||
assert asyncClient.getAsyncJobClient() != null;
|
||||
assert asyncClient.getAddressClient() != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -0,0 +1,145 @@
|
|||
/**
|
||||
*
|
||||
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||
*
|
||||
* ====================================================================
|
||||
* Licensed 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.cloudstack.features;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
import org.jclouds.cloudstack.options.AssociateIPAddressOptions;
|
||||
import org.jclouds.cloudstack.options.ListPublicIPAddressesOptions;
|
||||
import org.jclouds.http.HttpRequest;
|
||||
import org.jclouds.http.functions.ReleasePayloadAndReturn;
|
||||
import org.jclouds.http.functions.UnwrapOnlyJsonValue;
|
||||
import org.jclouds.http.functions.UnwrapOnlyNestedJsonValue;
|
||||
import org.jclouds.http.functions.UnwrapOnlyNestedJsonValueInSet;
|
||||
import org.jclouds.rest.functions.MapHttp4xxCodesToExceptions;
|
||||
import org.jclouds.rest.functions.ReturnEmptySetOnNotFoundOr404;
|
||||
import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404;
|
||||
import org.jclouds.rest.functions.ReturnVoidOnNotFoundOr404;
|
||||
import org.jclouds.rest.internal.RestAnnotationProcessor;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import com.google.inject.TypeLiteral;
|
||||
|
||||
/**
|
||||
* Tests behavior of {@code AddressAsyncClient}
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
// NOTE:without testName, this will not call @Before* and fail w/NPE during surefire
|
||||
@Test(groups = "unit", testName = "AddressAsyncClientTest")
|
||||
public class AddressAsyncClientTest extends BaseCloudStackAsyncClientTest<AddressAsyncClient> {
|
||||
public void testListPublicIPAddresses() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = AddressAsyncClient.class.getMethod("listPublicIPAddresses",
|
||||
ListPublicIPAddressesOptions[].class);
|
||||
HttpRequest httpRequest = processor.createRequest(method);
|
||||
|
||||
assertRequestLineEquals(httpRequest,
|
||||
"GET http://localhost:8080/client/api?response=json&command=listPublicIpAddresses HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\n");
|
||||
assertPayloadEquals(httpRequest, null, null, false);
|
||||
|
||||
assertResponseParserClassEquals(method, httpRequest, UnwrapOnlyNestedJsonValue.class);
|
||||
assertSaxResponseParserClassEquals(method, null);
|
||||
assertExceptionParserClassEquals(method, ReturnEmptySetOnNotFoundOr404.class);
|
||||
|
||||
checkFilters(httpRequest);
|
||||
|
||||
}
|
||||
|
||||
public void testListPublicIPAddressesOptions() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = AddressAsyncClient.class.getMethod("listPublicIPAddresses",
|
||||
ListPublicIPAddressesOptions[].class);
|
||||
HttpRequest httpRequest = processor.createRequest(method,
|
||||
ListPublicIPAddressesOptions.Builder.accountInDomain("adrian", 6).usesVirtualNetwork(true));
|
||||
|
||||
assertRequestLineEquals(
|
||||
httpRequest,
|
||||
"GET http://localhost:8080/client/api?response=json&command=listPublicIpAddresses&account=adrian&domainid=6&forvirtualnetwork=true HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\n");
|
||||
assertPayloadEquals(httpRequest, null, null, false);
|
||||
|
||||
assertResponseParserClassEquals(method, httpRequest, UnwrapOnlyNestedJsonValue.class);
|
||||
assertSaxResponseParserClassEquals(method, null);
|
||||
assertExceptionParserClassEquals(method, ReturnEmptySetOnNotFoundOr404.class);
|
||||
|
||||
checkFilters(httpRequest);
|
||||
|
||||
}
|
||||
|
||||
public void testGetPublicIPAddress() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = AddressAsyncClient.class.getMethod("getPublicIPAddress", long.class);
|
||||
HttpRequest httpRequest = processor.createRequest(method, 5);
|
||||
|
||||
assertRequestLineEquals(httpRequest,
|
||||
"GET http://localhost:8080/client/api?response=json&command=listPublicIpAddresses&id=5 HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\n");
|
||||
assertPayloadEquals(httpRequest, null, null, false);
|
||||
|
||||
assertResponseParserClassEquals(method, httpRequest, UnwrapOnlyNestedJsonValueInSet.class);
|
||||
assertSaxResponseParserClassEquals(method, null);
|
||||
assertExceptionParserClassEquals(method, ReturnNullOnNotFoundOr404.class);
|
||||
|
||||
checkFilters(httpRequest);
|
||||
|
||||
}
|
||||
|
||||
public void testAssociateIPAddress() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = AddressAsyncClient.class.getMethod("associateIPAddress",
|
||||
long.class, AssociateIPAddressOptions[].class);
|
||||
HttpRequest httpRequest = processor.createRequest(method, 6);
|
||||
|
||||
assertRequestLineEquals(
|
||||
httpRequest,
|
||||
"GET http://localhost:8080/client/api?response=json&command=associateIpAddress&zoneid=6 HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\n");
|
||||
assertPayloadEquals(httpRequest, null, null, false);
|
||||
|
||||
assertResponseParserClassEquals(method, httpRequest, UnwrapOnlyJsonValue.class);
|
||||
assertSaxResponseParserClassEquals(method, null);
|
||||
assertExceptionParserClassEquals(method, MapHttp4xxCodesToExceptions.class);
|
||||
|
||||
checkFilters(httpRequest);
|
||||
|
||||
}
|
||||
|
||||
public void testDisassociateIPAddress() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = AddressAsyncClient.class.getMethod("disassociateIPAddress", long.class);
|
||||
HttpRequest httpRequest = processor.createRequest(method, 5);
|
||||
|
||||
assertRequestLineEquals(httpRequest,
|
||||
"GET http://localhost:8080/client/api?response=json&command=disassociateIpAddress&id=5 HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(httpRequest, "");
|
||||
assertPayloadEquals(httpRequest, null, null, false);
|
||||
|
||||
assertResponseParserClassEquals(method, httpRequest, ReleasePayloadAndReturn.class);
|
||||
assertSaxResponseParserClassEquals(method, null);
|
||||
assertExceptionParserClassEquals(method, ReturnVoidOnNotFoundOr404.class);
|
||||
|
||||
checkFilters(httpRequest);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected TypeLiteral<RestAnnotationProcessor<AddressAsyncClient>> createTypeLiteral() {
|
||||
return new TypeLiteral<RestAnnotationProcessor<AddressAsyncClient>>() {
|
||||
};
|
||||
}
|
||||
}
|
|
@ -0,0 +1,97 @@
|
|||
/**
|
||||
*
|
||||
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||
*
|
||||
* ====================================================================
|
||||
* Licensed 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.cloudstack.features;
|
||||
|
||||
import static com.google.common.collect.Iterables.get;
|
||||
import static com.google.common.collect.Iterables.getOnlyElement;
|
||||
import static org.testng.Assert.assertEquals;
|
||||
import static org.testng.Assert.assertTrue;
|
||||
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.jclouds.cloudstack.domain.AsyncCreateResponse;
|
||||
import org.jclouds.cloudstack.domain.PublicIPAddress;
|
||||
import org.jclouds.cloudstack.domain.Zone;
|
||||
import org.jclouds.cloudstack.options.ListPublicIPAddressesOptions;
|
||||
import org.jclouds.cloudstack.predicates.JobComplete;
|
||||
import org.jclouds.predicates.RetryablePredicate;
|
||||
import org.testng.annotations.AfterGroups;
|
||||
import org.testng.annotations.BeforeGroups;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
/**
|
||||
* Tests behavior of {@code PublicIPAddressClientLiveTest}
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@Test(groups = "live", sequential = true, testName = "PublicIPAddressClientLiveTest")
|
||||
public class AddressClientLiveTest extends BaseCloudStackClientLiveTest {
|
||||
private PublicIPAddress ip = null;
|
||||
private RetryablePredicate<Long> jobComplete;
|
||||
|
||||
@BeforeGroups(groups = "live")
|
||||
public void setupClient() {
|
||||
super.setupClient();
|
||||
jobComplete = new RetryablePredicate<Long>(new JobComplete(client), 600, 5, TimeUnit.SECONDS);
|
||||
}
|
||||
|
||||
public void testAssociateDisassociatePublicIPAddress() throws Exception {
|
||||
final Zone zone = get(client.getZoneClient().listZones(), 0);
|
||||
|
||||
AsyncCreateResponse job = client.getAddressClient().associateIPAddress(zone.getId());
|
||||
assert jobComplete.apply(job.getJobId());
|
||||
ip = client.getAddressClient().getPublicIPAddress(job.getId());
|
||||
assertEquals(ip.getZoneId(), zone.getId());
|
||||
checkIP(ip);
|
||||
}
|
||||
|
||||
@AfterGroups(groups = "live")
|
||||
protected void tearDown() {
|
||||
if (ip != null) {
|
||||
client.getAddressClient().disassociateIPAddress(ip.getId());
|
||||
}
|
||||
super.tearDown();
|
||||
}
|
||||
|
||||
public void testListPublicIPAddresss() throws Exception {
|
||||
Set<PublicIPAddress> response = client.getAddressClient().listPublicIPAddresses();
|
||||
assert null != response;
|
||||
assertTrue(response.size() >= 0);
|
||||
for (PublicIPAddress ip : response) {
|
||||
PublicIPAddress newDetails = getOnlyElement(client.getAddressClient().listPublicIPAddresses(
|
||||
ListPublicIPAddressesOptions.Builder.id(ip.getId())));
|
||||
assertEquals(ip.getId(), newDetails.getId());
|
||||
checkIP(ip);
|
||||
}
|
||||
}
|
||||
|
||||
protected void checkIP(PublicIPAddress ip) {
|
||||
assertEquals(ip.getId(), client.getAddressClient().getPublicIPAddress(ip.getId()).getId());
|
||||
assert ip.getId() > 0 : ip;
|
||||
assert ip.getAccount() != null : ip;
|
||||
assert ip.getDomain() != null : ip;
|
||||
assert ip.getDomainId() > 0 : ip;
|
||||
assert ip.getState() != null : ip;
|
||||
assert ip.getZoneId() > 0 : ip;
|
||||
assert ip.getZoneName() != null : ip;
|
||||
|
||||
}
|
||||
}
|
|
@ -0,0 +1,75 @@
|
|||
/**
|
||||
*
|
||||
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||
*
|
||||
* ====================================================================
|
||||
* Licensed 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.cloudstack.functions;
|
||||
|
||||
import static org.testng.Assert.assertEquals;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.util.Set;
|
||||
|
||||
import org.jclouds.cloudstack.domain.PublicIPAddress;
|
||||
import org.jclouds.date.internal.SimpleDateFormatDateService;
|
||||
import org.jclouds.http.HttpResponse;
|
||||
import org.jclouds.http.functions.UnwrapOnlyNestedJsonValue;
|
||||
import org.jclouds.io.Payloads;
|
||||
import org.jclouds.json.config.GsonModule;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import com.google.common.collect.Iterables;
|
||||
import com.google.inject.Guice;
|
||||
import com.google.inject.Injector;
|
||||
import com.google.inject.Key;
|
||||
import com.google.inject.TypeLiteral;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@Test(groups = "unit")
|
||||
public class ListPublicIPAddressesResponseTest {
|
||||
|
||||
Injector i = Guice.createInjector(new GsonModule() {
|
||||
|
||||
@Override
|
||||
protected void configure() {
|
||||
bind(DateAdapter.class).to(Iso8601DateAdapter.class);
|
||||
super.configure();
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
public void test() {
|
||||
InputStream is = getClass().getResourceAsStream("/listpublicipaddressesresponse.json");
|
||||
|
||||
PublicIPAddress expects = PublicIPAddress.builder().id(30).IPAddress("72.52.126.59").allocated(
|
||||
new SimpleDateFormatDateService().iso8601SecondsDateParse("2011-02-19T21:15:01-0800")).zoneId(1)
|
||||
.zoneName("San Jose 1").isSourceNAT(false).account("adrian").domainId(1).domain("ROOT")
|
||||
.usesVirtualNetwork(true).isStaticNAT(false).associatedNetworkId(204).networkId(200).state(
|
||||
PublicIPAddress.State.ALLOCATED).build();
|
||||
|
||||
UnwrapOnlyNestedJsonValue<Set<PublicIPAddress>> parser = i.getInstance(Key
|
||||
.get(new TypeLiteral<UnwrapOnlyNestedJsonValue<Set<PublicIPAddress>>>() {
|
||||
}));
|
||||
Set<PublicIPAddress> response = parser.apply(new HttpResponse(200, "ok", Payloads.newInputStreamPayload(is)));
|
||||
|
||||
assertEquals(Iterables.getOnlyElement(response), expects);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,68 @@
|
|||
/**
|
||||
*
|
||||
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||
*
|
||||
* ====================================================================
|
||||
* Licensed 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.cloudstack.options;
|
||||
|
||||
import static org.jclouds.cloudstack.options.AssociateIPAddressOptions.Builder.account;
|
||||
import static org.jclouds.cloudstack.options.AssociateIPAddressOptions.Builder.domainId;
|
||||
import static org.jclouds.cloudstack.options.AssociateIPAddressOptions.Builder.networkId;
|
||||
import static org.testng.Assert.assertEquals;
|
||||
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
|
||||
/**
|
||||
* Tests behavior of {@code AssociateIPAddressOptions}
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@Test(groups = "unit")
|
||||
public class AssociateIPAddressOptionsTest {
|
||||
|
||||
public void testAccount() {
|
||||
AssociateIPAddressOptions options = new AssociateIPAddressOptions().account("account");
|
||||
assertEquals(ImmutableList.of("account"), options.buildQueryParameters().get("account"));
|
||||
}
|
||||
|
||||
public void testAccountStatic() {
|
||||
AssociateIPAddressOptions options = account("account");
|
||||
assertEquals(ImmutableList.of("account"), options.buildQueryParameters().get("account"));
|
||||
}
|
||||
|
||||
public void testDomainId() {
|
||||
AssociateIPAddressOptions options = new AssociateIPAddressOptions().domainId(6);
|
||||
assertEquals(ImmutableList.of("6"), options.buildQueryParameters().get("domainid"));
|
||||
}
|
||||
|
||||
public void testDomainIdStatic() {
|
||||
AssociateIPAddressOptions options = domainId(6);
|
||||
assertEquals(ImmutableList.of("6"), options.buildQueryParameters().get("domainid"));
|
||||
}
|
||||
|
||||
public void testNetworkId() {
|
||||
AssociateIPAddressOptions options = new AssociateIPAddressOptions().networkId(6);
|
||||
assertEquals(ImmutableList.of("6"), options.buildQueryParameters().get("networkid"));
|
||||
}
|
||||
|
||||
public void testNetworkIdStatic() {
|
||||
AssociateIPAddressOptions options = networkId(6);
|
||||
assertEquals(ImmutableList.of("6"), options.buildQueryParameters().get("networkid"));
|
||||
}
|
||||
}
|
|
@ -0,0 +1,136 @@
|
|||
/**
|
||||
*
|
||||
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||
*
|
||||
* ====================================================================
|
||||
* Licensed 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.cloudstack.options;
|
||||
|
||||
import static org.jclouds.cloudstack.options.ListPublicIPAddressesOptions.Builder.accountInDomain;
|
||||
import static org.jclouds.cloudstack.options.ListPublicIPAddressesOptions.Builder.domainId;
|
||||
import static org.jclouds.cloudstack.options.ListPublicIPAddressesOptions.Builder.IPAddress;
|
||||
import static org.jclouds.cloudstack.options.ListPublicIPAddressesOptions.Builder.allocatedOnly;
|
||||
import static org.jclouds.cloudstack.options.ListPublicIPAddressesOptions.Builder.id;
|
||||
import static org.jclouds.cloudstack.options.ListPublicIPAddressesOptions.Builder.networkId;
|
||||
import static org.jclouds.cloudstack.options.ListPublicIPAddressesOptions.Builder.VLANId;
|
||||
import static org.jclouds.cloudstack.options.ListPublicIPAddressesOptions.Builder.usesVirtualNetwork;
|
||||
import static org.jclouds.cloudstack.options.ListPublicIPAddressesOptions.Builder.zoneId;
|
||||
import static org.testng.Assert.assertEquals;
|
||||
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
|
||||
/**
|
||||
* Tests behavior of {@code ListIPAddressesOptions}
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@Test(groups = "unit")
|
||||
public class ListPublicIPAddressesOptionsTest {
|
||||
|
||||
public void testAllocatedOnly() {
|
||||
ListPublicIPAddressesOptions options = new ListPublicIPAddressesOptions().allocatedOnly(true);
|
||||
assertEquals(ImmutableList.of("true"), options.buildQueryParameters().get("allocatedonly"));
|
||||
}
|
||||
|
||||
public void testAllocatedOnlyStatic() {
|
||||
ListPublicIPAddressesOptions options = allocatedOnly(true);
|
||||
assertEquals(ImmutableList.of("true"), options.buildQueryParameters().get("allocatedonly"));
|
||||
}
|
||||
|
||||
public void testVLANId() {
|
||||
ListPublicIPAddressesOptions options = new ListPublicIPAddressesOptions().VLANId(6);
|
||||
assertEquals(ImmutableList.of("6"), options.buildQueryParameters().get("vlanid"));
|
||||
}
|
||||
|
||||
public void testVLANIdStatic() {
|
||||
ListPublicIPAddressesOptions options = VLANId(6);
|
||||
assertEquals(ImmutableList.of("6"), options.buildQueryParameters().get("vlanid"));
|
||||
}
|
||||
|
||||
public void testNetworkId() {
|
||||
ListPublicIPAddressesOptions options = new ListPublicIPAddressesOptions().networkId(6);
|
||||
assertEquals(ImmutableList.of("6"), options.buildQueryParameters().get("networkid"));
|
||||
}
|
||||
|
||||
public void testNetworkIdStatic() {
|
||||
ListPublicIPAddressesOptions options = networkId(6);
|
||||
assertEquals(ImmutableList.of("6"), options.buildQueryParameters().get("networkid"));
|
||||
}
|
||||
|
||||
public void testIPAddress() {
|
||||
ListPublicIPAddressesOptions options = new ListPublicIPAddressesOptions().IPAddress("10.1.1.1");
|
||||
assertEquals(ImmutableList.of("10.1.1.1"), options.buildQueryParameters().get("ipaddress"));
|
||||
}
|
||||
|
||||
public void testIPAddressStatic() {
|
||||
ListPublicIPAddressesOptions options = IPAddress("10.1.1.1");
|
||||
assertEquals(ImmutableList.of("10.1.1.1"), options.buildQueryParameters().get("ipaddress"));
|
||||
}
|
||||
|
||||
public void testAccountInDomainId() {
|
||||
ListPublicIPAddressesOptions options = new ListPublicIPAddressesOptions().accountInDomain("adrian", 6);
|
||||
assertEquals(ImmutableList.of("adrian"), options.buildQueryParameters().get("account"));
|
||||
assertEquals(ImmutableList.of("6"), options.buildQueryParameters().get("domainid"));
|
||||
}
|
||||
|
||||
public void testAccountInDomainIdStatic() {
|
||||
ListPublicIPAddressesOptions options = accountInDomain("adrian", 6);
|
||||
assertEquals(ImmutableList.of("adrian"), options.buildQueryParameters().get("account"));
|
||||
assertEquals(ImmutableList.of("6"), options.buildQueryParameters().get("domainid"));
|
||||
}
|
||||
|
||||
public void testZoneId() {
|
||||
ListPublicIPAddressesOptions options = new ListPublicIPAddressesOptions().zoneId(6);
|
||||
assertEquals(ImmutableList.of("6"), options.buildQueryParameters().get("zoneid"));
|
||||
}
|
||||
|
||||
public void testZoneIdStatic() {
|
||||
ListPublicIPAddressesOptions options = zoneId(6);
|
||||
assertEquals(ImmutableList.of("6"), options.buildQueryParameters().get("zoneid"));
|
||||
}
|
||||
|
||||
public void testUsingVirtualNetwork() {
|
||||
ListPublicIPAddressesOptions options = new ListPublicIPAddressesOptions().usesVirtualNetwork(true);
|
||||
assertEquals(ImmutableList.of("true"), options.buildQueryParameters().get("forvirtualnetwork"));
|
||||
}
|
||||
|
||||
public void testUsingVirtualNetworkStatic() {
|
||||
ListPublicIPAddressesOptions options = usesVirtualNetwork(true);
|
||||
assertEquals(ImmutableList.of("true"), options.buildQueryParameters().get("forvirtualnetwork"));
|
||||
}
|
||||
|
||||
public void testId() {
|
||||
ListPublicIPAddressesOptions options = new ListPublicIPAddressesOptions().id(6);
|
||||
assertEquals(ImmutableList.of("6"), options.buildQueryParameters().get("id"));
|
||||
}
|
||||
|
||||
public void testDomainId() {
|
||||
ListPublicIPAddressesOptions options = new ListPublicIPAddressesOptions().domainId(6);
|
||||
assertEquals(ImmutableList.of("6"), options.buildQueryParameters().get("domainid"));
|
||||
}
|
||||
|
||||
public void testIdStatic() {
|
||||
ListPublicIPAddressesOptions options = id(6);
|
||||
assertEquals(ImmutableList.of("6"), options.buildQueryParameters().get("id"));
|
||||
}
|
||||
|
||||
public void testDomainIdStatic() {
|
||||
ListPublicIPAddressesOptions options = domainId(6);
|
||||
assertEquals(ImmutableList.of("6"), options.buildQueryParameters().get("domainid"));
|
||||
}
|
||||
}
|
|
@ -0,0 +1 @@
|
|||
{ "listpublicipaddressesresponse" : { "publicipaddress" : [ {"id":30,"ipaddress":"72.52.126.59","allocated":"2011-02-19T21:15:01-0800","zoneid":1,"zonename":"San Jose 1","issourcenat":false,"account":"adrian","domainid":1,"domain":"ROOT","forvirtualnetwork":true,"isstaticnat":false,"associatednetworkid":204,"networkid":200,"state":"Allocated"} ] } }
|
Loading…
Reference in New Issue