Inheritance: ServiceManagementBaseCmdlet
Esempio n. 1
0
        public void ExecuteCommand()
        {
            if (GetAzureVMImage.CheckImageType(this.ComputeClient, this.ImageName, ImageType.VMImage))
            {
                // If there is another type of image with the same name, WAPS will stop here to avoid duplicates and potential conflicts
                var errorMsg = string.Format(Resources.ErrorAnotherImageTypeFoundWithTheSameName, ImageType.VMImage, this.ImageName);
                WriteError(new ErrorRecord(new Exception(errorMsg), string.Empty, ErrorCategory.CloseError, null));
            }
            else
            {
                var parameters = new VirtualMachineOSImageCreateParameters
                {
                    Name                = this.ImageName,
                    MediaLinkUri        = new Uri(this.MediaLocation),
                    Label               = string.IsNullOrEmpty(this.Label) ? this.ImageName : this.Label,
                    OperatingSystemType = this.OS,
                    Eula                = this.Eula,
                    Description         = this.Description,
                    ImageFamily         = this.ImageFamily,
                    PublishedDate       = this.PublishedDate,
                    PrivacyUri          = this.PrivacyUri,
                    RecommendedVMSize   = this.RecommendedVMSize
                };

                this.ExecuteClientActionNewSM(
                    null,
                    this.CommandRuntime.ToString(),
                    () => this.ComputeClient.VirtualMachineOSImages.Create(parameters),
                    (s, response) => this.ContextFactory <VirtualMachineOSImageCreateResponse, OSImageContext>(response, s));
            }
        }
Esempio n. 2
0
        public void RemoveVMImageProcess()
        {
            ServiceManagementProfile.Initialize(this);

            this.ExecuteClientActionNewSM(
                null,
                this.CommandRuntime.ToString(),
                () =>
            {
                OperationResponse op = null;

                bool isOSImage = GetAzureVMImage.CheckImageType(this.ComputeClient, this.ImageName, ImageType.OSImage);
                bool isVMImage = GetAzureVMImage.CheckImageType(this.ComputeClient, this.ImageName, ImageType.VMImage);

                if (isOSImage && isVMImage)
                {
                    var errorMsg = string.Format(Resources.DuplicateNamesFoundInBothVMAndOSImages, this.ImageName);
                    WriteError(new ErrorRecord(new Exception(errorMsg), string.Empty, ErrorCategory.CloseError, null));
                }
                else if (isVMImage)
                {
                    if (this.DeleteVHD.IsPresent)
                    {
                        op = this.ComputeClient.VirtualMachineVMImages.Delete(this.ImageName, true);
                    }
                    else
                    {
                        WriteErrorWithTimestamp(Resources.VMImageDeletionMustSpecifyDeleteVhdParameter);
                    }
                }
                else
                {
                    // Remove the image from the image repository
                    op = this.ComputeClient.VirtualMachineOSImages.Delete(this.ImageName, this.DeleteVHD.IsPresent);
                }

                return(op);
            });
        }