Skip to content

Commit

Permalink
Updates based on offline review
Browse files Browse the repository at this point in the history
  • Loading branch information
anuchandy committed Oct 20, 2016
1 parent 496a4cc commit 65acd9b
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 22 deletions.
Expand Up @@ -166,14 +166,14 @@ interface WithAutoUpgradeMinorVersion<ParentT> {
*
* @return the next stage of the definition
*/
WithAttach<ParentT> withAutoUpgradeMinorVersionEnabled();
WithAttach<ParentT> withMinorVersionAutoUpgrade();

/**
* disables auto upgrade of the extension.
*
* @return the next stage of the definition
*/
WithAttach<ParentT> withAutoUpgradeMinorVersionDisabled();
WithAttach<ParentT> withoutMinorVersionAutoUpgrade();
}

/**
Expand Down Expand Up @@ -357,14 +357,14 @@ interface WithAutoUpgradeMinorVersion<ParentT> {
*
* @return the next stage of the definition
*/
WithAttach<ParentT> withAutoUpgradeMinorVersionEnabled();
WithAttach<ParentT> withMinorVersionAutoUpgrade();

/**
* disables auto upgrade of the extension.
*
* @return the next stage of the definition
*/
WithAttach<ParentT> withAutoUpgradeMinorVersionDisabled();
WithAttach<ParentT> withoutMinorVersionAutoUpgrade();
}

/**
Expand Down Expand Up @@ -458,14 +458,14 @@ interface WithAutoUpgradeMinorVersion {
*
* @return the next stage of the update
*/
Update withAutoUpgradeMinorVersionEnabled();
Update withMinorVersionAutoUpgrade();

/**
* enables auto upgrade of the extension.
*
* @return the next stage of the update
*/
Update withAutoUpgradeMinorVersionDisabled();
Update withoutMinorVersionAutoUpgrade();
}

/**
Expand Down
Expand Up @@ -109,13 +109,13 @@ public String provisioningState() {
}

@Override
public VirtualMachineExtensionImpl withAutoUpgradeMinorVersionEnabled() {
public VirtualMachineExtensionImpl withMinorVersionAutoUpgrade() {
this.inner().withAutoUpgradeMinorVersion(true);
return this;
}

@Override
public VirtualMachineExtensionImpl withAutoUpgradeMinorVersionDisabled() {
public VirtualMachineExtensionImpl withoutMinorVersionAutoUpgrade() {
this.inner().withAutoUpgradeMinorVersion(false);
return this;
}
Expand Down
Expand Up @@ -149,7 +149,7 @@ public void canInstallUninstallCustomExtension() throws Exception {
.withPublisher("Microsoft.OSTCExtensions")
.withType("CustomScriptForLinux")
.withVersion("1.4")
.withAutoUpgradeMinorVersionEnabled()
.withMinorVersionAutoUpgrade()
.withPublicSetting("fileUris",fileUris)
.withPublicSetting("commandToExecute", installCommand)
.attach()
Expand Down
Expand Up @@ -14,18 +14,20 @@

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

/**
* Azure Compute sample for managing virtual machines -
* - Create a virtual machine
* - Stop a virtual machine
* - Deallocate the virtual machine
* - Capture the virtual machine to get a captured image
* - Create a second virtual machine using the captured image
* - Generalize the virtual machine
* - Capture the virtual machine to create a generalized image
* - Create a second virtual machine using the generalized image
* - Delete the second virtual machine
* - Create a new virtual machine by attaching OS disk of deleted VM to it.
*/
public final class VirtualMachinesFromCustomImageAndSpecializedVHD {
public final class CreateVirtualMachinesUsingCustomImageOrSpecializedVHD {
/**
* Main entry point.
* @param args the parameters
Expand All @@ -40,6 +42,11 @@ public static void main(String[] args) {
final String userName = "tirekicker";
final String password = "12NewPA$$w0rd!";

final String apacheInstallScript = "https://raw.githubusercontent.com/Azure/azure-sdk-for-java/master/azure-samples/src/main/resources/install_apache.sh";
final String apacheInstallCommand = "bash install_apache.sh";
List<String> apacheInstallScriptUris = new ArrayList<>();
apacheInstallScriptUris.add(apacheInstallScript);

try {

//=============================================================
Expand All @@ -58,7 +65,7 @@ public static void main(String[] args) {

try {
//=============================================================
// Create a Linux VM using an image from PIT (Platform Image Repository)
// Create a Linux VM using an image from PIR (Platform Image Repository)

System.out.println("Creating a Linux VM");

Expand All @@ -72,14 +79,22 @@ public static void main(String[] args) {
.withRootUserName(userName)
.withPassword(password)
.withSize(VirtualMachineSizeTypes.STANDARD_D3_V2)
.defineNewExtension("CustomScriptForLinux")
.withPublisher("Microsoft.OSTCExtensions")
.withType("CustomScriptForLinux")
.withVersion("1.4")
.withMinorVersionAutoUpgrade()
.withPublicSetting("fileUris", apacheInstallScriptUris)
.withPublicSetting("commandToExecute", apacheInstallCommand)
.attach()
.create();

System.out.println("Created a Linux VM: " + linuxVM.id());
Utils.print(linuxVM);

System.out.println("Please SSH into the VM [" + linuxVM.getPrimaryPublicIpAddress().fqdn() + "]");
System.out.println("SSH into the VM [" + linuxVM.getPrimaryPublicIpAddress().fqdn() + "]");
System.out.println("and run 'sudo waagent -deprovision+user' to prepare it for capturing");
System.out.println("after that please 'Enter' to continue.");
System.out.println("after that press 'Enter' to continue.");
System.in.read();

//=============================================================
Expand All @@ -99,15 +114,15 @@ public static void main(String[] args) {
System.out.println("Generalized VM: " + linuxVM.id());

//=============================================================
// Capture the virtual machine
// Capture the virtual machine to get a 'Generalized image' with Apache
System.out.println("Capturing VM: " + linuxVM.id());

String capturedResultJson = linuxVM.capture("capturedvhds", "img", true);

System.out.println("Captured VM: " + linuxVM.id());

//=============================================================
// Create a Linux VM using captured image
// Create a Linux VM using captured image (Generalized image)
String capturedImageUri = extractCapturedImageUri(capturedResultJson);

System.out.println("Creating a Linux VM using captured image - " + capturedImageUri);
Expand All @@ -118,7 +133,7 @@ public static void main(String[] args) {
.withNewPrimaryNetwork("10.0.0.0/28")
.withPrimaryPrivateIpAddressDynamic()
.withoutPrimaryPublicIpAddress()
.withStoredLinuxImage(capturedImageUri) // Note: A URI to generalized VHD is also considered as stored image
.withStoredLinuxImage(capturedImageUri) // Note: A Generalized Image can also be an uploaded VHD prepared from an on-premise generalized VM.
.withRootUserName(userName)
.withPassword(password)
.withSize(VirtualMachineSizeTypes.STANDARD_D3_V2)
Expand Down Expand Up @@ -178,7 +193,7 @@ public static void main(String[] args) {
}
}

private VirtualMachinesFromCustomImageAndSpecializedVHD() {
private CreateVirtualMachinesUsingCustomImageOrSpecializedVHD() {
}

private static String extractCapturedImageUri(String capturedResultJson) {
Expand Down
Expand Up @@ -191,7 +191,7 @@ public static void main(String[] args) {
.withPublisher(linuxCustomScriptExtensionPublisherName)
.withType(linuxCustomScriptExtensionTypeName)
.withVersion(linuxCustomScriptExtensionVersionName)
.withAutoUpgradeMinorVersionEnabled()
.withMinorVersionAutoUpgrade()
.withPublicSetting("fileUris", linuxScriptFileUris)
.withPublicSetting("commandToExecute", installMySQLLinuxCommand)
.attach()
Expand Down Expand Up @@ -229,7 +229,7 @@ public static void main(String[] args) {
.withPublisher(windowsCustomScriptExtensionPublisherName)
.withType(windowsCustomScriptExtensionTypeName)
.withVersion(windowsCustomScriptExtensionVersionName)
.withAutoUpgradeMinorVersionEnabled()
.withMinorVersionAutoUpgrade()
.withPublicSetting("fileUris", windowsScriptFileUris)
.withPublicSetting("commandToExecute", installMySQLWindowsCommand)
.attach()
Expand Down

0 comments on commit 65acd9b

Please sign in to comment.