-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Expand file tree
/
Copy pathAzureVmItem.cs
More file actions
137 lines (121 loc) · 7.08 KB
/
Copy pathAzureVmItem.cs
File metadata and controls
137 lines (121 loc) · 7.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
// ----------------------------------------------------------------------------------
//
// Copyright Microsoft Corporation
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// ----------------------------------------------------------------------------------
using System.Collections.Generic;
using Microsoft.Azure.Management.Internal.Resources.Utilities.Models;
using Microsoft.Azure.Management.RecoveryServices.Backup.Models;
using CrrModel = Microsoft.Azure.Management.RecoveryServices.Backup.CrossRegionRestore.Models;
namespace Microsoft.Azure.Commands.RecoveryServices.Backup.Cmdlets.Models
{
/// <summary>
/// IaaSVM Item Class
/// </summary>
public class AzureVmItem : AzureItem
{
public string VirtualMachineId { get; set; }
public string ContainerSubscriptionId { get; set; }
public string HealthStatus { get; set; }
public bool? IsInclusionList { get; set; }
public IList<int?> DiskLunList { get; set; }
/// <summary>
/// Constructor. Takes the service client object representing the protected item
/// and converts it in to the PS protected item model
/// </summary>
/// <param name="protectedItemResource">Service client object representing the protected item resource</param>
/// <param name="containerName">Name of the container associated with this protected item</param>
/// <param name="containerType">Type of the container associated with this protected item</param>
/// <param name="policyName">Name of the protection policy associated with this protected item</param>
public AzureVmItem(ProtectedItemResource protectedItemResource,
string containerName, ContainerType containerType, string policyName)
: base(protectedItemResource, containerName, containerType, policyName)
{
AzureIaaSVMProtectedItem protectedItem = (AzureIaaSVMProtectedItem)protectedItemResource.Properties;
LastBackupStatus = protectedItem.LastBackupStatus;
LastBackupTime = protectedItem.LastBackupTime;
ProtectionState =
EnumUtils.GetEnum<ItemProtectionState>(protectedItem.ProtectionState.ToString());
ProtectionStatus = EnumUtils.GetEnum<ItemProtectionStatus>(protectedItem.ProtectionStatus);
VirtualMachineId = protectedItem.VirtualMachineId;
HealthStatus = protectedItem.HealthStatus;
if (!string.IsNullOrEmpty(SourceResourceId))
{
var resourceIdentifier = new ResourceIdentifier(SourceResourceId);
ContainerSubscriptionId = resourceIdentifier.Subscription;
}
IsArchiveEnabled = protectedItem.IsArchiveEnabled;
SoftDeleteRetentionPeriodInDays = protectedItem.SoftDeleteRetentionPeriodInDays;
IsScheduledForDeferredDelete = protectedItem.IsScheduledForDeferredDelete;
DeferredDeleteTimeInUtc = protectedItem.DeferredDeleteTimeInUtc;
DateOfPurge = null;
DeleteState = EnumUtils.GetEnum<ItemDeleteState>("NotDeleted");
if (protectedItem.IsScheduledForDeferredDelete.HasValue && protectedItem.IsScheduledForDeferredDelete.Value)
{
int softDeleteRetentionDays = protectedItem?.SoftDeleteRetentionPeriodInDays ?? 14;
DateOfPurge = protectedItem.DeferredDeleteTimeInUtc.Value.AddDays((int)softDeleteRetentionDays);
DeleteState = EnumUtils.GetEnum<ItemDeleteState>("ToBeDeleted");
}
if (protectedItem.ExtendedProperties != null &&
protectedItem.ExtendedProperties.DiskExclusionProperties != null)
{
DiskExclusionProperties diskExclusionProperties = protectedItem.ExtendedProperties.DiskExclusionProperties;
IsInclusionList = diskExclusionProperties.IsInclusionList;
DiskLunList = diskExclusionProperties.DiskLunList;
}
}
/// <summary>
/// Constructor. Takes the service client object representing the protected item
/// and converts it in to the PS protected item model
/// </summary>
/// <param name="protectedItemResource">Service client object representing the protected item resource</param>
/// <param name="containerName">Name of the container associated with this protected item</param>
/// <param name="containerType">Type of the container associated with this protected item</param>
/// <param name="policyName">Name of the protection policy associated with this protected item</param>
public AzureVmItem(CrrModel.ProtectedItemResource protectedItemResource,
string containerName, ContainerType containerType, string policyName)
: base(protectedItemResource, containerName, containerType, policyName)
{
CrrModel.AzureIaaSVMProtectedItem protectedItem = (CrrModel.AzureIaaSVMProtectedItem)protectedItemResource.Properties;
LastBackupStatus = protectedItem.LastBackupStatus;
LastBackupTime = protectedItem.LastBackupTime;
ProtectionState =
EnumUtils.GetEnum<ItemProtectionState>(protectedItem.ProtectionState.ToString());
ProtectionStatus = EnumUtils.GetEnum<ItemProtectionStatus>(protectedItem.ProtectionStatus);
VirtualMachineId = protectedItem.VirtualMachineId;
HealthStatus = protectedItem.HealthStatus;
if (!string.IsNullOrEmpty(SourceResourceId))
{
var resourceIdentifier = new ResourceIdentifier(SourceResourceId);
ContainerSubscriptionId = resourceIdentifier.Subscription;
}
DateOfPurge = null;
DeleteState = EnumUtils.GetEnum<ItemDeleteState>("NotDeleted");
if (protectedItem.IsScheduledForDeferredDelete.HasValue)
{
DateOfPurge = protectedItem.DeferredDeleteTimeInUtc.Value.AddDays(14);
DeleteState = EnumUtils.GetEnum<ItemDeleteState>("ToBeDeleted");
}
if (protectedItem.ExtendedProperties != null &&
protectedItem.ExtendedProperties.DiskExclusionProperties != null)
{
CrrModel.DiskExclusionProperties diskExclusionProperties = protectedItem.ExtendedProperties.DiskExclusionProperties;
IsInclusionList = diskExclusionProperties.IsInclusionList;
DiskLunList = diskExclusionProperties.DiskLunList;
}
}
}
/// <summary>
/// IaaSVM Item ExtendedInfo Class
/// </summary>
public class AzureVmItemExtendedInfo : AzureItemExtendedInfo
{ }
}