mirror of https://github.com/apache/jclouds.git
Added Local Network Gateway API
This commit is contained in:
parent
36353d6157
commit
ff93565b1d
|
@ -28,6 +28,7 @@ import org.jclouds.azurecompute.arm.features.GraphRBACApi;
|
||||||
import org.jclouds.azurecompute.arm.features.ImageApi;
|
import org.jclouds.azurecompute.arm.features.ImageApi;
|
||||||
import org.jclouds.azurecompute.arm.features.JobApi;
|
import org.jclouds.azurecompute.arm.features.JobApi;
|
||||||
import org.jclouds.azurecompute.arm.features.LoadBalancerApi;
|
import org.jclouds.azurecompute.arm.features.LoadBalancerApi;
|
||||||
|
import org.jclouds.azurecompute.arm.features.LocalNetworkGatewayApi;
|
||||||
import org.jclouds.azurecompute.arm.features.LocationApi;
|
import org.jclouds.azurecompute.arm.features.LocationApi;
|
||||||
import org.jclouds.azurecompute.arm.features.MetricDefinitionsApi;
|
import org.jclouds.azurecompute.arm.features.MetricDefinitionsApi;
|
||||||
import org.jclouds.azurecompute.arm.features.MetricsApi;
|
import org.jclouds.azurecompute.arm.features.MetricsApi;
|
||||||
|
@ -262,6 +263,14 @@ public interface AzureComputeApi extends Closeable {
|
||||||
@Delegate
|
@Delegate
|
||||||
VaultApi getVaultApi(@PathParam("resourcegroup") String resourcegroup);
|
VaultApi getVaultApi(@PathParam("resourcegroup") String resourcegroup);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Management features for Local Network Gateways.
|
||||||
|
*
|
||||||
|
* @see <a href="https://docs.microsoft.com/en-us/rest/api/network-gateway/localnetworkgateways">docs</a>
|
||||||
|
*/
|
||||||
|
@Delegate
|
||||||
|
LocalNetworkGatewayApi getLocalNetworkGatewayApi(@PathParam("resourcegroup") String resourcegroup);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the information about the current service principal.
|
* Returns the information about the current service principal.
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -45,6 +45,7 @@ import org.jclouds.azurecompute.arm.features.DiskApi;
|
||||||
import org.jclouds.azurecompute.arm.features.GraphRBACApi;
|
import org.jclouds.azurecompute.arm.features.GraphRBACApi;
|
||||||
import org.jclouds.azurecompute.arm.features.ImageApi;
|
import org.jclouds.azurecompute.arm.features.ImageApi;
|
||||||
import org.jclouds.azurecompute.arm.features.LoadBalancerApi;
|
import org.jclouds.azurecompute.arm.features.LoadBalancerApi;
|
||||||
|
import org.jclouds.azurecompute.arm.features.LocalNetworkGatewayApi;
|
||||||
import org.jclouds.azurecompute.arm.features.LocationApi;
|
import org.jclouds.azurecompute.arm.features.LocationApi;
|
||||||
import org.jclouds.azurecompute.arm.features.MetricDefinitionsApi;
|
import org.jclouds.azurecompute.arm.features.MetricDefinitionsApi;
|
||||||
import org.jclouds.azurecompute.arm.features.MetricsApi;
|
import org.jclouds.azurecompute.arm.features.MetricsApi;
|
||||||
|
@ -130,6 +131,7 @@ public class AzureComputeProviderMetadata extends BaseProviderMetadata {
|
||||||
properties.put(API_VERSION_PREFIX + VirtualMachineScaleSetApi.class.getSimpleName(), "2017-03-30");
|
properties.put(API_VERSION_PREFIX + VirtualMachineScaleSetApi.class.getSimpleName(), "2017-03-30");
|
||||||
properties.put(API_VERSION_PREFIX + GraphRBACApi.class.getSimpleName(), "1.6");
|
properties.put(API_VERSION_PREFIX + GraphRBACApi.class.getSimpleName(), "1.6");
|
||||||
properties.put(API_VERSION_PREFIX + VaultApi.class.getSimpleName(), "2016-10-01");
|
properties.put(API_VERSION_PREFIX + VaultApi.class.getSimpleName(), "2016-10-01");
|
||||||
|
properties.put(API_VERSION_PREFIX + LocalNetworkGatewayApi.class.getSimpleName(), "2018-02-01");
|
||||||
|
|
||||||
return properties;
|
return properties;
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,75 @@
|
||||||
|
/*
|
||||||
|
* 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;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
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 LocalNetworkGateway {
|
||||||
|
|
||||||
|
@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 LocalNetworkGatewayProperties properties();
|
||||||
|
|
||||||
|
LocalNetworkGateway() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@SerializedNames({ "id", "name", "location", "type", "tags", "etag", "properties" })
|
||||||
|
public static LocalNetworkGateway create(String id, String name, String location, String type,
|
||||||
|
Map<String, String> tags, String etag, LocalNetworkGatewayProperties properties) {
|
||||||
|
return builder().id(id).name(name).location(location).type(type).tags(tags).etag(etag).properties(properties)
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
public abstract Builder toBuilder();
|
||||||
|
|
||||||
|
public static Builder builder() {
|
||||||
|
return new AutoValue_LocalNetworkGateway.Builder();
|
||||||
|
}
|
||||||
|
|
||||||
|
@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(LocalNetworkGatewayProperties properties);
|
||||||
|
|
||||||
|
abstract String location();
|
||||||
|
abstract Map<String, String> tags();
|
||||||
|
abstract LocalNetworkGateway autoBuild();
|
||||||
|
|
||||||
|
public LocalNetworkGateway build() {
|
||||||
|
tags(tags() != null ? ImmutableMap.copyOf(tags()) : null);
|
||||||
|
location(location().toLowerCase()); // Avoid issues in regions such as CanadaEast
|
||||||
|
return autoBuild();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,96 @@
|
||||||
|
/*
|
||||||
|
* 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;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
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 LocalNetworkGatewayProperties implements Provisionable {
|
||||||
|
|
||||||
|
@Nullable public abstract BGPSettings bgpSettings();
|
||||||
|
public abstract String gatewayIpAddress();
|
||||||
|
@Nullable public abstract AddressSpace localNetworkAddressSpace();
|
||||||
|
@Nullable public abstract String provisioningState();
|
||||||
|
@Nullable public abstract String resourceGuid();
|
||||||
|
|
||||||
|
@SerializedNames({ "bgpSettings", "gatewayIpAddress", "localNetworkAddressSpace", "provisioningState",
|
||||||
|
"resourceGuid" })
|
||||||
|
public static LocalNetworkGatewayProperties create(BGPSettings bgpSettings, String gatewayIpAddress,
|
||||||
|
AddressSpace localNetworkAddressSpace, String provisioningState, String resourceGuid) {
|
||||||
|
return builder().bgpSettings(bgpSettings).gatewayIpAddress(gatewayIpAddress)
|
||||||
|
.localNetworkAddressSpace(localNetworkAddressSpace).provisioningState(provisioningState)
|
||||||
|
.resourceGuid(resourceGuid).build();
|
||||||
|
}
|
||||||
|
|
||||||
|
LocalNetworkGatewayProperties() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public abstract LocalNetworkGatewayProperties.Builder toBuilder();
|
||||||
|
|
||||||
|
public static LocalNetworkGatewayProperties.Builder builder() {
|
||||||
|
return new AutoValue_LocalNetworkGatewayProperties.Builder();
|
||||||
|
}
|
||||||
|
|
||||||
|
@AutoValue.Builder
|
||||||
|
public abstract static class Builder {
|
||||||
|
public abstract Builder bgpSettings(BGPSettings bgpSettings);
|
||||||
|
public abstract Builder gatewayIpAddress(String gatewayIpAddress);
|
||||||
|
public abstract Builder localNetworkAddressSpace(AddressSpace localNetworkAddressSpace);
|
||||||
|
public abstract Builder provisioningState(String provisioningState);
|
||||||
|
public abstract Builder resourceGuid(String resourceGuid);
|
||||||
|
|
||||||
|
public abstract LocalNetworkGatewayProperties build();
|
||||||
|
}
|
||||||
|
|
||||||
|
@AutoValue
|
||||||
|
public abstract static class BGPSettings {
|
||||||
|
public abstract int asn();
|
||||||
|
public abstract String bgpPeeringAddress();
|
||||||
|
public abstract int peerWeight();
|
||||||
|
|
||||||
|
@SerializedNames({ "asn", "bgpPeeringAddress", "peerWeight" })
|
||||||
|
public static LocalNetworkGatewayProperties.BGPSettings create(int asn, String bgpPeeringAddress, int peerWeight) {
|
||||||
|
return new AutoValue_LocalNetworkGatewayProperties_BGPSettings(asn, bgpPeeringAddress, peerWeight);
|
||||||
|
}
|
||||||
|
|
||||||
|
BGPSettings() {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@AutoValue
|
||||||
|
public abstract static class AddressSpace {
|
||||||
|
public abstract List<String> addressPrefixes();
|
||||||
|
|
||||||
|
@SerializedNames({ "addressPrefixes" })
|
||||||
|
public static LocalNetworkGatewayProperties.AddressSpace create(List<String> addressPrefixes) {
|
||||||
|
return new AutoValue_LocalNetworkGatewayProperties_AddressSpace(
|
||||||
|
addressPrefixes == null ? ImmutableList.<String> of() : ImmutableList.copyOf(addressPrefixes));
|
||||||
|
}
|
||||||
|
|
||||||
|
AddressSpace() {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,81 @@
|
||||||
|
/*
|
||||||
|
* 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.LocalNetworkGateway;
|
||||||
|
import org.jclouds.azurecompute.arm.domain.LocalNetworkGatewayProperties;
|
||||||
|
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/localNetworkGateways")
|
||||||
|
@RequestFilters({ OAuthFilter.class, ApiVersionFilter.class })
|
||||||
|
@Consumes(MediaType.APPLICATION_JSON)
|
||||||
|
public interface LocalNetworkGatewayApi extends Closeable {
|
||||||
|
|
||||||
|
@Named("localnetworkgateway:list")
|
||||||
|
@GET
|
||||||
|
@SelectJson("value")
|
||||||
|
@Fallback(EmptyListOnNotFoundOr404.class)
|
||||||
|
List<LocalNetworkGateway> list();
|
||||||
|
|
||||||
|
@Named("localnetworkgateway:get")
|
||||||
|
@Path("/{name}")
|
||||||
|
@GET
|
||||||
|
@Fallback(NullOnNotFoundOr404.class)
|
||||||
|
LocalNetworkGateway get(@PathParam("name") String name);
|
||||||
|
|
||||||
|
@Named("localnetworkgateway:createOrUpdate")
|
||||||
|
@MapBinder(BindToJsonPayload.class)
|
||||||
|
@Path("/{name}")
|
||||||
|
@PUT
|
||||||
|
LocalNetworkGateway createOrUpdate(@PathParam("name") String name, @PayloadParam("location") String location,
|
||||||
|
@Nullable @PayloadParam("tags") Map<String, String> tags,
|
||||||
|
@PayloadParam("properties") LocalNetworkGatewayProperties properties);
|
||||||
|
|
||||||
|
@Named("localnetworkgateway:delete")
|
||||||
|
@Path("/{name}")
|
||||||
|
@DELETE
|
||||||
|
@ResponseParser(URIParser.class)
|
||||||
|
@Fallback(NullOnNotFoundOr404.class)
|
||||||
|
URI delete(@PathParam("name") String name);
|
||||||
|
|
||||||
|
}
|
|
@ -138,7 +138,7 @@ public class AvailabilitySetApiMockTest extends BaseAzureComputeApiMockTest {
|
||||||
assertSent(server, "DELETE", path);
|
assertSent(server, "DELETE", path);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void deleteSubnetResourceDoesNotExist() throws InterruptedException {
|
public void deleteAvailabilitySetDoesNotExist() throws InterruptedException {
|
||||||
|
|
||||||
server.enqueue(response204());
|
server.enqueue(response204());
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,122 @@
|
||||||
|
/*
|
||||||
|
* 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 org.testng.Assert.assertEquals;
|
||||||
|
import static org.testng.Assert.assertNotNull;
|
||||||
|
import static org.testng.Assert.assertTrue;
|
||||||
|
|
||||||
|
import java.net.URI;
|
||||||
|
|
||||||
|
import org.jclouds.azurecompute.arm.domain.LocalNetworkGateway;
|
||||||
|
import org.jclouds.azurecompute.arm.domain.LocalNetworkGatewayProperties;
|
||||||
|
import org.jclouds.azurecompute.arm.domain.LocalNetworkGatewayProperties.AddressSpace;
|
||||||
|
import org.jclouds.azurecompute.arm.domain.Provisionable;
|
||||||
|
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 = "LocalNetworkGatewayApiLiveTest", singleThreaded = true)
|
||||||
|
public class LocalNetworkGatewayApiLiveTest extends BaseAzureComputeApiLiveTest {
|
||||||
|
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
@BeforeClass
|
||||||
|
@Override
|
||||||
|
public void setup() {
|
||||||
|
super.setup();
|
||||||
|
createTestResourceGroup();
|
||||||
|
name = "jclouds-" + RAND;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void createLocalNetworkGateway() {
|
||||||
|
AddressSpace localAddresses = AddressSpace.create(ImmutableList.of("192.168.0.0/24"));
|
||||||
|
LocalNetworkGatewayProperties props = LocalNetworkGatewayProperties.builder().gatewayIpAddress("1.2.3.4")
|
||||||
|
.localNetworkAddressSpace(localAddresses).build();
|
||||||
|
|
||||||
|
LocalNetworkGateway gw = api().createOrUpdate(name, LOCATION, null, props);
|
||||||
|
|
||||||
|
assertNotNull(gw);
|
||||||
|
assertEquals(gw.name(), name);
|
||||||
|
assertNotNull(gw.properties());
|
||||||
|
assertNotNull(gw.properties().gatewayIpAddress());
|
||||||
|
assertEquals(gw.properties().gatewayIpAddress(), "1.2.3.4");
|
||||||
|
assertNotNull(gw.properties().localNetworkAddressSpace());
|
||||||
|
assertTrue(gw.properties().localNetworkAddressSpace().addressPrefixes().contains("192.168.0.0/24"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(dependsOnMethods = "createLocalNetworkGateway")
|
||||||
|
public void getLocalNetworkGateway() {
|
||||||
|
assertNotNull(api().get(name));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(dependsOnMethods = "createLocalNetworkGateway")
|
||||||
|
public void listLocalNetworkGateways() {
|
||||||
|
assertTrue(any(api().list(), new Predicate<LocalNetworkGateway>() {
|
||||||
|
@Override
|
||||||
|
public boolean apply(LocalNetworkGateway input) {
|
||||||
|
return name.equals(input.name());
|
||||||
|
}
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(dependsOnMethods = "createLocalNetworkGateway")
|
||||||
|
public void updateLocalNetworkGateway() {
|
||||||
|
// Make sure the resource is fully provisioned before modifying it
|
||||||
|
waitUntilAvailable(name);
|
||||||
|
|
||||||
|
LocalNetworkGateway gw = api().get(name);
|
||||||
|
AddressSpace localAddresses = AddressSpace.create(ImmutableList.of("192.168.0.0/24", "192.168.1.0/24"));
|
||||||
|
gw = api().createOrUpdate(name, LOCATION, ImmutableMap.of("foo", "bar"),
|
||||||
|
gw.properties().toBuilder().localNetworkAddressSpace(localAddresses).build());
|
||||||
|
|
||||||
|
assertNotNull(gw);
|
||||||
|
assertTrue(gw.tags().containsKey("foo"));
|
||||||
|
assertEquals(gw.tags().get("foo"), "bar");
|
||||||
|
assertTrue(gw.properties().localNetworkAddressSpace().addressPrefixes().contains("192.168.0.0/24"));
|
||||||
|
assertTrue(gw.properties().localNetworkAddressSpace().addressPrefixes().contains("192.168.1.0/24"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(dependsOnMethods = { "getLocalNetworkGateway", "listLocalNetworkGateways", "updateLocalNetworkGateway" }, alwaysRun = true)
|
||||||
|
public void deleteLocalNetworkGateway() {
|
||||||
|
// Make sure the resource is fully provisioned before deleting it
|
||||||
|
waitUntilAvailable(name);
|
||||||
|
URI uri = api().delete(name);
|
||||||
|
assertResourceDeleted(uri);
|
||||||
|
}
|
||||||
|
|
||||||
|
private LocalNetworkGatewayApi api() {
|
||||||
|
return api.getLocalNetworkGatewayApi(resourceGroupName);
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean waitUntilAvailable(final String name) {
|
||||||
|
return resourceAvailable.apply(new Supplier<Provisionable>() {
|
||||||
|
@Override
|
||||||
|
public Provisionable get() {
|
||||||
|
LocalNetworkGateway gw = api().get(name);
|
||||||
|
return gw == null ? null : gw.properties();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,148 @@
|
||||||
|
/*
|
||||||
|
* 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.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.LocalNetworkGateway;
|
||||||
|
import org.jclouds.azurecompute.arm.domain.LocalNetworkGatewayProperties;
|
||||||
|
import org.jclouds.azurecompute.arm.domain.LocalNetworkGatewayProperties.AddressSpace;
|
||||||
|
import org.jclouds.azurecompute.arm.internal.BaseAzureComputeApiMockTest;
|
||||||
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
|
import com.google.common.collect.ImmutableList;
|
||||||
|
|
||||||
|
@Test(groups = "unit", testName = "LocalNetworkGatewayApiMockTest", singleThreaded = true)
|
||||||
|
public class LocalNetworkGatewayApiMockTest extends BaseAzureComputeApiMockTest {
|
||||||
|
|
||||||
|
private final String subscriptionid = "SUBSCRIPTIONID";
|
||||||
|
private final String resourcegroup = "myresourcegroup";
|
||||||
|
private final String name = "mylocalgw";
|
||||||
|
private final String apiVersion = "api-version=2018-02-01";
|
||||||
|
|
||||||
|
public void createOrUpdateLocalNetworkGateway() throws InterruptedException {
|
||||||
|
server.enqueue(jsonResponse("/localnetworkgatewaycreate.json").setResponseCode(200));
|
||||||
|
LocalNetworkGatewayApi gwapi = api.getLocalNetworkGatewayApi(resourcegroup);
|
||||||
|
|
||||||
|
AddressSpace localAddresses = AddressSpace.create(ImmutableList.of("192.168.0.0/24"));
|
||||||
|
LocalNetworkGatewayProperties props = LocalNetworkGatewayProperties.builder().gatewayIpAddress("1.2.3.4")
|
||||||
|
.localNetworkAddressSpace(localAddresses).build();
|
||||||
|
LocalNetworkGateway gw = gwapi.createOrUpdate(name, "westeurope", null, props);
|
||||||
|
|
||||||
|
String path = String.format(
|
||||||
|
"/subscriptions/%s/resourcegroups/%s/providers/Microsoft.Network/localNetworkGateways/%s?%s",
|
||||||
|
subscriptionid, resourcegroup, name, apiVersion);
|
||||||
|
String json = "{\"location\":\"westeurope\",\"properties\":{\"gatewayIpAddress\":\"1.2.3.4\",\"localNetworkAddressSpace\":{\"addressPrefixes\":[\"192.168.0.0/24\"]}}}";
|
||||||
|
assertSent(server, "PUT", path, json);
|
||||||
|
|
||||||
|
assertEquals(gw.name(), name);
|
||||||
|
assertNotNull(gw.properties());
|
||||||
|
assertNotNull(gw.properties().gatewayIpAddress());
|
||||||
|
assertEquals(gw.properties().gatewayIpAddress(), "1.2.3.4");
|
||||||
|
assertNotNull(gw.properties().localNetworkAddressSpace());
|
||||||
|
assertTrue(gw.properties().localNetworkAddressSpace().addressPrefixes().contains("192.168.0.0/24"));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void getLocalNetworkGateway() throws InterruptedException {
|
||||||
|
server.enqueue(jsonResponse("/localnetworkgatewayget.json").setResponseCode(200));
|
||||||
|
LocalNetworkGatewayApi gwapi = api.getLocalNetworkGatewayApi(resourcegroup);
|
||||||
|
|
||||||
|
LocalNetworkGateway gw = gwapi.get(name);
|
||||||
|
|
||||||
|
String path = String.format(
|
||||||
|
"/subscriptions/%s/resourcegroups/%s/providers/Microsoft.Network/localNetworkGateways/%s?%s",
|
||||||
|
subscriptionid, resourcegroup, name, apiVersion);
|
||||||
|
assertSent(server, "GET", path);
|
||||||
|
|
||||||
|
assertEquals(gw.name(), name);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void getLocalNetworkGatewayReturns404() throws InterruptedException {
|
||||||
|
server.enqueue(response404());
|
||||||
|
LocalNetworkGatewayApi gwapi = api.getLocalNetworkGatewayApi(resourcegroup);
|
||||||
|
|
||||||
|
LocalNetworkGateway gw = gwapi.get(name);
|
||||||
|
|
||||||
|
String path = String.format(
|
||||||
|
"/subscriptions/%s/resourcegroups/%s/providers/Microsoft.Network/localNetworkGateways/%s?%s",
|
||||||
|
subscriptionid, resourcegroup, name, apiVersion);
|
||||||
|
assertSent(server, "GET", path);
|
||||||
|
|
||||||
|
assertNull(gw);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void listLocalNetworkGateways() throws InterruptedException {
|
||||||
|
server.enqueue(jsonResponse("/localnetworkgatewaylist.json").setResponseCode(200));
|
||||||
|
LocalNetworkGatewayApi gwapi = api.getLocalNetworkGatewayApi(resourcegroup);
|
||||||
|
|
||||||
|
List<LocalNetworkGateway> gws = gwapi.list();
|
||||||
|
|
||||||
|
String path = String.format(
|
||||||
|
"/subscriptions/%s/resourcegroups/%s/providers/Microsoft.Network/localNetworkGateways?%s",
|
||||||
|
subscriptionid, resourcegroup, apiVersion);
|
||||||
|
assertSent(server, "GET", path);
|
||||||
|
|
||||||
|
assertTrue(gws.size() > 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void listLocalNetworkGatewaysReturns404() throws InterruptedException {
|
||||||
|
server.enqueue(response404());
|
||||||
|
LocalNetworkGatewayApi gwapi = api.getLocalNetworkGatewayApi(resourcegroup);
|
||||||
|
|
||||||
|
List<LocalNetworkGateway> gws = gwapi.list();
|
||||||
|
|
||||||
|
String path = String.format(
|
||||||
|
"/subscriptions/%s/resourcegroups/%s/providers/Microsoft.Network/localNetworkGateways?%s",
|
||||||
|
subscriptionid, resourcegroup, apiVersion);
|
||||||
|
assertSent(server, "GET", path);
|
||||||
|
|
||||||
|
assertTrue(isEmpty(gws));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void deleteLocalNetworkGateway() throws InterruptedException {
|
||||||
|
server.enqueue(response202WithHeader());
|
||||||
|
LocalNetworkGatewayApi gwapi = api.getLocalNetworkGatewayApi(resourcegroup);
|
||||||
|
|
||||||
|
URI uri = gwapi.delete(name);
|
||||||
|
assertNotNull(uri);
|
||||||
|
|
||||||
|
String path = String.format(
|
||||||
|
"/subscriptions/%s/resourcegroups/%s/providers/Microsoft.Network/localNetworkGateways/%s?%s",
|
||||||
|
subscriptionid, resourcegroup, name, apiVersion);
|
||||||
|
assertSent(server, "DELETE", path);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void deleteLocalNetworkGatewayDoesNotExist() throws InterruptedException {
|
||||||
|
server.enqueue(response204());
|
||||||
|
LocalNetworkGatewayApi gwapi = api.getLocalNetworkGatewayApi(resourcegroup);
|
||||||
|
|
||||||
|
URI uri = gwapi.delete(name);
|
||||||
|
assertNull(uri);
|
||||||
|
|
||||||
|
String path = String.format(
|
||||||
|
"/subscriptions/%s/resourcegroups/%s/providers/Microsoft.Network/localNetworkGateways/%s?%s",
|
||||||
|
subscriptionid, resourcegroup, name, apiVersion);
|
||||||
|
assertSent(server, "DELETE", path);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,18 @@
|
||||||
|
{
|
||||||
|
"name": "mylocalgw",
|
||||||
|
"id": "/subscriptions/SUBSCRIPTIONID/resourceGroups/myresourcegroup/providers/Microsoft.Network/localNetworkGateways/mylocalgw",
|
||||||
|
"etag": "W/\"e76a6517-260a-4424-811b-b4d518109424\"",
|
||||||
|
"type": "Microsoft.Network/localNetworkGateways",
|
||||||
|
"location": "westeurope",
|
||||||
|
"properties": {
|
||||||
|
"provisioningState": "Updating",
|
||||||
|
"resourceGuid": "cd00ef09-fec6-4d6e-aa15-77cf06d14915",
|
||||||
|
"localNetworkAddressSpace": {
|
||||||
|
"addressPrefixes": [
|
||||||
|
"192.168.0.0/24"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"gatewayIpAddress": "1.2.3.4"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -0,0 +1,18 @@
|
||||||
|
{
|
||||||
|
"name": "mylocalgw",
|
||||||
|
"id": "/subscriptions/SUBSCRIPTIONID/resourceGroups/myresourcegroup/providers/Microsoft.Network/localNetworkGateways/mylocalgw",
|
||||||
|
"etag": "W/\"e76a6517-260a-4424-811b-b4d518109424\"",
|
||||||
|
"type": "Microsoft.Network/localNetworkGateways",
|
||||||
|
"location": "westeurope",
|
||||||
|
"properties": {
|
||||||
|
"provisioningState": "Updating",
|
||||||
|
"resourceGuid": "cd00ef09-fec6-4d6e-aa15-77cf06d14915",
|
||||||
|
"localNetworkAddressSpace": {
|
||||||
|
"addressPrefixes": [
|
||||||
|
"192.168.0.0/24"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"gatewayIpAddress": "1.2.3.4"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -0,0 +1,22 @@
|
||||||
|
{
|
||||||
|
"value": [
|
||||||
|
{
|
||||||
|
"name": "mylocalgw",
|
||||||
|
"id": "/subscriptions/SUBSCRIPTIONID/resourceGroups/myresourcegroup/providers/Microsoft.Network/localNetworkGateways/mylocalgw",
|
||||||
|
"etag": "W/\"e76a6517-260a-4424-811b-b4d518109424\"",
|
||||||
|
"type": "Microsoft.Network/localNetworkGateways",
|
||||||
|
"location": "westeurope",
|
||||||
|
"properties": {
|
||||||
|
"provisioningState": "Updating",
|
||||||
|
"resourceGuid": "cd00ef09-fec6-4d6e-aa15-77cf06d14915",
|
||||||
|
"localNetworkAddressSpace": {
|
||||||
|
"addressPrefixes": [
|
||||||
|
"192.168.0.0/24"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"gatewayIpAddress": "1.2.3.4"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue