use of com.microsoft.azure.management.compute.DataDisk in project azure-sdk-for-java by Azure.
the class VirtualMachineImpl method withExistingDataDisk.
@Override
public VirtualMachineImpl withExistingDataDisk(Disk disk, int newSizeInGB, int lun, CachingTypes cachingType) {
throwIfManagedDiskDisabled(ManagedUnmanagedDiskErrors.VM_BOTH_UNMANAGED_AND_MANAGED_DISK_NOT_ALLOWED);
ManagedDiskParametersInner managedDiskParameters = new ManagedDiskParametersInner();
managedDiskParameters.withId(disk.id());
this.managedDataDisks.existingDisksToAttach.add(new DataDisk().withLun(lun).withDiskSizeGB(newSizeInGB).withManagedDisk(managedDiskParameters).withCaching(cachingType));
return this;
}
use of com.microsoft.azure.management.compute.DataDisk in project azure-sdk-for-java by Azure.
the class UnmanagedDataDiskImpl method prepareDataDisk.
protected static UnmanagedDataDiskImpl prepareDataDisk(String name, VirtualMachineImpl parent) {
DataDisk dataDiskInner = new DataDisk();
dataDiskInner.withLun(-1).withName(name).withVhd(null);
return new UnmanagedDataDiskImpl(dataDiskInner, parent);
}
use of com.microsoft.azure.management.compute.DataDisk in project photon-model by vmware.
the class AzureComputeDiskDay2Service method updateDiskState.
/**
* Update status and LUN of DiskState
*/
private DeferredResult<Operation> updateDiskState(AzureComputeDiskDay2Context context) {
DiskState diskState = context.diskState;
if (context.request.operation.equals(ResourceOperation.ATTACH_DISK.operation)) {
diskState.status = DiskService.DiskStatus.ATTACHED;
} else if (context.request.operation.equals(ResourceOperation.DETACH_DISK.operation)) {
diskState.status = DiskService.DiskStatus.AVAILABLE;
diskState.customProperties.remove(DISK_CONTROLLER_NUMBER);
}
if (!context.request.isMockRequest) {
DataDisk dataDisk = context.provisionedVm.inner().storageProfile().dataDisks().stream().filter(dd -> diskState.name.equalsIgnoreCase(dd.name())).findFirst().orElse(null);
if (dataDisk != null) {
if (diskState.customProperties == null) {
diskState.customProperties = new HashMap<>();
}
diskState.customProperties.put(DISK_CONTROLLER_NUMBER, String.valueOf(dataDisk.lun()));
}
}
Operation diskPatchOp = null;
if (context.request.operation.equals(ResourceOperation.ATTACH_DISK.operation)) {
diskPatchOp = Operation.createPatch(createInventoryUri(this.getHost(), diskState.documentSelfLink)).setBody(diskState).setReferer(this.getUri());
} else if (context.request.operation.equals(ResourceOperation.DETACH_DISK.operation)) {
diskPatchOp = Operation.createPut(createInventoryUri(this.getHost(), diskState.documentSelfLink)).setBody(diskState).setReferer(this.getUri());
}
return this.sendWithDeferredResult(diskPatchOp);
}
use of com.microsoft.azure.management.compute.DataDisk in project photon-model by vmware.
the class AzureInstanceService method updateDiskStates.
/**
* Update {@code computeState.diskState[i].id} with Azure Disks' VHD URI.
*/
private DeferredResult<AzureInstanceContext> updateDiskStates(AzureInstanceContext ctx) {
if (ctx.provisionedVm == null) {
// Do nothing.
return DeferredResult.completed(ctx);
}
List<DeferredResult<Operation>> diskStateDRs = new ArrayList<>();
// Update boot DiskState with Azure osDisk VHD URI in case of unmanaged disks and
// disks id in case of managed disks
{
final OSDisk azureOsDisk = ctx.provisionedVm.storageProfile().osDisk();
final DiskState diskStateToUpdate = new DiskState();
diskStateToUpdate.documentSelfLink = ctx.bootDiskState.documentSelfLink;
diskStateToUpdate.persistent = ctx.bootDiskState.persistent;
diskStateToUpdate.regionId = ctx.provisionedVm.location();
diskStateToUpdate.endpointLink = ctx.endpoint.documentSelfLink;
AdapterUtils.addToEndpointLinks(diskStateToUpdate, ctx.endpoint.documentSelfLink);
// The actual value being updated
if (ctx.useManagedDisks()) {
diskStateToUpdate.id = azureOsDisk.managedDisk().id();
} else {
diskStateToUpdate.id = AzureUtils.canonizeId(azureOsDisk.vhd().uri());
}
diskStateToUpdate.status = DiskService.DiskStatus.ATTACHED;
Operation updateDiskState = Operation.createPatch(ctx.service, diskStateToUpdate.documentSelfLink).setBody(diskStateToUpdate);
DeferredResult<Operation> updateDR = ctx.service.sendWithDeferredResult(updateDiskState).whenComplete((op, exc) -> {
if (exc != null) {
logSevere(() -> String.format("Updating boot DiskState [%s] with VHD URI [%s]: FAILED with %s", ctx.bootDiskState.name, diskStateToUpdate.id, Utils.toString(exc)));
} else {
logFine(() -> String.format("Updating boot DiskState [%s] with VHD URI [%s]: SUCCESS", ctx.bootDiskState.name, diskStateToUpdate.id));
}
});
diskStateDRs.add(updateDR);
}
for (DataDisk azureDataDisk : ctx.provisionedVm.storageProfile().dataDisks()) {
// Find corresponding DiskState by name
Optional<DiskState> dataDiskOpt = ctx.dataDiskStates.stream().map(DiskState.class::cast).filter(dS -> azureDataDisk.name().equals(dS.name)).findFirst();
Optional<DiskState> externalDiskOpt = ctx.externalDataDisks.stream().map(DiskState.class::cast).filter(dS -> azureDataDisk.name().equals(dS.name)).findFirst();
// update disk state
if (dataDiskOpt.isPresent()) {
diskStateDRs.add(createDiskToUpdate(ctx, dataDiskOpt, azureDataDisk));
} else if (externalDiskOpt.isPresent()) {
diskStateDRs.add(createDiskToUpdate(ctx, externalDiskOpt, azureDataDisk));
} else {
// additional disks were created by the custom image. Will always be of
// managed disk type. Create new disk state.
DiskState diskStateToCreate = new DiskState();
diskStateToCreate.id = azureDataDisk.managedDisk().id();
diskStateToCreate.name = azureDataDisk.name();
diskStateToCreate.regionId = ctx.provisionedVm.location();
diskStateToCreate.customProperties = new HashMap<>();
diskStateToCreate.customProperties.put(DISK_CONTROLLER_NUMBER, String.valueOf(azureDataDisk.lun()));
if (azureDataDisk.managedDisk().storageAccountType() != null) {
diskStateToCreate.customProperties.put(AZURE_MANAGED_DISK_TYPE, azureDataDisk.managedDisk().storageAccountType().toString());
} else {
// set to Standard_LRS default
diskStateToCreate.customProperties.put(AZURE_MANAGED_DISK_TYPE, StorageAccountTypes.STANDARD_LRS.toString());
}
diskStateToCreate.customProperties.put(AZURE_DATA_DISK_CACHING, azureDataDisk.caching().toString());
if (azureDataDisk.diskSizeGB() != null) {
diskStateToCreate.capacityMBytes = azureDataDisk.diskSizeGB() * 1024;
}
diskStateToCreate.status = DiskService.DiskStatus.ATTACHED;
diskStateToCreate.persistent = ctx.bootDiskState.persistent;
diskStateToCreate.endpointLink = ctx.endpoint.documentSelfLink;
AdapterUtils.addToEndpointLinks(diskStateToCreate, ctx.endpoint.documentSelfLink);
Operation createDiskState = Operation.createPost(ctx.service, DiskService.FACTORY_LINK).setBody(diskStateToCreate);
DeferredResult<Operation> createDR = ctx.service.sendWithDeferredResult(createDiskState).whenComplete((op, exc) -> {
if (exc != null) {
logSevere(() -> String.format("Creating data DiskState [%s] with disk id [%s]: FAILED " + "with %s", azureDataDisk.name(), azureDataDisk.managedDisk().id(), Utils.toString(exc)));
} else {
logFine(() -> String.format("Creating data DiskState [%s] with disk id [%s]: SUCCESS", azureDataDisk.name(), azureDataDisk.managedDisk().id()));
// update compute state with data disks present on custom image
ComputeState cs = new ComputeState();
List<String> disksLinks = new ArrayList<>();
DiskState diskState = op.getBody(DiskState.class);
disksLinks.add(diskState.documentSelfLink);
cs.diskLinks = disksLinks;
Operation.CompletionHandler completionHandler = (ox, ex) -> {
if (ex != null) {
handleError(ctx, ex);
return;
}
};
sendRequest(Operation.createPatch(ctx.computeRequest.resourceReference).setBody(cs).setCompletion(completionHandler));
}
});
diskStateDRs.add(createDR);
}
}
return DeferredResult.allOf(diskStateDRs).thenApply(ignored -> ctx);
}
use of com.microsoft.azure.management.compute.DataDisk 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);
}
Aggregations