Java Code Examples for com.microsoft.azure.management.network.NicIPConfiguration#getNetwork()
The following examples show how to use
com.microsoft.azure.management.network.NicIPConfiguration#getNetwork() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: VirtualMachineOperationsTests.java From azure-libraries-for-java with MIT License | 4 votes |
@Test public void canCreateVirtualMachineWithNetworking() throws Exception { NetworkSecurityGroup nsg = this.networkManager.networkSecurityGroups().define("nsg") .withRegion(REGION) .withNewResourceGroup(RG_NAME) .defineRule("rule1") .allowInbound() .fromAnyAddress() .fromPort(80) .toAnyAddress() .toPort(80) .withProtocol(SecurityRuleProtocol.TCP) .attach() .create(); Creatable<Network> networkDefinition = this.networkManager.networks().define("network1") .withRegion(REGION) .withNewResourceGroup(RG_NAME) .withAddressSpace("10.0.0.0/28") .defineSubnet("subnet1") .withAddressPrefix("10.0.0.0/29") .withExistingNetworkSecurityGroup(nsg) .attach(); // Create VirtualMachine vm = computeManager.virtualMachines() .define(VMNAME) .withRegion(REGION) .withNewResourceGroup(RG_NAME) .withNewPrimaryNetwork(networkDefinition) .withPrimaryPrivateIPAddressDynamic() .withoutPrimaryPublicIPAddress() .withPopularLinuxImage(KnownLinuxVirtualMachineImage.UBUNTU_SERVER_16_04_LTS) .withRootUsername("Foo12") .withRootPassword("abc!@#F0orL") .create(); NetworkInterface primaryNic = vm.getPrimaryNetworkInterface(); Assert.assertNotNull(primaryNic); NicIPConfiguration primaryIpConfig = primaryNic.primaryIPConfiguration(); Assert.assertNotNull(primaryIpConfig); // Fetch the NSG the way before v1.2 Assert.assertNotNull(primaryIpConfig.networkId()); Network network = primaryIpConfig.getNetwork(); Assert.assertNotNull(primaryIpConfig.subnetName()); Subnet subnet = network.subnets().get(primaryIpConfig.subnetName()); Assert.assertNotNull(subnet); nsg = subnet.getNetworkSecurityGroup(); Assert.assertNotNull(nsg); Assert.assertEquals("nsg", nsg.name()); Assert.assertEquals(1, nsg.securityRules().size()); // Fetch the NSG the v1.2 way nsg = primaryIpConfig.getNetworkSecurityGroup(); Assert.assertEquals("nsg", nsg.name()); }
Example 2
Source File: TestNetworkInterface.java From azure-libraries-for-java with MIT License | 4 votes |
@Override public NetworkInterface createResource(NetworkInterfaces networkInterfaces) throws Exception { final String nicName = "nic" + this.testId; final String vnetName = "net" + this.testId; final String pipName = "pip" + this.testId; final Region region = Region.US_EAST; Network network = networkInterfaces.manager().networks().define(vnetName) .withRegion(region) .withNewResourceGroup() .withAddressSpace("10.0.0.0/28") .withSubnet("subnet1", "10.0.0.0/29") .withSubnet("subnet2", "10.0.0.8/29") .create(); NetworkInterface nic = networkInterfaces.define(nicName) .withRegion(region) .withExistingResourceGroup(network.resourceGroupName()) .withExistingPrimaryNetwork(network) .withSubnet("subnet1") .withPrimaryPrivateIPAddressDynamic() .withNewPrimaryPublicIPAddress(pipName) .withIPForwarding() .withAcceleratedNetworking() .create(); // Verify NIC settings Assert.assertTrue(nic.isAcceleratedNetworkingEnabled()); Assert.assertTrue(nic.isIPForwardingEnabled()); // Verify IP configs NicIPConfiguration ipConfig = nic.primaryIPConfiguration(); Assert.assertNotNull(ipConfig); network = ipConfig.getNetwork(); Assert.assertNotNull(network); Subnet subnet = network.subnets().get(ipConfig.subnetName()); Assert.assertNotNull(subnet); Assert.assertEquals(1, subnet.networkInterfaceIPConfigurationCount()); Collection<NicIPConfiguration> ipConfigs = subnet.listNetworkInterfaceIPConfigurations(); Assert.assertNotNull(ipConfigs); Assert.assertEquals(1, ipConfigs.size()); NicIPConfiguration ipConfig2 = null; for (NicIPConfiguration i : ipConfigs) { if (i.name().equalsIgnoreCase(ipConfig.name())) { ipConfig2 = i; break; } } Assert.assertNotNull(ipConfig2); Assert.assertTrue(ipConfig.name().equalsIgnoreCase(ipConfig2.name())); return nic; }