@Nullable public String virtualNetwork() { return extractVirtualNetwork(id()); }
@Nullable public String virtualNetwork() { return extractVirtualNetwork(id()); }
@BeforeMethod(alwaysRun=true) public void setUp() throws Exception { MockitoAnnotations.initMocks(this); // stock mock responses when(computeService.getContext()).thenReturn(computeServiceContext); when(computeServiceContext.unwrapApi(AzureComputeApi.class)).thenReturn(azureComputeApi); when(azureComputeApi.getResourceGroupApi()).thenReturn(resourceGroupApi); when(azureComputeApi.getSubnetApi(TEST_RESOURCE_GROUP, TEST_NETWORK_NAME)).thenReturn(subnetApi); when(azureComputeApi.getVirtualNetworkApi(TEST_RESOURCE_GROUP)).thenReturn(virtualNetworkApi); when(subnet.id()).thenReturn(TEST_SUBNET_ID); }
@BeforeClass @Override public void setup() { super.setup(); subscriptionid = getSubscriptionId(); createTestResourceGroup(); //BASE: Creates a random resource group using the properties location virtualNetworkName = String.format("vn-%s-%s", this.getClass().getSimpleName().toLowerCase(), System.getProperty("user.name")); // Subnets belong to a virtual network so that needs to be created first assertNotNull(createDefaultVirtualNetwork(resourceGroupName, virtualNetworkName, "10.2.0.0/16", LOCATION)); //Subnet needs to be up & running before NIC can be created String subnetName = String.format("s-%s-%s", this.getClass().getSimpleName().toLowerCase(), System.getProperty("user.name")); this.subnet = createDefaultSubnet(resourceGroupName, subnetName, virtualNetworkName, "10.2.0.0/23"); assertNotNull(subnet); assertNotNull(subnet.id()); this.subnetId = subnet.id(); vmssName = String.format("%3.24s", System.getProperty("user.name") + RAND + this.getClass().getSimpleName()).toLowerCase().substring(0, 15); }
@BeforeClass @Override public void setup() { super.setup(); createTestResourceGroup(); String virtualNetworkName = String.format("vn-%s-%s", this.getClass().getSimpleName().toLowerCase(), System.getProperty("user.name")); nicName = String.format("nic-%s-%s", this.getClass().getSimpleName().toLowerCase(), System.getProperty("user.name")); String subnetName = String.format("s-%s-%s", this.getClass().getSimpleName().toLowerCase(), System.getProperty("user.name")); //Subnets belong to a virtual network so that needs to be created first assertNotNull(createDefaultVirtualNetwork(resourceGroupName, virtualNetworkName, "10.2.0.0/16", LOCATION)); //Subnet needs to be up & running before NIC can be created Subnet subnet = createDefaultSubnet(resourceGroupName, subnetName, virtualNetworkName, "10.2.0.0/23"); assertNotNull(subnet); assertNotNull(subnet.id()); subnetId = subnet.id(); }
@BeforeClass @Override public void setup() { super.setup(); subscriptionid = getSubscriptionId(); createTestResourceGroup(); virtualNetworkName = String.format("vn-%s-%s", this.getClass().getSimpleName().toLowerCase(), System.getProperty("user.name")); // Subnets belong to a virtual network so that needs to be created first assertNotNull(createDefaultVirtualNetwork(resourceGroupName, virtualNetworkName, "10.2.0.0/16", LOCATION)); //Subnet needs to be up & running before NIC can be created String subnetName = String.format("s-%s-%s", this.getClass().getSimpleName().toLowerCase(), System.getProperty("user.name")); Subnet subnet = createDefaultSubnet(resourceGroupName, subnetName, virtualNetworkName, "10.2.0.0/23"); assertNotNull(subnet); assertNotNull(subnet.id()); subnetId = subnet.id(); NetworkInterfaceCard nic = createNetworkInterfaceCard(resourceGroupName, "jc-nic-" + RAND, LOCATION, "ipConfig-" + RAND); assertNotNull(nic); nicName = nic.name(); vmName = String.format("%3.24s", System.getProperty("user.name") + RAND + this.getClass().getSimpleName()).toLowerCase().substring(0, 15); }
@Test public void testPreExisting() throws Exception { //Setup config bag ConfigBag configBag = ConfigBag.newInstance(); configBag.put(CLOUD_REGION_ID, TEST_LOCATION); //Setup mocks when(subnetApi.get(TEST_SUBNET_NAME)).thenReturn(subnet); //Test DefaultAzureArmNetworkCreator.createDefaultNetworkAndAddToTemplateOptionsIfRequired(computeService, configBag); //verify verify(subnetApi).get(TEST_SUBNET_NAME); verify(subnet).id(); //verify templateOptions updated to include defaults Map<String, Object> templateOptions = configBag.get(TEMPLATE_OPTIONS); Map<String, Object> ipOptions = (Map<String, Object>) ((List)templateOptions.get("ipOptions")).iterator().next(); assertEquals(ipOptions.get("subnet"), TEST_SUBNET_ID); assertEquals(ipOptions.get("allocateNewPublicIp"), true); }
@Test public void testVanillaWhereExistingResourceGroup() throws Exception { //Setup config bag ConfigBag configBag = ConfigBag.newInstance(); configBag.put(CLOUD_REGION_ID, TEST_LOCATION); //Setup mocks when(subnetApi.get(TEST_SUBNET_NAME)).thenReturn(null).thenReturn(subnet); //null first time, subnet next when(resourceGroupApi.get(TEST_RESOURCE_GROUP)).thenReturn(resourceGroup); when(subnet.properties().provisioningState()).thenReturn("Updating").thenReturn("Succeeded"); //Test DefaultAzureArmNetworkCreator.createDefaultNetworkAndAddToTemplateOptionsIfRequired(computeService, configBag); //verify verify(subnetApi, atLeast(2)).get(TEST_SUBNET_NAME); verify(subnet).id(); verify(resourceGroupApi).get(TEST_RESOURCE_GROUP); verify(resourceGroupApi, never()).create(any(), any(), any()); verify(virtualNetworkApi).createOrUpdate(eq(TEST_NETWORK_NAME), eq(TEST_LOCATION), any()); //verify templateOptions updated to include defaults Map<String, Object> templateOptions = configBag.get(TEMPLATE_OPTIONS); Map<String, Object> ipOptions = (Map<String, Object>) ((List)templateOptions.get("ipOptions")).iterator().next(); assertEquals(ipOptions.get("subnet"), TEST_SUBNET_ID); assertEquals(ipOptions.get("allocateNewPublicIp"), true); }
protected ConfigBag runVanilla(Map<?, ?> additionalConfig) throws Exception { //Setup config bag ConfigBag configBag = ConfigBag.newInstance(); configBag.putAll(additionalConfig); configBag.put(CLOUD_REGION_ID, TEST_LOCATION); //Setup mocks when(subnetApi.get(TEST_SUBNET_NAME)).thenReturn(null).thenReturn(subnet); //null first time, subnet next when(resourceGroupApi.get(TEST_RESOURCE_GROUP)).thenReturn(null); when(subnet.properties().provisioningState()).thenReturn("Updating").thenReturn("Succeeded"); //Test DefaultAzureArmNetworkCreator.createDefaultNetworkAndAddToTemplateOptionsIfRequired(computeService, configBag); //verify calls made verify(subnet).id(); verify(subnetApi, atLeast(2)).get(TEST_SUBNET_NAME); verify(resourceGroupApi).get(TEST_RESOURCE_GROUP); verify(resourceGroupApi).create(eq(TEST_RESOURCE_GROUP), eq(TEST_LOCATION), any()); verify(virtualNetworkApi).createOrUpdate(eq(TEST_NETWORK_NAME), eq(TEST_LOCATION), any()); //verify templateOptions updated to include defaults Map<String, Object> templateOptions = configBag.get(TEMPLATE_OPTIONS); Map<String, Object> ipOptions = (Map<String, Object>) ((List)templateOptions.get("ipOptions")).iterator().next(); assertEquals(ipOptions.get("subnet"), TEST_SUBNET_ID); assertEquals(ipOptions.get("allocateNewPublicIp"), true); return configBag; }
@Test public void testVanillaWhereExistingNetworkButNoSubnet() throws Exception { //Setup config bag ConfigBag configBag = ConfigBag.newInstance(); configBag.put(CLOUD_REGION_ID, TEST_LOCATION); //Setup mocks when(subnetApi.get(TEST_SUBNET_NAME)).thenReturn(null).thenReturn(subnet); //null first time, subnet next when(virtualNetworkApi.get(TEST_NETWORK_NAME)).thenReturn(virtualNetwork); when(resourceGroupApi.get(TEST_RESOURCE_GROUP)).thenReturn(resourceGroup); when(subnet.properties().provisioningState()).thenReturn("Updating").thenReturn("Succeeded"); //Test DefaultAzureArmNetworkCreator.createDefaultNetworkAndAddToTemplateOptionsIfRequired(computeService, configBag); //verify verify(subnetApi).createOrUpdate(eq(TEST_SUBNET_NAME), any()); verify(subnetApi, atLeast(2)).get(TEST_SUBNET_NAME); verify(subnet).id(); verify(resourceGroupApi).get(TEST_RESOURCE_GROUP); verify(resourceGroupApi, never()).create(any(), any(), any()); verify(virtualNetworkApi, never()).createOrUpdate(any(), any(), any()); //verify templateOptions updated to include defaults Map<String, Object> templateOptions = configBag.get(TEMPLATE_OPTIONS); Map<String, Object> ipOptions = (Map<String, Object>) ((List)templateOptions.get("ipOptions")).iterator().next(); assertEquals(ipOptions.get("subnet"), TEST_SUBNET_ID); assertEquals(ipOptions.get("allocateNewPublicIp"), true); }
protected synchronized void createDefaultNetworkIfNeeded(String group, String location, AzureTemplateOptions options) { if (options.getIpOptions().isEmpty()) { String name = namingConvention.create().sharedNameForGroup(group); Subnet subnet = Subnet.builder().name(name) .properties(SubnetProperties.builder().addressPrefix(defaultSubnetAddressPrefix).build()).build(); VirtualNetworkProperties properties = VirtualNetworkProperties.builder() .addressSpace(AddressSpace.create(Arrays.asList(defaultVnetAddressPrefix))) .subnets(Arrays.asList(subnet)).build(); logger.debug(">> network options have not been configured. Creating network %s(%s) and subnet %s(%s)", name, defaultVnetAddressPrefix, name, defaultSubnetAddressPrefix); api.getVirtualNetworkApi(options.getResourceGroup()).createOrUpdate(name, location, null, properties); checkState(networkAvailable.create(options.getResourceGroup()).apply(name), "Network/Subnet was not created in the configured timeout"); Subnet createdSubnet = api.getSubnetApi(options.getResourceGroup(), name).get(name); options.ipOptions(IpOptions.builder().subnet(createdSubnet.id()).allocateNewPublicIp(true).build()); } }
protected synchronized void createDefaultNetworkIfNeeded(String group, String location, AzureTemplateOptions options) { if (options.getIpOptions().isEmpty()) { String name = namingConvention.create().sharedNameForGroup(group); Subnet subnet = Subnet.builder().name(name) .properties(SubnetProperties.builder().addressPrefix(defaultSubnetAddressPrefix).build()).build(); VirtualNetworkProperties properties = VirtualNetworkProperties.builder() .addressSpace(AddressSpace.create(Arrays.asList(defaultVnetAddressPrefix))) .subnets(Arrays.asList(subnet)).build(); logger.debug(">> network options have not been configured. Creating network %s(%s) and subnet %s(%s)", name, defaultVnetAddressPrefix, name, defaultSubnetAddressPrefix); api.getVirtualNetworkApi(options.getResourceGroup()).createOrUpdate(name, location, null, properties); Subnet createdSubnet = api.getSubnetApi(options.getResourceGroup(), name).get(name); options.ipOptions(IpOptions.builder().subnet(createdSubnet.id()).allocateNewPublicIp(true).build()); } }
private LoadBalancer createLoadBalancerWithPrivateIP(final String ipAddress) { FrontendIPConfigurationsProperties frontendProps = FrontendIPConfigurationsProperties.builder() .privateIPAddress(ipAddress).privateIPAllocationMethod("Static") .subnet(IdReference.create(api().get(virtualNetworkName).properties().subnets().get(0).id())).build(); FrontendIPConfigurations frontendIps = FrontendIPConfigurations.create("ipConfigs", null, frontendProps, null); LoadBalancerProperties props = LoadBalancerProperties.builder() .frontendIPConfigurations(ImmutableList.of(frontendIps)).build(); LoadBalancer lbCreated = lbApi().createOrUpdate("lbName", LOCATION, null, null, props); assertNotNull(lbCreated); return lbCreated; }
@BeforeClass @Override public void setup() { super.setup(); createTestResourceGroup(); name = "jclouds-" + RAND; virtualNetworkGatewayAvailable = virtualNetworkGatewayStatus.create(resourceGroupName); 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"); subnetId = subnet.id(); PublicIPAddressProperties props = PublicIPAddressProperties.builder() .publicIPAllocationMethod(IpAllocationMethod.Dynamic.name()).idleTimeoutInMinutes(4).build(); publicIp = api.getPublicIPAddressApi(resourceGroupName).createOrUpdate(name + "-publicip", LOCATION, Collections.<String, String> emptyMap(), null, props); }
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(), null, 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())); }