mirror of https://github.com/apache/jclouds.git
Issue 383: added new network features needed for terremark ecloud, so that default vdc will operate
This commit is contained in:
parent
1eda57537b
commit
d908600e8a
|
@ -42,15 +42,15 @@ public class VCloudExpressNetworkImpl extends ReferenceTypeImpl implements VClou
|
|||
|
||||
/** The serialVersionUID */
|
||||
private static final long serialVersionUID = 8464716396538298809L;
|
||||
private final String description;
|
||||
private final Set<String> dnsServers = Sets.newHashSet();
|
||||
private final String gateway;
|
||||
private final String netmask;
|
||||
private final Set<FenceMode> fenceModes = Sets.newHashSet();
|
||||
protected final String description;
|
||||
protected final Set<String> dnsServers = Sets.newHashSet();
|
||||
protected final String gateway;
|
||||
protected final String netmask;
|
||||
protected final Set<FenceMode> fenceModes = Sets.newHashSet();
|
||||
@Nullable
|
||||
private final Boolean dhcp;
|
||||
private final Set<PortForwardingRule> natRules = Sets.newHashSet();
|
||||
private final Set<FirewallRule> firewallRules = Sets.newHashSet();
|
||||
protected final Boolean dhcp;
|
||||
protected final Set<PortForwardingRule> natRules = Sets.newHashSet();
|
||||
protected final Set<FirewallRule> firewallRules = Sets.newHashSet();
|
||||
|
||||
public VCloudExpressNetworkImpl(String name, String type, URI id, String description, Set<String> dnsServers,
|
||||
String gateway, String netmask, Set<FenceMode> fenceModes, Boolean dhcp, Set<PortForwardingRule> natRules,
|
||||
|
@ -196,10 +196,9 @@ public class VCloudExpressNetworkImpl extends ReferenceTypeImpl implements VClou
|
|||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "NetworkImpl [id=" + getHref() + ", name=" + getName() + ", type=" + getType() + ", description="
|
||||
+ description + ", dhcp=" + dhcp + ", dnsServers=" + dnsServers + ", fenceModes=" + fenceModes
|
||||
+ ", firewallRules=" + firewallRules + ", gateway=" + gateway + ", natRules=" + natRules + ", netmask="
|
||||
+ netmask + "]";
|
||||
return "[id=" + getHref() + ", name=" + getName() + ", type=" + getType() + ", description=" + description
|
||||
+ ", dhcp=" + dhcp + ", dnsServers=" + dnsServers + ", fenceModes=" + fenceModes + ", firewallRules="
|
||||
+ firewallRules + ", gateway=" + gateway + ", natRules=" + natRules + ", netmask=" + netmask + "]";
|
||||
}
|
||||
|
||||
}
|
|
@ -50,28 +50,28 @@ public class VCloudExpressNetworkHandler extends ParseSax.HandlerWithResult<VClo
|
|||
@Resource
|
||||
protected Logger logger = Logger.NULL;
|
||||
|
||||
private StringBuilder currentText = new StringBuilder();
|
||||
protected StringBuilder currentText = new StringBuilder();
|
||||
|
||||
private ReferenceType network;
|
||||
protected ReferenceType network;
|
||||
|
||||
private String description;
|
||||
protected String description;
|
||||
|
||||
private Set<String> dnsServers = Sets.newLinkedHashSet();
|
||||
private String gateway;
|
||||
private String netmask;
|
||||
private Set<FenceMode> fenceModes = Sets.newLinkedHashSet();
|
||||
private Boolean dhcp;
|
||||
private Set<PortForwardingRule> natRules = Sets.newLinkedHashSet();
|
||||
private Set<FirewallRule> firewallRules = Sets.newLinkedHashSet();
|
||||
protected Set<String> dnsServers = Sets.newLinkedHashSet();
|
||||
protected String gateway;
|
||||
protected String netmask;
|
||||
protected Set<FenceMode> fenceModes = Sets.newLinkedHashSet();
|
||||
protected Boolean dhcp;
|
||||
protected Set<PortForwardingRule> natRules = Sets.newLinkedHashSet();
|
||||
protected Set<FirewallRule> firewallRules = Sets.newLinkedHashSet();
|
||||
|
||||
private String externalIP;
|
||||
private Integer externalPort;
|
||||
private String internalIP;
|
||||
private Integer internalPort;
|
||||
protected String externalIP;
|
||||
protected Integer externalPort;
|
||||
protected String internalIP;
|
||||
protected Integer internalPort;
|
||||
|
||||
private FirewallPolicy policy;
|
||||
private String sourceIP;
|
||||
private int sourcePort;
|
||||
protected FirewallPolicy policy;
|
||||
protected String sourceIP;
|
||||
protected int sourcePort;
|
||||
|
||||
public VCloudExpressNetwork getResult() {
|
||||
return new VCloudExpressNetworkImpl(network.getName(), network.getType(), network.getHref(), description,
|
||||
|
|
|
@ -52,11 +52,13 @@ import org.jclouds.rest.functions.ReturnVoidOnNotFoundOr404;
|
|||
import org.jclouds.rest.internal.RestAnnotationProcessor;
|
||||
import org.jclouds.util.Utils;
|
||||
import org.jclouds.vcloud.config.VCloudRestClientModule;
|
||||
import org.jclouds.vcloud.domain.AllocationModel;
|
||||
import org.jclouds.vcloud.domain.GuestCustomizationSection;
|
||||
import org.jclouds.vcloud.domain.Org;
|
||||
import org.jclouds.vcloud.domain.ReferenceType;
|
||||
import org.jclouds.vcloud.domain.Task;
|
||||
import org.jclouds.vcloud.domain.VCloudSession;
|
||||
import org.jclouds.vcloud.domain.VDCStatus;
|
||||
import org.jclouds.vcloud.domain.internal.CatalogImpl;
|
||||
import org.jclouds.vcloud.domain.internal.CatalogItemImpl;
|
||||
import org.jclouds.vcloud.domain.internal.OrgImpl;
|
||||
|
@ -86,6 +88,7 @@ import com.google.common.base.Supplier;
|
|||
import com.google.common.base.Suppliers;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.inject.Injector;
|
||||
import com.google.inject.Module;
|
||||
import com.google.inject.TypeLiteral;
|
||||
|
@ -350,6 +353,22 @@ public class VCloudAsyncClientTest extends RestClientTest<VCloudAsyncClient> {
|
|||
checkFilters(request);
|
||||
}
|
||||
|
||||
public void testFindNetworkInOrgVDCNamed() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = VCloudAsyncClient.class.getMethod("findNetworkInOrgVDCNamed", String.class, String.class,
|
||||
String.class);
|
||||
HttpRequest request = processor.createRequest(method, "org", "vdc", "network");
|
||||
|
||||
assertRequestLineEquals(request, "GET https://vcenterprise.bluelock.com/api/v1.0/vdcItem/2 HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.network+xml\n");
|
||||
assertPayloadEquals(request, null, null, false);
|
||||
|
||||
assertResponseParserClassEquals(method, request, ParseSax.class);
|
||||
assertSaxResponseParserClassEquals(method, OrgNetworkHandler.class);
|
||||
assertExceptionParserClassEquals(method, ReturnNullOnNotFoundOr404.class);
|
||||
|
||||
checkFilters(request);
|
||||
}
|
||||
|
||||
public void testCatalogItemURI() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = VCloudAsyncClient.class.getMethod("getCatalogItem", URI.class);
|
||||
HttpRequest request = processor.createRequest(method, URI
|
||||
|
@ -908,11 +927,11 @@ public class VCloudAsyncClientTest extends RestClientTest<VCloudAsyncClient> {
|
|||
null,
|
||||
URI
|
||||
.create("https://vcenterprise.bluelock.com/api/v1.0/vdc/1"),
|
||||
null,
|
||||
VDCStatus.READY,
|
||||
null,
|
||||
"description",
|
||||
null,
|
||||
null,
|
||||
ImmutableSet.<Task> of(),
|
||||
AllocationModel.ALLOCATION_POOL,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
|
@ -930,7 +949,8 @@ public class VCloudAsyncClientTest extends RestClientTest<VCloudAsyncClient> {
|
|||
"application/vnd.vmware.vcloud.vAppTemplate+xml",
|
||||
URI
|
||||
.create("https://vcenterprise.bluelock.com/api/v1.0/vdcItem/2"))),
|
||||
null, 0, 0, 0, false))));
|
||||
ImmutableMap.<String, ReferenceType> of(), 0, 0, 0,
|
||||
false))));
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -54,15 +54,15 @@ public class VCloudExpressOrgNetworkAdapterTest {
|
|||
Factory factory = injector.getInstance(ParseSax.Factory.class);
|
||||
VCloudExpressNetwork in = factory.create(injector.getInstance(VCloudExpressNetworkHandler.class)).parse(is);
|
||||
OrgNetwork result = new VCloudExpressOrgNetworkAdapter(in);
|
||||
assertEquals(result.getName(), "10.114.34.128/26");
|
||||
assertEquals(result.getHref(), URI.create("https://services.vcloudexpress.terremark.com/api/v0.8/network/1708"));
|
||||
assertEquals(result.getName(), "10.122.209.128/28");
|
||||
assertEquals(result.getHref(), URI.create("https://services.enterprisecloud.terremark.com/api/v0.8b-ext2.5/network/40031"));
|
||||
assertEquals(result.getType(), "application/vnd.vmware.vcloud.network+xml");
|
||||
assertEquals(result.getOrg(), null);
|
||||
assertEquals(result.getDescription(), null);
|
||||
assertEquals(result.getTasks(), ImmutableList.of());
|
||||
assert result.getConfiguration() != null;
|
||||
|
||||
assertEquals(result.getConfiguration().getIpScope(), new IpScope(true, "10.114.34.129", "255.255.255.192", null,
|
||||
assertEquals(result.getConfiguration().getIpScope(), new IpScope(true, "10.122.209.129", "255.255.255.240", null,
|
||||
null, null, ImmutableSet.<IpRange> of(), ImmutableSet.<String> of()));
|
||||
|
||||
assertEquals(result.getConfiguration().getParentNetwork(), null);
|
||||
|
|
|
@ -23,7 +23,6 @@ import static org.testng.Assert.assertEquals;
|
|||
|
||||
import java.io.InputStream;
|
||||
import java.net.URI;
|
||||
import java.net.UnknownHostException;
|
||||
|
||||
import org.jclouds.http.functions.ParseSax;
|
||||
import org.jclouds.http.functions.ParseSax.Factory;
|
||||
|
@ -51,20 +50,20 @@ public class VCloudExpressNetworkHandlerTest {
|
|||
|
||||
private Factory factory;
|
||||
|
||||
public void testTerremark() throws UnknownHostException {
|
||||
public void testTerremark() {
|
||||
InputStream is = getClass().getResourceAsStream("/express/network-terremark.xml");
|
||||
injector = Guice.createInjector(new SaxParserModule());
|
||||
factory = injector.getInstance(ParseSax.Factory.class);
|
||||
VCloudExpressNetwork result = factory.create(injector.getInstance(VCloudExpressNetworkHandler.class)).parse(is);
|
||||
assertEquals(result, new VCloudExpressNetworkImpl("10.114.34.128/26",
|
||||
assertEquals(result, new VCloudExpressNetworkImpl("10.122.209.128/28",
|
||||
"application/vnd.vmware.vcloud.network+xml", URI
|
||||
.create("https://services.vcloudexpress.terremark.com/api/v0.8/network/1708"), null,
|
||||
ImmutableSet.<String> of(), "10.114.34.129", "255.255.255.192", ImmutableSet
|
||||
.create("https://services.enterprisecloud.terremark.com/api/v0.8b-ext2.5/network/40031"), null,
|
||||
ImmutableSet.<String> of(), "10.122.209.129", "255.255.255.240", ImmutableSet
|
||||
.<FenceMode> of(FenceMode.ISOLATED), null, ImmutableSet.<PortForwardingRule> of(), ImmutableSet
|
||||
.<FirewallRule> of()));
|
||||
}
|
||||
|
||||
public void testHosting() throws UnknownHostException {
|
||||
public void testHosting() {
|
||||
InputStream is = getClass().getResourceAsStream("/express/network-hosting.xml");
|
||||
injector = Guice.createInjector(new SaxParserModule());
|
||||
factory = injector.getInstance(ParseSax.Factory.class);
|
||||
|
@ -76,7 +75,7 @@ public class VCloudExpressNetworkHandlerTest {
|
|||
.<FenceMode> of(), null, ImmutableSet.<PortForwardingRule> of(), ImmutableSet.<FirewallRule> of()));
|
||||
}
|
||||
|
||||
public void testBluelock() throws UnknownHostException {
|
||||
public void testBluelock() {
|
||||
InputStream is = getClass().getResourceAsStream("/express/network-bluelock.xml");
|
||||
injector = Guice.createInjector(new SaxParserModule());
|
||||
factory = injector.getInstance(ParseSax.Factory.class);
|
||||
|
|
|
@ -1,8 +1,10 @@
|
|||
<Network href="https://services.vcloudexpress.terremark.com/api/v0.8/network/1708" type="application/vnd.vmware.vcloud.network+xml" name="10.114.34.128/26" xmlns="http://www.vmware.com/vcloud/v1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
|
||||
<Link rel="down" href="https://services.vcloudexpress.terremark.com/api/v0.8/network/1708/ipAddresses" type="application/xml" name="IP Addresses"/>
|
||||
<Network href="https://services.enterprisecloud.terremark.com/api/v0.8b-ext2.5/network/40031" type="application/vnd.vmware.vcloud.network+xml" name="10.122.209.128/28" xmlns="http://www.vmware.com/vcloud/v0.8"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
|
||||
<Link rel="down" href="https://services.enterprisecloud.terremark.com/api/v0.8b-ext2.5/extensions/network/40031" type="application/xml" name="10.122.209.128/28"/>
|
||||
<Link rel="down" href="https://services.enterprisecloud.terremark.com/api/v0.8b-ext2.5/extensions/network/40031/ips" type="application/xml" name="IP Addresses"/>
|
||||
<Configuration>
|
||||
<Gateway>10.114.34.129</Gateway>
|
||||
<Netmask>255.255.255.192</Netmask>
|
||||
<Gateway>10.122.209.129</Gateway>
|
||||
<Netmask>255.255.255.240</Netmask>
|
||||
</Configuration>
|
||||
<Features>
|
||||
<FenceMode>isolated</FenceMode>
|
||||
|
|
|
@ -20,6 +20,7 @@
|
|||
package org.jclouds.vcloud.terremark;
|
||||
|
||||
import static javax.ws.rs.core.MediaType.APPLICATION_XML;
|
||||
import static org.jclouds.vcloud.VCloudMediaType.NETWORK_XML;
|
||||
import static org.jclouds.vcloud.terremark.TerremarkECloudMediaType.INTERNETSERVICESLIST_XML;
|
||||
import static org.jclouds.vcloud.terremark.TerremarkECloudMediaType.INTERNETSERVICE_XML;
|
||||
import static org.jclouds.vcloud.terremark.TerremarkECloudMediaType.KEYSLIST_XML;
|
||||
|
@ -45,12 +46,16 @@ import org.jclouds.rest.annotations.XMLResponseParser;
|
|||
import org.jclouds.rest.functions.ReturnEmptySetOnNotFoundOr404;
|
||||
import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404;
|
||||
import org.jclouds.rest.functions.ReturnVoidOnNotFoundOr404;
|
||||
import org.jclouds.vcloud.VCloudClient;
|
||||
import org.jclouds.vcloud.filters.SetVCloudTokenCookie;
|
||||
import org.jclouds.vcloud.functions.OrgNameVDCNameResourceEntityNameToEndpoint;
|
||||
import org.jclouds.vcloud.terremark.binders.BindCreateKeyToXmlPayload;
|
||||
import org.jclouds.vcloud.terremark.domain.InternetService;
|
||||
import org.jclouds.vcloud.terremark.domain.KeyPair;
|
||||
import org.jclouds.vcloud.terremark.domain.Protocol;
|
||||
import org.jclouds.vcloud.terremark.domain.PublicIpAddress;
|
||||
import org.jclouds.vcloud.terremark.domain.TerremarkNetwork;
|
||||
import org.jclouds.vcloud.terremark.domain.TerremarkOrgNetwork;
|
||||
import org.jclouds.vcloud.terremark.functions.OrgURIToKeysListEndpoint;
|
||||
import org.jclouds.vcloud.terremark.functions.VDCURIToInternetServicesEndpoint;
|
||||
import org.jclouds.vcloud.terremark.functions.VDCURIToPublicIPsEndpoint;
|
||||
|
@ -61,6 +66,8 @@ import org.jclouds.vcloud.terremark.xml.KeyPairByNameHandler;
|
|||
import org.jclouds.vcloud.terremark.xml.KeyPairHandler;
|
||||
import org.jclouds.vcloud.terremark.xml.KeyPairsHandler;
|
||||
import org.jclouds.vcloud.terremark.xml.PublicIpAddressesHandler;
|
||||
import org.jclouds.vcloud.terremark.xml.TerremarkNetworkHandler;
|
||||
import org.jclouds.vcloud.terremark.xml.TerremarkOrgNetworkFromTerremarkVCloudExpressNetworkHandler;
|
||||
|
||||
import com.google.common.util.concurrent.ListenableFuture;
|
||||
|
||||
|
@ -156,7 +163,7 @@ public interface TerremarkECloudAsyncClient extends TerremarkVCloudAsyncClient {
|
|||
@Nullable @EndpointParam(parser = OrgURIToKeysListEndpoint.class) URI org);
|
||||
|
||||
/**
|
||||
* @see TerremarkVCloudExpressClient#listKeyPairs
|
||||
* @see TerremarkECloudClient#listKeyPairs
|
||||
*/
|
||||
@GET
|
||||
@Path("")
|
||||
|
@ -166,7 +173,7 @@ public interface TerremarkECloudAsyncClient extends TerremarkVCloudAsyncClient {
|
|||
ListenableFuture<? extends Set<KeyPair>> listKeyPairs(@EndpointParam URI keysList);
|
||||
|
||||
/**
|
||||
* @see TerremarkVCloudExpressClient#generateKeyPairInOrg
|
||||
* @see TerremarkECloudClient#generateKeyPairInOrg
|
||||
*/
|
||||
@POST
|
||||
@Path("")
|
||||
|
@ -179,7 +186,7 @@ public interface TerremarkECloudAsyncClient extends TerremarkVCloudAsyncClient {
|
|||
@MapPayloadParam("isDefault") boolean makeDefault);
|
||||
|
||||
/**
|
||||
* @see TerremarkVCloudExpressClient#getKeyPair
|
||||
* @see TerremarkECloudClient#getKeyPair
|
||||
*/
|
||||
@GET
|
||||
@Path("")
|
||||
|
@ -204,10 +211,45 @@ public interface TerremarkECloudAsyncClient extends TerremarkVCloudAsyncClient {
|
|||
// KeyPairConfiguration keyConfiguration);
|
||||
|
||||
/**
|
||||
* @see TerremarkVCloudExpressClient#deleteKeyPair
|
||||
* @see TerremarkECloudClient#deleteKeyPair
|
||||
*/
|
||||
@DELETE
|
||||
@Path("")
|
||||
@ExceptionParser(ReturnVoidOnNotFoundOr404.class)
|
||||
ListenableFuture<Void> deleteKeyPair(@EndpointParam URI keyId);
|
||||
|
||||
/**
|
||||
* @see TerremarkECloudClient#findNetworkInOrgVDCNamed
|
||||
*/
|
||||
@Override
|
||||
@GET
|
||||
@Path("")
|
||||
@Consumes(NETWORK_XML)
|
||||
@XMLResponseParser(TerremarkOrgNetworkFromTerremarkVCloudExpressNetworkHandler.class)
|
||||
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
|
||||
ListenableFuture<? extends TerremarkOrgNetwork> findNetworkInOrgVDCNamed(
|
||||
@Nullable @EndpointParam(parser = OrgNameVDCNameResourceEntityNameToEndpoint.class) String orgName,
|
||||
@Nullable @EndpointParam(parser = OrgNameVDCNameResourceEntityNameToEndpoint.class) String catalogName,
|
||||
@EndpointParam(parser = OrgNameVDCNameResourceEntityNameToEndpoint.class) String networkName);
|
||||
|
||||
/**
|
||||
* @see TerremarkECloudClient#getNetwork
|
||||
*/
|
||||
@Override
|
||||
@GET
|
||||
@Path("")
|
||||
@Consumes(NETWORK_XML)
|
||||
@XMLResponseParser(TerremarkOrgNetworkFromTerremarkVCloudExpressNetworkHandler.class)
|
||||
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
|
||||
ListenableFuture<? extends TerremarkOrgNetwork> getNetwork(@EndpointParam URI network);
|
||||
|
||||
/**
|
||||
* @see TerremarkECloudClient#getTerremarkNetwork
|
||||
*/
|
||||
@GET
|
||||
@Path("")
|
||||
@XMLResponseParser(TerremarkNetworkHandler.class)
|
||||
@Consumes(APPLICATION_XML)
|
||||
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
|
||||
ListenableFuture<? extends TerremarkNetwork> getTerremarkNetwork(@EndpointParam URI network);
|
||||
}
|
||||
|
|
|
@ -22,16 +22,18 @@ package org.jclouds.vcloud.terremark;
|
|||
import java.net.URI;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import org.jclouds.concurrent.Timeout;
|
||||
import org.jclouds.vcloud.terremark.domain.PublicIpAddress;
|
||||
import org.jclouds.vcloud.terremark.domain.TerremarkNetwork;
|
||||
import org.jclouds.vcloud.terremark.domain.TerremarkOrgNetwork;
|
||||
|
||||
/**
|
||||
* Provides access to VCloud resources via their REST API.
|
||||
* <p/>
|
||||
*
|
||||
* @see <a href=
|
||||
* "http://support.theenterprisecloud.com/kb/default.asp?id=645&Lang=1&SID="
|
||||
* />
|
||||
* @see <a href= "http://support.theenterprisecloud.com/kb/default.asp?id=645&Lang=1&SID=" />
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@Timeout(duration = 300, timeUnit = TimeUnit.SECONDS)
|
||||
|
@ -44,4 +46,11 @@ public interface TerremarkECloudClient extends TerremarkVCloudClient {
|
|||
* @return
|
||||
*/
|
||||
PublicIpAddress activatePublicIpInVDC(URI vDCId);
|
||||
|
||||
TerremarkOrgNetwork findNetworkInOrgVDCNamed(@Nullable String orgName, @Nullable String vdc, String networkName);
|
||||
|
||||
TerremarkOrgNetwork getNetwork(URI network);
|
||||
|
||||
TerremarkNetwork getTerremarkNetwork(URI network);
|
||||
|
||||
}
|
||||
|
|
|
@ -214,8 +214,12 @@ public class TerremarkVCloudComputeClient extends VCloudExpressComputeClientImpl
|
|||
Set<InternetService> services = client.getInternetServicesOnPublicIp(address.getId());
|
||||
if (services.size() == 0) {
|
||||
logger.debug(">> deleting PublicIpAddress(%s) %s", address.getId(), address.getAddress());
|
||||
try {
|
||||
client.deletePublicIp(address.getId());
|
||||
logger.debug("<< deleted PublicIpAddress(%s)", address.getId());
|
||||
} catch (UnsupportedOperationException e) {
|
||||
logger.trace("cannot delete PublicIpAddress(%s) as it is unsupported", address.getId());
|
||||
}
|
||||
continue IPADDRESS;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,6 +19,8 @@
|
|||
|
||||
package org.jclouds.vcloud.terremark.config;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import java.net.URI;
|
||||
import java.util.Map;
|
||||
import java.util.NoSuchElementException;
|
||||
|
@ -31,11 +33,12 @@ import org.jclouds.rest.ResourceNotFoundException;
|
|||
import org.jclouds.vcloud.VCloudExpressAsyncClient;
|
||||
import org.jclouds.vcloud.VCloudExpressClient;
|
||||
import org.jclouds.vcloud.domain.ReferenceType;
|
||||
import org.jclouds.vcloud.domain.network.OrgNetwork;
|
||||
import org.jclouds.vcloud.terremark.TerremarkECloudAsyncClient;
|
||||
import org.jclouds.vcloud.terremark.TerremarkECloudClient;
|
||||
import org.jclouds.vcloud.terremark.TerremarkVCloudAsyncClient;
|
||||
import org.jclouds.vcloud.terremark.TerremarkVCloudClient;
|
||||
import org.jclouds.vcloud.terremark.domain.TerremarkNetwork;
|
||||
import org.jclouds.vcloud.terremark.domain.TerremarkOrgNetwork;
|
||||
|
||||
import com.google.common.base.Predicate;
|
||||
import com.google.common.collect.Iterables;
|
||||
|
@ -97,9 +100,14 @@ public class TerremarkECloudRestClientModule extends
|
|||
|
||||
@Override
|
||||
public boolean apply(ReferenceType input) {
|
||||
OrgNetwork network = injector.getInstance(TerremarkECloudClient.class).getNetwork(input.getHref());
|
||||
// TODO: get extension data on this network and check NetworkType == DMZ
|
||||
return network.getDescription() != null &&network.getDescription().toLowerCase().contains("dmz");
|
||||
TerremarkOrgNetwork network = injector.getInstance(TerremarkECloudClient.class).getNetwork(
|
||||
input.getHref());
|
||||
TerremarkNetwork terremarkNetwork = injector.getInstance(TerremarkECloudClient.class)
|
||||
.getTerremarkNetwork(
|
||||
checkNotNull(checkNotNull(network, "network at: " + input).getNetworkExtension(),
|
||||
"network extension for: " + input).getHref());
|
||||
return checkNotNull(terremarkNetwork, "terremark network extension at: " + network.getNetworkExtension())
|
||||
.getNetworkType() == TerremarkNetwork.Type.DMZ;
|
||||
}
|
||||
|
||||
}).getHref();
|
||||
|
|
|
@ -0,0 +1,196 @@
|
|||
/**
|
||||
*
|
||||
* 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.vcloud.terremark.domain;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import java.net.URI;
|
||||
|
||||
/**
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
public class TerremarkNetwork implements Comparable<TerremarkNetwork> {
|
||||
public enum Type {
|
||||
INTERNAL, DMZ, UNRECOGNIZED;
|
||||
public static Type fromValue(String type) {
|
||||
try {
|
||||
return valueOf(checkNotNull(type, "type").toUpperCase());
|
||||
} catch (IllegalArgumentException e) {
|
||||
return UNRECOGNIZED;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private final String id;
|
||||
private final URI href;
|
||||
private final String name;
|
||||
private final String rnatAddress;
|
||||
private final String address;
|
||||
private final String broadcastAddress;
|
||||
private final String gatewayAddress;
|
||||
private final Type networkType;
|
||||
private final String vlan;
|
||||
private final String friendlyName;
|
||||
|
||||
public TerremarkNetwork(String id, URI href, String name, String rnatAddress, String address,
|
||||
String broadcastAddress, String gatewayAddress, Type networkType, String vlan, String friendlyName) {
|
||||
this.id = id;
|
||||
this.href = href;
|
||||
this.name = name;
|
||||
this.rnatAddress = rnatAddress;
|
||||
this.address = address;
|
||||
this.broadcastAddress = broadcastAddress;
|
||||
this.gatewayAddress = gatewayAddress;
|
||||
this.networkType = networkType;
|
||||
this.vlan = vlan;
|
||||
this.friendlyName = friendlyName;
|
||||
}
|
||||
|
||||
public int compareTo(TerremarkNetwork that) {
|
||||
return (this == that) ? 0 : getHref().compareTo(that.getHref());
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public URI getHref() {
|
||||
return href;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public String getRnatAddress() {
|
||||
return rnatAddress;
|
||||
}
|
||||
|
||||
public String getAddress() {
|
||||
return address;
|
||||
}
|
||||
|
||||
public String getBroadcastAddress() {
|
||||
return broadcastAddress;
|
||||
}
|
||||
|
||||
public String getGatewayAddress() {
|
||||
return gatewayAddress;
|
||||
}
|
||||
|
||||
public Type getNetworkType() {
|
||||
return networkType;
|
||||
}
|
||||
|
||||
public String getVlan() {
|
||||
return vlan;
|
||||
}
|
||||
|
||||
public String getFriendlyName() {
|
||||
return friendlyName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
result = prime * result + ((address == null) ? 0 : address.hashCode());
|
||||
result = prime * result + ((broadcastAddress == null) ? 0 : broadcastAddress.hashCode());
|
||||
result = prime * result + ((friendlyName == null) ? 0 : friendlyName.hashCode());
|
||||
result = prime * result + ((gatewayAddress == null) ? 0 : gatewayAddress.hashCode());
|
||||
result = prime * result + ((href == null) ? 0 : href.hashCode());
|
||||
result = prime * result + ((id == null) ? 0 : id.hashCode());
|
||||
result = prime * result + ((name == null) ? 0 : name.hashCode());
|
||||
result = prime * result + ((networkType == null) ? 0 : networkType.hashCode());
|
||||
result = prime * result + ((rnatAddress == null) ? 0 : rnatAddress.hashCode());
|
||||
result = prime * result + ((vlan == null) ? 0 : vlan.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;
|
||||
TerremarkNetwork other = (TerremarkNetwork) obj;
|
||||
if (address == null) {
|
||||
if (other.address != null)
|
||||
return false;
|
||||
} else if (!address.equals(other.address))
|
||||
return false;
|
||||
if (broadcastAddress == null) {
|
||||
if (other.broadcastAddress != null)
|
||||
return false;
|
||||
} else if (!broadcastAddress.equals(other.broadcastAddress))
|
||||
return false;
|
||||
if (friendlyName == null) {
|
||||
if (other.friendlyName != null)
|
||||
return false;
|
||||
} else if (!friendlyName.equals(other.friendlyName))
|
||||
return false;
|
||||
if (gatewayAddress == null) {
|
||||
if (other.gatewayAddress != null)
|
||||
return false;
|
||||
} else if (!gatewayAddress.equals(other.gatewayAddress))
|
||||
return false;
|
||||
if (href == null) {
|
||||
if (other.href != null)
|
||||
return false;
|
||||
} else if (!href.equals(other.href))
|
||||
return false;
|
||||
if (id == null) {
|
||||
if (other.id != null)
|
||||
return false;
|
||||
} else if (!id.equals(other.id))
|
||||
return false;
|
||||
if (name == null) {
|
||||
if (other.name != null)
|
||||
return false;
|
||||
} else if (!name.equals(other.name))
|
||||
return false;
|
||||
if (networkType == null) {
|
||||
if (other.networkType != null)
|
||||
return false;
|
||||
} else if (!networkType.equals(other.networkType))
|
||||
return false;
|
||||
if (rnatAddress == null) {
|
||||
if (other.rnatAddress != null)
|
||||
return false;
|
||||
} else if (!rnatAddress.equals(other.rnatAddress))
|
||||
return false;
|
||||
if (vlan == null) {
|
||||
if (other.vlan != null)
|
||||
return false;
|
||||
} else if (!vlan.equals(other.vlan))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "[address=" + address + ", broadcastAddress=" + broadcastAddress + ", friendlyName=" + friendlyName
|
||||
+ ", gatewayAddress=" + gatewayAddress + ", href=" + href + ", id=" + id + ", name=" + name
|
||||
+ ", networkType=" + networkType + ", rnatAddress=" + rnatAddress + ", vlan=" + vlan + "]";
|
||||
}
|
||||
}
|
|
@ -0,0 +1,46 @@
|
|||
/**
|
||||
*
|
||||
* 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.vcloud.terremark.domain;
|
||||
|
||||
import org.jclouds.vcloud.domain.ReferenceType;
|
||||
import org.jclouds.vcloud.domain.network.internal.VCloudExpressOrgNetworkAdapter;
|
||||
import org.jclouds.vcloud.terremark.domain.internal.TerremarkVCloudExpressNetwork;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
public class TerremarkOrgNetwork extends VCloudExpressOrgNetworkAdapter {
|
||||
|
||||
private final TerremarkVCloudExpressNetwork delegate;
|
||||
|
||||
public TerremarkOrgNetwork(TerremarkVCloudExpressNetwork in) {
|
||||
super(in);
|
||||
this.delegate = in;
|
||||
}
|
||||
|
||||
public ReferenceType getNetworkExtension() {
|
||||
return delegate.getNetworkExtension();
|
||||
}
|
||||
|
||||
public ReferenceType getIps() {
|
||||
return delegate.getIps();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,95 @@
|
|||
/**
|
||||
*
|
||||
* 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.vcloud.terremark.domain.internal;
|
||||
|
||||
import java.net.URI;
|
||||
import java.util.Set;
|
||||
|
||||
import org.jclouds.vcloud.domain.ReferenceType;
|
||||
import org.jclouds.vcloud.domain.network.FenceMode;
|
||||
import org.jclouds.vcloud.domain.network.firewall.FirewallRule;
|
||||
import org.jclouds.vcloud.domain.network.internal.VCloudExpressNetworkImpl;
|
||||
import org.jclouds.vcloud.domain.network.nat.rules.PortForwardingRule;
|
||||
|
||||
/**
|
||||
* Locations of resources in vCloud
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*
|
||||
*/
|
||||
public class TerremarkVCloudExpressNetwork extends VCloudExpressNetworkImpl {
|
||||
private final ReferenceType networkExtension;
|
||||
private final ReferenceType ips;
|
||||
|
||||
public TerremarkVCloudExpressNetwork(String name, String type, URI id, String description, Set<String> dnsServers,
|
||||
String gateway, String netmask, Set<FenceMode> fenceModes, Boolean dhcp, Set<PortForwardingRule> natRules,
|
||||
Set<FirewallRule> firewallRules, ReferenceType networkExtension, ReferenceType ips) {
|
||||
super(name, type, id, description, dnsServers, gateway, netmask, fenceModes, dhcp, natRules, firewallRules);
|
||||
this.networkExtension = networkExtension;
|
||||
this.ips = ips;
|
||||
}
|
||||
|
||||
public ReferenceType getNetworkExtension() {
|
||||
return networkExtension;
|
||||
}
|
||||
|
||||
public ReferenceType getIps() {
|
||||
return ips;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = super.hashCode();
|
||||
result = prime * result + ((ips == null) ? 0 : ips.hashCode());
|
||||
result = prime * result + ((networkExtension == null) ? 0 : networkExtension.hashCode());
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj)
|
||||
return true;
|
||||
if (!super.equals(obj))
|
||||
return false;
|
||||
if (getClass() != obj.getClass())
|
||||
return false;
|
||||
TerremarkVCloudExpressNetwork other = (TerremarkVCloudExpressNetwork) obj;
|
||||
if (ips == null) {
|
||||
if (other.ips != null)
|
||||
return false;
|
||||
} else if (!ips.equals(other.ips))
|
||||
return false;
|
||||
if (networkExtension == null) {
|
||||
if (other.networkExtension != null)
|
||||
return false;
|
||||
} else if (!networkExtension.equals(other.networkExtension))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "[id=" + getHref() + ", name=" + getName() + ", type=" + getType() + ", description=" + description
|
||||
+ ", dhcp=" + dhcp + ", dnsServers=" + dnsServers + ", fenceModes=" + fenceModes + ", firewallRules="
|
||||
+ firewallRules + ", gateway=" + gateway + ", natRules=" + natRules + ", netmask=" + netmask + ",ips="
|
||||
+ ips + ", networkExtension=" + networkExtension + "]";
|
||||
}
|
||||
}
|
|
@ -81,6 +81,9 @@ public class ParseTerremarkVCloudErrorFromHttpResponse implements HttpErrorHandl
|
|||
}
|
||||
exception = new ResourceNotFoundException(message, exception);
|
||||
break;
|
||||
case 405:
|
||||
exception = new UnsupportedOperationException(response.getMessage(), exception);
|
||||
break;
|
||||
case 501:
|
||||
if (response.getMessage() != null && (response.getMessage().indexOf("NotImplemented") != -1))
|
||||
exception = new UnsupportedOperationException(response.getMessage(), exception);
|
||||
|
|
|
@ -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.vcloud.terremark.xml;
|
||||
|
||||
import java.net.URI;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
import org.jclouds.http.functions.ParseSax.HandlerWithResult;
|
||||
import org.jclouds.logging.Logger;
|
||||
import org.jclouds.vcloud.terremark.domain.TerremarkNetwork;
|
||||
import org.jclouds.vcloud.terremark.domain.TerremarkNetwork.Type;
|
||||
|
||||
/**
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
public class TerremarkNetworkHandler extends HandlerWithResult<TerremarkNetwork> {
|
||||
|
||||
@Resource
|
||||
protected Logger logger = Logger.NULL;
|
||||
private StringBuilder currentText = new StringBuilder();
|
||||
|
||||
private String id;
|
||||
private URI href;
|
||||
private String name;
|
||||
private String rnatAddress;
|
||||
private String address;
|
||||
private String broadcastAddress;
|
||||
private String gatewayAddress;
|
||||
private Type networkType;
|
||||
private String vlan;
|
||||
private String friendlyName;
|
||||
|
||||
protected String currentOrNull() {
|
||||
String returnVal = currentText.toString().trim();
|
||||
return returnVal.equals("") ? null : returnVal;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TerremarkNetwork getResult() {
|
||||
return new TerremarkNetwork(id, href, name, rnatAddress, address, broadcastAddress, gatewayAddress, networkType,
|
||||
vlan, friendlyName);
|
||||
}
|
||||
|
||||
public void endElement(String uri, String name, String qName) {
|
||||
if (qName.equals("Href") && currentOrNull() != null) {
|
||||
href = URI.create(currentOrNull());
|
||||
} else if (qName.equals("Id")) {
|
||||
id = currentOrNull();
|
||||
} else if (qName.equals("Name")) {
|
||||
this.name = currentOrNull();
|
||||
} else if (qName.equals("RnatAddress")) {
|
||||
rnatAddress = currentOrNull();
|
||||
} else if (qName.equals("Address")) {
|
||||
address = currentOrNull();
|
||||
} else if (qName.equals("BroadcastAddress")) {
|
||||
broadcastAddress = currentOrNull();
|
||||
} else if (qName.equals("GatewayAddress")) {
|
||||
gatewayAddress = currentOrNull();
|
||||
} else if (qName.equals("NetworkType")) {
|
||||
networkType = TerremarkNetwork.Type.fromValue(currentOrNull());
|
||||
} else if (qName.equals("Vlan")) {
|
||||
vlan = currentOrNull();
|
||||
} else if (qName.equals("FriendlyName")) {
|
||||
friendlyName = currentOrNull();
|
||||
}
|
||||
currentText = new StringBuilder();
|
||||
}
|
||||
|
||||
public void characters(char ch[], int start, int length) {
|
||||
currentText.append(ch, start, length);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,59 @@
|
|||
/**
|
||||
*
|
||||
* 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.vcloud.terremark.xml;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import org.jclouds.http.functions.ParseSax;
|
||||
import org.jclouds.vcloud.terremark.domain.TerremarkOrgNetwork;
|
||||
import org.xml.sax.Attributes;
|
||||
import org.xml.sax.SAXException;
|
||||
|
||||
/**
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
public class TerremarkOrgNetworkFromTerremarkVCloudExpressNetworkHandler extends
|
||||
ParseSax.HandlerWithResult<TerremarkOrgNetwork> {
|
||||
|
||||
protected final TerremarkVCloudExpressNetworkHandler vcxHandler;
|
||||
|
||||
@Inject
|
||||
public TerremarkOrgNetworkFromTerremarkVCloudExpressNetworkHandler(TerremarkVCloudExpressNetworkHandler vcxHandler) {
|
||||
this.vcxHandler = vcxHandler;
|
||||
}
|
||||
|
||||
public TerremarkOrgNetwork getResult() {
|
||||
return new TerremarkOrgNetwork(vcxHandler.getResult());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException {
|
||||
vcxHandler.startElement(uri, localName, qName, attributes);
|
||||
}
|
||||
|
||||
public void endElement(String uri, String name, String qName) {
|
||||
vcxHandler.endElement(uri, name, qName);
|
||||
}
|
||||
|
||||
public void characters(char ch[], int start, int length) {
|
||||
vcxHandler.characters(ch, start, length);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,66 @@
|
|||
/**
|
||||
*
|
||||
* 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.vcloud.terremark.xml;
|
||||
|
||||
import static org.jclouds.vcloud.util.Utils.cleanseAttributes;
|
||||
import static org.jclouds.vcloud.util.Utils.newReferenceType;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
import org.jclouds.logging.Logger;
|
||||
import org.jclouds.vcloud.domain.ReferenceType;
|
||||
import org.jclouds.vcloud.terremark.domain.internal.TerremarkVCloudExpressNetwork;
|
||||
import org.jclouds.vcloud.xml.VCloudExpressNetworkHandler;
|
||||
import org.xml.sax.Attributes;
|
||||
import org.xml.sax.SAXException;
|
||||
|
||||
/**
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
public class TerremarkVCloudExpressNetworkHandler extends VCloudExpressNetworkHandler {
|
||||
|
||||
@Resource
|
||||
protected Logger logger = Logger.NULL;
|
||||
|
||||
private ReferenceType ips;
|
||||
private ReferenceType extension;
|
||||
|
||||
public TerremarkVCloudExpressNetwork getResult() {
|
||||
return new TerremarkVCloudExpressNetwork(network.getName(), network.getType(), network.getHref(), description,
|
||||
dnsServers, gateway, netmask, fenceModes, dhcp, natRules, firewallRules, extension, ips);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void startElement(String uri, String localName, String qName, Attributes attrs) throws SAXException {
|
||||
Map<String, String> attributes = cleanseAttributes(attrs);
|
||||
if (qName.equals("Network")) {
|
||||
network = newReferenceType(attributes);
|
||||
} else if (qName.equals("Link")) {
|
||||
if ("IP Addresses".equals(attributes.get("name"))) {
|
||||
ips = newReferenceType(attributes);
|
||||
} else if ("down".equals(attributes.get("rel"))) {
|
||||
extension = newReferenceType(attributes);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -74,6 +74,7 @@ import org.jclouds.vcloud.terremark.xml.KeyPairsHandler;
|
|||
import org.jclouds.vcloud.terremark.xml.NodeHandler;
|
||||
import org.jclouds.vcloud.terremark.xml.NodesHandler;
|
||||
import org.jclouds.vcloud.terremark.xml.PublicIpAddressesHandler;
|
||||
import org.jclouds.vcloud.terremark.xml.TerremarkOrgNetworkFromTerremarkVCloudExpressNetworkHandler;
|
||||
import org.jclouds.vcloud.terremark.xml.TerremarkVDCHandler;
|
||||
import org.jclouds.vcloud.xml.CatalogHandler;
|
||||
import org.jclouds.vcloud.xml.VCloudExpressVAppHandler;
|
||||
|
@ -96,6 +97,38 @@ import domain.VCloudVersionsAsyncClient;
|
|||
*/
|
||||
@Test(groups = "unit", sequential = true, testName = "TerremarkECloudAsyncClientTest")
|
||||
public class TerremarkECloudAsyncClientTest extends RestClientTest<TerremarkECloudAsyncClient> {
|
||||
public void testNetwork() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = TerremarkECloudAsyncClient.class.getMethod("getNetwork", URI.class);
|
||||
HttpRequest request = processor.createRequest(method, URI
|
||||
.create("https://vcloud.safesecureweb.com/api/v0.8/vdcItem/2"));
|
||||
|
||||
assertRequestLineEquals(request, "GET https://vcloud.safesecureweb.com/api/v0.8/vdcItem/2 HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.network+xml\n");
|
||||
assertPayloadEquals(request, null, null, false);
|
||||
|
||||
assertResponseParserClassEquals(method, request, ParseSax.class);
|
||||
assertSaxResponseParserClassEquals(method, TerremarkOrgNetworkFromTerremarkVCloudExpressNetworkHandler.class);
|
||||
assertExceptionParserClassEquals(method, ReturnNullOnNotFoundOr404.class);
|
||||
|
||||
checkFilters(request);
|
||||
}
|
||||
|
||||
public void testFindNetworkInOrgVDCNamed() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = TerremarkECloudAsyncClient.class.getMethod("findNetworkInOrgVDCNamed", String.class,
|
||||
String.class, String.class);
|
||||
HttpRequest request = processor.createRequest(method, "org", "vdc", "network");
|
||||
|
||||
assertRequestLineEquals(request, "GET https://vcloud.safesecureweb.com/api/v0.8/vdcItem/2 HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.network+xml\n");
|
||||
assertPayloadEquals(request, null, null, false);
|
||||
|
||||
assertResponseParserClassEquals(method, request, ParseSax.class);
|
||||
assertSaxResponseParserClassEquals(method, TerremarkOrgNetworkFromTerremarkVCloudExpressNetworkHandler.class);
|
||||
assertExceptionParserClassEquals(method, ReturnNullOnNotFoundOr404.class);
|
||||
|
||||
checkFilters(request);
|
||||
}
|
||||
|
||||
/**
|
||||
* ignore parameter of catalog id since this doesn't work
|
||||
*/
|
||||
|
|
|
@ -0,0 +1,49 @@
|
|||
/**
|
||||
*
|
||||
* 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.vcloud.terremark.xml;
|
||||
|
||||
import static org.testng.Assert.assertEquals;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.net.URI;
|
||||
import java.net.UnknownHostException;
|
||||
|
||||
import org.jclouds.http.functions.BaseHandlerTest;
|
||||
import org.jclouds.vcloud.terremark.domain.TerremarkNetwork;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
/**
|
||||
* Tests behavior of {@code TerremarkNetworkHandler}
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@Test(groups = "unit", testName = "terremark.TerremarkNetworkHandlerTest")
|
||||
public class TerremarkNetworkHandlerTest extends BaseHandlerTest {
|
||||
|
||||
public void test1() throws UnknownHostException {
|
||||
InputStream is = getClass().getResourceAsStream("/terremark/TerremarkNetwork.xml");
|
||||
|
||||
TerremarkNetwork result = factory.create(injector.getInstance(TerremarkNetworkHandler.class)).parse(is);
|
||||
assertEquals(result, new TerremarkNetwork("XXXXX", URI
|
||||
.create("https://services.enterprisecloud.terremark.com/api/v0.8b-ext2.5/extensions/network/XXXXX"),
|
||||
"10.X.X.0/27", "209.X.X.X", "10.X.X.0", "10.X.X.X", "10.X.X.1", TerremarkNetwork.Type.DMZ, "279",
|
||||
"10.X.X.0/27 (DMZ_279)"));
|
||||
}
|
||||
}
|
|
@ -0,0 +1,87 @@
|
|||
/**
|
||||
*
|
||||
* 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.vcloud.terremark.xml;
|
||||
|
||||
import static org.testng.Assert.assertEquals;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.net.URI;
|
||||
|
||||
import org.jclouds.http.functions.ParseSax;
|
||||
import org.jclouds.http.functions.ParseSax.Factory;
|
||||
import org.jclouds.http.functions.config.SaxParserModule;
|
||||
import org.jclouds.vcloud.domain.internal.ReferenceTypeImpl;
|
||||
import org.jclouds.vcloud.domain.network.FenceMode;
|
||||
import org.jclouds.vcloud.domain.network.VCloudExpressNetwork;
|
||||
import org.jclouds.vcloud.domain.network.firewall.FirewallRule;
|
||||
import org.jclouds.vcloud.domain.network.nat.rules.PortForwardingRule;
|
||||
import org.jclouds.vcloud.terremark.domain.internal.TerremarkVCloudExpressNetwork;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.inject.Guice;
|
||||
import com.google.inject.Injector;
|
||||
|
||||
/**
|
||||
* Tests behavior of {@code TerremarkVCloudExpressNetworkHandler}
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@Test(groups = "unit", testName = "terremark.TerremarkVCloudExpressNetworkHandlerTest")
|
||||
public class TerremarkVCloudExpressNetworkHandlerTest {
|
||||
|
||||
private Injector injector;
|
||||
|
||||
private Factory factory;
|
||||
|
||||
public void testTerremark() {
|
||||
InputStream is = getClass().getResourceAsStream("/express/network-terremark.xml");
|
||||
injector = Guice.createInjector(new SaxParserModule());
|
||||
factory = injector.getInstance(ParseSax.Factory.class);
|
||||
VCloudExpressNetwork result = factory.create(injector.getInstance(TerremarkVCloudExpressNetworkHandler.class))
|
||||
.parse(is);
|
||||
assertEquals(
|
||||
result,
|
||||
new TerremarkVCloudExpressNetwork(
|
||||
"10.122.209.128/28",
|
||||
"application/vnd.vmware.vcloud.network+xml",
|
||||
URI.create("https://services.enterprisecloud.terremark.com/api/v0.8b-ext2.5/network/40031"),
|
||||
null,
|
||||
ImmutableSet.<String> of(),
|
||||
"10.122.209.129",
|
||||
"255.255.255.240",
|
||||
ImmutableSet.<FenceMode> of(FenceMode.ISOLATED),
|
||||
null,
|
||||
ImmutableSet.<PortForwardingRule> of(),
|
||||
ImmutableSet.<FirewallRule> of(),
|
||||
|
||||
new ReferenceTypeImpl(
|
||||
"10.122.209.128/28",
|
||||
"application/xml",
|
||||
URI
|
||||
.create("https://services.enterprisecloud.terremark.com/api/v0.8b-ext2.5/extensions/network/40031")),
|
||||
new ReferenceTypeImpl(
|
||||
"IP Addresses",
|
||||
"application/xml",
|
||||
URI
|
||||
.create("https://services.enterprisecloud.terremark.com/api/v0.8b-ext2.5/extensions/network/40031/ips"))));
|
||||
|
||||
}
|
||||
}
|
|
@ -0,0 +1,12 @@
|
|||
<Network xmlns="urn:tmrk:eCloudExtensions-2.5" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
|
||||
<Id>XXXXX</Id>
|
||||
<Href>https://services.enterprisecloud.terremark.com/api/v0.8b-ext2.5/extensions/network/XXXXX</Href>
|
||||
<Name>10.X.X.0/27</Name>
|
||||
<RnatAddress>209.X.X.X</RnatAddress>
|
||||
<Address>10.X.X.0</Address>
|
||||
<BroadcastAddress>10.X.X.X</BroadcastAddress>
|
||||
<GatewayAddress>10.X.X.1</GatewayAddress>
|
||||
<NetworkType>DMZ</NetworkType>
|
||||
<Vlan>279</Vlan>
|
||||
<FriendlyName>10.X.X.0/27 (DMZ_279)</FriendlyName>
|
||||
</Network>
|
Loading…
Reference in New Issue