コード例 #1
0
        public override void ExecuteCmdlet()
        {
            if (ParameterSetName == ParentObjectParameterSet)
            {
                ResourceGroupName = AccountObject.ResourceGroupName;
                Location          = AccountObject.Location;
                var NameParts = AccountObject.Name.Split('/');
                AccountName = NameParts[0];
            }

            var snapshotPolicyBody = new Management.NetApp.Models.SnapshotPolicy()
            {
                Location        = Location,
                Enabled         = Enabled,
                HourlySchedule  = (HourlySchedule != null) ? HourlySchedule.ConvertFromPs() : null,
                DailySchedule   = (DailySchedule != null) ? DailySchedule.ConvertFromPs() : null,
                WeeklySchedule  = (WeeklySchedule != null) ? WeeklySchedule.ConvertFromPs() : null,
                MonthlySchedule = (MonthlySchedule != null) ? MonthlySchedule.ConvertFromPs() : null
            };

            if (ShouldProcess(Name, string.Format(PowerShell.Cmdlets.NetAppFiles.Properties.Resources.CreateResourceMessage, ResourceGroupName)))
            {
                var anfSnapshotPolicy = AzureNetAppFilesManagementClient.SnapshotPolicies.Create(snapshotPolicyBody, ResourceGroupName, AccountName, snapshotPolicyName: Name);
                WriteObject(anfSnapshotPolicy.ConvertToPs());
            }
        }
コード例 #2
0
        public override void ExecuteCmdlet()
        {
            if (ParameterSetName == ResourceIdParameterSet)
            {
                var resourceIdentifier = new ResourceIdentifier(ResourceId);
                ResourceGroupName = resourceIdentifier.ResourceGroupName;
                Name = resourceIdentifier.ResourceName;
            }
            if (ParameterSetName == ParentObjectParameterSet)
            {
                ResourceGroupName = AccountObject.ResourceGroupName;
                Location          = AccountObject.Location;
                var NameParts = AccountObject.Name.Split('/');
                AccountName = NameParts[0];
            }
            Management.NetApp.Models.SnapshotPolicy existingSnapshotPolicy = null;
            try
            {
                existingSnapshotPolicy = AzureNetAppFilesManagementClient.SnapshotPolicies.Get(ResourceGroupName, AccountName, Name);
            }
            catch
            {
                existingSnapshotPolicy = null;
            }
            if (existingSnapshotPolicy == null)
            {
                throw new AzPSResourceNotFoundCloudException($"A Snapshot Policy with name '{this.Name}' in resource group '{this.ResourceGroupName}' does not exists. Please use New-AzNetAppFilesSnapshotPolicy to create a Snapshot Policy.");
            }

            var snapshotPolicyBody = new Management.NetApp.Models.SnapshotPolicy()
            {
                Location        = Location,
                Enabled         = Enabled,
                HourlySchedule  = (HourlySchedule != null) ? HourlySchedule.ConvertFromPs() : null,
                DailySchedule   = (DailySchedule != null) ? DailySchedule.ConvertFromPs() : null,
                WeeklySchedule  = (WeeklySchedule != null) ? WeeklySchedule.ConvertFromPs() : null,
                MonthlySchedule = (MonthlySchedule != null) ? MonthlySchedule.ConvertFromPs() : null
            };

            if (ShouldProcess(Name, string.Format(PowerShell.Cmdlets.NetAppFiles.Properties.Resources.UpdateResourceMessage, ResourceGroupName)))
            {
                var anfSnapshotPolicy = AzureNetAppFilesManagementClient.SnapshotPolicies.Create(snapshotPolicyBody, ResourceGroupName, AccountName, snapshotPolicyName: Name);
                WriteObject(anfSnapshotPolicy.ConvertToPs());
            }
        }