use of com.microsoft.azure.management.network.implementation.SubnetInner in project photon-model by vmware.
the class AzureSubnetTaskServiceTest method testCreateSubnet.
@Test
public void testCreateSubnet() throws Throwable {
SubnetState subnetState = createSubnetState(this.subnetName);
kickOffSubnetProvision(InstanceRequestType.CREATE, subnetState, TaskStage.FINISHED);
subnetState = getServiceSynchronously(subnetState.documentSelfLink, SubnetState.class);
assertNotNull(subnetState.id);
assertNotEquals(subnetState.id, this.subnetName);
assertEquals(LifecycleState.READY, subnetState.lifecycleState);
if (!this.isMock) {
// Verify that the subnet was deleted.
SubnetInner subnetResponse = this.subnetsClient.get(this.rgName, this.vNetName, this.subnetName, null);
assertEquals(this.subnetName, subnetResponse.name());
}
}
use of com.microsoft.azure.management.network.implementation.SubnetInner in project photon-model by vmware.
the class AzureSubnetTaskServiceTest method testDeleteSubnet.
@Test
public void testDeleteSubnet() throws Throwable {
SubnetInner azureSubnet = createAzureSubnet();
SubnetState subnetState = createSubnetState(azureSubnet.id());
kickOffSubnetProvision(InstanceRequestType.DELETE, subnetState, TaskStage.FINISHED);
if (!this.isMock) {
// Verify that the subnet was deleted.
SubnetInner subnetInner = this.subnetsClient.get(this.rgName, this.vNetName, this.subnetName, null);
if (subnetInner != null) {
fail("Subnet should not exist in Azure.");
}
}
}
use of com.microsoft.azure.management.network.implementation.SubnetInner in project photon-model by vmware.
the class AzureTestUtil method createAzureVirtualNetwork.
private static void createAzureVirtualNetwork(String resourceGroupName, AzureNicSpecs azureNicSpecs, NetworkManagementClientImpl networkManagementClient) throws Exception {
try {
VirtualNetworkInner vNet = new VirtualNetworkInner();
vNet.withLocation(azureNicSpecs.network.zoneId);
AddressSpace addressSpace = new AddressSpace();
// Azure's custom serializers don't handle well collections constructed with
// Collections.singletonList(), so initialize an ArrayList
List<String> cidrs = new ArrayList<>();
cidrs.add(azureNicSpecs.network.cidr);
addressSpace.withAddressPrefixes(cidrs);
vNet.withAddressSpace(addressSpace);
List<SubnetInner> subnetList = new ArrayList<>();
for (int i = 0; i < azureNicSpecs.nicSpecs.size(); i++) {
SubnetInner subnet = new SubnetInner();
subnet.withName(azureNicSpecs.nicSpecs.get(i).subnetSpec.name);
subnet.withAddressPrefix(azureNicSpecs.nicSpecs.get(i).subnetSpec.cidr);
subnetList.add(subnet);
}
vNet.withSubnets(subnetList);
networkManagementClient.virtualNetworks().createOrUpdate(resourceGroupName, azureNicSpecs.network.name, vNet);
addAzureGatewayToVirtualNetwork(resourceGroupName, azureNicSpecs, networkManagementClient);
} catch (CloudException ex) {
/*
* CloudException is thrown if the vNet already exists and we are trying to do an
* update, because there are objects (GatewaySubnet) attached to it
*/
assertTrue(ex.body().code().equals("InUseSubnetCannotBeDeleted"));
}
}
use of com.microsoft.azure.management.network.implementation.SubnetInner in project photon-model by vmware.
the class AzureTestUtil method addAzureGatewayToVirtualNetwork.
/**
* Adds Gateway to Virtual Network in Azure
*/
private static void addAzureGatewayToVirtualNetwork(String resourceGroupName, AzureNicSpecs nicSpecs, NetworkManagementClientImpl networkManagementClient) throws CloudException, IOException, InterruptedException {
// create Gateway Subnet
SubnetInner gatewaySubnetParams = new SubnetInner();
gatewaySubnetParams.withName(nicSpecs.gateway.name);
gatewaySubnetParams.withAddressPrefix(nicSpecs.gateway.cidr);
SubnetInner gatewaySubnet = networkManagementClient.subnets().createOrUpdate(resourceGroupName, nicSpecs.network.name, AzureConstants.GATEWAY_SUBNET_NAME, gatewaySubnetParams);
// create Public IP
PublicIPAddressInner publicIPAddressParams = new PublicIPAddressInner();
publicIPAddressParams.withPublicIPAllocationMethod(IPAllocationMethod.DYNAMIC);
publicIPAddressParams.withLocation(nicSpecs.gateway.zoneId);
PublicIPAddressInner publicIPAddress = networkManagementClient.publicIPAddresses().createOrUpdate(resourceGroupName, nicSpecs.gateway.publicIpName, publicIPAddressParams);
SubResource publicIPSubResource = new SubResource();
publicIPSubResource.withId(publicIPAddress.id());
// create IP Configuration
VirtualNetworkGatewayIPConfigurationInner ipConfiguration = new VirtualNetworkGatewayIPConfigurationInner();
ipConfiguration.withName(nicSpecs.gateway.ipConfigurationName);
ipConfiguration.withSubnet(gatewaySubnet);
ipConfiguration.withPrivateIPAllocationMethod(IPAllocationMethod.DYNAMIC);
ipConfiguration.withPublicIPAddress(publicIPSubResource);
// create Virtual Network Gateway
VirtualNetworkGatewayInner virtualNetworkGateway = new VirtualNetworkGatewayInner();
virtualNetworkGateway.withGatewayType(VirtualNetworkGatewayType.VPN);
virtualNetworkGateway.withVpnType(VpnType.ROUTE_BASED);
VirtualNetworkGatewaySku vNetGatewaySku = new VirtualNetworkGatewaySku();
vNetGatewaySku.withName(VirtualNetworkGatewaySkuName.STANDARD);
vNetGatewaySku.withTier(VirtualNetworkGatewaySkuTier.STANDARD);
vNetGatewaySku.withCapacity(2);
virtualNetworkGateway.withSku(vNetGatewaySku);
virtualNetworkGateway.withLocation(AZURE_RESOURCE_GROUP_LOCATION);
List<VirtualNetworkGatewayIPConfigurationInner> ipConfigurations = new ArrayList<>();
ipConfigurations.add(ipConfiguration);
virtualNetworkGateway.withIpConfigurations(ipConfigurations);
// Call the async variant because the virtual network gateway provisioning depends on
// the public IP address assignment which is time-consuming operation
networkManagementClient.virtualNetworkGateways().createOrUpdateAsync(resourceGroupName, nicSpecs.gateway.name, virtualNetworkGateway, new ServiceCallback<VirtualNetworkGatewayInner>() {
@Override
public void failure(Throwable throwable) {
throw new RuntimeException("Error creating Azure Virtual Network Gateway.", throwable);
}
@Override
public void success(VirtualNetworkGatewayInner response) {
}
});
}
Aggregations