Skip to content

Commit 9228f99

Browse files
committed
commit post merge
2 parents 59a90f0 + 0d4af69 commit 9228f99

13 files changed

+98
-35
lines changed

src/ResourceManager/AzureBackup/Commands.AzureBackup/AzureBackupCmdletBase.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,11 @@ public abstract class AzureBackupCmdletBase : AzurePSCmdlet
4141
/// </summary>
4242
private string resourceName { get; set; }
4343

44+
/// <summary>
45+
/// Resource context for the operation
46+
/// </summary>
47+
private string location { get; set; }
48+
4449
/// <summary>
4550
/// Client request id.
4651
/// </summary>
@@ -82,10 +87,11 @@ protected void RefreshClientRequestId()
8287
clientRequestId = Guid.NewGuid().ToString() + "-" + DateTime.Now.ToUniversalTime().ToString("yyyy-MM-dd HH:mm:ssZ") + "-PS";
8388
}
8489

85-
public void InitializeAzureBackupCmdlet(string rgName, string rName)
90+
public void InitializeAzureBackupCmdlet(string rgName, string rName, string locationName)
8691
{
8792
resourceGroupName = rgName;
8893
resourceName = rName;
94+
location = locationName;
8995

9096
RefreshClientRequestId();
9197
WriteDebug(string.Format("Initialized AzureBackup Cmdlet, ClientRequestId: {0}, ResourceGroupName: {1}, ResourceName : {2}", this.clientRequestId, resourceGroupName, resourceName));

src/ResourceManager/AzureBackup/Commands.AzureBackup/AzureBackupCmdletHelpMessage.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ internal static class AzureBackupCmdletHelpMessage
2020
public const string PolicyName = "The protection policy name.";
2121
public const string ResourceGroupName = "The ResourceGroup name.";
2222
public const string ResourceName = "The Resource name.";
23+
public const string Location = "Location.";
2324
public const string TargetLocation = "The directory where the credentials file will be saved.";
2425
public const string ContainerResourceName = "The container resource name aka friendly name.";
2526
public const string ContainerId = "The container ID.";

src/ResourceManager/AzureBackup/Commands.AzureBackup/AzureBackupContainerCmdletBase.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,9 @@ public override void ExecuteCmdlet()
3838
{
3939
base.ExecuteCmdlet();
4040

41-
WriteDebug(String.Format("Cmdlet called for ResourceGroupName: {0}, ResourceName: {1}", AzureBackupContainer.ResourceGroupName, AzureBackupContainer.ResourceName));
41+
WriteDebug(String.Format("Cmdlet called for ResourceGroupName: {0}, ResourceName: {1}, Location: {2}", AzureBackupContainer.ResourceGroupName, AzureBackupContainer.ResourceName, AzureBackupContainer.Location));
4242

43-
InitializeAzureBackupCmdlet(AzureBackupContainer.ResourceGroupName, AzureBackupContainer.ResourceName);
43+
InitializeAzureBackupCmdlet(AzureBackupContainer.ResourceGroupName, AzureBackupContainer.ResourceName, AzureBackupContainer.Location);
4444
}
4545
}
4646
}

src/ResourceManager/AzureBackup/Commands.AzureBackup/AzureBackupDSCmdletBase.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public override void ExecuteCmdlet()
4040

4141
WriteDebug(String.Format("Cmdlet called for ResourceGroupName: {0}, ResourceName: {1}", item.ResourceGroupName, item.ResourceName));
4242

43-
InitializeAzureBackupCmdlet(item.ResourceGroupName, item.ResourceName);
43+
InitializeAzureBackupCmdlet(item.ResourceGroupName, item.ResourceName, item.Location);
4444
}
4545
}
4646
}

src/ResourceManager/AzureBackup/Commands.AzureBackup/AzureBackupVaultCmdletBase.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,17 @@ public abstract class AzureBackupVaultCmdletBase : AzureBackupCmdletBase
3636
[ValidateNotNullOrEmpty]
3737
public string ResourceName { get; set; }
3838

39+
[Parameter(Position = 2, Mandatory = true, HelpMessage = AzureBackupCmdletHelpMessage.Location, ValueFromPipelineByPropertyName = true)]
40+
[ValidateNotNullOrEmpty]
41+
public string Location { get; set; }
3942

4043
public override void ExecuteCmdlet()
4144
{
4245
base.ExecuteCmdlet();
4346

4447
WriteDebug(String.Format("Cmdlet called for ResourceGroupName: {0}, ResourceName: {1}", ResourceGroupName, ResourceName));
4548

46-
InitializeAzureBackupCmdlet(ResourceGroupName, ResourceName);
49+
InitializeAzureBackupCmdlet(ResourceGroupName, ResourceName, Location);
4750
}
4851
}
4952
}

src/ResourceManager/AzureBackup/Commands.AzureBackup/Cmdlets/Container/GetAzureBackupContainer.cs

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,11 @@ public class GetAzureBackupContainer : AzureBackupVaultCmdletBase
4040

4141
[Parameter(Mandatory = false, HelpMessage = AzureBackupCmdletHelpMessage.ContainerRegistrationStatus)]
4242
[ValidateNotNullOrEmpty]
43-
public AzureBackupContainerStatus Status { get; set; }
43+
public AzureBackupContainerStatusInput Status { get; set; }
4444

4545
[Parameter(Mandatory = false, HelpMessage = AzureBackupCmdletHelpMessage.ContainerType)]
4646
[ValidateNotNullOrEmpty]
47-
public AzureBackupContainerType Type { get; set; }
47+
public AzureBackupContainerTypeInput Type { get; set; }
4848

4949
public override void ExecuteCmdlet()
5050
{
@@ -57,6 +57,8 @@ public override void ExecuteCmdlet()
5757
ListContainerResponse listContainerResponse = AzureBackupClient.Container.ListAsync(queryFilterString,
5858
GetCustomRequestHeaders(), CmdletCancellationToken).Result;
5959

60+
WriteVerbose(string.Format("# of fetched containers = {0}", listContainerResponse.Objects.Count));
61+
6062
List<ContainerInfo> containerInfos = listContainerResponse.Objects.ToList();
6163

6264
// When resource group name is specified, remove all containers whose resource group name
@@ -69,10 +71,24 @@ public override void ExecuteCmdlet()
6971
});
7072
}
7173

72-
WriteObject(containerInfos.ConvertAll(containerInfo =>
74+
WriteVerbose(string.Format("# of containers after resource group filter = {0}", listContainerResponse.Objects.Count));
75+
76+
List<AzureBackupContainer> containers = containerInfos.ConvertAll(containerInfo =>
7377
{
74-
return new AzureBackupContainer(containerInfo);
75-
}));
78+
return new AzureBackupContainer(containerInfo, ResourceGroupName, ResourceName, Location);
79+
});
80+
81+
if (!string.IsNullOrEmpty(ResourceName) & !string.IsNullOrEmpty(ResourceGroupName))
82+
{
83+
if (containers.Any())
84+
{
85+
WriteObject(containers.First());
86+
}
87+
}
88+
else
89+
{
90+
WriteObject(containers);
91+
}
7692
});
7793
}
7894

@@ -82,7 +98,7 @@ private string ConstructQueryFilterString()
8298

8399
switch (Type)
84100
{
85-
case AzureBackupContainerType.AzureVirtualMachine:
101+
case AzureBackupContainerTypeInput.AzureVirtualMachine:
86102
containerQueryObject.Type = BCI.ContainerType.IaasVMContainer.ToString();
87103
break;
88104
default:
@@ -91,15 +107,12 @@ private string ConstructQueryFilterString()
91107

92108
switch (Status)
93109
{
94-
case AzureBackupContainerStatus.Registered:
110+
case AzureBackupContainerStatusInput.Registered:
95111
containerQueryObject.Status = BCI.RegistrationStatus.Registered.ToString();
96112
break;
97-
case AzureBackupContainerStatus.Registering:
113+
case AzureBackupContainerStatusInput.Registering:
98114
containerQueryObject.Status = BCI.RegistrationStatus.Registering.ToString();
99115
break;
100-
case AzureBackupContainerStatus.NotRegistered:
101-
containerQueryObject.Status = BCI.RegistrationStatus.NotRegistered.ToString();
102-
break;
103116
default:
104117
break;
105118
}

src/ResourceManager/AzureBackup/Commands.AzureBackup/Cmdlets/ProtectionPolicy/GetAzureBackupProtectionPolicy.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ namespace Microsoft.Azure.Commands.AzureBackup.Cmdlets
2727
[Cmdlet(VerbsCommon.Get, "AzureBackupProtectionPolicy"), OutputType(typeof(AzureBackupProtectionPolicy), typeof(List<AzureBackupProtectionPolicy>))]
2828
public class GetAzureBackupProtectionPolicy : AzureBackupVaultCmdletBase
2929
{
30-
[Parameter(Position = 2, Mandatory = false, HelpMessage = AzureBackupCmdletHelpMessage.PolicyName)]
30+
[Parameter(Position = 3, Mandatory = false, HelpMessage = AzureBackupCmdletHelpMessage.PolicyName)]
3131
[ValidateNotNullOrEmpty]
3232
public string Name { get; set; }
3333

@@ -60,7 +60,7 @@ public override void ExecuteCmdlet()
6060

6161
public void WriteAzureBackupProtectionPolicy(ProtectionPolicyInfo sourcePolicy)
6262
{
63-
this.WriteObject(new AzureBackupProtectionPolicy(ResourceGroupName, ResourceName, sourcePolicy));
63+
this.WriteObject(new AzureBackupProtectionPolicy(ResourceGroupName, ResourceName, Location, sourcePolicy));
6464
}
6565

6666
public void WriteAzureBackupProtectionPolicy(IEnumerable<ProtectionPolicyInfo> sourcePolicyList)
@@ -69,7 +69,7 @@ public void WriteAzureBackupProtectionPolicy(IEnumerable<ProtectionPolicyInfo> s
6969

7070
foreach (var sourcePolicy in sourcePolicyList)
7171
{
72-
targetList.Add(new AzureBackupProtectionPolicy(ResourceGroupName, ResourceName, sourcePolicy));
72+
targetList.Add(new AzureBackupProtectionPolicy(ResourceGroupName, ResourceName, Location, sourcePolicy));
7373
}
7474

7575
this.WriteObject(targetList, true);

src/ResourceManager/AzureBackup/Commands.AzureBackup/Cmdlets/VaultCredentials/GetAzureBackupVaultCredentials.cs

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,11 @@ public override void ExecuteCmdlet()
4545

4646
ExecutionBlock(() =>
4747
{
48-
WriteVerbose(string.Format("Profile == null : {0}", (Profile == null).ToString()));
49-
WriteVerbose(string.Format("Profile.DefaultSubscription == null : {0}", (Profile.DefaultSubscription == null).ToString()));
48+
if (!Directory.Exists(TargetLocation))
49+
{
50+
throw new ArgumentException("The target location provided is not a directory. Please provide a directory.");
51+
}
52+
5053
string subscriptionId = Profile.DefaultSubscription.Id.ToString();
5154
string resourceType = "resourceType";
5255
string displayName = subscriptionId + "_" + ResourceGroupName + "_" + ResourceName;
@@ -62,7 +65,6 @@ public override void ExecuteCmdlet()
6265
DateTime.UtcNow.AddHours(this.GetCertificateExpiryInHours()));
6366

6467
AcsNamespace acsNamespace = new AcsNamespace();
65-
6668
string channelIntegrityKey = string.Empty;
6769
try
6870
{
@@ -80,8 +82,16 @@ public override void ExecuteCmdlet()
8082
string vaultCredsFileContent = GenerateVaultCreds(cert, subscriptionId, resourceType, acsNamespace);
8183

8284
// prepare for download
83-
string fileName = string.Format("{0}_{1}.VaultCredentials", displayName, DateTime.UtcNow.ToLongDateString());
84-
string filePath = Path.Combine(Path.GetDirectoryName(TargetLocation), fileName);
85+
string fileName = string.Format("{0}_{1}.VaultCredentials", displayName, DateTime.UtcNow.ToString("yyyy-dd-M--HH-mm-ss"));
86+
string directoryPath = Path.GetDirectoryName(TargetLocation);
87+
if (directoryPath == null)
88+
{
89+
// TargetLocation is a root path
90+
directoryPath = TargetLocation;
91+
}
92+
string filePath = Path.Combine(directoryPath, fileName);
93+
WriteVerbose(string.Format("Saving Vault Credentials to file : {0}", filePath));
94+
8595
File.WriteAllBytes(filePath, Encoding.UTF8.GetBytes(vaultCredsFileContent));
8696

8797
// Output filename back to user

src/ResourceManager/AzureBackup/Commands.AzureBackup/Commands.AzureBackup.csproj

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,14 @@
4343
<Prefer32Bit>false</Prefer32Bit>
4444
</PropertyGroup>
4545
<ItemGroup>
46+
<Reference Include="BackupManagementInterface, Version=1.0.523.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
47+
<SpecificVersion>False</SpecificVersion>
48+
<HintPath>Resources\BackupManagementInterface.dll</HintPath>
49+
</Reference>
50+
<Reference Include="BMSCommonInterface, Version=1.0.523.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
51+
<SpecificVersion>False</SpecificVersion>
52+
<HintPath>Resources\BMSCommonInterface.dll</HintPath>
53+
</Reference>
4654
<Reference Include="Hyak.Common">
4755
<HintPath>..\..\..\packages\Hyak.Common.1.0.2\lib\portable-net403+win+wpa81\Hyak.Common.dll</HintPath>
4856
</Reference>
@@ -117,13 +125,14 @@
117125
<Reference Include="System.Xml" />
118126
</ItemGroup>
119127
<ItemGroup>
128+
<Compile Include="AzureBackupContainerCmdletBase.cs" />
120129
<Compile Include="AzureBackupDSCmdletBase.cs" />
121130
<Compile Include="AzureBackupVaultCmdletBase.cs" />
122131
<Compile Include="AzureBackupCmdletBase.cs" />
123132
<Compile Include="AzureBackupCmdletHelpMessage.cs" />
124133
<Compile Include="Cmdlets\BackUp\TriggerBackUp.cs" />
125134
<Compile Include="Cmdlets\RecoveryPoint\GetAzureBackupRecoveryPoint.cs" />
126-
<None Include="Cmdlets\Container\GetAzureBackupContainer.cs" />
135+
<Compile Include="Cmdlets\Container\GetAzureBackupContainer.cs" />
127136
<Compile Include="Cmdlets\Container\RegisterAzureBackupContainer.cs" />
128137
<Compile Include="Cmdlets\Container\UnregisterAzureBackupContainer.cs" />
129138
<Compile Include="Cmdlets\Jobs\GetAzureBackupJob.cs" />
@@ -177,6 +186,8 @@
177186
</EmbeddedResource>
178187
</ItemGroup>
179188
<ItemGroup>
189+
<Content Include="Resources\BackupManagementInterface.dll" />
190+
<Content Include="Resources\BMSCommonInterface.dll" />
180191
<Content Include="Resources\Microsoft.WindowsAzure.Management.Common.dll" />
181192
<Content Include="Resources\Security.Cryptography.dll" />
182193
</ItemGroup>

src/ResourceManager/AzureBackup/Commands.AzureBackup/Models/AzureBackupBaseObjects.cs

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,20 @@ public class AzureBackupVaultContextObject
2727
/// </summary>
2828
public string ResourceName { get; set; }
2929

30+
/// <summary>
31+
/// ResourceName of the azurebackup object
32+
/// </summary>
33+
public string Location { get; set; }
34+
3035
public AzureBackupVaultContextObject()
3136
{
3237
}
33-
34-
public AzureBackupVaultContextObject(string resourceGroupName, string resourceName)
38+
39+
public AzureBackupVaultContextObject(string resourceGroupName, string resourceName, string locationName)
3540
{
3641
ResourceGroupName = resourceGroupName;
3742
ResourceName = resourceName;
43+
Location = locationName;
3844
}
3945
}
4046

@@ -60,20 +66,20 @@ public AzureBackupContainerContextObject()
6066
}
6167

6268
public AzureBackupContainerContextObject(AzureBackupContainerContextObject azureBackupContainerContextObject)
63-
: base(azureBackupContainerContextObject.ResourceGroupName, azureBackupContainerContextObject.ResourceName)
69+
: base(azureBackupContainerContextObject.ResourceGroupName, azureBackupContainerContextObject.ResourceName, azureBackupContainerContextObject.Location)
6470
{
6571
ContainerType = azureBackupContainerContextObject.ContainerType;
6672
ContainerUniqueName = azureBackupContainerContextObject.ContainerUniqueName;
6773
}
6874
public AzureBackupContainerContextObject(AzureBackupContainer azureBackupContainer)
69-
: base(azureBackupContainer.ResourceGroupName, azureBackupContainer.ResourceName)
75+
: base(azureBackupContainer.ResourceGroupName, azureBackupContainer.ResourceName, azureBackupContainer.Location)
7076
{
7177
ContainerType = azureBackupContainer.ContainerType;
7278
ContainerUniqueName = azureBackupContainer.ContainerUniqueName;
7379
}
7480

75-
public AzureBackupContainerContextObject(ContainerInfo containerInfo)
76-
: base(containerInfo.ParentContainerName, containerInfo.FriendlyName)
81+
public AzureBackupContainerContextObject(ContainerInfo containerInfo, string rgName, string rName, string location)
82+
: base(rgName, rName, location)
7783
{
7884
ContainerType = containerInfo.ContainerType;
7985
ContainerUniqueName = containerInfo.Name;

src/ResourceManager/AzureBackup/Commands.AzureBackup/Models/AzureBackupContainer.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ public class AzureBackupContainer : AzureBackupContainerContextObject
3838

3939
public AzureBackupContainer() : base() { }
4040

41-
public AzureBackupContainer(ContainerInfo containerInfo)
42-
: base(containerInfo)
41+
public AzureBackupContainer(ContainerInfo containerInfo, string rgName, string rName, string location)
42+
: base(containerInfo, rgName, rName, location)
4343
{
4444
HealthStatus = containerInfo.HealthStatus;
4545
RegistrationStatus = containerInfo.RegistrationStatus;

src/ResourceManager/AzureBackup/Commands.AzureBackup/Models/AzureBackupEnums.cs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,20 @@
2020
using System.Threading.Tasks;
2121

2222
namespace Microsoft.Azure.Commands.AzureBackup.Cmdlets
23-
2423
{
24+
public enum AzureBackupContainerTypeInput
25+
{
26+
All,
27+
AzureVirtualMachine,
28+
}
29+
30+
public enum AzureBackupContainerStatusInput
31+
{
32+
All,
33+
Registering,
34+
Registered,
35+
}
36+
2537
public enum AzureBackupContainerType
2638
{
2739
Invalid = 0,

src/ResourceManager/AzureBackup/Commands.AzureBackup/Models/ProtectionPolicy.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@ public AzureBackupProtectionPolicy()
4848
{
4949
}
5050

51-
public AzureBackupProtectionPolicy(string resourceGroupName, string resourceName, ProtectionPolicyInfo sourcePolicy) : base(resourceGroupName, resourceName)
51+
public AzureBackupProtectionPolicy(string resourceGroupName, string resourceName, string location, ProtectionPolicyInfo sourcePolicy)
52+
: base(resourceGroupName, resourceName, location)
5253
{
5354
InstanceId = sourcePolicy.InstanceId;
5455
Name = sourcePolicy.Name;

0 commit comments

Comments
 (0)