Пример #1
0
        /// <summary>
        /// Process
        /// </summary>
        protected override void ProcessRecord()
        {
            var  domain          = RestApiCommon.GetStorageDomainByName(Session.ApiClient, StorageDomainName);
            long storageDomainId = (long)domain.Id;

            var request = new Model.CreateViewRequest(name: Name, viewBoxId: storageDomainId)
            {
                Description    = Description,
                ProtocolAccess = (Model.CreateViewRequest.ProtocolAccessEnum)AccessProtocol,
                Qos            = new Model.QoS(principalName: QosPolicy),
                CaseInsensitiveNamesEnabled     = CaseInsensitiveNames.IsPresent,
                EnableSmbViewDiscovery          = BrowsableShares.IsPresent,
                EnableSmbAccessBasedEnumeration = SmbAccessBasedEnumeration.IsPresent,
                StoragePolicyOverride           = new Model.StoragePolicyOverride(DisableInlineDedupAndCompression.IsPresent)
            };

            if (LogicalQuotaInBytes != null || AlertQuotaInBytes != null)
            {
                request.LogicalQuota = new Model.QuotaPolicy();

                if (LogicalQuotaInBytes != null)
                {
                    request.LogicalQuota.HardLimitBytes = LogicalQuotaInBytes;
                }

                if (AlertQuotaInBytes != null)
                {
                    request.LogicalQuota.AlertLimitBytes = AlertQuotaInBytes;
                }
            }

            var preparedUrl = $"/public/views";
            var result      = Session.ApiClient.Post <Model.View>(preparedUrl, request);

            WriteObject(result);
        }
        protected override void ProcessRecord()
        {
            if (string.IsNullOrWhiteSpace(Timezone))
            {
                Timezone = TimeZoneInfoExtensions.GetOlsonTimeZone();
            }

            if (!string.IsNullOrWhiteSpace(PolicyName))
            {
                var policy = RestApiCommon.GetPolicyByName(Session.ApiClient, PolicyName);
                PolicyId = policy.Id;
            }

            if (!string.IsNullOrWhiteSpace(StorageDomainName))
            {
                var domain = RestApiCommon.GetStorageDomainByName(Session.ApiClient, StorageDomainName);
                StorageDomainId = (long)domain.Id;
            }

            var newProtectionJob = new Model.ProtectionJob(name: Name, policyId: PolicyId, viewBoxId: StorageDomainId)
            {
                Timezone  = Timezone,
                StartTime = new TimeOfDay(ScheduleStartTime.Hour, ScheduleStartTime.Minute)
            };

            if (ParentSourceId.HasValue)
            {
                newProtectionJob.ParentSourceId = ParentSourceId;
            }

            if (SourceIds != null && SourceIds.Any())
            {
                newProtectionJob.SourceIds = SourceIds.ToList();
            }

            if (ExcludeSourceIds != null && ExcludeSourceIds.Any())
            {
                newProtectionJob.ExcludeSourceIds = ExcludeSourceIds.ToList();
            }

            if (VmTagIds != null && VmTagIds.Any())
            {
                var vmTagIdsList = VmTagIds.ToList();
                newProtectionJob.VmTagIds = new List <List <long> >();
                foreach (var vmTagIds in vmTagIdsList)
                {
                    newProtectionJob.VmTagIds.Add(new List <long> {
                        vmTagIds
                    });
                }
            }

            if (ExcludeVmTagIds != null && ExcludeVmTagIds.Any())
            {
                var excludeVmTagIdsList = ExcludeVmTagIds.ToList();
                newProtectionJob.ExcludeVmTagIds = new List <List <long> >();
                foreach (var excludeVmTagIds in excludeVmTagIdsList)
                {
                    newProtectionJob.ExcludeVmTagIds.Add(new List <long> {
                        excludeVmTagIds
                    });
                }
            }

            if (!string.IsNullOrWhiteSpace(ViewName))
            {
                newProtectionJob.ViewName = ViewName;
            }

            newProtectionJob.Environment = Environment != null ? Environment : Model.ProtectionJob.EnvironmentEnum.KView;

            if (FullSLATimeInMinutes != null)
            {
                newProtectionJob.FullProtectionSlaTimeMins = FullSLATimeInMinutes;
            }

            if (IncrementalSLATimeInMinutes != null)
            {
                newProtectionJob.IncrementalProtectionSlaTimeMins = IncrementalSLATimeInMinutes;
            }

            if (SourceSpecialParameters != null && SourceSpecialParameters.Any())
            {
                newProtectionJob.SourceSpecialParameters = SourceSpecialParameters.ToList();
            }

            var preparedUrl = $"/public/protectionJobs";
            var result      = Session.ApiClient.Post <Model.ProtectionJob>(preparedUrl, newProtectionJob);

            WriteObject(result);
        }