Search in sources :

Example 1 with OSDisk

use of com.microsoft.azure.management.compute.OSDisk in project azure-sdk-for-java by Azure.

the class VirtualMachinesImpl method wrapModel.

// Helper methods
@Override
protected VirtualMachineImpl wrapModel(String name) {
    VirtualMachineInner inner = new VirtualMachineInner();
    inner.withStorageProfile(new StorageProfile().withOsDisk(new OSDisk()).withDataDisks(new ArrayList<DataDisk>()));
    inner.withOsProfile(new OSProfile());
    inner.withHardwareProfile(new HardwareProfile());
    inner.withNetworkProfile(new NetworkProfile().withNetworkInterfaces(new ArrayList<NetworkInterfaceReferenceInner>()));
    return new VirtualMachineImpl(name, inner, this.manager(), this.storageManager, this.networkManager);
}
Also used : StorageProfile(com.microsoft.azure.management.compute.StorageProfile) OSDisk(com.microsoft.azure.management.compute.OSDisk) NetworkProfile(com.microsoft.azure.management.compute.NetworkProfile) OSProfile(com.microsoft.azure.management.compute.OSProfile) HardwareProfile(com.microsoft.azure.management.compute.HardwareProfile) ArrayList(java.util.ArrayList)

Example 2 with OSDisk

use of com.microsoft.azure.management.compute.OSDisk in project azure-sdk-for-java by Azure.

the class VirtualMachineImpl method setOSProfileDefaults.

private void setOSProfileDefaults() {
    if (isInUpdateMode()) {
        return;
    }
    StorageProfile storageProfile = this.inner().storageProfile();
    OSDisk osDisk = storageProfile.osDisk();
    if (isOSDiskFromImage(osDisk)) {
        //
        if (osDisk.osType() == OperatingSystemTypes.LINUX || this.isMarketplaceLinuxImage) {
            // linux image: PlatformImage | CustomImage | StoredImage
            //
            OSProfile osProfile = this.inner().osProfile();
            if (osProfile.linuxConfiguration() == null) {
                osProfile.withLinuxConfiguration(new LinuxConfiguration());
            }
            this.inner().osProfile().linuxConfiguration().withDisablePasswordAuthentication(osProfile.adminPassword() == null);
        }
        if (this.inner().osProfile().computerName() == null) {
            //
            if (vmName.matches("[0-9]+")) {
                this.inner().osProfile().withComputerName(SdkContext.randomResourceName("vm", 15));
            } else if (vmName.length() <= 15) {
                this.inner().osProfile().withComputerName(vmName);
            } else {
                this.inner().osProfile().withComputerName(SdkContext.randomResourceName("vm", 15));
            }
        }
    } else {
        // ODDisk CreateOption: ATTACH
        //
        // OS Profile must be set to null when an VM's OS disk is ATTACH-ed to a managed disk or
        // Specialized VHD
        //
        this.inner().withOsProfile(null);
    }
}
Also used : StorageProfile(com.microsoft.azure.management.compute.StorageProfile) OSDisk(com.microsoft.azure.management.compute.OSDisk) OSProfile(com.microsoft.azure.management.compute.OSProfile) LinuxConfiguration(com.microsoft.azure.management.compute.LinuxConfiguration)

Example 3 with OSDisk

use of com.microsoft.azure.management.compute.OSDisk in project azure-sdk-for-java by Azure.

the class VirtualMachineImpl method withOSDiskVhdLocation.

@Override
public VirtualMachineImpl withOSDiskVhdLocation(String containerName, String vhdName) {
    //
    if (isManagedDiskEnabled()) {
        return this;
    }
    StorageProfile storageProfile = this.inner().storageProfile();
    OSDisk osDisk = storageProfile.osDisk();
    //
    if (!this.isOSDiskFromImage(osDisk)) {
        return this;
    }
    //
    if (this.isOsDiskFromCustomImage(storageProfile)) {
        return this;
    }
    //
    if (this.isOSDiskFromPlatformImage(storageProfile)) {
        VirtualHardDisk osVhd = new VirtualHardDisk();
        osVhd.withUri(temporaryBlobUrl(containerName, vhdName));
        this.inner().storageProfile().osDisk().withVhd(osVhd);
        return this;
    }
    // as the image.
    if (this.isOSDiskFromStoredImage(storageProfile)) {
        VirtualHardDisk osVhd = new VirtualHardDisk();
        try {
            URL sourceCustomImageUrl = new URL(osDisk.image().uri());
            URL destinationVhdUrl = new URL(sourceCustomImageUrl.getProtocol(), sourceCustomImageUrl.getHost(), "/" + containerName + "/" + vhdName);
            osVhd.withUri(destinationVhdUrl.toString());
        } catch (MalformedURLException ex) {
            throw new RuntimeException(ex);
        }
        this.inner().storageProfile().osDisk().withVhd(osVhd);
    }
    return this;
}
Also used : StorageProfile(com.microsoft.azure.management.compute.StorageProfile) OSDisk(com.microsoft.azure.management.compute.OSDisk) MalformedURLException(java.net.MalformedURLException) VirtualHardDisk(com.microsoft.azure.management.compute.VirtualHardDisk) URL(java.net.URL)

Example 4 with OSDisk

use of com.microsoft.azure.management.compute.OSDisk in project azure-sdk-for-java by Azure.

the class VirtualMachineImpl method setOSDiskDefaults.

private void setOSDiskDefaults() {
    if (isInUpdateMode()) {
        return;
    }
    StorageProfile storageProfile = this.inner().storageProfile();
    OSDisk osDisk = storageProfile.osDisk();
    if (isOSDiskFromImage(osDisk)) {
        //
        if (isManagedDiskEnabled()) {
            //
            if (osDisk.managedDisk() == null) {
                osDisk.withManagedDisk(new ManagedDiskParametersInner());
            }
            if (osDisk.managedDisk().storageAccountType() == null) {
                osDisk.managedDisk().withStorageAccountType(StorageAccountTypes.STANDARD_LRS);
            }
            osDisk.withVhd(null);
        // We won't set osDisk.name() explicitly for managed disk, if it is null CRP generates unique
        // name for the disk resource within the resource group.
        } else {
            //
            if (isOSDiskFromPlatformImage(storageProfile) || isOSDiskFromStoredImage(storageProfile)) {
                if (osDisk.vhd() == null) {
                    String osDiskVhdContainerName = "vhds";
                    String osDiskVhdName = this.vmName + "-os-disk-" + UUID.randomUUID().toString() + ".vhd";
                    withOSDiskVhdLocation(osDiskVhdContainerName, osDiskVhdName);
                }
                osDisk.withManagedDisk(null);
            }
            if (osDisk.name() == null) {
                withOSDiskName(this.vmName + "-os-disk");
            }
        }
    } else {
        //
        if (isManagedDiskEnabled()) {
            //
            if (osDisk.managedDisk() != null) {
                osDisk.managedDisk().withStorageAccountType(null);
            }
            osDisk.withVhd(null);
        } else {
            osDisk.withManagedDisk(null);
            if (osDisk.name() == null) {
                withOSDiskName(this.vmName + "-os-disk");
            }
        }
    }
    if (osDisk.caching() == null) {
        withOSDiskCaching(CachingTypes.READ_WRITE);
    }
}
Also used : StorageProfile(com.microsoft.azure.management.compute.StorageProfile) OSDisk(com.microsoft.azure.management.compute.OSDisk)

Aggregations

OSDisk (com.microsoft.azure.management.compute.OSDisk)4 StorageProfile (com.microsoft.azure.management.compute.StorageProfile)4 OSProfile (com.microsoft.azure.management.compute.OSProfile)2 HardwareProfile (com.microsoft.azure.management.compute.HardwareProfile)1 LinuxConfiguration (com.microsoft.azure.management.compute.LinuxConfiguration)1 NetworkProfile (com.microsoft.azure.management.compute.NetworkProfile)1 VirtualHardDisk (com.microsoft.azure.management.compute.VirtualHardDisk)1 MalformedURLException (java.net.MalformedURLException)1 URL (java.net.URL)1 ArrayList (java.util.ArrayList)1