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);
}
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);
}
}
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);
}
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;
}
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);
}
}
Aggregations