Added Virtual Network Gateway Connection API

This commit is contained in:
Ignasi Barrera 2018-07-03 18:36:52 +02:00
parent e9f29f35e7
commit 00b6697d09
14 changed files with 768 additions and 6 deletions

View File

@ -47,6 +47,7 @@ import org.jclouds.azurecompute.arm.features.VirtualMachineApi;
import org.jclouds.azurecompute.arm.features.VirtualMachineScaleSetApi;
import org.jclouds.azurecompute.arm.features.VirtualNetworkApi;
import org.jclouds.azurecompute.arm.features.VirtualNetworkGatewayApi;
import org.jclouds.azurecompute.arm.features.VirtualNetworkGatewayConnectionApi;
import org.jclouds.rest.annotations.Delegate;
import com.google.common.base.Supplier;
@ -280,6 +281,14 @@ public interface AzureComputeApi extends Closeable {
@Delegate
VirtualNetworkGatewayApi getVirtualNetworkGatewayApi(@PathParam("resourcegroup") String resourcegroup);
/**
* Management features for Virtual Network Gateway Connections.
*
* @see <a href="https://docs.microsoft.com/en-us/rest/api/network-gateway/virtualnetworkgatewayconnections">docs</a>
*/
@Delegate
VirtualNetworkGatewayConnectionApi getVirtualNetworkGatewayConnectionApi(@PathParam("resourcegroup") String resourcegroup);
/**
* Returns the information about the current service principal.
*/

View File

@ -64,6 +64,7 @@ import org.jclouds.azurecompute.arm.features.VirtualMachineApi;
import org.jclouds.azurecompute.arm.features.VirtualMachineScaleSetApi;
import org.jclouds.azurecompute.arm.features.VirtualNetworkApi;
import org.jclouds.azurecompute.arm.features.VirtualNetworkGatewayApi;
import org.jclouds.azurecompute.arm.features.VirtualNetworkGatewayConnectionApi;
import org.jclouds.providers.ProviderMetadata;
import org.jclouds.providers.internal.BaseProviderMetadata;
@ -134,6 +135,7 @@ public class AzureComputeProviderMetadata extends BaseProviderMetadata {
properties.put(API_VERSION_PREFIX + VaultApi.class.getSimpleName(), "2016-10-01");
properties.put(API_VERSION_PREFIX + LocalNetworkGatewayApi.class.getSimpleName(), "2018-02-01");
properties.put(API_VERSION_PREFIX + VirtualNetworkGatewayApi.class.getSimpleName(), "2018-02-01");
properties.put(API_VERSION_PREFIX + VirtualNetworkGatewayConnectionApi.class.getSimpleName(), "2018-02-01");
return properties;
}

View File

@ -0,0 +1,45 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jclouds.azurecompute.arm.domain.vpn;
import org.jclouds.azurecompute.arm.domain.vpn.VirtualNetworkGatewayConnection.Status;
import org.jclouds.javax.annotation.Nullable;
import org.jclouds.json.SerializedNames;
import com.google.auto.value.AutoValue;
@AutoValue
public abstract class TunnelConnectionHealth {
public abstract Status connectionStatus();
public abstract int egressBytesTransferred();
public abstract int ingressBytesTransferred();
@Nullable public abstract String lastConnectionEstablishedUtcTime();
public abstract String tunnel();
TunnelConnectionHealth() {
}
@SerializedNames({ "connectionStatus", "egressBytesTransferred", "ingressBytesTransferred",
"lastConnectionEstablishedUtcTime", "tunnel" })
public static TunnelConnectionHealth create(Status connectionStatus, int egressBytesTransferred,
int ingressBytesTransferred, String lastConnectionEstablishedUtcTime, String tunnel) {
return new AutoValue_TunnelConnectionHealth(connectionStatus, egressBytesTransferred, ingressBytesTransferred,
lastConnectionEstablishedUtcTime, tunnel);
}
}

View File

@ -0,0 +1,90 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jclouds.azurecompute.arm.domain.vpn;
import java.util.Map;
import org.jclouds.azurecompute.arm.util.GetEnumValue;
import org.jclouds.javax.annotation.Nullable;
import org.jclouds.json.SerializedNames;
import com.google.auto.value.AutoValue;
import com.google.common.collect.ImmutableMap;
@AutoValue
public abstract class VirtualNetworkGatewayConnection {
public static enum Status {
Connected, Connecting, NotConnected, Unknown;
public static Status fromValue(final String text) {
return (Status) GetEnumValue.fromValueOrDefault(text, Status.Unknown);
}
}
public static enum Type {
ExpressRoute, IPsec, VPNClient, Vnet2Vnet, Unrecognized;
public static Type fromValue(final String text) {
return (Type) GetEnumValue.fromValueOrDefault(text, Type.Unrecognized);
}
}
@Nullable public abstract String id();
public abstract String name();
public abstract String location();
@Nullable public abstract String type();
@Nullable public abstract Map<String, String> tags();
@Nullable public abstract String etag();
public abstract VirtualNetworkGatewayConnectionProperties properties();
VirtualNetworkGatewayConnection() {
}
@SerializedNames({ "id", "name", "location", "type", "tags", "etag", "properties" })
public static VirtualNetworkGatewayConnection create(String id, String name, String location, String type,
Map<String, String> tags, String etag, VirtualNetworkGatewayConnectionProperties properties) {
return builder(name, location, properties).id(id).type(type).tags(tags).etag(etag).build();
}
public abstract Builder toBuilder();
public static Builder builder(String name, String location, VirtualNetworkGatewayConnectionProperties properties) {
return new AutoValue_VirtualNetworkGatewayConnection.Builder().name(name).location(location)
.properties(properties);
}
@AutoValue.Builder
public abstract static class Builder {
public abstract Builder id(String id);
public abstract Builder name(String name);
public abstract Builder location(String location);
public abstract Builder type(String type);
public abstract Builder tags(Map<String, String> tags);
public abstract Builder etag(String etag);
public abstract Builder properties(VirtualNetworkGatewayConnectionProperties properties);
abstract Map<String, String> tags();
abstract VirtualNetworkGatewayConnection autoBuild();
public VirtualNetworkGatewayConnection build() {
tags(tags() != null ? ImmutableMap.copyOf(tags()) : null);
return autoBuild();
}
}
}

View File

@ -0,0 +1,117 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jclouds.azurecompute.arm.domain.vpn;
import java.util.List;
import org.jclouds.azurecompute.arm.domain.IdReference;
import org.jclouds.azurecompute.arm.domain.Provisionable;
import org.jclouds.azurecompute.arm.domain.vpn.VirtualNetworkGatewayConnection.Status;
import org.jclouds.azurecompute.arm.domain.vpn.VirtualNetworkGatewayConnection.Type;
import org.jclouds.javax.annotation.Nullable;
import org.jclouds.json.SerializedNames;
import com.google.auto.value.AutoValue;
import com.google.common.collect.ImmutableList;
@AutoValue
public abstract class VirtualNetworkGatewayConnectionProperties implements Provisionable {
@Nullable public abstract String authorizationKey();
@Nullable public abstract Status connectionStatus();
public abstract Type connectionType();
@Nullable public abstract Integer egressBytesTransferred();
@Nullable public abstract Integer ingressBytesTransferred();
public abstract boolean enableBGP();
public abstract List<IPSecPolicy> ipsecPolicies();
@Nullable public abstract IdReference peer();
@Nullable public abstract String provisioningState();
@Nullable public abstract String resourceGuid();
@Nullable public abstract Integer routingWeight();
@Nullable public abstract String sharedKey();
public abstract List<TunnelConnectionHealth> tunnelConnectionStatus();
public abstract boolean usePolicyBasedTrafficSelectors();
public abstract IdReference localNetworkGateway2();
public abstract IdReference virtualNetworkGateway1();
@Nullable public abstract IdReference virtualNetworkGateway2();
VirtualNetworkGatewayConnectionProperties() {
}
@SerializedNames({ "authorizationKey", "connectionStatus", "connectionType", "egressBytesTransferred",
"ingressBytesTransferred", "enableBGP", "ipsecPolicies", "peer", "provisioningState", "resourceGuid",
"routingWeight", "sharedKey", "tunnelConnectionStatus", "usePolicyBasedTrafficSelectors",
"localNetworkGateway2", "virtualNetworkGateway1", "virtualNetworkGateway2" })
public static VirtualNetworkGatewayConnectionProperties create(String authorizationKey, Status connectionStatus,
Type connectionType, Integer egressBytesTransferred, Integer ingressBytesTransferred, boolean enableBGP,
List<IPSecPolicy> ipsecPolicies, IdReference peer, String provisioningState, String resourceGuid,
Integer routingWeight, String sharedKey, List<TunnelConnectionHealth> tunnelConnectionStatus,
boolean usePolicyBasedTrafficSelectors, IdReference localNetworkGateway2, IdReference virtualNetworkGateway1,
IdReference virtualNetworkGateway2) {
return builder(connectionType, enableBGP, usePolicyBasedTrafficSelectors, localNetworkGateway2,
virtualNetworkGateway1).authorizationKey(authorizationKey).connectionStatus(connectionStatus)
.egressBytesTransferred(egressBytesTransferred).ingressBytesTransferred(ingressBytesTransferred)
.ipsecPolicies(ipsecPolicies).peer(peer).provisioningState(provisioningState).resourceGuid(resourceGuid)
.routingWeight(routingWeight).sharedKey(sharedKey).tunnelConnectionStatus(tunnelConnectionStatus)
.virtualNetworkGateway2(virtualNetworkGateway2).build();
}
public static Builder builder(Type connectionType, boolean enableBGP, boolean usePolicyBasedTrafficSelectors,
IdReference localNetworkGateway2, IdReference virtualNetworkGateway1) {
return new AutoValue_VirtualNetworkGatewayConnectionProperties.Builder().connectionType(connectionType)
.enableBGP(enableBGP).usePolicyBasedTrafficSelectors(usePolicyBasedTrafficSelectors)
.localNetworkGateway2(localNetworkGateway2).virtualNetworkGateway1(virtualNetworkGateway1)
.ipsecPolicies(ImmutableList.<IPSecPolicy> of())
.tunnelConnectionStatus(ImmutableList.<TunnelConnectionHealth> of());
}
public abstract Builder toBuilder();
@AutoValue.Builder
public abstract static class Builder {
public abstract Builder authorizationKey(String authorizationKey);
public abstract Builder connectionStatus(Status connectionStatus);
public abstract Builder connectionType(Type connectionType);
public abstract Builder egressBytesTransferred(Integer egressBytesTransferred);
public abstract Builder ingressBytesTransferred(Integer ingressBytesTransferred);
public abstract Builder enableBGP(boolean enableBGP);
public abstract Builder ipsecPolicies(List<IPSecPolicy> ipsecPolicies);
public abstract Builder peer(IdReference peer);
public abstract Builder provisioningState(String provisioningState);
public abstract Builder resourceGuid(String resourceGuid);
public abstract Builder routingWeight(Integer routingWeight);
public abstract Builder sharedKey(String sharedKey);
public abstract Builder tunnelConnectionStatus(List<TunnelConnectionHealth> tunnelConnectionStatus);
public abstract Builder usePolicyBasedTrafficSelectors(boolean usePolicyBasedTrafficSelectors);
public abstract Builder localNetworkGateway2(IdReference localNetworkGateway2);
public abstract Builder virtualNetworkGateway1(IdReference virtualNetworkGateway1);
public abstract Builder virtualNetworkGateway2(IdReference virtualNetworkGateway2);
abstract List<IPSecPolicy> ipsecPolicies();
abstract List<TunnelConnectionHealth> tunnelConnectionStatus();
abstract VirtualNetworkGatewayConnectionProperties autoBuild();
public VirtualNetworkGatewayConnectionProperties build() {
ipsecPolicies(ipsecPolicies() == null ? ImmutableList.<IPSecPolicy> of() : ImmutableList
.copyOf(ipsecPolicies()));
tunnelConnectionStatus(tunnelConnectionStatus() == null ? ImmutableList.<TunnelConnectionHealth> of()
: ImmutableList.copyOf(tunnelConnectionStatus()));
return autoBuild();
}
}
}

View File

@ -60,7 +60,7 @@ public abstract class VirtualNetworkGatewayProperties implements Provisionable {
public static Builder builder(boolean enableBGP, VirtualNetworkGatewayType virtualNetworkGatewayType, SKU sku) {
return new AutoValue_VirtualNetworkGatewayProperties.Builder().enableBGP(enableBGP)
.gatewayType(virtualNetworkGatewayType).sku(sku);
.gatewayType(virtualNetworkGatewayType).sku(sku).ipConfigurations(ImmutableList.<IpConfiguration> of());
}
public abstract Builder toBuilder();

View File

@ -0,0 +1,86 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jclouds.azurecompute.arm.features;
import java.io.Closeable;
import java.net.URI;
import java.util.List;
import java.util.Map;
import javax.inject.Named;
import javax.ws.rs.Consumes;
import javax.ws.rs.DELETE;
import javax.ws.rs.GET;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.core.MediaType;
import org.jclouds.Fallbacks.EmptyListOnNotFoundOr404;
import org.jclouds.Fallbacks.NullOnNotFoundOr404;
import org.jclouds.azurecompute.arm.domain.vpn.VirtualNetworkGatewayConnection;
import org.jclouds.azurecompute.arm.domain.vpn.VirtualNetworkGatewayConnectionProperties;
import org.jclouds.azurecompute.arm.filters.ApiVersionFilter;
import org.jclouds.azurecompute.arm.functions.URIParser;
import org.jclouds.javax.annotation.Nullable;
import org.jclouds.oauth.v2.filters.OAuthFilter;
import org.jclouds.rest.annotations.Fallback;
import org.jclouds.rest.annotations.MapBinder;
import org.jclouds.rest.annotations.PayloadParam;
import org.jclouds.rest.annotations.RequestFilters;
import org.jclouds.rest.annotations.ResponseParser;
import org.jclouds.rest.annotations.SelectJson;
import org.jclouds.rest.binders.BindToJsonPayload;
@Path("/resourcegroups/{resourcegroup}/providers/Microsoft.Network/connections")
@RequestFilters({ OAuthFilter.class, ApiVersionFilter.class })
@Consumes(MediaType.APPLICATION_JSON)
public interface VirtualNetworkGatewayConnectionApi extends Closeable {
@Named("virtualnetworkgatewayconnection:list")
@GET
@SelectJson("value")
@Fallback(EmptyListOnNotFoundOr404.class)
List<VirtualNetworkGatewayConnection> list();
@Named("virtualnetworkgatewayconnection:get")
@Path("/{name}")
@GET
@Fallback(NullOnNotFoundOr404.class)
VirtualNetworkGatewayConnection get(@PathParam("name") String name);
@Named("virtualnetworkgatewayconnection:getSharedKey")
@Path("/{name}/sharedkey")
@GET
@Fallback(NullOnNotFoundOr404.class)
String getSharedKey(@PathParam("name") String name);
@Named("virtualnetworkgatewayconnection:createOrUpdate")
@MapBinder(BindToJsonPayload.class)
@Path("/{name}")
@PUT
VirtualNetworkGatewayConnection createOrUpdate(@PathParam("name") String name,
@PayloadParam("location") String location, @Nullable @PayloadParam("tags") Map<String, String> tags,
@PayloadParam("properties") VirtualNetworkGatewayConnectionProperties properties);
@Named("virtualnetworkgatewayconnection:delete")
@Path("/{name}")
@DELETE
@ResponseParser(URIParser.class)
@Fallback(NullOnNotFoundOr404.class)
URI delete(@PathParam("name") String name);
}

View File

@ -98,7 +98,7 @@ public class LocalNetworkGatewayApiLiveTest extends BaseAzureComputeApiLiveTest
assertTrue(gw.properties().localNetworkAddressSpace().addressPrefixes().contains("192.168.1.0/24"));
}
@Test(dependsOnMethods = { "getLocalNetworkGateway", "listLocalNetworkGateways", "updateLocalNetworkGateway" }, alwaysRun = true)
@Test(dependsOnMethods = { "getLocalNetworkGateway", "listLocalNetworkGateways", "updateLocalNetworkGateway" })
public void deleteLocalNetworkGateway() {
// Make sure the resource is fully provisioned before deleting it
waitUntilAvailable(name);
@ -110,13 +110,13 @@ public class LocalNetworkGatewayApiLiveTest extends BaseAzureComputeApiLiveTest
return api.getLocalNetworkGatewayApi(resourceGroupName);
}
private boolean waitUntilAvailable(final String name) {
return resourceAvailable.apply(new Supplier<Provisionable>() {
private void waitUntilAvailable(final String name) {
assertTrue(resourceAvailable.apply(new Supplier<Provisionable>() {
@Override
public Provisionable get() {
LocalNetworkGateway gw = api().get(name);
return gw == null ? null : gw.properties();
}
});
}));
}
}

View File

@ -18,6 +18,7 @@ package org.jclouds.azurecompute.arm.features;
import static com.google.common.collect.Iterables.any;
import static java.util.Collections.singletonList;
import static java.util.logging.Logger.getAnonymousLogger;
import static org.jclouds.azurecompute.arm.domain.vpn.VirtualNetworkGatewayType.Vpn;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertNotNull;
@ -83,6 +84,7 @@ public class VirtualNetworkGatewayApiLiveTest extends BaseAzureComputeApiLiveTes
.builder(false, Vpn, SKU.create(1, SKUName.Basic, SKUTier.Basic)).vpnType(VPNType.PolicyBased)
.ipConfigurations(singletonList(ipconf)).build();
getAnonymousLogger().info(String.format("Creating virtual network gateway %s. This may take a while...", name));
VirtualNetworkGateway gw = api().createOrUpdate(name, LOCATION, null, props);
assertNotNull(gw);
@ -118,7 +120,7 @@ public class VirtualNetworkGatewayApiLiveTest extends BaseAzureComputeApiLiveTes
assertEquals(gw.tags().get("foo"), "bar");
}
@Test(dependsOnMethods = { "getVirtualNetworkGateway", "listVirtualNetworkGateways", "updateVirtualNetworkGateway" }, alwaysRun = true)
@Test(dependsOnMethods = { "getVirtualNetworkGateway", "listVirtualNetworkGateways", "updateVirtualNetworkGateway" })
public void deleteVirtualNetworkGateway() {
// Make sure the resource is fully provisioned before deleting it
assertTrue(virtualNetworkGatewayAvailable.apply(name));

View File

@ -0,0 +1,181 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jclouds.azurecompute.arm.features;
import static com.google.common.collect.Iterables.any;
import static java.util.Collections.singletonList;
import static java.util.logging.Logger.getAnonymousLogger;
import static org.jclouds.azurecompute.arm.domain.vpn.VirtualNetworkGatewayConnection.Type.IPsec;
import static org.jclouds.azurecompute.arm.domain.vpn.VirtualNetworkGatewayType.Vpn;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertNotNull;
import static org.testng.Assert.assertTrue;
import java.net.URI;
import java.util.Collections;
import org.jclouds.azurecompute.arm.domain.AddressSpace;
import org.jclouds.azurecompute.arm.domain.IdReference;
import org.jclouds.azurecompute.arm.domain.IpAllocationMethod;
import org.jclouds.azurecompute.arm.domain.Provisionable;
import org.jclouds.azurecompute.arm.domain.PublicIPAddress;
import org.jclouds.azurecompute.arm.domain.PublicIPAddressProperties;
import org.jclouds.azurecompute.arm.domain.Subnet;
import org.jclouds.azurecompute.arm.domain.VirtualNetwork;
import org.jclouds.azurecompute.arm.domain.vpn.LocalNetworkGateway;
import org.jclouds.azurecompute.arm.domain.vpn.LocalNetworkGatewayProperties;
import org.jclouds.azurecompute.arm.domain.vpn.SKU;
import org.jclouds.azurecompute.arm.domain.vpn.SKU.SKUName;
import org.jclouds.azurecompute.arm.domain.vpn.SKU.SKUTier;
import org.jclouds.azurecompute.arm.domain.vpn.VPNType;
import org.jclouds.azurecompute.arm.domain.vpn.VirtualNetworkGateway;
import org.jclouds.azurecompute.arm.domain.vpn.VirtualNetworkGatewayConnection;
import org.jclouds.azurecompute.arm.domain.vpn.VirtualNetworkGatewayConnectionProperties;
import org.jclouds.azurecompute.arm.domain.vpn.VirtualNetworkGatewayProperties;
import org.jclouds.azurecompute.arm.domain.vpn.VirtualNetworkGatewayProperties.IpConfiguration;
import org.jclouds.azurecompute.arm.domain.vpn.VirtualNetworkGatewayProperties.IpConfiguration.IpConfigurationProperties;
import org.jclouds.azurecompute.arm.internal.BaseAzureComputeApiLiveTest;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
import com.google.common.base.Predicate;
import com.google.common.base.Supplier;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
@Test(groups = "live", testName = "VirtualNetworkGatewayConnectionApiLiveTest", singleThreaded = true)
public class VirtualNetworkGatewayConnectionApiLiveTest extends BaseAzureComputeApiLiveTest {
private String name;
private LocalNetworkGateway localGateway;
private VirtualNetworkGateway virtualGateway;
@BeforeClass
@Override
public void setup() {
super.setup();
createTestResourceGroup();
name = "jclouds-" + RAND;
setupLocalGateway();
setupVirtualGateway();
}
private void setupLocalGateway() {
AddressSpace localAddresses = AddressSpace.create(ImmutableList.of("192.168.0.0/24"));
LocalNetworkGatewayProperties props = LocalNetworkGatewayProperties.builder("1.2.3.4")
.localNetworkAddressSpace(localAddresses).build();
final LocalNetworkGatewayApi lgwApi = api.getLocalNetworkGatewayApi(resourceGroupName);
localGateway = lgwApi.createOrUpdate(name + "-lgw", LOCATION, null, props);
assertTrue(resourceAvailable.apply(new Supplier<Provisionable>() {
@Override
public Provisionable get() {
LocalNetworkGateway gw = lgwApi.get(localGateway.name());
return gw == null ? null : gw.properties();
}
}));
}
private void setupVirtualGateway() {
VirtualNetwork vnet = createDefaultVirtualNetwork(resourceGroupName, name + "-net", "10.2.0.0/16", LOCATION);
Subnet subnet = createDefaultSubnet(resourceGroupName, Subnet.GATEWAY_SUBNET_NAME, vnet.name(), "10.2.0.0/23");
PublicIPAddressProperties props = PublicIPAddressProperties.builder()
.publicIPAllocationMethod(IpAllocationMethod.Dynamic.name()).idleTimeoutInMinutes(4).build();
PublicIPAddress publicIp = api.getPublicIPAddressApi(resourceGroupName).createOrUpdate(name + "-publicip",
LOCATION, Collections.<String, String> emptyMap(), props);
IpConfigurationProperties ipprops = IpConfigurationProperties.builder(IpAllocationMethod.Dynamic)
.subnet(IdReference.create(subnet.id())).publicIPAddress(IdReference.create(publicIp.id())).build();
IpConfiguration ipconf = IpConfiguration.create(null, name + "-ipconf", null, ipprops);
VirtualNetworkGatewayProperties gwProps = VirtualNetworkGatewayProperties
.builder(false, Vpn, SKU.create(1, SKUName.Basic, SKUTier.Basic)).vpnType(VPNType.PolicyBased)
.ipConfigurations(singletonList(ipconf)).build();
getAnonymousLogger().info(
String.format("Creating virtual network gateway %s-vgw. This may take a while...", name));
virtualGateway = api.getVirtualNetworkGatewayApi(resourceGroupName).createOrUpdate(name + "-vgw", LOCATION, null,
gwProps);
assertTrue(virtualNetworkGatewayStatus.create(resourceGroupName).apply(virtualGateway.name()));
}
@Test
public void createVirtualNetworkGatewayConnection() {
VirtualNetworkGatewayConnectionProperties props = VirtualNetworkGatewayConnectionProperties
.builder(IPsec, false, false, IdReference.create(localGateway.id()),
IdReference.create(virtualGateway.id())).sharedKey("jcl0uds").build();
VirtualNetworkGatewayConnection conn = api().createOrUpdate(name, LOCATION, null, props);
assertNotNull(conn);
assertEquals(conn.name(), name);
assertNotNull(conn.properties());
}
@Test(dependsOnMethods = "createVirtualNetworkGatewayConnection")
public void getVirtualNetworkGatewayConnection() {
assertNotNull(api().get(name));
}
@Test(dependsOnMethods = "createVirtualNetworkGatewayConnection")
public void listVirtualNetworkGatewayConnections() {
assertTrue(any(api().list(), new Predicate<VirtualNetworkGatewayConnection>() {
@Override
public boolean apply(VirtualNetworkGatewayConnection input) {
return name.equals(input.name());
}
}));
}
@Test(dependsOnMethods = "createVirtualNetworkGatewayConnection")
public void updateVirtualNetworkGatewayConnection() {
// Make sure the resource is fully provisioned before modifying it
waitUntilAvailable(name);
VirtualNetworkGatewayConnection conn = api().get(name);
conn = api().createOrUpdate(name, LOCATION, ImmutableMap.of("foo", "bar"), conn.properties());
assertNotNull(conn);
assertTrue(conn.tags().containsKey("foo"));
assertEquals(conn.tags().get("foo"), "bar");
}
@Test(dependsOnMethods = { "getVirtualNetworkGatewayConnection", "listVirtualNetworkGatewayConnections",
"updateVirtualNetworkGatewayConnection" })
public void deleteVirtualNetworkGatewayConnection() {
// Make sure the resource is fully provisioned before deleting it
waitUntilAvailable(name);
URI uri = api().delete(name);
assertResourceDeleted(uri);
}
private void waitUntilAvailable(final String name) {
assertTrue(resourceAvailable.apply(new Supplier<Provisionable>() {
@Override
public Provisionable get() {
VirtualNetworkGatewayConnection gw = api().get(name);
return gw == null ? null : gw.properties();
}
}));
}
private VirtualNetworkGatewayConnectionApi api() {
return api.getVirtualNetworkGatewayConnectionApi(resourceGroupName);
}
}

View File

@ -0,0 +1,149 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jclouds.azurecompute.arm.features;
import static com.google.common.collect.Iterables.isEmpty;
import static org.jclouds.azurecompute.arm.domain.vpn.VirtualNetworkGatewayConnection.Type.IPsec;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertNotNull;
import static org.testng.Assert.assertNull;
import static org.testng.Assert.assertTrue;
import java.net.URI;
import java.util.List;
import org.jclouds.azurecompute.arm.domain.IdReference;
import org.jclouds.azurecompute.arm.domain.vpn.VirtualNetworkGatewayConnection;
import org.jclouds.azurecompute.arm.domain.vpn.VirtualNetworkGatewayConnection.Type;
import org.jclouds.azurecompute.arm.domain.vpn.VirtualNetworkGatewayConnectionProperties;
import org.jclouds.azurecompute.arm.internal.BaseAzureComputeApiMockTest;
import org.testng.annotations.Test;
@Test(groups = "unit", testName = "VirtualNetworkGatewayConnectionApiMockTest", singleThreaded = true)
public class VirtualNetworkGatewayConnectionApiMockTest extends BaseAzureComputeApiMockTest {
private final String subscriptionid = "SUBSCRIPTIONID";
private final String resourcegroup = "myresourcegroup";
private final String name = "myconn";
private final String apiVersion = "api-version=2018-02-01";
private static final String LG_ID = "/subscriptions/SUBSCRIPTIONID/resourceGroups/rg-virtualnetworkgatewayconnectionapilivetest-nacx/providers/Microsoft.Network/localNetworkGateways/jclouds-827-lgw";
private static final String VG_ID = "/subscriptions/SUBSCRIPTIONID/resourceGroups/rg-virtualnetworkgatewayconnectionapilivetest-nacx/providers/Microsoft.Network/virtualNetworkGateways/jclouds-827-vgw";
public void createOrUpdateVirtualNetworkGateway() throws InterruptedException {
server.enqueue(jsonResponse("/connectioncreate.json").setResponseCode(200));
VirtualNetworkGatewayConnectionApi connapi = api.getVirtualNetworkGatewayConnectionApi(resourcegroup);
VirtualNetworkGatewayConnectionProperties props = VirtualNetworkGatewayConnectionProperties
.builder(IPsec, false, false, IdReference.create(LG_ID), IdReference.create(VG_ID)).sharedKey("jcl0uds")
.build();
VirtualNetworkGatewayConnection conn = connapi.createOrUpdate(name, "westeurope", null, props);
String path = String.format(
"/subscriptions/%s/resourcegroups/%s/providers/Microsoft.Network/connections/%s?%s",
subscriptionid, resourcegroup, name, apiVersion);
String json = "{\"location\":\"westeurope\",\"properties\":{\"connectionType\":\"IPsec\",\"enableBGP\":false,\"ipsecPolicies\":[],\"sharedKey\":\"jcl0uds\",\"tunnelConnectionStatus\":[],\"usePolicyBasedTrafficSelectors\":false,\"localNetworkGateway2\":{\"id\":\"/subscriptions/SUBSCRIPTIONID/resourceGroups/rg-virtualnetworkgatewayconnectionapilivetest-nacx/providers/Microsoft.Network/localNetworkGateways/jclouds-827-lgw\"},\"virtualNetworkGateway1\":{\"id\":\"/subscriptions/SUBSCRIPTIONID/resourceGroups/rg-virtualnetworkgatewayconnectionapilivetest-nacx/providers/Microsoft.Network/virtualNetworkGateways/jclouds-827-vgw\"}}}";
assertSent(server, "PUT", path, json);
assertEquals(conn.name(), name);
assertNotNull(conn.properties());
assertEquals(conn.properties().connectionType(), Type.IPsec);
}
public void getVirtualNetworkGateway() throws InterruptedException {
server.enqueue(jsonResponse("/connectionget.json").setResponseCode(200));
VirtualNetworkGatewayConnectionApi connapi = api.getVirtualNetworkGatewayConnectionApi(resourcegroup);
VirtualNetworkGatewayConnection conn = connapi.get(name);
String path = String.format(
"/subscriptions/%s/resourcegroups/%s/providers/Microsoft.Network/connections/%s?%s",
subscriptionid, resourcegroup, name, apiVersion);
assertSent(server, "GET", path);
assertEquals(conn.name(), name);
}
public void getVirtualNetworkGatewayReturns404() throws InterruptedException {
server.enqueue(response404());
VirtualNetworkGatewayConnectionApi connapi = api.getVirtualNetworkGatewayConnectionApi(resourcegroup);
VirtualNetworkGatewayConnection conn = connapi.get(name);
String path = String.format(
"/subscriptions/%s/resourcegroups/%s/providers/Microsoft.Network/connections/%s?%s",
subscriptionid, resourcegroup, name, apiVersion);
assertSent(server, "GET", path);
assertNull(conn);
}
public void listVirtualNetworkGateways() throws InterruptedException {
server.enqueue(jsonResponse("/connectionlist.json").setResponseCode(200));
VirtualNetworkGatewayConnectionApi connapi = api.getVirtualNetworkGatewayConnectionApi(resourcegroup);
List<VirtualNetworkGatewayConnection> conns = connapi.list();
String path = String.format(
"/subscriptions/%s/resourcegroups/%s/providers/Microsoft.Network/connections?%s",
subscriptionid, resourcegroup, apiVersion);
assertSent(server, "GET", path);
assertTrue(conns.size() > 0);
}
public void listVirtualNetworkGatewaysReturns404() throws InterruptedException {
server.enqueue(response404());
VirtualNetworkGatewayConnectionApi connapi = api.getVirtualNetworkGatewayConnectionApi(resourcegroup);
List<VirtualNetworkGatewayConnection> conns = connapi.list();
String path = String.format(
"/subscriptions/%s/resourcegroups/%s/providers/Microsoft.Network/connections?%s",
subscriptionid, resourcegroup, apiVersion);
assertSent(server, "GET", path);
assertTrue(isEmpty(conns));
}
public void deleteVirtualNetworkGateway() throws InterruptedException {
server.enqueue(response202WithHeader());
VirtualNetworkGatewayConnectionApi connapi = api.getVirtualNetworkGatewayConnectionApi(resourcegroup);
URI uri = connapi.delete(name);
assertNotNull(uri);
String path = String.format(
"/subscriptions/%s/resourcegroups/%s/providers/Microsoft.Network/connections/%s?%s",
subscriptionid, resourcegroup, name, apiVersion);
assertSent(server, "DELETE", path);
}
public void deleteVirtualNetworkGatewayDoesNotExist() throws InterruptedException {
server.enqueue(response204());
VirtualNetworkGatewayConnectionApi connapi = api.getVirtualNetworkGatewayConnectionApi(resourcegroup);
URI uri = connapi.delete(name);
assertNull(uri);
String path = String.format(
"/subscriptions/%s/resourcegroups/%s/providers/Microsoft.Network/connections/%s?%s",
subscriptionid, resourcegroup, name, apiVersion);
assertSent(server, "DELETE", path);
}
}

View File

@ -0,0 +1,26 @@
{
"name": "myconn",
"id": "/subscriptions/SUBSCRIPTIONID/resourceGroups/rg-virtualnetworkgatewayconnectionapilivetest-nacx/providers/Microsoft.Network/connections/myconn",
"etag": "W/\"e6f08058-3815-4498-858b-0fe750e086c8\"",
"type": "Microsoft.Network/connections",
"location": "westeurope",
"properties": {
"provisioningState": "Updating",
"resourceGuid": "1c7fc4e8-5d48-476b-b951-38279aec7d63",
"virtualNetworkGateway1": {
"id": "/subscriptions/SUBSCRIPTIONID/resourceGroups/rg-virtualnetworkgatewayconnectionapilivetest-nacx/providers/Microsoft.Network/virtualNetworkGateways/jclouds-827-vgw"
},
"localNetworkGateway2": {
"id": "/subscriptions/SUBSCRIPTIONID/resourceGroups/rg-virtualnetworkgatewayconnectionapilivetest-nacx/providers/Microsoft.Network/localNetworkGateways/jclouds-827-lgw"
},
"connectionType": "IPsec",
"routingWeight": 0,
"sharedKey": "jcl0uds",
"enableBgp": false,
"usePolicyBasedTrafficSelectors": false,
"ipsecPolicies": [],
"ingressBytesTransferred": 0,
"egressBytesTransferred": 0,
"tunnelConnectionStatus": []
}
}

View File

@ -0,0 +1,26 @@
{
"name": "myconn",
"id": "/subscriptions/SUBSCRIPTIONID/resourceGroups/rg-virtualnetworkgatewayconnectionapilivetest-nacx/providers/Microsoft.Network/connections/myconn",
"etag": "W/\"e6f08058-3815-4498-858b-0fe750e086c8\"",
"type": "Microsoft.Network/connections",
"location": "westeurope",
"properties": {
"provisioningState": "Updating",
"resourceGuid": "1c7fc4e8-5d48-476b-b951-38279aec7d63",
"virtualNetworkGateway1": {
"id": "/subscriptions/SUBSCRIPTIONID/resourceGroups/rg-virtualnetworkgatewayconnectionapilivetest-nacx/providers/Microsoft.Network/virtualNetworkGateways/jclouds-827-vgw"
},
"localNetworkGateway2": {
"id": "/subscriptions/SUBSCRIPTIONID/resourceGroups/rg-virtualnetworkgatewayconnectionapilivetest-nacx/providers/Microsoft.Network/localNetworkGateways/jclouds-827-lgw"
},
"connectionType": "IPsec",
"routingWeight": 0,
"sharedKey": "jcl0uds",
"enableBgp": false,
"usePolicyBasedTrafficSelectors": false,
"ipsecPolicies": [],
"ingressBytesTransferred": 0,
"egressBytesTransferred": 0,
"tunnelConnectionStatus": []
}
}

View File

@ -0,0 +1,29 @@
{
"value": [
{
"name": "myconn",
"id": "/subscriptions/SUBSCRIPTIONID/resourceGroups/rg-virtualnetworkgatewayconnectionapilivetest-nacx/providers/Microsoft.Network/connections/myconn",
"etag": "W/\"e6f08058-3815-4498-858b-0fe750e086c8\"",
"type": "Microsoft.Network/connections",
"location": "westeurope",
"properties": {
"provisioningState": "Updating",
"resourceGuid": "1c7fc4e8-5d48-476b-b951-38279aec7d63",
"virtualNetworkGateway1": {
"id": "/subscriptions/SUBSCRIPTIONID/resourceGroups/rg-virtualnetworkgatewayconnectionapilivetest-nacx/providers/Microsoft.Network/virtualNetworkGateways/jclouds-827-vgw"
},
"localNetworkGateway2": {
"id": "/subscriptions/SUBSCRIPTIONID/resourceGroups/rg-virtualnetworkgatewayconnectionapilivetest-nacx/providers/Microsoft.Network/localNetworkGateways/jclouds-827-lgw"
},
"connectionType": "IPsec",
"routingWeight": 0,
"enableBgp": false,
"usePolicyBasedTrafficSelectors": false,
"ipsecPolicies": [],
"ingressBytesTransferred": 0,
"egressBytesTransferred": 0,
"tunnelConnectionStatus": []
}
}
]
}