Skip to content

Commit

Permalink
Merge pull request #10 from Azure-Samples/UpdatedSample
Browse files Browse the repository at this point in the history
Moved samples to 4.1
  • Loading branch information
anudeepsharma authored Apr 15, 2017
2 parents 5b16063 + c45eb47 commit e594c47
Show file tree
Hide file tree
Showing 3 changed files with 376 additions and 141 deletions.
130 changes: 64 additions & 66 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -1,66 +1,64 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.microsoft.azure</groupId>
<artifactId>network-java-manage-ip-address</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>ManageIPAddress.java</name>
<description></description>
<url>https://github.com/Azure/network-java-manage-ip-address</url>
<dependencies>
<dependency>
<groupId>com.microsoft.azure</groupId>
<artifactId>azure</artifactId>
<version>1.0.0-beta5</version>
</dependency>
</dependencies>
<build>
<sourceDirectory>src</sourceDirectory>
<resources>
<resource>
<directory>resources</directory>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.4.0</version>
<configuration>
<mainClass>com.microsoft.azure.management.network.samples.ManageIPAddress</mainClass>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.0</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
<plugin>
<!-- Generate a fully packaged executable jar with dependencies -->
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>attached</goal>
</goals>
<phase>package</phase>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<archive>
<manifest>
<mainClass>com.microsoft.azure.management.network.samples.ManageIPAddress.java</mainClass>
</manifest>
</archive>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
<?xml version="1.0" encoding="UTF-8"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<groupId>com.microsoft.azure</groupId>
<artifactId>network-java-manage-ip-address</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>ManageIPAddress.java</name>
<description></description>
<url>https://github.com/Azure/network-java-manage-ip-address</url>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.4.0</version>
<configuration>
<mainClass>com.microsoft.azure.management.network.samples.ManageIPAddress</mainClass>
</configuration>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.0</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>attached</goal>
</goals>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<archive>
<manifest>
<mainClass>com.microsoft.azure.management.network.samples.ManageIPAddress.java</mainClass>
</manifest>
</archive>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>com.microsoft.azure</groupId>
<artifactId>azure</artifactId>
<version>1.0.0</version>
</dependency>
<dependency>
<groupId>commons-net</groupId>
<artifactId>commons-net</artifactId>
<version>3.3</version>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
/**
*
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*
* Licensed under the MIT License. See License.txt in the project root for
* license information.
*/

package com.microsoft.azure.management.network.samples;
Expand All @@ -12,7 +11,7 @@
import com.microsoft.azure.management.compute.VirtualMachine;
import com.microsoft.azure.management.compute.VirtualMachineSizeTypes;
import com.microsoft.azure.management.network.NetworkInterface;
import com.microsoft.azure.management.network.PublicIpAddress;
import com.microsoft.azure.management.network.PublicIPAddress;
import com.microsoft.azure.management.resources.fluentcore.arm.Region;
import com.microsoft.azure.management.resources.fluentcore.utils.SdkContext;
import com.microsoft.azure.management.samples.Utils;
Expand All @@ -37,10 +36,10 @@ public final class ManageIPAddress {
* @return true if sample runs successfully
*/
public static boolean runSample(Azure azure) {
final String publicIpAddressName1 = SdkContext.randomResourceName("pip1", 20);
final String publicIpAddressName2 = SdkContext.randomResourceName("pip2", 20);
final String publicIpAddressLeafDNS1 = SdkContext.randomResourceName("pip1", 20);
final String publicIpAddressLeafDNS2 = SdkContext.randomResourceName("pip2", 20);
final String publicIPAddressName1 = SdkContext.randomResourceName("pip1", 20);
final String publicIPAddressName2 = SdkContext.randomResourceName("pip2", 20);
final String publicIPAddressLeafDNS1 = SdkContext.randomResourceName("pip1", 20);
final String publicIPAddressLeafDNS2 = SdkContext.randomResourceName("pip2", 20);
final String vmName = SdkContext.randomResourceName("vm", 8);
final String rgName = SdkContext.randomResourceName("rgNEMP", 24);
final String userName = "tirekicker";
Expand All @@ -55,16 +54,16 @@ public static boolean runSample(Azure azure) {

System.out.println("Creating a public IP address...");

PublicIpAddress publicIpAddress = azure.publicIpAddresses().define(publicIpAddressName1)
PublicIPAddress publicIPAddress = azure.publicIPAddresses().define(publicIPAddressName1)
.withRegion(Region.US_EAST)
.withNewResourceGroup(rgName)
.withLeafDomainLabel(publicIpAddressLeafDNS1)
.withLeafDomainLabel(publicIPAddressLeafDNS1)
.create();

System.out.println("Created a public IP address");

// Print public IP address details
Utils.print(publicIpAddress);
Utils.print(publicIPAddress);

// Use the pre-created public IP for the new VM

Expand All @@ -76,8 +75,8 @@ public static boolean runSample(Azure azure) {
.withRegion(Region.US_EAST)
.withExistingResourceGroup(rgName)
.withNewPrimaryNetwork("10.0.0.0/28")
.withPrimaryPrivateIpAddressDynamic()
.withExistingPrimaryPublicIpAddress(publicIpAddress)
.withPrimaryPrivateIPAddressDynamic()
.withExistingPrimaryPublicIPAddress(publicIPAddress)
.withPopularWindowsImage(KnownWindowsVirtualMachineImage.WINDOWS_SERVER_2012_R2_DATACENTER)
.withAdminUsername(userName)
.withAdminPassword(password)
Expand All @@ -96,18 +95,18 @@ public static boolean runSample(Azure azure) {

System.out.println("Public IP address associated with the VM's primary NIC [After create]");
// Print the public IP address details
Utils.print(vm.getPrimaryPublicIpAddress());
Utils.print(vm.getPrimaryPublicIPAddress());


//============================================================
// Assign a new public IP address for the VM

// Define a new public IP address

PublicIpAddress publicIpAddress2 = azure.publicIpAddresses().define(publicIpAddressName2)
PublicIPAddress publicIPAddress2 = azure.publicIPAddresses().define(publicIPAddressName2)
.withRegion(Region.US_EAST)
.withNewResourceGroup(rgName)
.withLeafDomainLabel(publicIpAddressLeafDNS2)
.withLeafDomainLabel(publicIPAddressLeafDNS2)
.create();

// Update VM's primary NIC to use the new public IP address
Expand All @@ -116,7 +115,7 @@ public static boolean runSample(Azure azure) {

NetworkInterface primaryNetworkInterface = vm.getPrimaryNetworkInterface();
primaryNetworkInterface.update()
.withExistingPrimaryPublicIpAddress(publicIpAddress2)
.withExistingPrimaryPublicIPAddress(publicIPAddress2)
.apply();


Expand All @@ -126,7 +125,7 @@ public static boolean runSample(Azure azure) {
// Get the associated public IP address for a virtual machine
System.out.println("Public IP address associated with the VM's primary NIC [After Update]");
vm.refresh();
Utils.print(vm.getPrimaryPublicIpAddress());
Utils.print(vm.getPrimaryPublicIPAddress());


//============================================================
Expand All @@ -135,9 +134,9 @@ public static boolean runSample(Azure azure) {
System.out.println("Removing public IP address associated with the VM");
vm.refresh();
primaryNetworkInterface = vm.getPrimaryNetworkInterface();
publicIpAddress = primaryNetworkInterface.primaryIpConfiguration().getPublicIpAddress();
publicIPAddress = primaryNetworkInterface.primaryIPConfiguration().getPublicIPAddress();
primaryNetworkInterface.update()
.withoutPrimaryPublicIpAddress()
.withoutPrimaryPublicIPAddress()
.apply();

System.out.println("Removed public IP address associated with the VM");
Expand All @@ -146,7 +145,7 @@ public static boolean runSample(Azure azure) {
//============================================================
// Delete the public ip
System.out.println("Deleting the public IP address");
azure.publicIpAddresses().deleteById(publicIpAddress.id());
azure.publicIPAddresses().deleteById(publicIPAddress.id());
System.out.println("Deleted the public IP address");
return true;
} catch (Exception e) {
Expand Down
Loading

0 comments on commit e594c47

Please sign in to comment.