Skip to content

Commit

Permalink
Fix the issue of New-AzureRmDisk, New-AzureRmSnapshot, Update-AzureRm…
Browse files Browse the repository at this point in the history
…Disk and Update-AzureRmSnapshot.
  • Loading branch information
hyonholee committed Jul 13, 2017
1 parent 27fce5c commit a62ef99
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
// Changes to this file may cause incorrect behavior and will be lost if the
// code is regenerated.

using AutoMapper;
using Microsoft.Azure.Commands.Compute.Automation.Models;
using Microsoft.Azure.Management.Compute;
using Microsoft.Azure.Management.Compute.Models;
Expand Down Expand Up @@ -117,16 +118,20 @@ public partial class NewAzureRmDisk : ComputeAutomationBaseCmdlet
{
protected override void ProcessRecord()
{
ComputeAutomationAutoMapperProfile.Initialize();
ExecuteClientAction(() =>
{
if (ShouldProcess(this.ResourceGroupName, VerbsCommon.New))
{
string resourceGroupName = this.ResourceGroupName;
string diskName = this.DiskName;
PSDisk disk = this.Disk;

Disk disk = new Disk();
Mapper.Map<PSDisk, Disk>(this.Disk, disk);
var result = DisksClient.CreateOrUpdate(resourceGroupName, diskName, disk);
WriteObject(result);

PSDisk psResult = new PSDisk();
Mapper.Map<Disk, PSDisk>(result, psResult);
WriteObject(psResult);
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,19 +121,23 @@ public partial class UpdateAzureRmDisk : ComputeAutomationBaseCmdlet
{
protected override void ProcessRecord()
{
ComputeAutomationAutoMapperProfile.Initialize();
ExecuteClientAction(() =>
{
if (ShouldProcess(this.ResourceGroupName, VerbsData.Update))
{

string resourceGroupName = this.ResourceGroupName;
string diskName = this.DiskName;
PSDiskUpdate disk = this.DiskUpdate;
PSDisk diskOrg = this.Disk;

var result = (disk == null)
? DisksClient.CreateOrUpdate(resourceGroupName, diskName, diskOrg)
: DisksClient.Update(resourceGroupName, diskName, disk);
Disk diskObj = new Disk();
Mapper.Map<PSDisk, Disk>(this.Disk, diskObj);

DiskUpdate diskUpdateObj= new DiskUpdate();
Mapper.Map<PSDiskUpdate, DiskUpdate>(this.DiskUpdate, diskUpdateObj);

var result = (this.DiskUpdate == null)
? DisksClient.CreateOrUpdate(resourceGroupName, diskName, diskObj)
: DisksClient.Update(resourceGroupName, diskName, diskUpdateObj);

var psObject = new PSDisk();
Mapper.Map<Disk, PSDisk>(result, psObject);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,14 @@ protected override void Configure()
Mapper.CreateMap<FROM.DiskUpdate, FROM.Disk>();
Mapper.CreateMap<FROM.Snapshot, FROM.SnapshotUpdate>();
Mapper.CreateMap<FROM.SnapshotUpdate, FROM.Snapshot>();
Mapper.CreateMap<FROM.Disk, TO.PSDisk>();
Mapper.CreateMap<TO.PSDisk, FROM.Disk>();
Mapper.CreateMap<FROM.DiskUpdate, TO.PSDiskUpdate>();
Mapper.CreateMap<TO.PSDiskUpdate, FROM.DiskUpdate>();
Mapper.CreateMap<FROM.Snapshot, TO.PSSnapshot>();
Mapper.CreateMap<TO.PSSnapshot, FROM.Snapshot>();
Mapper.CreateMap<FROM.SnapshotUpdate, TO.PSSnapshotUpdate>();
Mapper.CreateMap<TO.PSSnapshotUpdate, FROM.SnapshotUpdate>();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
// Changes to this file may cause incorrect behavior and will be lost if the
// code is regenerated.

using AutoMapper;
using Microsoft.Azure.Commands.Compute.Automation.Models;
using Microsoft.Azure.Management.Compute;
using Microsoft.Azure.Management.Compute.Models;
Expand Down Expand Up @@ -117,16 +118,21 @@ public partial class NewAzureRmSnapshot : ComputeAutomationBaseCmdlet
{
protected override void ProcessRecord()
{
ComputeAutomationAutoMapperProfile.Initialize();
ExecuteClientAction(() =>
{
if (ShouldProcess(this.ResourceGroupName, VerbsCommon.New))
{
string resourceGroupName = this.ResourceGroupName;
string snapshotName = this.SnapshotName;
PSSnapshot snapshot = this.Snapshot;
Snapshot snapshot = new Snapshot();
Mapper.Map<PSSnapshot, Snapshot>(this.Snapshot, snapshot);

var result = SnapshotsClient.CreateOrUpdate(resourceGroupName, snapshotName, snapshot);
WriteObject(result);

PSSnapshot psResult = new PSSnapshot();
Mapper.Map<Snapshot, PSSnapshot>(result, psResult);
WriteObject(psResult);
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,15 +125,18 @@ protected override void ProcessRecord()
{
if (ShouldProcess(this.ResourceGroupName, VerbsData.Update))
{

string resourceGroupName = this.ResourceGroupName;
string snapshotName = this.SnapshotName;
PSSnapshotUpdate snapshot = this.SnapshotUpdate;
PSSnapshot snapshotOrg = this.Snapshot;

var result = (snapshot == null)
? SnapshotsClient.CreateOrUpdate(resourceGroupName, snapshotName, snapshotOrg)
: SnapshotsClient.Update(resourceGroupName, snapshotName, snapshot);
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);
Expand Down

0 comments on commit a62ef99

Please sign in to comment.