protected override void ProcessRecord() { ComputeAutomationAutoMapperProfile.Initialize(); ExecuteClientAction(() => { if (ShouldProcess(this.ResourceGroupName, VerbsData.Update)) { string resourceGroupName = this.ResourceGroupName; string snapshotName = this.SnapshotName; Snapshot snapshotObj = new Snapshot(); Mapper.Map <PSSnapshot, Snapshot>(this.Snapshot, snapshotObj); SnapshotUpdate snapshotUpdateObj = new SnapshotUpdate(); Mapper.Map <PSSnapshotUpdate, SnapshotUpdate>(this.SnapshotUpdate, snapshotUpdateObj); var result = (this.SnapshotUpdate == null) ? SnapshotsClient.CreateOrUpdate(resourceGroupName, snapshotName, snapshotObj) : SnapshotsClient.Update(resourceGroupName, snapshotName, snapshotUpdateObj); var psObject = new PSSnapshot(); Mapper.Map <Snapshot, PSSnapshot>(result, psObject); WriteObject(psObject); } }); }
public virtual ArmOperation <Snapshot> Update(bool waitForCompletion, SnapshotUpdate snapshot, CancellationToken cancellationToken = default) { if (snapshot == null) { throw new ArgumentNullException(nameof(snapshot)); } using var scope = _snapshotClientDiagnostics.CreateScope("Snapshot.Update"); scope.Start(); try { var response = _snapshotRestClient.Update(Id.SubscriptionId, Id.ResourceGroupName, Id.Name, snapshot, cancellationToken); var operation = new ComputeArmOperation <Snapshot>(new SnapshotOperationSource(Client), _snapshotClientDiagnostics, Pipeline, _snapshotRestClient.CreateUpdateRequest(Id.SubscriptionId, Id.ResourceGroupName, Id.Name, snapshot).Request, response, OperationFinalStateVia.Location); if (waitForCompletion) { operation.WaitForCompletion(cancellationToken); } return(operation); } catch (Exception e) { scope.Failed(e); throw; } }
public virtual SnapshotUpdateOperation Update(SnapshotUpdate snapshot, bool waitForCompletion = true, CancellationToken cancellationToken = default) { if (snapshot == null) { throw new ArgumentNullException(nameof(snapshot)); } using var scope = _clientDiagnostics.CreateScope("Snapshot.Update"); scope.Start(); try { var response = _restClient.Update(Id.ResourceGroupName, Id.Name, snapshot, cancellationToken); var operation = new SnapshotUpdateOperation(this, _clientDiagnostics, Pipeline, _restClient.CreateUpdateRequest(Id.ResourceGroupName, Id.Name, snapshot).Request, response); if (waitForCompletion) { operation.WaitForCompletion(cancellationToken); } return(operation); } catch (Exception e) { scope.Failed(e); throw; } }
public override void ExecuteCmdlet() { ExecuteClientAction(() => { WriteWarning("Update-AzureRmSnapshot: A property of the output of this cmdlet will change in an upcoming breaking change release. " + "The Name property for a Sku will return Standard_LRS and Premium_LRS"); if (ShouldProcess(this.SnapshotName, VerbsData.Update)) { string resourceGroupName = this.ResourceGroupName; string snapshotName = this.SnapshotName; SnapshotUpdate snapshotupdate = new SnapshotUpdate(); ComputeAutomationAutoMapperProfile.Mapper.Map <PSSnapshotUpdate, SnapshotUpdate>(this.SnapshotUpdate, snapshotupdate); Snapshot snapshot = new Snapshot(); ComputeAutomationAutoMapperProfile.Mapper.Map <PSSnapshot, Snapshot>(this.Snapshot, snapshot); var result = (this.SnapshotUpdate == null) ? SnapshotsClient.CreateOrUpdate(resourceGroupName, snapshotName, snapshot) : SnapshotsClient.Update(resourceGroupName, snapshotName, snapshotupdate); var psObject = new PSSnapshot(); ComputeAutomationAutoMapperProfile.Mapper.Map <Snapshot, PSSnapshot>(result, psObject); WriteObject(psObject); } }); }
public async virtual Task <SnapshotUpdateOperation> UpdateAsync(SnapshotUpdate snapshot, bool waitForCompletion = true, CancellationToken cancellationToken = default) { if (snapshot == null) { throw new ArgumentNullException(nameof(snapshot)); } using var scope = _clientDiagnostics.CreateScope("Snapshot.Update"); scope.Start(); try { var response = await _snapshotsRestClient.UpdateAsync(Id.SubscriptionId, Id.ResourceGroupName, Id.Name, snapshot, cancellationToken).ConfigureAwait(false); var operation = new SnapshotUpdateOperation(this, _clientDiagnostics, Pipeline, _snapshotsRestClient.CreateUpdateRequest(Id.SubscriptionId, Id.ResourceGroupName, Id.Name, snapshot).Request, response); if (waitForCompletion) { await operation.WaitForCompletionAsync(cancellationToken).ConfigureAwait(false); } return(operation); } catch (Exception e) { scope.Failed(e); throw; } }
public async Task <UpdateStatus> AddGameSnapshot([FromBody] AddGameSnapshotRequest request) { UpdateStatus status = new UpdateStatus(); var game = (await gameRepository.Lookup(request.gameLookup)).FirstOrDefault(); if (game == null) { throw new ArgumentException(); } var update = new SnapshotUpdate(); if (request.profileLookup != null) { var profile = (await profileRepository.Lookup(request.profileLookup)).FirstOrDefault(); if (profile != null) { update.profileid = profile.Id; } } update.data = request.keyValueList; update.gameid = game.Id; update.completed = request.complete.HasValue && request.complete.Value; status.success = await snapshotRepository.AppendSnapshotUpdate(request._id, update); return(status); }
public Response Update(string resourceGroupName, string snapshotName, SnapshotUpdate snapshot, CancellationToken cancellationToken = default) { if (resourceGroupName == null) { throw new ArgumentNullException(nameof(resourceGroupName)); } if (snapshotName == null) { throw new ArgumentNullException(nameof(snapshotName)); } if (snapshot == null) { throw new ArgumentNullException(nameof(snapshot)); } using var message = CreateUpdateRequest(resourceGroupName, snapshotName, snapshot); _pipeline.Send(message, cancellationToken); switch (message.Response.Status) { case 200: case 202: return(message.Response); default: throw _clientDiagnostics.CreateRequestFailedException(message.Response); } }
protected PSArgument[] CreateSnapshotUpdateParameters() { string resourceGroupName = string.Empty; string snapshotName = string.Empty; SnapshotUpdate snapshot = new SnapshotUpdate(); return(ConvertFromObjectsToArguments( new string[] { "ResourceGroupName", "SnapshotName", "Snapshot" }, new object[] { resourceGroupName, snapshotName, snapshot })); }
protected void ExecuteSnapshotUpdateMethod(object[] invokeMethodInputParameters) { string resourceGroupName = (string)ParseParameter(invokeMethodInputParameters[0]); string snapshotName = (string)ParseParameter(invokeMethodInputParameters[1]); SnapshotUpdate snapshot = (SnapshotUpdate)ParseParameter(invokeMethodInputParameters[2]); Snapshot snapshotOrg = (Snapshot)ParseParameter(invokeMethodInputParameters[3]); var result = (snapshot == null) ? SnapshotsClient.CreateOrUpdate(resourceGroupName, snapshotName, snapshotOrg) : SnapshotsClient.Update(resourceGroupName, snapshotName, snapshot); WriteObject(result); }
public override void ExecuteCmdlet() { ExecuteClientAction(() => { if (ShouldProcess(this.SnapshotName, VerbsData.Update)) { string resourceGroupName = this.ResourceGroupName; string snapshotName = this.SnapshotName; SnapshotUpdate snapshotupdate = new SnapshotUpdate(); ComputeAutomationAutoMapperProfile.Mapper.Map <PSSnapshotUpdate, SnapshotUpdate>(this.SnapshotUpdate, snapshotupdate); Snapshot snapshot = new Snapshot(); ComputeAutomationAutoMapperProfile.Mapper.Map <PSSnapshot, Snapshot>(this.Snapshot, snapshot); var result = (this.SnapshotUpdate == null) ? SnapshotsClient.CreateOrUpdate(resourceGroupName, snapshotName, snapshot) : SnapshotsClient.Update(resourceGroupName, snapshotName, snapshotupdate); var psObject = new PSSnapshot(); ComputeAutomationAutoMapperProfile.Mapper.Map <Snapshot, PSSnapshot>(result, psObject); WriteObject(psObject); } }); }
public virtual SnapshotsUpdateOperation StartUpdate(string resourceGroupName, string snapshotName, SnapshotUpdate snapshot, CancellationToken cancellationToken = default) { if (resourceGroupName == null) { throw new ArgumentNullException(nameof(resourceGroupName)); } if (snapshotName == null) { throw new ArgumentNullException(nameof(snapshotName)); } if (snapshot == null) { throw new ArgumentNullException(nameof(snapshot)); } using var scope = _clientDiagnostics.CreateScope("SnapshotsOperations.StartUpdate"); scope.Start(); try { var originalResponse = RestClient.Update(resourceGroupName, snapshotName, snapshot, cancellationToken); return(new SnapshotsUpdateOperation(_clientDiagnostics, _pipeline, RestClient.CreateUpdateRequest(resourceGroupName, snapshotName, snapshot).Request, originalResponse)); } catch (Exception e) { scope.Failed(e); throw; } }
/// <summary> /// Updates (patches) a snapshot. /// </summary> /// <param name='operations'> /// The operations group for this extension method. /// </param> /// <param name='resourceGroupName'> /// The name of the resource group. /// </param> /// <param name='snapshotName'> /// The name of the snapshot that is being created. The name can't be changed /// after the snapshot is created. Supported characters for the name are a-z, /// A-Z, 0-9 and _. The max name length is 80 characters. /// </param> /// <param name='snapshot'> /// Snapshot object supplied in the body of the Patch snapshot operation. /// </param> /// <param name='cancellationToken'> /// The cancellation token. /// </param> public static async Task <SnapshotInner> UpdateAsync(this ISnapshotsOperations operations, string resourceGroupName, string snapshotName, SnapshotUpdate snapshot, CancellationToken cancellationToken = default(CancellationToken)) { using (var _result = await operations.UpdateWithHttpMessagesAsync(resourceGroupName, snapshotName, snapshot, null, cancellationToken).ConfigureAwait(false)) { return(_result.Body); } }
/// <summary> /// Updates (patches) a snapshot. /// </summary> /// <param name='operations'> /// The operations group for this extension method. /// </param> /// <param name='resourceGroupName'> /// The name of the resource group. /// </param> /// <param name='snapshotName'> /// The name of the snapshot that is being created. The name can't be changed /// after the snapshot is created. Supported characters for the name are a-z, /// A-Z, 0-9 and _. The max name length is 80 characters. /// </param> /// <param name='snapshot'> /// Snapshot object supplied in the body of the Patch snapshot operation. /// </param> public static Snapshot Update(this ISnapshotsOperations operations, string resourceGroupName, string snapshotName, SnapshotUpdate snapshot) { return(operations.UpdateAsync(resourceGroupName, snapshotName, snapshot).GetAwaiter().GetResult()); }
private void Run() { // CreationData Microsoft.Azure.Management.Compute.Models.CreationData vCreationData = null; // EncryptionSettings Microsoft.Azure.Management.Compute.Models.EncryptionSettings vEncryptionSettings = null; if (this.CreateOption.HasValue) { if (vCreationData == null) { vCreationData = new Microsoft.Azure.Management.Compute.Models.CreationData(); } vCreationData.CreateOption = this.CreateOption.Value; } if (this.StorageAccountId != null) { if (vCreationData == null) { vCreationData = new Microsoft.Azure.Management.Compute.Models.CreationData(); } vCreationData.StorageAccountId = this.StorageAccountId; } if (this.ImageReference != null) { if (vCreationData == null) { vCreationData = new Microsoft.Azure.Management.Compute.Models.CreationData(); } vCreationData.ImageReference = this.ImageReference; } if (this.SourceUri != null) { if (vCreationData == null) { vCreationData = new Microsoft.Azure.Management.Compute.Models.CreationData(); } vCreationData.SourceUri = this.SourceUri; } if (this.SourceResourceId != null) { if (vCreationData == null) { vCreationData = new Microsoft.Azure.Management.Compute.Models.CreationData(); } vCreationData.SourceResourceId = this.SourceResourceId; } if (this.EncryptionSettingsEnabled != null) { if (vEncryptionSettings == null) { vEncryptionSettings = new Microsoft.Azure.Management.Compute.Models.EncryptionSettings(); } vEncryptionSettings.Enabled = this.EncryptionSettingsEnabled; } if (this.DiskEncryptionKey != null) { if (vEncryptionSettings == null) { vEncryptionSettings = new Microsoft.Azure.Management.Compute.Models.EncryptionSettings(); } vEncryptionSettings.DiskEncryptionKey = this.DiskEncryptionKey; } if (this.KeyEncryptionKey != null) { if (vEncryptionSettings == null) { vEncryptionSettings = new Microsoft.Azure.Management.Compute.Models.EncryptionSettings(); } vEncryptionSettings.KeyEncryptionKey = this.KeyEncryptionKey; } var vSnapshotUpdate = new SnapshotUpdate { AccountType = this.AccountType, OsType = this.OsType, DiskSizeGB = this.DiskSizeGB, Tags = (this.Tag == null) ? null : this.Tag.Cast <DictionaryEntry>().ToDictionary(ht => (string)ht.Key, ht => (string)ht.Value), CreationData = vCreationData, EncryptionSettings = vEncryptionSettings, }; WriteObject(vSnapshotUpdate); }
protected void Snapshot_CRUD_Execute(string diskCreateOption, string methodName, int?diskSizeGB = null, string location = null) { using (MockContext context = MockContext.Start(this.GetType().FullName, methodName)) { EnsureClientsInitialized(context); DiskRPLocation = location ?? DiskRPLocation; // Data var rgName = TestUtilities.GenerateName(TestPrefix); var diskName = TestUtilities.GenerateName(DiskNamePrefix); var snapshotName = TestUtilities.GenerateName(DiskNamePrefix); Disk sourceDisk = GenerateDefaultDisk(diskCreateOption, rgName, diskSizeGB); try { // ********** // SETUP // ********** // Create resource group m_ResourcesClient.ResourceGroups.CreateOrUpdate(rgName, new ResourceGroup { Location = DiskRPLocation }); // Put disk Disk diskOut = m_CrpClient.Disks.CreateOrUpdate(rgName, diskName, sourceDisk); Validate(sourceDisk, diskOut, DiskRPLocation); // Generate snapshot using disk info Snapshot snapshot = GenerateDefaultSnapshot(diskOut.Id); // ********** // TEST // ********** // Put Snapshot snapshotOut = m_CrpClient.Snapshots.CreateOrUpdate(rgName, snapshotName, snapshot); Validate(snapshot, snapshotOut); // Get snapshotOut = m_CrpClient.Snapshots.Get(rgName, snapshotName); Validate(snapshot, snapshotOut); // Get access AccessUri accessUri = m_CrpClient.Snapshots.GrantAccess(rgName, snapshotName, AccessDataDefault); Assert.NotNull(accessUri.AccessSAS); // Get snapshotOut = m_CrpClient.Snapshots.Get(rgName, snapshotName); Validate(snapshot, snapshotOut); // Patch var updatesnapshot = new SnapshotUpdate(); const string tagKey = "tageKey"; updatesnapshot.Tags = new Dictionary <string, string>() { { tagKey, "tagvalue" } }; snapshotOut = m_CrpClient.Snapshots.Update(rgName, snapshotName, updatesnapshot); Validate(snapshot, snapshotOut); // Get snapshotOut = m_CrpClient.Snapshots.Get(rgName, snapshotName); Validate(snapshot, snapshotOut); // End access m_CrpClient.Snapshots.RevokeAccess(rgName, snapshotName); // Delete m_CrpClient.Snapshots.Delete(rgName, snapshotName); try { // Ensure it was really deleted m_CrpClient.Snapshots.Get(rgName, snapshotName); Assert.False(true); } catch (CloudException ex) { Assert.Equal(HttpStatusCode.NotFound, ex.Response.StatusCode); } } finally { // Delete resource group m_ResourcesClient.ResourceGroups.Delete(rgName); } } }
internal HttpMessage CreateUpdateRequest(string resourceGroupName, string snapshotName, SnapshotUpdate snapshot) { var message = _pipeline.CreateMessage(); var request = message.Request; request.Method = RequestMethod.Patch; var uri = new RawRequestUriBuilder(); uri.Reset(endpoint); uri.AppendPath("/subscriptions/", false); uri.AppendPath(subscriptionId, true); uri.AppendPath("/resourceGroups/", false); uri.AppendPath(resourceGroupName, true); uri.AppendPath("/providers/Microsoft.Compute/snapshots/", false); uri.AppendPath(snapshotName, true); uri.AppendQuery("api-version", "2019-11-01", true); request.Uri = uri; request.Headers.Add("Content-Type", "application/json"); var content = new Utf8JsonRequestContent(); content.JsonWriter.WriteObjectValue(snapshot); request.Content = content; return(message); }
protected async Task Snapshot_CRUD_Execute(string diskCreateOption, string methodName, int?diskSizeGB = null, string location = null, bool incremental = false) { EnsureClientsInitialized(DefaultLocation); DiskRPLocation = location ?? DiskRPLocation; // Data var rgName = Recording.GenerateAssetName(TestPrefix); var diskName = Recording.GenerateAssetName(DiskNamePrefix); var snapshotName = Recording.GenerateAssetName(DiskNamePrefix); Disk sourceDisk = await GenerateDefaultDisk(diskCreateOption, rgName, diskSizeGB); // ********** // SETUP // ********** // Create resource group await ResourceGroupsOperations.CreateOrUpdateAsync(rgName, new ResourceGroup(DiskRPLocation)); // Put disk Disk diskOut = await WaitForCompletionAsync(await DisksOperations.StartCreateOrUpdateAsync(rgName, diskName, sourceDisk)); Validate(sourceDisk, diskOut, DiskRPLocation); // Generate snapshot using disk info Snapshot snapshot = GenerateDefaultSnapshot(diskOut.Id, incremental: incremental); // ********** // TEST // ********** // Put Snapshot snapshotOut = await WaitForCompletionAsync(await SnapshotsOperations.StartCreateOrUpdateAsync(rgName, snapshotName, snapshot)); Validate(snapshot, snapshotOut, incremental: incremental); // Get snapshotOut = (await SnapshotsOperations.GetAsync(rgName, snapshotName)).Value; Validate(snapshot, snapshotOut, incremental: incremental); // Get access AccessUri accessUri = await WaitForCompletionAsync((await SnapshotsOperations.StartGrantAccessAsync(rgName, snapshotName, new GrantAccessData(AccessDataDefault.Access, AccessDataDefault.DurationInSeconds)))); Assert.NotNull(accessUri.AccessSAS); // Get snapshotOut = (await SnapshotsOperations.GetAsync(rgName, snapshotName)).Value; Validate(snapshot, snapshotOut, incremental: incremental); // Patch var updatesnapshot = new SnapshotUpdate(); const string tagKey = "tageKey"; updatesnapshot.Tags = new Dictionary <string, string>() { { tagKey, "tagvalue" } }; snapshotOut = await WaitForCompletionAsync(await SnapshotsOperations.StartUpdateAsync(rgName, snapshotName, updatesnapshot)); Validate(snapshot, snapshotOut, incremental: incremental); // Get snapshotOut = (await SnapshotsOperations.GetAsync(rgName, snapshotName)).Value; Validate(snapshot, snapshotOut, incremental: incremental); // End access await WaitForCompletionAsync(await SnapshotsOperations.StartRevokeAccessAsync(rgName, snapshotName)); // Delete await WaitForCompletionAsync(await SnapshotsOperations.StartDeleteAsync(rgName, snapshotName)); try { // Ensure it was really deleted await SnapshotsOperations.GetAsync(rgName, snapshotName); Assert.False(true); } catch (Exception ex) { Assert.NotNull(ex); //Assert.AreEqual(HttpStatusCode.NotFound, ex.Response.StatusCode); } }
public async ValueTask <Response> UpdateAsync(string resourceGroupName, string snapshotName, SnapshotUpdate snapshot, CancellationToken cancellationToken = default) { if (resourceGroupName == null) { throw new ArgumentNullException(nameof(resourceGroupName)); } if (snapshotName == null) { throw new ArgumentNullException(nameof(snapshotName)); } if (snapshot == null) { throw new ArgumentNullException(nameof(snapshot)); } using var message = CreateUpdateRequest(resourceGroupName, snapshotName, snapshot); await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false); switch (message.Response.Status) { case 202: case 200: return(message.Response); default: throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(false); } }