Search in sources :

Example 1 with StorageProfile

use of com.microsoft.azure.management.compute.StorageProfile 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 StorageProfile

use of com.microsoft.azure.management.compute.StorageProfile 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 StorageProfile

use of com.microsoft.azure.management.compute.StorageProfile in project cloudbreak by hortonworks.

the class AzureResourceConnector method collectRemovableDisks.

private void collectRemovableDisks(Map<String, Object> resourcesToRemove, VirtualMachine virtualMachine) {
    StorageProfile storageProfile = virtualMachine.storageProfile();
    List<DataDisk> dataDisks = storageProfile.dataDisks();
    Collection<String> storageProfileDiskNames = new ArrayList<>();
    Collection<String> managedDiskIds = new ArrayList<>();
    for (DataDisk datadisk : dataDisks) {
        VirtualHardDisk vhd = datadisk.vhd();
        if (datadisk.vhd() != null) {
            storageProfileDiskNames.add(getNameFromConnectionString(vhd.uri()));
        } else {
            managedDiskIds.add(datadisk.managedDisk().id());
        }
    }
    OSDisk osDisk = storageProfile.osDisk();
    if (osDisk.vhd() != null) {
        VirtualHardDisk vhd = osDisk.vhd();
        storageProfileDiskNames.add(getNameFromConnectionString(vhd.uri()));
    } else {
        managedDiskIds.add(osDisk.managedDisk().id());
    }
    resourcesToRemove.put(STORAGE_PROFILE_DISK_NAMES, storageProfileDiskNames);
    resourcesToRemove.put(MANAGED_DISK_IDS, managedDiskIds);
}
Also used : StorageProfile(com.microsoft.azure.management.compute.StorageProfile) OSDisk(com.microsoft.azure.management.compute.OSDisk) DataDisk(com.microsoft.azure.management.compute.DataDisk) ArrayList(java.util.ArrayList) VirtualHardDisk(com.microsoft.azure.management.compute.VirtualHardDisk)

Example 4 with StorageProfile

use of com.microsoft.azure.management.compute.StorageProfile 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 5 with StorageProfile

use of com.microsoft.azure.management.compute.StorageProfile 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)6 StorageProfile (com.microsoft.azure.management.compute.StorageProfile)6 OSProfile (com.microsoft.azure.management.compute.OSProfile)3 VirtualHardDisk (com.microsoft.azure.management.compute.VirtualHardDisk)3 DataDisk (com.microsoft.azure.management.compute.DataDisk)2 HardwareProfile (com.microsoft.azure.management.compute.HardwareProfile)2 NetworkProfile (com.microsoft.azure.management.compute.NetworkProfile)2 ArrayList (java.util.ArrayList)2 CloudError (com.microsoft.azure.CloudError)1 CloudException (com.microsoft.azure.CloudException)1 SubResource (com.microsoft.azure.SubResource)1 ApplicationTokenCredentials (com.microsoft.azure.credentials.ApplicationTokenCredentials)1 AvailabilitySet (com.microsoft.azure.management.compute.AvailabilitySet)1 AvailabilitySetSkuTypes (com.microsoft.azure.management.compute.AvailabilitySetSkuTypes)1 CachingTypes (com.microsoft.azure.management.compute.CachingTypes)1 Disk (com.microsoft.azure.management.compute.Disk)1 DiskCreateOptionTypes (com.microsoft.azure.management.compute.DiskCreateOptionTypes)1 LinuxConfiguration (com.microsoft.azure.management.compute.LinuxConfiguration)1 StorageAccountTypes (com.microsoft.azure.management.compute.StorageAccountTypes)1 VirtualMachine (com.microsoft.azure.management.compute.VirtualMachine)1