Пример #1
0
        /// <summary>
        ///     The process record method.
        /// </summary>
        protected override void ProcessRecord()
        {
            base.ProcessRecord();

            try
            {
                if (Mcp1.IsPresent)
                {
                    if (Network != null && string.IsNullOrEmpty(DataCenterId))
                    {
                        DataCenterId = Network.location;
                    }

                    IEnumerable <ImagesWithDiskSpeedImage> resultlist =
                        Connection.ApiClient.GetCustomerServerImages(ImageId == Guid.Empty ? null : ImageId.ToString(), Name, DataCenterId, OperatingSystemId,
                                                                     OperatingSystemFamily).Result;
                    WriteObject(resultlist, true);
                    return;
                }

                ServerCustomerImageListOptions options = new ServerCustomerImageListOptions
                {
                    Id                    = ImageId == Guid.Empty ? (Guid?)null : ImageId,
                    DatacenterId          = DataCenterId,
                    Name                  = Name,
                    OperatingSystemId     = OperatingSystemId,
                    OperatingSystemFamily = OperatingSystemFamily
                };

                this.WritePagedObject(Connection.ApiClient.ServerManagement.ServerImage.GetCustomerImages(options, PageableRequest).Result);
            }
            catch (AggregateException ae)
            {
                ae.Handle(
                    e =>
                {
                    if (e is ComputeApiException)
                    {
                        WriteError(new ErrorRecord(e, "-2", ErrorCategory.InvalidOperation, Connection));
                    }
                    else
                    {
                        ThrowTerminatingError(new ErrorRecord(e, "-1", ErrorCategory.ConnectionError, Connection));
                    }

                    return(true);
                });
            }
        }
        /// <summary>
        /// Get Customer Images
        /// </summary>
        /// <param name="filteringOptions">Filtering options</param>
        /// <param name="pagingOptions">Paging options</param>
        /// <returns>Customer Images</returns>
        public async Task <PagedResponse <CustomerImageType> > GetCustomerImages(ServerCustomerImageListOptions filteringOptions = null, IPageableRequest pagingOptions = null)
        {
            var response = await _apiClient.GetAsync <customerImages>(
                ApiUris.GetMcp2CustomerImages(_apiClient.OrganizationId),
                pagingOptions,
                filteringOptions);

            return(new PagedResponse <CustomerImageType>
            {
                items = response.customerImage,
                totalCount = response.totalCountSpecified ? response.totalCount : (int?)null,
                pageCount = response.pageCountSpecified ? response.pageCount : (int?)null,
                pageNumber = response.pageNumberSpecified ? response.pageNumber : (int?)null,
                pageSize = response.pageSizeSpecified ? response.pageSize : (int?)null
            });
        }