Exemple #1
0
        //---------------------------------------------------------------------
        // Loading.
        //---------------------------------------------------------------------

        public async static Task <InstanceDetailsModel> LoadAsync(
            InstanceLocator instanceLocator,
            IComputeEngineAdapter computeEngineAdapter,
            IInventoryService inventoryService,
            CancellationToken token)
        {
            var instance = await computeEngineAdapter
                           .GetInstanceAsync(
                instanceLocator,
                token)
                           .ConfigureAwait(false);

            var project = await computeEngineAdapter
                          .GetProjectAsync(
                instanceLocator.ProjectId,
                token)
                          .ConfigureAwait(false);

            var osInfo = await inventoryService.GetInstanceInventoryAsync(
                instanceLocator,
                token)
                         .ConfigureAwait(false);

            return(new InstanceDetailsModel(
                       project,
                       instance,
                       osInfo));
        }
        //---------------------------------------------------------------------
        // Loading.
        //---------------------------------------------------------------------

        public async static Task <InstanceDetailsModel> LoadAsync(
            InstanceLocator instanceLocator,
            IComputeEngineAdapter adapter,
            CancellationToken token)
        {
            var instance = await adapter
                           .GetInstanceAsync(
                instanceLocator,
                token)
                           .ConfigureAwait(false);

            var guestAttributes = await adapter
                                  .GetGuestAttributesAsync(
                instanceLocator,
                GuestOsInfo.GuestAttributePath,
                token)
                                  .ConfigureAwait(false);

            var guestAttributesList = guestAttributes?.QueryValue?.Items;

            return(new InstanceDetailsModel(
                       instance,
                       guestAttributesList != null
                    ? GuestOsInfo.FromGuestAttributes(guestAttributesList)
                    : null));
        }
        public async static Task <InstancePropertiesInspectorModel> LoadAsync(
            InstanceLocator instanceLocator,
            IComputeEngineAdapter computeEngineAdapter,
            IInventoryService inventoryService,
            CancellationToken token)
        {
            var instance = await computeEngineAdapter
                           .GetInstanceAsync(
                instanceLocator,
                token)
                           .ConfigureAwait(false);

            var project = await computeEngineAdapter
                          .GetProjectAsync(
                instanceLocator.ProjectId,
                token)
                          .ConfigureAwait(false);

            //
            // Reading OS inventory data can fail because of a
            // `compute.disableGuestAttributesAccess` constraint.
            //
            GuestOsInfo osInfo;

            try
            {
                osInfo = await inventoryService.GetInstanceInventoryAsync(
                    instanceLocator,
                    token)
                         .ConfigureAwait(false);
            }
            catch (Exception e) when(e.Unwrap() is GoogleApiException apiEx &&
                                     apiEx.IsConstraintViolation())
            {
                TraceSources.IapDesktop.TraceWarning(
                    "Failed to load OS inventory data: {0}", e);

                // Proceed with empty data.
                osInfo = null;
            }

            return(new InstancePropertiesInspectorModel(
                       project,
                       instance,
                       osInfo));
        }
    }