protected override void ProcessRecord()
        {
            var queries = new Dictionary <string, string>();

            // Always include last run and stats
            queries.Add("includeLastRunAndStats", true.ToString().ToLower());

            if (OnlyActive.IsPresent)
            {
                queries.Add("isActive", true.ToString().ToLower());
            }

            if (OnlyInactive.IsPresent)
            {
                queries.Add("isActive", false.ToString().ToLower());
            }

            if (OnlyDeleted.IsPresent)
            {
                queries.Add("isDeleted", true.ToString().ToLower());
            }

            if (Ids != null && Ids.Any())
            {
                queries.Add("ids", string.Join(",", Ids));
            }

            if (Names != null && Names.Any())
            {
                queries.Add("names", string.Join(",", Names));
            }

            if (PolicyIds != null && PolicyIds.Any())
            {
                queries.Add("policyIds", string.Join(",", PolicyIds));
            }

            if (Environments != null && Environments.Any())
            {
                List <string> envs = Environments.ToList().ConvertAll <string>(x => x.ToString().First().ToString().ToLower() + x.ToString().Substring(1));
                queries.Add("environments", string.Join(",", envs));
            }

            var queryString = string.Empty;

            if (queries.Any())
            {
                queryString = "?" + string.Join("&", queries.Select(q => $"{q.Key}={q.Value}"));
            }

            var preparedUrl = $"/public/protectionJobs{queryString}";
            var results     = Session.ApiClient.Get <IEnumerable <Model.ProtectionJob> >(preparedUrl);

            // Hide deleted protection jobs unless explicitly asked for
            if (!OnlyDeleted.IsPresent)
            {
                results = results.Where(x => !(x.Name.StartsWith("_DELETED"))).ToList();
            }
            WriteObject(results, true);
        }
Example #2
0
        protected override void ProcessRecord()
        {
            var qb = new QuerystringBuilder();

            if (Environments != null && Environments.Any())
            {
                List <string> envs = Environments.ToList().ConvertAll <string>(x => x.ToString().First().ToString().ToLower() + x.ToString().Substring(1));
                qb.Add("environments", string.Join(",", envs));
            }

            if (Ids != null && Ids.Any())
            {
                qb.Add("ids", string.Join(",", Ids));
            }

            if (Names != null && Names.Any())
            {
                qb.Add("names", string.Join(",", Names));
            }

            var preparedUrl = $"/public/protectionPolicies{qb.Build()}";
            var result      = Session.ApiClient.Get <IEnumerable <Model.ProtectionPolicy> >(preparedUrl);

            WriteObject(result, true);
        }
        protected override void ProcessRecord()
        {
            var qb = new QuerystringBuilder();

            if (Id.HasValue)
            {
                var url    = $"/public/protectionSources/objects/{Id.ToString()}";
                var result = Session.ApiClient.Get <Model.ProtectionSource>(url);
                WriteObject(result);
            }
            else
            {
                if (Environments != null && Environments.Any())
                {
                    List <string> environments =
                        Environments.ToList().ConvertAll <string>(x => x.ToString().First().ToString().ToLower() + x.ToString().Substring(1));
                    qb.Add("environments", string.Join(",", environments));
                }

                var url     = $"/public/protectionSources/rootNodes{qb.Build()}";
                var results = Session.ApiClient.Get <List <ProtectionSourceNode> >(url);

                // Get the list of all group nodes
                var groups = results.Where(x => x.RegistrationInfo == null).ToList();

                foreach (var group in groups)
                {
                    // Get children for each group node
                    qb = new QuerystringBuilder();
                    qb.Add("id", group.ProtectionSource.Id.ToString());
                    url = $"/public/protectionSources{qb.Build()}";
                    var children = Session.ApiClient.Get <List <ProtectionSourceNode> >(url);
                    children = FlattenNodes(children);

                    foreach (var child in children)
                    {
                        if (child.RegistrationInfo != null)
                        {
                            results.Add(child);
                        }
                    }
                }

                // Skip kView, kAgent, kPuppeteer environment types and group nodes themselves
                results = results.Where(x =>
                                        (x.ProtectionSource.Environment != Model.ProtectionSource.EnvironmentEnum.KAgent) &&
                                        (x.ProtectionSource.Environment != Model.ProtectionSource.EnvironmentEnum.KView) &&
                                        (x.ProtectionSource.Environment != Model.ProtectionSource.EnvironmentEnum.KPuppeteer) &&
                                        (x.RegistrationInfo != null)
                                        ).ToList();

                // Make sure each source id is only listed once as it might repeat under different environments
                var sources = results.GroupBy(x => x.ProtectionSource.Id).Select(y => y.FirstOrDefault());
                WriteObject(sources, true);
            }
        }
Example #4
0
        protected override object Clone([NotNull] object model)
        {
            var clone = (ScenarioModel)base.Clone(model);

            clone.Definitions  = Definitions.Select(d => (DefinitionModel)d.Clone()).ToList();
            clone.Environments = Environments.ToList();
            clone.Actions      = Actions.ToList();

            return(clone);
        }
Example #5
0
        protected override void ProcessRecord()
        {
            var queries = new Dictionary <string, string>();

            if (StartTime.HasValue)
            {
                queries.Add("startTimeUsecs", StartTime.ToString());
            }

            if (EndTime.HasValue)
            {
                queries.Add("endTimeUsecs", EndTime.ToString());
            }

            if (Search != null)
            {
                queries.Add("search", Search);
            }

            if (Environments != null && Environments.Any())
            {
                List <string> envs = Environments.ToList().ConvertAll <string>(x => x.ToString().First().ToString().ToLower() + x.ToString().Substring(1));
                queries.Add("environments", string.Join(",", envs));
            }

            if (JobIds != null && JobIds.Any())
            {
                queries.Add("jobIds", string.Join(",", JobIds));
            }

            if (RegisteredSourceIds != null && RegisteredSourceIds.Any())
            {
                queries.Add("registeredSourceIds", string.Join(",", RegisteredSourceIds));
            }

            if (StorageDomainIds != null && StorageDomainIds.Any())
            {
                queries.Add("viewBoxIds", string.Join(",", StorageDomainIds));
            }

            var queryString = string.Empty;

            if (queries.Any())
            {
                queryString = "?" + string.Join("&", queries.Select(q => $"{q.Key}={q.Value}"));
            }

            var url    = $"/public/restore/objects{queryString}";
            var result = Session.ApiClient.Get <ObjectSearchResults>(url);

            WriteObject(result.ObjectSnapshotInfo, true);
        }
        protected override void ProcessRecord()
        {
            var qb = new QuerystringBuilder();

            if (Id.HasValue)
            {
                var url    = $"/public/protectionSources/objects/{Id.ToString()}";
                var result = Session.ApiClient.Get <Model.ProtectionSource>(url);
                WriteObject(result);
            }
            else
            {
                if (IncludeDatastores.IsPresent)
                {
                    qb.Add("includeDatastores", true);
                }

                if (IncludeNetworks.IsPresent)
                {
                    qb.Add("includeNetworks", true);
                }

                if (IncludeVMFolders.IsPresent)
                {
                    qb.Add("includeVMFolders", true);
                }

                if (Environments != null && Environments.Any())
                {
                    List <string> envs = Environments.ToList().ConvertAll <string>(x => x.ToString().First().ToString().ToLower() + x.ToString().Substring(1));
                    qb.Add("environments", string.Join(",", envs));
                }

                if (ExcludeTypes != null && ExcludeTypes.Any())
                {
                    qb.Add("excludeTypes", ExcludeTypes);
                }

                var url     = $"/public/protectionSources{qb.Build()}";
                var results = Session.ApiClient.Get <IEnumerable <ProtectionSourceNode> >(url);
                results = FlattenNodes(results);

                // Extract ProtectionSource objects
                List <Model.ProtectionSource> sources = results.Select(x => x.ProtectionSource).ToList();

                WriteObject(sources, true);
            }
        }
        protected override void ProcessRecord()
        {
            var queries = new Dictionary <string, string>();

            if (StartTime.HasValue)
            {
                if (false == IsValidTime(StartTime))
                {
                    WriteObject("Invalid start time : " + StartTime.ToString());
                    return;
                }
                queries.Add("startTimeUsecs", StartTime.ToString());
            }

            if (EndTime.HasValue)
            {
                if (false == IsValidTime(EndTime))
                {
                    WriteObject("Invalid end time : " + EndTime.ToString());
                    return;
                }
                queries.Add("endTimeUsecs", EndTime.ToString());
            }

            if (Search != null)
            {
                queries.Add("search", Search);
            }

            if (FolderOnly != null && FolderOnly.HasValue)
            {
                queries.Add("folderOnly", FolderOnly.ToString());
            }

            if (Environments != null && Environments.Any())
            {
                List <string> envs = Environments.ToList().ConvertAll <string>(x => x.ToString().First().ToString().ToLower() + x.ToString().Substring(1));
                queries.Add("environments", string.Join(",", envs));
            }

            if (JobIds != null && JobIds.Any())
            {
                queries.Add("jobIds", string.Join(",", JobIds));
            }

            if (SourceIds != null && SourceIds.Any())
            {
                queries.Add("sourceIds", string.Join(",", SourceIds));
            }

            if (RegisteredSourceIds != null && RegisteredSourceIds.Any())
            {
                queries.Add("registeredSourceIds", string.Join(",", RegisteredSourceIds));
            }

            if (StorageDomainIds != null && StorageDomainIds.Any())
            {
                queries.Add("viewBoxIds", string.Join(",", StorageDomainIds));
            }

            var queryString = string.Empty;

            if (queries.Any())
            {
                queryString = "?" + string.Join("&", queries.Select(q => $"{q.Key}={q.Value}"));
            }

            var url    = $"/public/restore/files{queryString}";
            var result = Session.ApiClient.Get <FileSearchResults>(url);

            WriteObject(result.Files, true);
        }