Java Code Examples for com.microsoft.azure.management.compute.VirtualMachine#deallocate()

The following examples show how to use com.microsoft.azure.management.compute.VirtualMachine#deallocate() . 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: AzureTests.java    From azure-libraries-for-java with MIT License 5 votes vote down vote up
@Test
public void testManagedDiskVMUpdate() throws Exception {
    final String rgName = SdkContext.randomResourceName("rg", 13);
    final String linuxVM2Name = SdkContext.randomResourceName("vm" + "-", 10);
    final String linuxVM2Pip = SdkContext.randomResourceName("pip" + "-", 18);
    VirtualMachine linuxVM2 = azure.virtualMachines().define(linuxVM2Name)
            .withRegion(Region.US_EAST)
            .withNewResourceGroup(rgName)
            .withNewPrimaryNetwork("10.0.0.0/28")
            .withPrimaryPrivateIPAddressDynamic()
            .withNewPrimaryPublicIPAddress(linuxVM2Pip)
            .withPopularLinuxImage(KnownLinuxVirtualMachineImage.UBUNTU_SERVER_16_04_LTS)
            .withRootUsername("tester")
            .withRootPassword("Abcdef.123456!")
            // Begin: Managed data disks
            .withNewDataDisk(100)
            .withNewDataDisk(100, 1, CachingTypes.READ_WRITE)
            // End: Managed data disks
            .withSize(VirtualMachineSizeTypes.STANDARD_D3_V2)
            .create();

    linuxVM2.deallocate();
    linuxVM2.update()
            .withoutDataDisk(2)
            .withNewDataDisk(200)
            .apply();
    azure.resourceGroups().beginDeleteByName(rgName);
}
 
Example 2
Source File: TestVirtualMachineNics.java    From azure-libraries-for-java with MIT License 5 votes vote down vote up
@Override
public VirtualMachine updateResource(VirtualMachine virtualMachine) throws Exception {
    final String secondaryNicName = "nic" + this.testId;
    virtualMachine.powerOff();
    virtualMachine.deallocate();
    virtualMachine = virtualMachine.update()
            .withoutSecondaryNetworkInterface(secondaryNicName)
            .apply();

    Assert.assertTrue(virtualMachine.networkInterfaceIds().size() == 2);
    return virtualMachine;
}
 
Example 3
Source File: ManageManagedDisks.java    From azure-libraries-for-java with MIT License 5 votes vote down vote up
private static VirtualMachine prepareSpecializedUnmanagedVirtualMachine(Azure azure, Region region, String rgName) {
    final String userName = "tirekicker";
    // [SuppressMessage("Microsoft.Security", "CS002:SecretInNextLine", Justification="Serves as an example, not for deployment. Please change when using this in your code.")]
    final String password = "12NewPA$$w0rd!";
    final String linuxVMName1 = SdkContext.randomResourceName("vm" + "-", 10);
    final String publicIpDnsLabel = SdkContext.randomResourceName("pip" + "-", 20);

    VirtualMachine linuxVM = azure.virtualMachines().define(linuxVMName1)
            .withRegion(region)
            .withNewResourceGroup(rgName)
            .withNewPrimaryNetwork("10.0.0.0/28")
            .withPrimaryPrivateIPAddressDynamic()
            .withNewPrimaryPublicIPAddress(publicIpDnsLabel)
            .withPopularLinuxImage(KnownLinuxVirtualMachineImage.UBUNTU_SERVER_16_04_LTS)
            .withRootUsername(userName)
            .withRootPassword(password)
            .withUnmanagedDisks()
            .defineUnmanagedDataDisk("disk-1")
                .withNewVhd(100)
                .withLun(1)
                .attach()
            .defineUnmanagedDataDisk("disk-2")
                .withNewVhd(50)
                .withLun(2)
                .attach()
            .withSize(VirtualMachineSizeTypes.STANDARD_D3_V2)
            .create();

    // De-provision the virtual machine
    deprovisionAgentInLinuxVM(linuxVM.getPrimaryPublicIPAddress().fqdn(), 22, userName, password);
    System.out.println("Deallocate VM: " + linuxVM.id());
    linuxVM.deallocate();
    System.out.println("Deallocated VM: " + linuxVM.id() + "; state = " + linuxVM.powerState());
    System.out.println("Generalize VM: " + linuxVM.id());
    linuxVM.generalize();
    System.out.println("Generalized VM: " + linuxVM.id());
    return linuxVM;
}
 
Example 4
Source File: ManageManagedDisks.java    From azure-libraries-for-java with MIT License 5 votes vote down vote up
private static VirtualMachine prepareSpecializedManagedVirtualMachine(Azure azure, Region region, String rgName) {
    final String userName = "tirekicker";
    // [SuppressMessage("Microsoft.Security", "CS002:SecretInNextLine", Justification="Serves as an example, not for deployment. Please change when using this in your code.")]
    final String password = "12NewPA$$w0rd!";
    final String linuxVMName1 = SdkContext.randomResourceName("vm" + "-", 10);
    final String publicIPDnsLabel = SdkContext.randomResourceName("pip" + "-", 20);

    VirtualMachine linuxVM = azure.virtualMachines().define(linuxVMName1)
            .withRegion(region)
            .withNewResourceGroup(rgName)
            .withNewPrimaryNetwork("10.0.0.0/28")
            .withPrimaryPrivateIPAddressDynamic()
            .withNewPrimaryPublicIPAddress(publicIPDnsLabel)
            .withPopularLinuxImage(KnownLinuxVirtualMachineImage.UBUNTU_SERVER_16_04_LTS)
            .withRootUsername(userName)
            .withRootPassword(password)
            .withNewDataDisk(100)
            .withNewDataDisk(200)
            .withSize(VirtualMachineSizeTypes.STANDARD_D3_V2)
            .create();

    // De-provision the virtual machine
    deprovisionAgentInLinuxVM(linuxVM.getPrimaryPublicIPAddress().fqdn(), 22, userName, password);
    System.out.println("Deallocate VM: " + linuxVM.id());
    linuxVM.deallocate();
    System.out.println("Deallocated VM: " + linuxVM.id() + "; state = " + linuxVM.powerState());
    System.out.println("Generalize VM: " + linuxVM.id());
    linuxVM.generalize();
    System.out.println("Generalized VM: " + linuxVM.id());
    return linuxVM;
}
 
Example 5
Source File: ConvertVirtualMachineToManagedDisks.java    From azure-libraries-for-java with MIT License 4 votes vote down vote up
/**
 * Main function which runs the actual sample.
 *
 * @param azure instance of the azure client
 * @return true if sample runs successfully
 */
public static boolean runSample(Azure azure) {
    final String linuxVMName = Utils.createRandomName("VM1");
    final String rgName = Utils.createRandomName("rgCOMV");
    final String userName = "tirekicker";
    // [SuppressMessage("Microsoft.Security", "CS002:SecretInNextLine", Justification="Serves as an example, not for deployment. Please change when using this in your code.")]
    final String password = "12NewPA$$w0rd!";
    final Region region = Region.US_WEST_CENTRAL;

    try {
        //=============================================================
        // Create a Linux VM using a PIR image with un-managed OS and data disks

        System.out.println("Creating an un-managed Linux VM");

        VirtualMachine linuxVM = azure.virtualMachines().define(linuxVMName)
                .withRegion(region)
                .withNewResourceGroup(rgName)
                .withNewPrimaryNetwork("10.0.0.0/28")
                .withPrimaryPrivateIPAddressDynamic()
                .withoutPrimaryPublicIPAddress()
                .withPopularLinuxImage(KnownLinuxVirtualMachineImage.UBUNTU_SERVER_16_04_LTS)
                .withRootUsername(userName)
                .withRootPassword(password)
                .withUnmanagedDisks()
                .defineUnmanagedDataDisk("disk-1")
                    .withNewVhd(100)
                    .withLun(1)
                    .attach()
                .defineUnmanagedDataDisk("disk-2")
                    .withNewVhd(50)
                    .withLun(2)
                    .attach()
                .withSize(VirtualMachineSizeTypes.STANDARD_D3_V2)
                .create();

        System.out.println("Created a Linux VM with un-managed OS and data disks: " + linuxVM.id());
        Utils.print(linuxVM);

        //=============================================================
        // Deallocate the virtual machine
        System.out.println("Deallocate VM: " + linuxVM.id());

        linuxVM.deallocate();

        System.out.println("De-allocated VM: " + linuxVM.id() + "; state = " + linuxVM.powerState());

        //=============================================================
        // Migrate the virtual machine
        System.out.println("Migrate VM: " + linuxVM.id());

        linuxVM.convertToManaged();

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

        Utils.print(linuxVM);

        return true;
    } catch (Exception f) {
        System.out.println(f.getMessage());
        f.printStackTrace();
    } finally {
        try {
            System.out.println("Deleting Resource Group: " + rgName);
            azure.resourceGroups().deleteByName(rgName);
            System.out.println("Deleted Resource Group: " + rgName);
        } catch (NullPointerException npe) {
            System.out.println("Did not create any resources in Azure. No clean up is necessary");
        } catch (Exception g) {
            g.printStackTrace();
        }
    }

    return false;
}