use of com.microsoft.azure.management.network.NetworkInterface in project azure-sdk-for-java by Azure.
the class LoadBalancerBackendImpl method getVirtualMachineIds.
@Override
public Set<String> getVirtualMachineIds() {
Set<String> vmIds = new HashSet<>();
Map<String, String> nicConfigs = this.backendNicIPConfigurationNames();
if (nicConfigs != null) {
for (String nicId : nicConfigs.keySet()) {
try {
NetworkInterface nic = this.parent().manager().networkInterfaces().getById(nicId);
if (nic == null || nic.virtualMachineId() == null) {
continue;
} else {
vmIds.add(nic.virtualMachineId());
}
} catch (CloudException | IllegalArgumentException e) {
continue;
}
}
}
return vmIds;
}
use of com.microsoft.azure.management.network.NetworkInterface in project azure-sdk-for-java by Azure.
the class VirtualMachineImpl method handleNetworkSettings.
private void handleNetworkSettings() {
if (isInCreateMode()) {
NetworkInterface primaryNetworkInterface = null;
if (this.creatablePrimaryNetworkInterfaceKey != null) {
primaryNetworkInterface = (NetworkInterface) this.createdResource(this.creatablePrimaryNetworkInterfaceKey);
} else if (this.existingPrimaryNetworkInterfaceToAssociate != null) {
primaryNetworkInterface = this.existingPrimaryNetworkInterfaceToAssociate;
}
if (primaryNetworkInterface != null) {
NetworkInterfaceReferenceInner nicReference = new NetworkInterfaceReferenceInner();
nicReference.withPrimary(true);
nicReference.withId(primaryNetworkInterface.id());
this.inner().networkProfile().networkInterfaces().add(nicReference);
}
}
//
for (String creatableSecondaryNetworkInterfaceKey : this.creatableSecondaryNetworkInterfaceKeys) {
NetworkInterface secondaryNetworkInterface = (NetworkInterface) this.createdResource(creatableSecondaryNetworkInterfaceKey);
NetworkInterfaceReferenceInner nicReference = new NetworkInterfaceReferenceInner();
nicReference.withPrimary(false);
nicReference.withId(secondaryNetworkInterface.id());
this.inner().networkProfile().networkInterfaces().add(nicReference);
}
for (NetworkInterface secondaryNetworkInterface : this.existingSecondaryNetworkInterfacesToAssociate) {
NetworkInterfaceReferenceInner nicReference = new NetworkInterfaceReferenceInner();
nicReference.withPrimary(false);
nicReference.withId(secondaryNetworkInterface.id());
this.inner().networkProfile().networkInterfaces().add(nicReference);
}
}
use of com.microsoft.azure.management.network.NetworkInterface in project azure-sdk-for-java by Azure.
the class TestNSG method createResource.
@Override
public NetworkSecurityGroup createResource(NetworkSecurityGroups nsgs) throws Exception {
final String newName = "nsg" + this.testId;
final String resourceGroupName = "rg" + this.testId;
final String nicName = "nic" + this.testId;
final Region region = Region.US_WEST;
final SettableFuture<NetworkSecurityGroup> nsgFuture = SettableFuture.create();
// Create
Observable<Indexable> resourceStream = nsgs.define(newName).withRegion(region).withNewResourceGroup(resourceGroupName).defineRule("rule1").allowOutbound().fromAnyAddress().fromPort(80).toAnyAddress().toPort(80).withProtocol(SecurityRuleProtocol.TCP).attach().defineRule("rule2").allowInbound().fromAnyAddress().fromAnyPort().toAnyAddress().toPortRange(22, 25).withAnyProtocol().withPriority(200).withDescription("foo!!").attach().createAsync();
Utils.<NetworkSecurityGroup>rootResource(resourceStream).subscribe(new Subscriber<NetworkSecurityGroup>() {
@Override
public void onCompleted() {
System.out.print("completed");
}
@Override
public void onError(Throwable throwable) {
nsgFuture.setException(throwable);
}
@Override
public void onNext(NetworkSecurityGroup networkSecurityGroup) {
nsgFuture.set(networkSecurityGroup);
}
});
NetworkSecurityGroup nsg = nsgFuture.get();
NetworkInterface nic = nsgs.manager().networkInterfaces().define(nicName).withRegion(region).withExistingResourceGroup(resourceGroupName).withNewPrimaryNetwork("10.0.0.0/28").withPrimaryPrivateIPAddressDynamic().withExistingNetworkSecurityGroup(nsg).create();
nsg.refresh();
// Verify
Assert.assertTrue(nsg.region().equals(region));
Assert.assertTrue(nsg.securityRules().size() == 2);
// Confirm NIC association
Assert.assertEquals(1, nsg.networkInterfaceIds().size());
Assert.assertTrue(nsg.networkInterfaceIds().contains(nic.id()));
return nsg;
}
use of com.microsoft.azure.management.network.NetworkInterface in project azure-sdk-for-java by Azure.
the class TestVirtualMachineNics method createResource.
@Override
public VirtualMachine createResource(VirtualMachines virtualMachines) throws Exception {
// Prepare the resource group definition
final String rgName = "rg" + this.testId;
Creatable<ResourceGroup> resourceGroupCreatable = virtualMachines.manager().resourceManager().resourceGroups().define(rgName).withRegion(Region.US_EAST);
// Prepare the virtual network definition [shared by primary and secondary network interfaces]
final String vnetName = "vnet" + this.testId;
Creatable<Network> networkCreatable = this.networkManager.networks().define(vnetName).withRegion(Region.US_EAST).withNewResourceGroup(resourceGroupCreatable).withAddressSpace("10.0.0.0/28");
// Prepare the secondary network interface definition
final String secondaryNicName = "nic" + this.testId;
Creatable<NetworkInterface> secondaryNetworkInterfaceCreatable = this.networkManager.networkInterfaces().define(secondaryNicName).withRegion(Region.US_EAST).withNewResourceGroup(resourceGroupCreatable).withNewPrimaryNetwork(networkCreatable).withPrimaryPrivateIPAddressStatic("10.0.0.5");
// .withNewPrimaryPublicIPAddress();
// [Secondary NIC cannot have PublicIP - Only primary network interface can reference a public IP address]
// Prepare the secondary network interface definition
final String secondaryNicName2 = "nic2" + this.testId;
Creatable<NetworkInterface> secondaryNetworkInterfaceCreatable2 = this.networkManager.networkInterfaces().define(secondaryNicName2).withRegion(Region.US_EAST).withNewResourceGroup(resourceGroupCreatable).withNewPrimaryNetwork(networkCreatable).withPrimaryPrivateIPAddressStatic("10.0.0.6");
// Create Virtual Machine
final String vmName = "vm" + this.testId;
final String primaryPipName = "pip" + vmName;
VirtualMachine virtualMachine = virtualMachines.define(vmName).withRegion(Region.US_EAST).withNewResourceGroup(resourceGroupCreatable).withNewPrimaryNetwork(networkCreatable).withPrimaryPrivateIPAddressStatic("10.0.0.4").withNewPrimaryPublicIPAddress(primaryPipName).withPopularLinuxImage(KnownLinuxVirtualMachineImage.UBUNTU_SERVER_14_04_LTS).withRootUsername("testuser").withRootPassword("12NewPA$$w0rd!").withSize(VirtualMachineSizeTypes.STANDARD_A9).withNewSecondaryNetworkInterface(secondaryNetworkInterfaceCreatable).withNewSecondaryNetworkInterface(secondaryNetworkInterfaceCreatable2).create();
Assert.assertTrue(virtualMachine.networkInterfaceIds().size() == 3);
NetworkInterface primaryNetworkInterface = virtualMachine.getPrimaryNetworkInterface();
Assert.assertEquals(primaryNetworkInterface.primaryPrivateIP(), "10.0.0.4");
PublicIPAddress primaryPublicIPAddress = primaryNetworkInterface.primaryIPConfiguration().getPublicIPAddress();
Assert.assertTrue(primaryPublicIPAddress.fqdn().startsWith(primaryPipName));
return virtualMachine;
}
use of com.microsoft.azure.management.network.NetworkInterface in project azure-sdk-for-java by Azure.
the class TestPublicIPAddress method printPIP.
public static void printPIP(PublicIPAddress resource) {
StringBuilder info = new StringBuilder().append("Public IP Address: ").append(resource.id()).append("\n\tName: ").append(resource.name()).append("\n\tResource group: ").append(resource.resourceGroupName()).append("\n\tRegion: ").append(resource.region()).append("\n\tTags: ").append(resource.tags()).append("\n\tIP Address: ").append(resource.ipAddress()).append("\n\tLeaf domain label: ").append(resource.leafDomainLabel()).append("\n\tFQDN: ").append(resource.fqdn()).append("\n\tReverse FQDN: ").append(resource.reverseFqdn()).append("\n\tIdle timeout (minutes): ").append(resource.idleTimeoutInMinutes()).append("\n\tIP allocation method: ").append(resource.ipAllocationMethod().toString()).append("\n\tIP version: ").append(resource.version().toString());
// Show the associated load balancer if any
info.append("\n\tLoad balancer association: ");
if (resource.hasAssignedLoadBalancer()) {
final LoadBalancerPublicFrontend frontend = resource.getAssignedLoadBalancerFrontend();
final LoadBalancer lb = frontend.parent();
info.append("\n\t\tLoad balancer ID: ").append(lb.id()).append("\n\t\tFrontend name: ").append(frontend.name());
} else {
info.append("(None)");
}
// Show the associated NIC if any
info.append("\n\tNetwork interface association: ");
if (resource.hasAssignedNetworkInterface()) {
final NicIPConfiguration nicIp = resource.getAssignedNetworkInterfaceIPConfiguration();
final NetworkInterface nic = nicIp.parent();
info.append("\n\t\tNetwork interface ID: ").append(nic.id()).append("\n\t\tIP config name: ").append(nicIp.name());
} else {
info.append("(None)");
}
System.out.println(info.toString());
}
Aggregations