Skip to content

Commit

Permalink
Compute: append storage account id when create option is import (#1004)
Browse files Browse the repository at this point in the history
* Compute: append storage account id when create option is import

* Compute: update comments
  • Loading branch information
xseeseesee authored Mar 13, 2020
1 parent bc4c347 commit 7b933ba
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -170,10 +170,11 @@ Snapshot.Definition.IWithCreate Snapshot.Definition.IWithDataSnapshotFromSnapsho
/// Specifies the source data VHD.
/// </summary>
/// <param name="vhdUrl">A source VHD URL.</param>
/// <param name="storageAccountId">A storage account ID.</param>
/// <return>The next stage of the definition.</return>
Snapshot.Definition.IWithCreate Snapshot.Definition.IWithDataSnapshotFromVhd.WithDataFromVhd(string vhdUrl)
Snapshot.Definition.IWithCreate Snapshot.Definition.IWithDataSnapshotFromVhd.WithDataFromVhd(string vhdUrl, string storageAccountId)
{
return this.WithDataFromVhd(vhdUrl);
return this.WithDataFromVhd(vhdUrl, storageAccountId);
}

/// <summary>
Expand Down Expand Up @@ -220,10 +221,11 @@ Snapshot.Definition.IWithCreate Snapshot.Definition.IWithLinuxSnapshotSource.Wit
/// Specifies the source specialized or generalized Linux OS VHD.
/// </summary>
/// <param name="vhdUrl">The source VHD URL.</param>
/// <param name="storageAccountId">The storage account ID.</param>
/// <return>The next stage of the definition.</return>
Snapshot.Definition.IWithCreate Snapshot.Definition.IWithLinuxSnapshotSource.WithLinuxFromVhd(string vhdUrl)
Snapshot.Definition.IWithCreate Snapshot.Definition.IWithLinuxSnapshotSource.WithLinuxFromVhd(string vhdUrl, string storageAccountId)
{
return this.WithLinuxFromVhd(vhdUrl);
return this.WithLinuxFromVhd(vhdUrl, storageAccountId);
}

/// <summary>
Expand Down Expand Up @@ -342,10 +344,11 @@ Snapshot.Definition.IWithCreate Snapshot.Definition.IWithWindowsSnapshotSource.W
/// Specifies the source specialized or generalized Windows OS VHD.
/// </summary>
/// <param name="vhdUrl">The source VHD URL.</param>
/// <param name="storageAccountId">The storage account ID.</param>
/// <return>The next stage of the definition.</return>
Snapshot.Definition.IWithCreate Snapshot.Definition.IWithWindowsSnapshotSource.WithWindowsFromVhd(string vhdUrl)
Snapshot.Definition.IWithCreate Snapshot.Definition.IWithWindowsSnapshotSource.WithWindowsFromVhd(string vhdUrl, string storageAccountId)
{
return this.WithWindowsFromVhd(vhdUrl);
return this.WithWindowsFromVhd(vhdUrl, storageAccountId);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -217,11 +217,12 @@ public interface IWithLinuxSnapshotSource
Microsoft.Azure.Management.Compute.Fluent.Snapshot.Definition.IWithCreate WithLinuxFromSnapshot(ISnapshot sourceSnapshot);

/// <summary>
/// Specifies the source specialized or generalized Linux OS VHD.
/// Specifies the source specialized or generalized Linux OS VHD and the storage account ID.
/// </summary>
/// <param name="vhdUrl">The source VHD URL.</param>
/// <param name="storageAccountId">The storage account ID.</param>
/// <return>The next stage of the definition.</return>
Microsoft.Azure.Management.Compute.Fluent.Snapshot.Definition.IWithCreate WithLinuxFromVhd(string vhdUrl);
Microsoft.Azure.Management.Compute.Fluent.Snapshot.Definition.IWithCreate WithLinuxFromVhd(string vhdUrl, string storageAccountId = default(string));
}

/// <summary>
Expand Down Expand Up @@ -277,11 +278,12 @@ public interface IWithWindowsSnapshotSource
Microsoft.Azure.Management.Compute.Fluent.Snapshot.Definition.IWithCreate WithWindowsFromSnapshot(ISnapshot sourceSnapshot);

/// <summary>
/// Specifies the source specialized or generalized Windows OS VHD.
/// Specifies the source specialized or generalized Windows OS VHD and the storage account ID.
/// </summary>
/// <param name="vhdUrl">The source VHD URL.</param>
/// <param name="storageAccountId">The storage account ID.</param>
/// <return>The next stage of the definition.</return>
Microsoft.Azure.Management.Compute.Fluent.Snapshot.Definition.IWithCreate WithWindowsFromVhd(string vhdUrl);
Microsoft.Azure.Management.Compute.Fluent.Snapshot.Definition.IWithCreate WithWindowsFromVhd(string vhdUrl, string storageAccountId = default(string));
}

/// <summary>
Expand Down Expand Up @@ -322,10 +324,11 @@ public interface IWithDataSnapshotFromVhd
{

/// <summary>
/// Specifies the source data VHD.
/// Specifies the source data VHD and the storage account ID.
/// </summary>
/// <param name="vhdUrl">A source VHD URL.</param>
/// <param name="vhdUrl">The source VHD URL.</param>
/// <param name="storageAccountId">The storage account ID.</param>
/// <return>The next stage of the definition.</return>
Microsoft.Azure.Management.Compute.Fluent.Snapshot.Definition.IWithCreate WithDataFromVhd(string vhdUrl);
Microsoft.Azure.Management.Compute.Fluent.Snapshot.Definition.IWithCreate WithDataFromVhd(string vhdUrl, string storageAccountId = default(string));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public CreationData()
/// <summary>
/// Gets or sets if createOption is Import, the Azure Resource Manager
/// identifier of the storage account containing the blob to import as
/// a disk. Required only if the blob is in a different subscription
/// a disk.
/// </summary>
[JsonProperty(PropertyName = "storageAccountId")]
public string StorageAccountId { get; set; }
Expand Down
51 changes: 39 additions & 12 deletions src/ResourceManagement/Compute/SnapshotImpl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ namespace Microsoft.Azure.Management.Compute.Fluent
using Models;
using ResourceManager.Fluent;
using Microsoft.Azure.Management.ResourceManager.Fluent.Core;
using System;

/// <summary>
/// The implementation for Snapshot and its create and update interfaces.
Expand Down Expand Up @@ -70,12 +71,15 @@ public SnapshotImpl WithIncremental(bool enabled)
}

///GENMHASH:AAD8E592A024E583CCB079E40FA35511:86D949645392B88CC8EBDF08E3E0EDF8
public SnapshotImpl WithLinuxFromVhd(string vhdUrl)
public SnapshotImpl WithLinuxFromVhd(string vhdUrl, string storageAccountId)
{
Inner.OsType = OperatingSystemTypes.Linux;
Inner.CreationData = new CreationData();
Inner.CreationData.CreateOption = DiskCreateOption.Import;
Inner.CreationData.SourceUri = vhdUrl;
Inner.CreationData = new CreationData
{
CreateOption = DiskCreateOption.Import,
SourceUri = vhdUrl,
StorageAccountId = storageAccountId ?? ConstructStorageAccountId(vhdUrl)
};
return this;
}

Expand Down Expand Up @@ -180,11 +184,14 @@ public CreationSource Source()
}

///GENMHASH:BE7E147B48A8E5D7518DE00A1A239664:B42B6D1380F4A7780F5B729A33312605
public SnapshotImpl WithDataFromVhd(string vhdUrl)
public SnapshotImpl WithDataFromVhd(string vhdUrl, string storageAccountId)
{
Inner.CreationData = new CreationData();
Inner.CreationData.CreateOption = DiskCreateOption.Import;
Inner.CreationData.SourceUri = vhdUrl;
Inner.CreationData = new CreationData
{
CreateOption = DiskCreateOption.Import,
SourceUri = vhdUrl,
StorageAccountId = storageAccountId ?? ConstructStorageAccountId(vhdUrl)
};
return this;
}

Expand All @@ -199,12 +206,15 @@ public DiskCreateOption CreationMethod()
}

///GENMHASH:28C892DD6868506954A9B3D406FE4710:E57D05C8BB272E6441E14E0F73F93F60
public SnapshotImpl WithWindowsFromVhd(string vhdUrl)
public SnapshotImpl WithWindowsFromVhd(string vhdUrl, string storageAccountId)
{
Inner.OsType = OperatingSystemTypes.Windows;
Inner.CreationData = new CreationData();
Inner.CreationData.CreateOption = DiskCreateOption.Import;
Inner.CreationData.SourceUri = vhdUrl;
Inner.CreationData = new CreationData
{
CreateOption = DiskCreateOption.Import,
SourceUri = vhdUrl,
StorageAccountId = storageAccountId ?? ConstructStorageAccountId(vhdUrl)
};
return this;
}

Expand Down Expand Up @@ -338,5 +348,22 @@ public SnapshotImpl WithLinuxFromSnapshot(ISnapshot sourceSnapshot)
SetInner(snapshotInner);
return this;
}

internal string ConstructStorageAccountId(string vhdUrl)
{
try
{
return ResourceUtils.ConstructResourceId(Manager.SubscriptionId,
ResourceGroupName,
"Microsoft.Storage",
"storageAccounts",
vhdUrl.Split('.')[0].Replace("https://", ""),
"");
}
catch (Exception)
{
throw new ArgumentException(string.Format("%s is not valid URI of a blob to import.", vhdUrl));
}
}
}
}

0 comments on commit 7b933ba

Please sign in to comment.