mirror of https://github.com/apache/jclouds.git
added firewall rules to cloudstack
This commit is contained in:
parent
69e909144a
commit
9943169a80
|
@ -21,6 +21,7 @@ package org.jclouds.cloudstack;
|
||||||
|
|
||||||
import org.jclouds.cloudstack.features.AddressAsyncClient;
|
import org.jclouds.cloudstack.features.AddressAsyncClient;
|
||||||
import org.jclouds.cloudstack.features.AsyncJobAsyncClient;
|
import org.jclouds.cloudstack.features.AsyncJobAsyncClient;
|
||||||
|
import org.jclouds.cloudstack.features.FirewallAsyncClient;
|
||||||
import org.jclouds.cloudstack.features.NATAsyncClient;
|
import org.jclouds.cloudstack.features.NATAsyncClient;
|
||||||
import org.jclouds.cloudstack.features.NetworkAsyncClient;
|
import org.jclouds.cloudstack.features.NetworkAsyncClient;
|
||||||
import org.jclouds.cloudstack.features.OfferingAsyncClient;
|
import org.jclouds.cloudstack.features.OfferingAsyncClient;
|
||||||
|
@ -93,4 +94,10 @@ public interface CloudStackAsyncClient {
|
||||||
*/
|
*/
|
||||||
@Delegate
|
@Delegate
|
||||||
NATAsyncClient getNATClient();
|
NATAsyncClient getNATClient();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Provides asynchronous access to Firewall features.
|
||||||
|
*/
|
||||||
|
@Delegate
|
||||||
|
FirewallAsyncClient getFirewallClient();
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,6 +23,7 @@ import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
import org.jclouds.cloudstack.features.AddressClient;
|
import org.jclouds.cloudstack.features.AddressClient;
|
||||||
import org.jclouds.cloudstack.features.AsyncJobClient;
|
import org.jclouds.cloudstack.features.AsyncJobClient;
|
||||||
|
import org.jclouds.cloudstack.features.FirewallClient;
|
||||||
import org.jclouds.cloudstack.features.NATClient;
|
import org.jclouds.cloudstack.features.NATClient;
|
||||||
import org.jclouds.cloudstack.features.NetworkClient;
|
import org.jclouds.cloudstack.features.NetworkClient;
|
||||||
import org.jclouds.cloudstack.features.OfferingClient;
|
import org.jclouds.cloudstack.features.OfferingClient;
|
||||||
|
@ -96,4 +97,10 @@ public interface CloudStackClient {
|
||||||
*/
|
*/
|
||||||
@Delegate
|
@Delegate
|
||||||
NATClient getNATClient();
|
NATClient getNATClient();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Provides synchronous access to Firewall features.
|
||||||
|
*/
|
||||||
|
@Delegate
|
||||||
|
FirewallClient getFirewallClient();
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,6 +27,8 @@ import org.jclouds.cloudstack.features.AddressAsyncClient;
|
||||||
import org.jclouds.cloudstack.features.AddressClient;
|
import org.jclouds.cloudstack.features.AddressClient;
|
||||||
import org.jclouds.cloudstack.features.AsyncJobAsyncClient;
|
import org.jclouds.cloudstack.features.AsyncJobAsyncClient;
|
||||||
import org.jclouds.cloudstack.features.AsyncJobClient;
|
import org.jclouds.cloudstack.features.AsyncJobClient;
|
||||||
|
import org.jclouds.cloudstack.features.FirewallAsyncClient;
|
||||||
|
import org.jclouds.cloudstack.features.FirewallClient;
|
||||||
import org.jclouds.cloudstack.features.NATAsyncClient;
|
import org.jclouds.cloudstack.features.NATAsyncClient;
|
||||||
import org.jclouds.cloudstack.features.NATClient;
|
import org.jclouds.cloudstack.features.NATClient;
|
||||||
import org.jclouds.cloudstack.features.NetworkAsyncClient;
|
import org.jclouds.cloudstack.features.NetworkAsyncClient;
|
||||||
|
@ -73,6 +75,7 @@ public class CloudStackRestClientModule extends RestClientModule<CloudStackClien
|
||||||
.put(AsyncJobClient.class, AsyncJobAsyncClient.class)//
|
.put(AsyncJobClient.class, AsyncJobAsyncClient.class)//
|
||||||
.put(AddressClient.class, AddressAsyncClient.class)//
|
.put(AddressClient.class, AddressAsyncClient.class)//
|
||||||
.put(NATClient.class, NATAsyncClient.class)//
|
.put(NATClient.class, NATAsyncClient.class)//
|
||||||
|
.put(FirewallClient.class, FirewallAsyncClient.class)//
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
public CloudStackRestClientModule() {
|
public CloudStackRestClientModule() {
|
||||||
|
|
|
@ -25,7 +25,7 @@ import com.google.gson.annotations.SerializedName;
|
||||||
*
|
*
|
||||||
* @author Adrian Cole
|
* @author Adrian Cole
|
||||||
*/
|
*/
|
||||||
public class IPForwardingRule implements Comparable<IPForwardingRule> {
|
public class PortForwardingRule implements Comparable<PortForwardingRule> {
|
||||||
public static Builder builder() {
|
public static Builder builder() {
|
||||||
return new Builder();
|
return new Builder();
|
||||||
}
|
}
|
||||||
|
@ -92,8 +92,8 @@ public class IPForwardingRule implements Comparable<IPForwardingRule> {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public IPForwardingRule build() {
|
public PortForwardingRule build() {
|
||||||
return new IPForwardingRule(id, IPAddress, IPAddressId, privatePort, protocol, publicPort, state,
|
return new PortForwardingRule(id, IPAddress, IPAddressId, privatePort, protocol, publicPort, state,
|
||||||
virtualMachineDisplayName, virtualMachineId, virtualMachineName);
|
virtualMachineDisplayName, virtualMachineId, virtualMachineName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -107,7 +107,7 @@ public class IPForwardingRule implements Comparable<IPForwardingRule> {
|
||||||
private int privatePort;
|
private int privatePort;
|
||||||
private String protocol;
|
private String protocol;
|
||||||
@SerializedName("publicport")
|
@SerializedName("publicport")
|
||||||
public int publicPort;
|
public String publicPort;
|
||||||
private String state;
|
private String state;
|
||||||
@SerializedName("virtualmachinedisplayname")
|
@SerializedName("virtualmachinedisplayname")
|
||||||
private String virtualMachineDisplayName;
|
private String virtualMachineDisplayName;
|
||||||
|
@ -116,7 +116,12 @@ public class IPForwardingRule implements Comparable<IPForwardingRule> {
|
||||||
@SerializedName("virtualmachinename")
|
@SerializedName("virtualmachinename")
|
||||||
private String virtualMachineName;
|
private String virtualMachineName;
|
||||||
|
|
||||||
public IPForwardingRule(long id, String iPAddress, long iPAddressId, int privatePort, String protocol,
|
// for deserializer
|
||||||
|
PortForwardingRule() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public PortForwardingRule(long id, String iPAddress, long iPAddressId, int privatePort, String protocol,
|
||||||
int publicPort, String state, String virtualMachineDisplayName, long virtualMachineId,
|
int publicPort, String state, String virtualMachineDisplayName, long virtualMachineId,
|
||||||
String virtualMachineName) {
|
String virtualMachineName) {
|
||||||
this.id = id;
|
this.id = id;
|
||||||
|
@ -124,7 +129,7 @@ public class IPForwardingRule implements Comparable<IPForwardingRule> {
|
||||||
this.IPAddressId = iPAddressId;
|
this.IPAddressId = iPAddressId;
|
||||||
this.privatePort = privatePort;
|
this.privatePort = privatePort;
|
||||||
this.protocol = protocol;
|
this.protocol = protocol;
|
||||||
this.publicPort = publicPort;
|
this.publicPort = publicPort+"";
|
||||||
this.state = state;
|
this.state = state;
|
||||||
this.virtualMachineDisplayName = virtualMachineDisplayName;
|
this.virtualMachineDisplayName = virtualMachineDisplayName;
|
||||||
this.virtualMachineId = virtualMachineId;
|
this.virtualMachineId = virtualMachineId;
|
||||||
|
@ -132,7 +137,7 @@ public class IPForwardingRule implements Comparable<IPForwardingRule> {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int compareTo(IPForwardingRule arg0) {
|
public int compareTo(PortForwardingRule arg0) {
|
||||||
return new Long(id).compareTo(arg0.getId());
|
return new Long(id).compareTo(arg0.getId());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -181,7 +186,7 @@ public class IPForwardingRule implements Comparable<IPForwardingRule> {
|
||||||
* @return the public port for the port forwarding rule
|
* @return the public port for the port forwarding rule
|
||||||
*/
|
*/
|
||||||
public int getPublicPort() {
|
public int getPublicPort() {
|
||||||
return publicPort;
|
return Integer.parseInt(publicPort);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -225,7 +230,7 @@ public class IPForwardingRule implements Comparable<IPForwardingRule> {
|
||||||
result = prime * result + (int) (id ^ (id >>> 32));
|
result = prime * result + (int) (id ^ (id >>> 32));
|
||||||
result = prime * result + privatePort;
|
result = prime * result + privatePort;
|
||||||
result = prime * result + ((protocol == null) ? 0 : protocol.hashCode());
|
result = prime * result + ((protocol == null) ? 0 : protocol.hashCode());
|
||||||
result = prime * result + publicPort;
|
result = prime * result + ((publicPort == null) ? 0 : publicPort.hashCode());
|
||||||
result = prime * result + ((state == null) ? 0 : state.hashCode());
|
result = prime * result + ((state == null) ? 0 : state.hashCode());
|
||||||
result = prime * result + ((virtualMachineDisplayName == null) ? 0 : virtualMachineDisplayName.hashCode());
|
result = prime * result + ((virtualMachineDisplayName == null) ? 0 : virtualMachineDisplayName.hashCode());
|
||||||
result = prime * result + (int) (virtualMachineId ^ (virtualMachineId >>> 32));
|
result = prime * result + (int) (virtualMachineId ^ (virtualMachineId >>> 32));
|
||||||
|
@ -241,7 +246,7 @@ public class IPForwardingRule implements Comparable<IPForwardingRule> {
|
||||||
return false;
|
return false;
|
||||||
if (getClass() != obj.getClass())
|
if (getClass() != obj.getClass())
|
||||||
return false;
|
return false;
|
||||||
IPForwardingRule other = (IPForwardingRule) obj;
|
PortForwardingRule other = (PortForwardingRule) obj;
|
||||||
if (IPAddress == null) {
|
if (IPAddress == null) {
|
||||||
if (other.IPAddress != null)
|
if (other.IPAddress != null)
|
||||||
return false;
|
return false;
|
||||||
|
@ -258,7 +263,10 @@ public class IPForwardingRule implements Comparable<IPForwardingRule> {
|
||||||
return false;
|
return false;
|
||||||
} else if (!protocol.equals(other.protocol))
|
} else if (!protocol.equals(other.protocol))
|
||||||
return false;
|
return false;
|
||||||
if (publicPort != other.publicPort)
|
if (publicPort == null) {
|
||||||
|
if (other.publicPort != null)
|
||||||
|
return false;
|
||||||
|
} else if (!publicPort.equals(other.publicPort))
|
||||||
return false;
|
return false;
|
||||||
if (state == null) {
|
if (state == null) {
|
||||||
if (other.state != null)
|
if (other.state != null)
|
|
@ -0,0 +1,84 @@
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* 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.PortForwardingRule;
|
||||||
|
import org.jclouds.cloudstack.filters.QuerySigner;
|
||||||
|
import org.jclouds.cloudstack.options.ListPortForwardingRulesOptions;
|
||||||
|
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.ReturnVoidOnNotFoundOr404;
|
||||||
|
|
||||||
|
import com.google.common.util.concurrent.ListenableFuture;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Provides asynchronous access to cloudstack via their REST API.
|
||||||
|
* <p/>
|
||||||
|
*
|
||||||
|
* @see FirewallClient
|
||||||
|
* @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 FirewallAsyncClient {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see FirewallClient#listPortForwardingRules
|
||||||
|
*/
|
||||||
|
@GET
|
||||||
|
@QueryParams(keys = "command", values = "listPortForwardingRules")
|
||||||
|
@Unwrap(depth = 2)
|
||||||
|
@Consumes(MediaType.APPLICATION_JSON)
|
||||||
|
@ExceptionParser(ReturnEmptySetOnNotFoundOr404.class)
|
||||||
|
ListenableFuture<Set<PortForwardingRule>> listPortForwardingRules(ListPortForwardingRulesOptions... options);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see FirewallClient#createPortForwardingRuleForVirtualMachine
|
||||||
|
*/
|
||||||
|
@GET
|
||||||
|
@QueryParams(keys = "command", values = "createPortForwardingRule")
|
||||||
|
@Unwrap
|
||||||
|
@Consumes(MediaType.APPLICATION_JSON)
|
||||||
|
ListenableFuture<AsyncCreateResponse> createPortForwardingRuleForVirtualMachine(
|
||||||
|
@QueryParam("virtualmachineid") long virtualMachineId, @QueryParam("ipaddressid") long IPAddressId,
|
||||||
|
@QueryParam("protocol") String protocol, @QueryParam("privateport") int privatePort,
|
||||||
|
@QueryParam("publicport") int publicPort);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see FirewallClient#deletePortForwardingRule
|
||||||
|
*/
|
||||||
|
@GET
|
||||||
|
@QueryParams(keys = "command", values = "deletePortForwardingRule")
|
||||||
|
@ExceptionParser(ReturnVoidOnNotFoundOr404.class)
|
||||||
|
ListenableFuture<Void> deletePortForwardingRule(@QueryParam("id") long id);
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,76 @@
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* 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.PortForwardingRule;
|
||||||
|
import org.jclouds.cloudstack.options.ListPortForwardingRulesOptions;
|
||||||
|
import org.jclouds.concurrent.Timeout;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Provides synchronous access to CloudStack PortForwardingRule features.
|
||||||
|
* <p/>
|
||||||
|
*
|
||||||
|
* @see PortForwardingRuleAsyncClient
|
||||||
|
* @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 FirewallClient {
|
||||||
|
/**
|
||||||
|
* List the port forwarding rules
|
||||||
|
*
|
||||||
|
* @param options
|
||||||
|
* if present, how to constrain the list.
|
||||||
|
* @return PortForwardingRulees matching query, or empty set, if no PortForwardingRulees are
|
||||||
|
* found
|
||||||
|
*/
|
||||||
|
Set<PortForwardingRule> listPortForwardingRules(ListPortForwardingRulesOptions... options);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates an port forwarding rule
|
||||||
|
*
|
||||||
|
* @param virtualMachineId
|
||||||
|
* the ID of the virtual machine for the port forwarding rule
|
||||||
|
* @param IPAddressId
|
||||||
|
* the public IP address id of the forwarding rule, already associated via
|
||||||
|
* associatePort
|
||||||
|
* @param protocol
|
||||||
|
* the protocol for the rule. Valid values are TCP or UDP.
|
||||||
|
* @param privatePort
|
||||||
|
* the private port of the port forwarding rule
|
||||||
|
* @param publicPort
|
||||||
|
* the public port of the port forwarding rule
|
||||||
|
* @return response used to track creation
|
||||||
|
*/
|
||||||
|
AsyncCreateResponse createPortForwardingRuleForVirtualMachine(long virtualMachineId, long IPAddressId,
|
||||||
|
String protocol, int privatePort, int publicPort);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Deletes an port forwarding rule
|
||||||
|
*
|
||||||
|
* @param id
|
||||||
|
* the id of the forwarding rule
|
||||||
|
*/
|
||||||
|
void deletePortForwardingRule(long id);
|
||||||
|
}
|
|
@ -27,7 +27,7 @@ import javax.ws.rs.QueryParam;
|
||||||
import javax.ws.rs.core.MediaType;
|
import javax.ws.rs.core.MediaType;
|
||||||
|
|
||||||
import org.jclouds.cloudstack.domain.AsyncCreateResponse;
|
import org.jclouds.cloudstack.domain.AsyncCreateResponse;
|
||||||
import org.jclouds.cloudstack.domain.IPForwardingRule;
|
import org.jclouds.cloudstack.domain.PortForwardingRule;
|
||||||
import org.jclouds.cloudstack.filters.QuerySigner;
|
import org.jclouds.cloudstack.filters.QuerySigner;
|
||||||
import org.jclouds.cloudstack.options.CreateIPForwardingRuleOptions;
|
import org.jclouds.cloudstack.options.CreateIPForwardingRuleOptions;
|
||||||
import org.jclouds.cloudstack.options.ListIPForwardingRulesOptions;
|
import org.jclouds.cloudstack.options.ListIPForwardingRulesOptions;
|
||||||
|
@ -61,7 +61,7 @@ public interface NATAsyncClient {
|
||||||
@Unwrap(depth = 2)
|
@Unwrap(depth = 2)
|
||||||
@Consumes(MediaType.APPLICATION_JSON)
|
@Consumes(MediaType.APPLICATION_JSON)
|
||||||
@ExceptionParser(ReturnEmptySetOnNotFoundOr404.class)
|
@ExceptionParser(ReturnEmptySetOnNotFoundOr404.class)
|
||||||
ListenableFuture<Set<IPForwardingRule>> listIPForwardingRules(ListIPForwardingRulesOptions... options);
|
ListenableFuture<Set<PortForwardingRule>> listIPForwardingRules(ListIPForwardingRulesOptions... options);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see NATClient#getIPForwardingRule
|
* @see NATClient#getIPForwardingRule
|
||||||
|
@ -71,7 +71,7 @@ public interface NATAsyncClient {
|
||||||
@Unwrap(depth = 3, edgeCollection = Set.class)
|
@Unwrap(depth = 3, edgeCollection = Set.class)
|
||||||
@Consumes(MediaType.APPLICATION_JSON)
|
@Consumes(MediaType.APPLICATION_JSON)
|
||||||
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
|
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
|
||||||
ListenableFuture<IPForwardingRule> getIPForwardingRule(@QueryParam("id") long id);
|
ListenableFuture<PortForwardingRule> getIPForwardingRule(@QueryParam("id") long id);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see NATClient#createIPForwardingRuleForVirtualMachine
|
* @see NATClient#createIPForwardingRuleForVirtualMachine
|
||||||
|
|
|
@ -23,7 +23,7 @@ import java.util.Set;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
import org.jclouds.cloudstack.domain.AsyncCreateResponse;
|
import org.jclouds.cloudstack.domain.AsyncCreateResponse;
|
||||||
import org.jclouds.cloudstack.domain.IPForwardingRule;
|
import org.jclouds.cloudstack.domain.PortForwardingRule;
|
||||||
import org.jclouds.cloudstack.options.CreateIPForwardingRuleOptions;
|
import org.jclouds.cloudstack.options.CreateIPForwardingRuleOptions;
|
||||||
import org.jclouds.cloudstack.options.ListIPForwardingRulesOptions;
|
import org.jclouds.cloudstack.options.ListIPForwardingRulesOptions;
|
||||||
import org.jclouds.concurrent.Timeout;
|
import org.jclouds.concurrent.Timeout;
|
||||||
|
@ -45,7 +45,7 @@ public interface NATClient {
|
||||||
* if present, how to constrain the list.
|
* if present, how to constrain the list.
|
||||||
* @return IPForwardingRulees matching query, or empty set, if no IPForwardingRulees are found
|
* @return IPForwardingRulees matching query, or empty set, if no IPForwardingRulees are found
|
||||||
*/
|
*/
|
||||||
Set<IPForwardingRule> listIPForwardingRules(ListIPForwardingRulesOptions... options);
|
Set<PortForwardingRule> listIPForwardingRules(ListIPForwardingRulesOptions... options);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* get a specific IPForwardingRule by id
|
* get a specific IPForwardingRule by id
|
||||||
|
@ -54,7 +54,7 @@ public interface NATClient {
|
||||||
* IPForwardingRule to get
|
* IPForwardingRule to get
|
||||||
* @return IPForwardingRule or null if not found
|
* @return IPForwardingRule or null if not found
|
||||||
*/
|
*/
|
||||||
IPForwardingRule getIPForwardingRule(long id);
|
PortForwardingRule getIPForwardingRule(long id);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates an ip forwarding rule
|
* Creates an ip forwarding rule
|
||||||
|
|
|
@ -46,7 +46,7 @@ public class CreateIPForwardingRuleOptions extends BaseHttpRequestOptions {
|
||||||
public static class Builder {
|
public static class Builder {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see CreateIPForwardingRuleOptions#endPort
|
* @see CreatePortForwardingRuleOptions#endPort
|
||||||
*/
|
*/
|
||||||
public static CreateIPForwardingRuleOptions endPort(int endPort) {
|
public static CreateIPForwardingRuleOptions endPort(int endPort) {
|
||||||
CreateIPForwardingRuleOptions options = new CreateIPForwardingRuleOptions();
|
CreateIPForwardingRuleOptions options = new CreateIPForwardingRuleOptions();
|
||||||
|
|
|
@ -47,7 +47,7 @@ public class DeployVirtualMachineOptions extends BaseHttpRequestOptions {
|
||||||
*/
|
*/
|
||||||
public DeployVirtualMachineOptions accountInDomain(String account, long domain) {
|
public DeployVirtualMachineOptions accountInDomain(String account, long domain) {
|
||||||
this.queryParameters.replaceValues("account", ImmutableSet.of(account));
|
this.queryParameters.replaceValues("account", ImmutableSet.of(account));
|
||||||
this.queryParameters.replaceValues("domain", ImmutableSet.of(domain + ""));
|
this.queryParameters.replaceValues("domainid", ImmutableSet.of(domain + ""));
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -57,9 +57,13 @@ public class ListIPForwardingRulesOptions extends BaseHttpRequestOptions {
|
||||||
* @param account
|
* @param account
|
||||||
* the account associated with the ip forwarding rule. Must be used with the domainId
|
* the account associated with the ip forwarding rule. Must be used with the domainId
|
||||||
* parameter.
|
* parameter.
|
||||||
|
*
|
||||||
|
* @param domain
|
||||||
|
* domain id
|
||||||
*/
|
*/
|
||||||
public ListIPForwardingRulesOptions account(String account) {
|
public ListIPForwardingRulesOptions accountInDomain(String account, long domain) {
|
||||||
this.queryParameters.replaceValues("account", ImmutableSet.of(account));
|
this.queryParameters.replaceValues("account", ImmutableSet.of(account));
|
||||||
|
this.queryParameters.replaceValues("domainid", ImmutableSet.of(domain + ""));
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -86,11 +90,11 @@ public class ListIPForwardingRulesOptions extends BaseHttpRequestOptions {
|
||||||
public static class Builder {
|
public static class Builder {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see ListIPForwardingRulesOptions#account
|
* @see ListIPForwardingRulesOptions#accountInDomain
|
||||||
*/
|
*/
|
||||||
public static ListIPForwardingRulesOptions account(String account) {
|
public static ListIPForwardingRulesOptions accountInDomain(String account, long domain) {
|
||||||
ListIPForwardingRulesOptions options = new ListIPForwardingRulesOptions();
|
ListIPForwardingRulesOptions options = new ListIPForwardingRulesOptions();
|
||||||
return options.account(account);
|
return options.accountInDomain(account, domain);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -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.options;
|
||||||
|
|
||||||
|
import org.jclouds.http.options.BaseHttpRequestOptions;
|
||||||
|
|
||||||
|
import com.google.common.collect.ImmutableSet;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Options used to control what port forwarding rules are returned
|
||||||
|
*
|
||||||
|
* @see <a href="http://download.cloud.com/releases/2.2.0/api/user/listIpForwardingRules.html" />
|
||||||
|
* @author Adrian Cole
|
||||||
|
*/
|
||||||
|
public class ListPortForwardingRulesOptions extends BaseHttpRequestOptions {
|
||||||
|
|
||||||
|
public static final ListPortForwardingRulesOptions NONE = new ListPortForwardingRulesOptions();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param domainId
|
||||||
|
* Lists all rules for this id. If used with the account parameter, returns all rules
|
||||||
|
* for an account in the specified domain ID.
|
||||||
|
*/
|
||||||
|
public ListPortForwardingRulesOptions domainId(long domainId) {
|
||||||
|
this.queryParameters.replaceValues("domainid", ImmutableSet.of(domainId + ""));
|
||||||
|
return this;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param account
|
||||||
|
* the account associated with the port forwarding rule. Must be used with the domainId
|
||||||
|
* parameter.
|
||||||
|
*
|
||||||
|
* @param domain
|
||||||
|
* domain id
|
||||||
|
*/
|
||||||
|
public ListPortForwardingRulesOptions accountInDomain(String account, long domain) {
|
||||||
|
this.queryParameters.replaceValues("account", ImmutableSet.of(account));
|
||||||
|
this.queryParameters.replaceValues("domainid", ImmutableSet.of(domain + ""));
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param IPAddressId
|
||||||
|
* list the rule belonging to this public ip address
|
||||||
|
*/
|
||||||
|
public ListPortForwardingRulesOptions IPAddressId(long IPAddressId) {
|
||||||
|
this.queryParameters.replaceValues("ipaddressid", ImmutableSet.of(IPAddressId + ""));
|
||||||
|
return this;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class Builder {
|
||||||
|
/**
|
||||||
|
* @see ListPortForwardingRulesOptions#accountInDomain
|
||||||
|
*/
|
||||||
|
public static ListPortForwardingRulesOptions accountInDomain(String account, long domain) {
|
||||||
|
ListPortForwardingRulesOptions options = new ListPortForwardingRulesOptions();
|
||||||
|
return options.accountInDomain(account, domain);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see ListPortForwardingRulesOptions#IPAddressId
|
||||||
|
*/
|
||||||
|
public static ListPortForwardingRulesOptions IPAddressId(long IPAddressId) {
|
||||||
|
ListPortForwardingRulesOptions options = new ListPortForwardingRulesOptions();
|
||||||
|
return options.IPAddressId(IPAddressId);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see ListPortForwardingRulesOptions#domainId
|
||||||
|
*/
|
||||||
|
public static ListPortForwardingRulesOptions domainId(long id) {
|
||||||
|
ListPortForwardingRulesOptions options = new ListPortForwardingRulesOptions();
|
||||||
|
return options.domainId(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,124 @@
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* 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.ListPortForwardingRulesOptions;
|
||||||
|
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.rest.functions.MapHttp4xxCodesToExceptions;
|
||||||
|
import org.jclouds.rest.functions.ReturnEmptySetOnNotFoundOr404;
|
||||||
|
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 FirewallAsyncClient}
|
||||||
|
*
|
||||||
|
* @author Adrian Cole
|
||||||
|
*/
|
||||||
|
// NOTE:without testName, this will not call @Before* and fail w/NPE during surefire
|
||||||
|
@Test(groups = "unit", testName = "FirewallAsyncClientTest")
|
||||||
|
public class FirewallAsyncClientTest extends BaseCloudStackAsyncClientTest<FirewallAsyncClient> {
|
||||||
|
public void testListPortForwardingRules() throws SecurityException, NoSuchMethodException, IOException {
|
||||||
|
Method method = FirewallAsyncClient.class.getMethod("listPortForwardingRules",
|
||||||
|
ListPortForwardingRulesOptions[].class);
|
||||||
|
HttpRequest httpRequest = processor.createRequest(method);
|
||||||
|
|
||||||
|
assertRequestLineEquals(httpRequest,
|
||||||
|
"GET http://localhost:8080/client/api?response=json&command=listPortForwardingRules 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 testListPortForwardingRulesOptions() throws SecurityException, NoSuchMethodException, IOException {
|
||||||
|
Method method = FirewallAsyncClient.class.getMethod("listPortForwardingRules",
|
||||||
|
ListPortForwardingRulesOptions[].class);
|
||||||
|
HttpRequest httpRequest = processor.createRequest(method, ListPortForwardingRulesOptions.Builder.IPAddressId(3));
|
||||||
|
|
||||||
|
assertRequestLineEquals(httpRequest,
|
||||||
|
"GET http://localhost:8080/client/api?response=json&command=listPortForwardingRules&ipaddressid=3 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 testCreatePortForwardingRuleForVirtualMachine() throws SecurityException, NoSuchMethodException,
|
||||||
|
IOException {
|
||||||
|
Method method = FirewallAsyncClient.class.getMethod("createPortForwardingRuleForVirtualMachine", long.class,
|
||||||
|
long.class, String.class, int.class, int.class);
|
||||||
|
HttpRequest httpRequest = processor.createRequest(method, 6, 7, "tcp", 22, 22);
|
||||||
|
|
||||||
|
assertRequestLineEquals(
|
||||||
|
httpRequest,
|
||||||
|
"GET http://localhost:8080/client/api?response=json&command=createPortForwardingRule&virtualmachineid=6&protocol=tcp&ipaddressid=7&privateport=22&publicport=22 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 testDeletePortForwardingRule() throws SecurityException, NoSuchMethodException, IOException {
|
||||||
|
Method method = FirewallAsyncClient.class.getMethod("deletePortForwardingRule", long.class);
|
||||||
|
HttpRequest httpRequest = processor.createRequest(method, 5);
|
||||||
|
|
||||||
|
assertRequestLineEquals(httpRequest,
|
||||||
|
"GET http://localhost:8080/client/api?response=json&command=deletePortForwardingRule&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<FirewallAsyncClient>> createTypeLiteral() {
|
||||||
|
return new TypeLiteral<RestAnnotationProcessor<FirewallAsyncClient>>() {
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,120 @@
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* 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 agred 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.
|
||||||
|
* Se 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.find;
|
||||||
|
import static org.testng.Assert.assertEquals;
|
||||||
|
import static org.testng.Assert.assertTrue;
|
||||||
|
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
import org.jclouds.cloudstack.domain.AsyncCreateResponse;
|
||||||
|
import org.jclouds.cloudstack.domain.PortForwardingRule;
|
||||||
|
import org.jclouds.cloudstack.domain.PublicIPAddress;
|
||||||
|
import org.jclouds.cloudstack.domain.VirtualMachine;
|
||||||
|
import org.jclouds.net.IPSocket;
|
||||||
|
import org.testng.annotations.AfterGroups;
|
||||||
|
import org.testng.annotations.BeforeGroups;
|
||||||
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
|
import com.google.common.base.Predicate;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tests behavior of {@code FirewallClientLiveTest}
|
||||||
|
*
|
||||||
|
* @author Adrian Cole
|
||||||
|
*/
|
||||||
|
@Test(groups = "live", sequential = true, testName = "FirewallClientLiveTest")
|
||||||
|
public class FirewallClientLiveTest extends BaseCloudStackClientLiveTest {
|
||||||
|
private PublicIPAddress ip = null;
|
||||||
|
private VirtualMachine vm;
|
||||||
|
private PortForwardingRule rule;
|
||||||
|
|
||||||
|
@BeforeGroups(groups = "live")
|
||||||
|
public void setupClient() {
|
||||||
|
super.setupClient();
|
||||||
|
prefix += "rule";
|
||||||
|
ip = AddressClientLiveTest.createPublicIPAddress(client, jobComplete);
|
||||||
|
vm = VirtualMachineClientLiveTest.createVirtualMachine(client, jobComplete, virtualMachineRunning);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testCreatePortForwardingRule() throws Exception {
|
||||||
|
AsyncCreateResponse job = client.getFirewallClient().createPortForwardingRuleForVirtualMachine(vm.getId(),
|
||||||
|
ip.getId(), "tcp", 22, 22);
|
||||||
|
assert jobComplete.apply(job.getJobId());
|
||||||
|
rule = findRuleWithId(job.getId());
|
||||||
|
assertEquals(rule.getIPAddressId(), ip.getId());
|
||||||
|
assertEquals(rule.getVirtualMachineId(), vm.getId());
|
||||||
|
assertEquals(rule.getPublicPort(), 22);
|
||||||
|
assertEquals(rule.getProtocol(), "tcp");
|
||||||
|
checkRule(rule);
|
||||||
|
IPSocket socket = new IPSocket(ip.getIPAddress(), 22);
|
||||||
|
socketTester.apply(socket);
|
||||||
|
}
|
||||||
|
|
||||||
|
@AfterGroups(groups = "live")
|
||||||
|
protected void tearDown() {
|
||||||
|
if (rule != null) {
|
||||||
|
client.getFirewallClient().deletePortForwardingRule(rule.getId());
|
||||||
|
}
|
||||||
|
if (ip != null) {
|
||||||
|
client.getAddressClient().disassociateIPAddress(ip.getId());
|
||||||
|
}
|
||||||
|
if (vm != null) {
|
||||||
|
assert jobComplete.apply(client.getVirtualMachineClient().destroyVirtualMachine(vm.getId()));
|
||||||
|
}
|
||||||
|
super.tearDown();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testListPortForwardingRules() throws Exception {
|
||||||
|
Set<PortForwardingRule> response = client.getFirewallClient().listPortForwardingRules();
|
||||||
|
assert null != response;
|
||||||
|
assertTrue(response.size() >= 0);
|
||||||
|
for (final PortForwardingRule rule : response) {
|
||||||
|
PortForwardingRule newDetails = findRuleWithId(rule.getId());
|
||||||
|
assertEquals(rule.getId(), newDetails.getId());
|
||||||
|
checkRule(rule);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private PortForwardingRule findRuleWithId(final long id) {
|
||||||
|
return find(client.getFirewallClient().listPortForwardingRules(), new Predicate<PortForwardingRule>() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean apply(PortForwardingRule arg0) {
|
||||||
|
return arg0.getId() == id;
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void checkRule(PortForwardingRule rule) {
|
||||||
|
assertEquals(rule.getId(), findRuleWithId(rule.getId()).getId());
|
||||||
|
assert rule.getId() > 0 : rule;
|
||||||
|
assert rule.getIPAddress() != null : rule;
|
||||||
|
assert rule.getIPAddressId() > 0 : rule;
|
||||||
|
assert rule.getPrivatePort() > 0 : rule;
|
||||||
|
assert rule.getProtocol() != null : rule;
|
||||||
|
assert rule.getPublicPort() > 0 : rule;
|
||||||
|
assert rule.getState() != null : rule;
|
||||||
|
assert rule.getVirtualMachineId() > 0 : rule;
|
||||||
|
assert rule.getVirtualMachineName() != null : rule;
|
||||||
|
}
|
||||||
|
}
|
|
@ -26,7 +26,7 @@ import static org.testng.Assert.assertTrue;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import org.jclouds.cloudstack.domain.AsyncCreateResponse;
|
import org.jclouds.cloudstack.domain.AsyncCreateResponse;
|
||||||
import org.jclouds.cloudstack.domain.IPForwardingRule;
|
import org.jclouds.cloudstack.domain.PortForwardingRule;
|
||||||
import org.jclouds.cloudstack.domain.PublicIPAddress;
|
import org.jclouds.cloudstack.domain.PublicIPAddress;
|
||||||
import org.jclouds.cloudstack.domain.VirtualMachine;
|
import org.jclouds.cloudstack.domain.VirtualMachine;
|
||||||
import org.jclouds.cloudstack.options.ListIPForwardingRulesOptions;
|
import org.jclouds.cloudstack.options.ListIPForwardingRulesOptions;
|
||||||
|
@ -44,7 +44,7 @@ import org.testng.annotations.Test;
|
||||||
public class NATClientLiveTest extends BaseCloudStackClientLiveTest {
|
public class NATClientLiveTest extends BaseCloudStackClientLiveTest {
|
||||||
private PublicIPAddress ip = null;
|
private PublicIPAddress ip = null;
|
||||||
private VirtualMachine vm;
|
private VirtualMachine vm;
|
||||||
private IPForwardingRule rule;
|
private PortForwardingRule rule;
|
||||||
|
|
||||||
@BeforeGroups(groups = "live")
|
@BeforeGroups(groups = "live")
|
||||||
public void setupClient() {
|
public void setupClient() {
|
||||||
|
@ -84,18 +84,18 @@ public class NATClientLiveTest extends BaseCloudStackClientLiveTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testListIPForwardingRules() throws Exception {
|
public void testListIPForwardingRules() throws Exception {
|
||||||
Set<IPForwardingRule> response = client.getNATClient().listIPForwardingRules();
|
Set<PortForwardingRule> response = client.getNATClient().listIPForwardingRules();
|
||||||
assert null != response;
|
assert null != response;
|
||||||
assertTrue(response.size() >= 0);
|
assertTrue(response.size() >= 0);
|
||||||
for (IPForwardingRule rule : response) {
|
for (PortForwardingRule rule : response) {
|
||||||
IPForwardingRule newDetails = getOnlyElement(client.getNATClient().listIPForwardingRules(
|
PortForwardingRule newDetails = getOnlyElement(client.getNATClient().listIPForwardingRules(
|
||||||
ListIPForwardingRulesOptions.Builder.id(rule.getId())));
|
ListIPForwardingRulesOptions.Builder.id(rule.getId())));
|
||||||
assertEquals(rule.getId(), newDetails.getId());
|
assertEquals(rule.getId(), newDetails.getId());
|
||||||
checkRule(rule);
|
checkRule(rule);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void checkRule(IPForwardingRule rule) {
|
protected void checkRule(PortForwardingRule rule) {
|
||||||
assertEquals(rule.getId(), client.getNATClient().getIPForwardingRule(rule.getId()).getId());
|
assertEquals(rule.getId(), client.getNATClient().getIPForwardingRule(rule.getId()).getId());
|
||||||
assert rule.getId() > 0 : rule;
|
assert rule.getId() > 0 : rule;
|
||||||
assert rule.getIPAddress() != null : rule;
|
assert rule.getIPAddress() != null : rule;
|
||||||
|
|
|
@ -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.PortForwardingRule;
|
||||||
|
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.ImmutableSortedSet;
|
||||||
|
import com.google.common.collect.Sets;
|
||||||
|
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 ListPortForwardingRuleResponseTest {
|
||||||
|
|
||||||
|
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("/listportforwardingrulesresponse.json");
|
||||||
|
|
||||||
|
Set<PortForwardingRule> expects = ImmutableSortedSet.<PortForwardingRule> of(PortForwardingRule.builder().id(15)
|
||||||
|
.privatePort(22).protocol("tcp").publicPort(2022).virtualMachineId(3).virtualMachineName("i-3-3-VM")
|
||||||
|
.IPAddressId(3).IPAddress("72.52.126.32").state("Active").build(), PortForwardingRule.builder().id(18)
|
||||||
|
.privatePort(22).protocol("tcp").publicPort(22).virtualMachineId(89).virtualMachineName("i-3-89-VM")
|
||||||
|
.IPAddressId(34).IPAddress("72.52.126.63").state("Active").build());
|
||||||
|
|
||||||
|
UnwrapOnlyNestedJsonValue<Set<PortForwardingRule>> parser = i.getInstance(Key
|
||||||
|
.get(new TypeLiteral<UnwrapOnlyNestedJsonValue<Set<PortForwardingRule>>>() {
|
||||||
|
}));
|
||||||
|
Set<PortForwardingRule> response = parser.apply(new HttpResponse(200, "ok", Payloads.newInputStreamPayload(is)));
|
||||||
|
|
||||||
|
assertEquals(Sets.newTreeSet(response), expects);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -19,7 +19,7 @@
|
||||||
|
|
||||||
package org.jclouds.cloudstack.options;
|
package org.jclouds.cloudstack.options;
|
||||||
|
|
||||||
import static org.jclouds.cloudstack.options.ListIPForwardingRulesOptions.Builder.account;
|
import static org.jclouds.cloudstack.options.ListIPForwardingRulesOptions.Builder.accountInDomain;
|
||||||
import static org.jclouds.cloudstack.options.ListIPForwardingRulesOptions.Builder.domainId;
|
import static org.jclouds.cloudstack.options.ListIPForwardingRulesOptions.Builder.domainId;
|
||||||
import static org.jclouds.cloudstack.options.ListIPForwardingRulesOptions.Builder.id;
|
import static org.jclouds.cloudstack.options.ListIPForwardingRulesOptions.Builder.id;
|
||||||
import static org.jclouds.cloudstack.options.ListIPForwardingRulesOptions.Builder.IPAddressId;
|
import static org.jclouds.cloudstack.options.ListIPForwardingRulesOptions.Builder.IPAddressId;
|
||||||
|
@ -49,13 +49,15 @@ public class ListIPForwardingRulesOptionsTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testAccount() {
|
public void testAccount() {
|
||||||
ListIPForwardingRulesOptions options = new ListIPForwardingRulesOptions().account("account");
|
ListIPForwardingRulesOptions options = new ListIPForwardingRulesOptions().accountInDomain("account", 6);
|
||||||
assertEquals(ImmutableList.of("account"), options.buildQueryParameters().get("account"));
|
assertEquals(ImmutableList.of("account"), options.buildQueryParameters().get("account"));
|
||||||
|
assertEquals(ImmutableList.of("6"), options.buildQueryParameters().get("domainid"));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testAccountStatic() {
|
public void testAccountStatic() {
|
||||||
ListIPForwardingRulesOptions options = account("account");
|
ListIPForwardingRulesOptions options = accountInDomain("account", 6);
|
||||||
assertEquals(ImmutableList.of("account"), options.buildQueryParameters().get("account"));
|
assertEquals(ImmutableList.of("account"), options.buildQueryParameters().get("account"));
|
||||||
|
assertEquals(ImmutableList.of("6"), options.buildQueryParameters().get("domainid"));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testName() {
|
public void testName() {
|
||||||
|
|
|
@ -0,0 +1,71 @@
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* 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.ListPortForwardingRulesOptions.Builder.IPAddressId;
|
||||||
|
import static org.jclouds.cloudstack.options.ListPortForwardingRulesOptions.Builder.accountInDomain;
|
||||||
|
import static org.jclouds.cloudstack.options.ListPortForwardingRulesOptions.Builder.domainId;
|
||||||
|
import static org.testng.Assert.assertEquals;
|
||||||
|
|
||||||
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
|
import com.google.common.collect.ImmutableList;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tests behavior of {@code ListPortForwardingRulesOptions}
|
||||||
|
*
|
||||||
|
* @author Adrian Cole
|
||||||
|
*/
|
||||||
|
@Test(groups = "unit")
|
||||||
|
public class ListPortForwardingRulesOptionsTest {
|
||||||
|
|
||||||
|
public void testAccount() {
|
||||||
|
ListPortForwardingRulesOptions options = new ListPortForwardingRulesOptions().accountInDomain("account", 6);
|
||||||
|
assertEquals(ImmutableList.of("account"), options.buildQueryParameters().get("account"));
|
||||||
|
assertEquals(ImmutableList.of("6"), options.buildQueryParameters().get("domainid"));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testAccountStatic() {
|
||||||
|
ListPortForwardingRulesOptions options = accountInDomain("account", 6);
|
||||||
|
assertEquals(ImmutableList.of("account"), options.buildQueryParameters().get("account"));
|
||||||
|
assertEquals(ImmutableList.of("6"), options.buildQueryParameters().get("domainid"));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testName() {
|
||||||
|
ListPortForwardingRulesOptions options = new ListPortForwardingRulesOptions().IPAddressId(9);
|
||||||
|
assertEquals(ImmutableList.of("9"), options.buildQueryParameters().get("ipaddressid"));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testNameStatic() {
|
||||||
|
ListPortForwardingRulesOptions options = IPAddressId(9);
|
||||||
|
assertEquals(ImmutableList.of("9"), options.buildQueryParameters().get("ipaddressid"));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testDomainId() {
|
||||||
|
ListPortForwardingRulesOptions options = new ListPortForwardingRulesOptions().domainId(6);
|
||||||
|
assertEquals(ImmutableList.of("6"), options.buildQueryParameters().get("domainid"));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testDomainIdStatic() {
|
||||||
|
ListPortForwardingRulesOptions options = domainId(6);
|
||||||
|
assertEquals(ImmutableList.of("6"), options.buildQueryParameters().get("domainid"));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1 @@
|
||||||
|
{ "listportforwardingrulesresponse" : { "portforwardingrule" : [ {"id":18,"privateport":"22","protocol":"tcp","publicport":"22","virtualmachineid":89,"virtualmachinename":"i-3-89-VM","ipaddressid":34,"ipaddress":"72.52.126.63","state":"Active"}, {"id":15,"privateport":"22","protocol":"tcp","publicport":"2022","virtualmachineid":3,"virtualmachinename":"i-3-3-VM","ipaddressid":3,"ipaddress":"72.52.126.32","state":"Active"} ] } }
|
Loading…
Reference in New Issue