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());
            }
        }
        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());
            }
        }
Ejemplo n.º 3
0
        public static PSNetAppFilesSnapshotPolicy ConvertToPs(this Management.NetApp.Models.SnapshotPolicy snapshotPolicy)
        {
            var psSnapshotPolicy = new PSNetAppFilesSnapshotPolicy
            {
                ResourceGroupName = new ResourceIdentifier(snapshotPolicy.Id).ResourceGroupName,
                Location          = snapshotPolicy.Location,
                Id   = snapshotPolicy.Id,
                Name = snapshotPolicy.Name,
                Type = snapshotPolicy.Type,
                Tags = snapshotPolicy.Tags,
                ProvisioningState = snapshotPolicy.ProvisioningState,
                Enabled           = snapshotPolicy.Enabled,
                HourlySchedule    = snapshotPolicy.HourlySchedule.ConvertToPs(),
                DailySchedule     = snapshotPolicy.DailySchedule.ConvertToPs(),
                WeeklySchedule    = snapshotPolicy.WeeklySchedule.ConvertToPs(),
                MonthlySchedule   = snapshotPolicy.MonthlySchedule.ConvertToPs()
            };

            return(psSnapshotPolicy);
        }