Ejemplo n.º 1
0
 public ReportViewModel(ReportArchive model)
 {
     this.Model              = model;
     this.NodeReportPane     = new ReportNodesTabViewModel(this);
     this.InstanceReportPane = new ReportInstancesTabViewModel(this);
     this.LicensesReportPane = new ReportLicensesTabViewModel(this);
 }
Ejemplo n.º 2
0
 public ReportItemsViewModelBase(ReportArchive model)
 {
     this.model         = model;
     this.dateSelection = new DateSelection()
     {
         StartDate = model.History.StartDate,
         EndDate   = model.History.EndDate
     };
 }
Ejemplo n.º 3
0
        public async Task <ReportArchive> BuildAsync(CancellationToken cancellationToken)
        {
            using (TraceSources.IapDesktop.TraceMethod().WithoutParameters())
            {
                this.PercentageDone = 5;
                this.BuildStatus    = "Analyzing current state...";

                foreach (var projectId in this.projectIds)
                {
                    //
                    // Load disks.
                    //
                    // NB. Instances.list returns the disks associated with each
                    // instance, but lacks the information about the source image.
                    // Therefore, we load disks first and then join the data.
                    //
                    var disks = await this.computeEngineAdapter.ListDisksAsync(
                        projectId,
                        cancellationToken).ConfigureAwait(false);

                    //
                    // Load instances.
                    //
                    var instances = await this.computeEngineAdapter.ListInstancesAsync(
                        projectId,
                        cancellationToken).ConfigureAwait(false);

                    this.builder.AddExistingInstances(
                        instances,
                        disks,
                        projectId);
                }

                this.PercentageDone = 10;
                this.BuildStatus    = $"Analyzing changes made since {this.builder.StartDate:d}...";

                await this.auditLogAdapter.ListInstanceEventsAsync(
                    this.projectIds,
                    null,  // all zones.
                    null,  // all instances.
                    this.builder.StartDate,
                    this,
                    cancellationToken).ConfigureAwait(false);

                this.PercentageDone = 90;
                this.BuildStatus    = "Finalizing report...";

                var archive = ReportArchive.FromInstanceSetHistory(this.builder.Build());

                await archive.LoadLicenseAnnotationsAsync(
                    this.computeEngineAdapter,
                    cancellationToken).ConfigureAwait(false);

                return(archive);
            }
        }
Ejemplo n.º 4
0
 public Envelope(
     [JsonProperty("@type")] string typeAnnotation,
     [JsonProperty("instanceSetHistory")] ReportArchive instanceSetHistory)
     : this(instanceSetHistory)
 {
     if (typeAnnotation != TypeAnnotation)
     {
         throw new FormatException("Missing type annotation: " + TypeAnnotation);
     }
 }
Ejemplo n.º 5
0
        public static async Task LoadLicenseAnnotationsAsync(
            ReportArchive annotatedSet,
            IComputeEngineAdapter computeEngineAdapter,
            CancellationToken cancellationToken)
        {
            foreach (var image in annotatedSet.History.Instances
                     .Where(i => i.Image != null)
                     .Select(i => i.Image)
                     .Distinct())
            {
                try
                {
                    Image imageInfo = await computeEngineAdapter
                                      .GetImage(image, cancellationToken)
                                      .ConfigureAwait(false);

                    // Images can contain more than one license, and liceses like
                    // "/compute/v1/projects/compute-image-tools/global/licenses/virtual-disk-import"
                    // are not helpful here. So do some filtering.

                    var license = TryGetRelevantLicenseFromImage(imageInfo);
                    annotatedSet.AddLicenseAnnotation(
                        image,
                        license);

                    TraceSources.IapDesktop.TraceVerbose("License for {0} is {1}", image, license);
                }
                catch (ResourceNotFoundException) when(image.ProjectId == "windows-cloud")
                {
                    // That image might not exist anymore, but we know it's
                    // a Windows SPLA image.
                    annotatedSet.AddLicenseAnnotation(
                        image,
                        OperatingSystemTypes.Windows,
                        LicenseTypes.Spla);

                    TraceSources.IapDesktop.TraceVerbose(
                        "License for {0} could not be found, but must be Windows/SPLA", image);
                }
                catch (ResourceNotFoundException e)
                {
                    // Unknown or inaccessible image, skip.
                    TraceSources.IapDesktop.TraceWarning(
                        "License for {0} could not be found: {0}", image, e);
                }
                catch (ResourceAccessDeniedException e)
                {
                    // Unknown or inaccessible image, skip.
                    TraceSources.IapDesktop.TraceWarning(
                        "License for {0} could not be accessed: {0}", image, e);
                }
            }
        }
Ejemplo n.º 6
0
 public Envelope(
     ReportArchive instanceSetHistory)
 {
     this.InstanceSetHistory = instanceSetHistory;
 }