public async Task CreateDisk() { #region Snippet:Managing_Disks_CreateADisk ArmClient armClient = new ArmClient(new DefaultAzureCredential()); Subscription subscription = armClient.DefaultSubscription; // first we need to get the resource group string rgName = "myRgName"; ResourceGroup resourceGroup = await subscription.GetResourceGroups().GetAsync(rgName); // Now we get the virtual machine container from the resource group DiskContainer diskContainer = resourceGroup.GetDisks(); // Use the same location as the resource group string diskName = "myDisk"; var input = new DiskData(resourceGroup.Data.Location) { Sku = new DiskSku() { Name = DiskStorageAccountTypes.StandardLRS }, CreationData = new CreationData(DiskCreateOption.Empty), DiskSizeGB = 1, }; DiskCreateOrUpdateOperation lro = await diskContainer.CreateOrUpdateAsync(diskName, input); Disk disk = lro.Value; #endregion Snippet:Managing_Disks_CreateADisk }
public virtual DiskCreateOrUpdateOperation CreateOrUpdate(string diskName, DiskData disk, bool waitForCompletion = true, CancellationToken cancellationToken = default) { if (diskName == null) { throw new ArgumentNullException(nameof(diskName)); } if (disk == null) { throw new ArgumentNullException(nameof(disk)); } using var scope = _clientDiagnostics.CreateScope("DiskContainer.CreateOrUpdate"); scope.Start(); try { var response = _restClient.CreateOrUpdate(Id.ResourceGroupName, diskName, disk, cancellationToken); var operation = new DiskCreateOrUpdateOperation(Parent, _clientDiagnostics, Pipeline, _restClient.CreateCreateOrUpdateRequest(Id.ResourceGroupName, diskName, disk).Request, response); if (waitForCompletion) { operation.WaitForCompletion(cancellationToken); } return(operation); } catch (Exception e) { scope.Failed(e); throw; } }
public async virtual Task <DiskCreateOrUpdateOperation> CreateOrUpdateAsync(bool waitForCompletion, string diskName, DiskData disk, CancellationToken cancellationToken = default) { if (diskName == null) { throw new ArgumentNullException(nameof(diskName)); } if (disk == null) { throw new ArgumentNullException(nameof(disk)); } using var scope = _clientDiagnostics.CreateScope("DiskCollection.CreateOrUpdate"); scope.Start(); try { var response = await _disksRestClient.CreateOrUpdateAsync(Id.SubscriptionId, Id.ResourceGroupName, diskName, disk, cancellationToken).ConfigureAwait(false); var operation = new DiskCreateOrUpdateOperation(this, _clientDiagnostics, Pipeline, _disksRestClient.CreateCreateOrUpdateRequest(Id.SubscriptionId, Id.ResourceGroupName, diskName, disk).Request, response); if (waitForCompletion) { await operation.WaitForCompletionAsync(cancellationToken).ConfigureAwait(false); } return(operation); } catch (Exception e) { scope.Failed(e); throw; } }
public virtual DiskCreateOrUpdateOperation CreateOrUpdate(bool waitForCompletion, string diskName, DiskData disk, CancellationToken cancellationToken = default) { Argument.AssertNotNullOrEmpty(diskName, nameof(diskName)); if (disk == null) { throw new ArgumentNullException(nameof(disk)); } using var scope = _diskClientDiagnostics.CreateScope("DiskCollection.CreateOrUpdate"); scope.Start(); try { var response = _diskRestClient.CreateOrUpdate(Id.SubscriptionId, Id.ResourceGroupName, diskName, disk, cancellationToken); var operation = new DiskCreateOrUpdateOperation(ArmClient, _diskClientDiagnostics, Pipeline, _diskRestClient.CreateCreateOrUpdateRequest(Id.SubscriptionId, Id.ResourceGroupName, diskName, disk).Request, response); if (waitForCompletion) { operation.WaitForCompletion(cancellationToken); } return(operation); } catch (Exception e) { scope.Failed(e); throw; } }