Ejemplo 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));
            }
        }
        protected void ExecuteVirtualMachineOSImageCreateMethod(object[] invokeMethodInputParameters)
        {
            VirtualMachineOSImageCreateParameters parameters = (VirtualMachineOSImageCreateParameters)ParseParameter(invokeMethodInputParameters[0]);

            var result = VirtualMachineOSImageClient.Create(parameters);

            WriteObject(result);
        }
Ejemplo n.º 3
0
        public void ExecuteCommand()
        {
            var  imageType = new VirtualMachineImageHelper(this.ComputeClient).GetImageType(this.ImageName);
            bool isOSImage = imageType.HasFlag(VirtualMachineImageType.OSImage);
            bool isVMImage = imageType.HasFlag(VirtualMachineImageType.VMImage);

            if (isVMImage)
            {
                // If there is another type of image with the same name,
                // WAPS will stop here to avoid duplicates and potential conflicts
                WriteErrorWithTimestamp(
                    string.Format(
                        Resources.ErrorAnotherImageTypeFoundWithTheSameName,
                        VirtualMachineImageType.VMImage,
                        this.ImageName));
            }
            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,
                    IconUri             = this.IconUri,
                    SmallIconUri        = this.SmallIconUri,
                    ShowInGui           = this.ShowInGui
                };

                this.ExecuteClientActionNewSM(
                    null,
                    this.CommandRuntime.ToString(),
                    () => this.ComputeClient.VirtualMachineOSImages.Create(parameters),
                    (s, response) => this.ContextFactory <VirtualMachineOSImageCreateResponse, OSImageContext>(response, s));
            }
        }
Ejemplo n.º 4
0
        public void ExecuteCommand()
        {
            var imageType = new VirtualMachineImageHelper(this.ComputeClient).GetImageType(this.ImageName);
            bool isOSImage = imageType.HasFlag(VirtualMachineImageType.OSImage);
            bool isVMImage = imageType.HasFlag(VirtualMachineImageType.VMImage);

            if (isVMImage)
            {
                // If there is another type of image with the same name,
                // WAPS will stop here to avoid duplicates and potential conflicts
                WriteErrorWithTimestamp(
                    string.Format(
                        Resources.ErrorAnotherImageTypeFoundWithTheSameName,
                        VirtualMachineImageType.VMImage,
                        this.ImageName));
            }
            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));
            }
        }
Ejemplo n.º 5
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));
            }
        }
Ejemplo n.º 6
0
 /// <summary>
 /// The Create OS Image operation adds an operating system image that
 /// is stored in a storage account and is available from the image
 /// repository.  (see
 /// http://msdn.microsoft.com/en-us/library/windowsazure/jj157192.aspx
 /// for more information)
 /// </summary>
 /// <param name='operations'>
 /// Reference to the
 /// Microsoft.WindowsAzure.Management.Compute.IVirtualMachineOSImageOperations.
 /// </param>
 /// <param name='parameters'>
 /// Required. Parameters supplied to the Create Virtual Machine Image
 /// operation.
 /// </param>
 /// <returns>
 /// Parameters returned from the Create Virtual Machine Image operation.
 /// </returns>
 public static Task <VirtualMachineOSImageCreateResponse> CreateAsync(this IVirtualMachineOSImageOperations operations, VirtualMachineOSImageCreateParameters parameters)
 {
     return(operations.CreateAsync(parameters, CancellationToken.None));
 }
Ejemplo n.º 7
0
 /// <summary>
 /// The Create OS Image operation adds an operating system image that
 /// is stored in a storage account and is available from the image
 /// repository.  (see
 /// http://msdn.microsoft.com/en-us/library/windowsazure/jj157192.aspx
 /// for more information)
 /// </summary>
 /// <param name='operations'>
 /// Reference to the
 /// Microsoft.WindowsAzure.Management.Compute.IVirtualMachineOSImageOperations.
 /// </param>
 /// <param name='parameters'>
 /// Required. Parameters supplied to the Create Virtual Machine Image
 /// operation.
 /// </param>
 /// <returns>
 /// Parameters returned from the Create Virtual Machine Image operation.
 /// </returns>
 public static VirtualMachineOSImageCreateResponse Create(this IVirtualMachineOSImageOperations operations, VirtualMachineOSImageCreateParameters parameters)
 {
     return(Task.Factory.StartNew((object s) =>
     {
         return ((IVirtualMachineOSImageOperations)s).CreateAsync(parameters);
     }
                                  , operations, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default).Unwrap().GetAwaiter().GetResult());
 }
Ejemplo n.º 8
0
        protected override void OnProcessRecord()
        {
            ServiceManagementProfile.Initialize();

            if (string.Equals(ParameterSetName, VMImageParamSet, StringComparison.OrdinalIgnoreCase))
            {
                var osDiskConfig    = DiskConfig == null ? null : DiskConfig.OSDiskConfiguration;
                var dataDiskConfigs =
                    (DiskConfig == null || DiskConfig.DataDiskConfigurations == null)
                    ? null
                    : DiskConfig.DataDiskConfigurations.ToList();

                var parameters = new VirtualMachineVMImageCreateParameters
                {
                    Name = this.ImageName,
                    OSDiskConfiguration = osDiskConfig == null ? null : new OSDiskConfigurationCreateParameters
                    {
                        OS          = osDiskConfig.OS,
                        OSState     = osDiskConfig.OSState,
                        HostCaching = osDiskConfig.HostCaching,
                        MediaLink   = osDiskConfig.MediaLink
                    },
                    DataDiskConfigurations = dataDiskConfigs == null ? null : dataDiskConfigs.Select(d => new DataDiskConfigurationCreateParameters
                    {
                        HostCaching       = d.HostCaching,
                        LogicalUnitNumber = d.Lun,
                        MediaLink         = d.MediaLink
                    }).ToList(),
                    Label             = string.IsNullOrEmpty(this.Label) ? this.ImageName : this.Label,
                    Eula              = this.Eula,
                    Description       = this.Description,
                    ImageFamily       = this.ImageFamily,
                    PublishedDate     = this.PublishedDate,
                    PrivacyUri        = this.PrivacyUri,
                    RecommendedVMSize = this.RecommendedVMSize,
                    IconUri           = this.IconName,
                    SmallIconUri      = this.SmallIconName,
                    ShowInGui         = this.ShowInGui
                };

                this.ExecuteClientActionNewSM(
                    null,
                    this.CommandRuntime.ToString(),
                    () => this.ComputeClient.VirtualMachineVMImages.Create(parameters));
            }
            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,
                    IconUri             = this.IconName,
                    SmallIconUri        = this.SmallIconName,
                    ShowInGui           = this.ShowInGui
                };

                this.ExecuteClientActionNewSM(
                    null,
                    this.CommandRuntime.ToString(),
                    () => this.ComputeClient.VirtualMachineOSImages.Create(parameters),
                    (s, response) => this.ContextFactory(response, s,
                                                         ServiceManagementProfile.Mapper.Map <VirtualMachineOSImageCreateResponse, OSImageContext>,
                                                         ServiceManagementProfile.Mapper.Map));
            }
        }
        protected PSArgument[] CreateVirtualMachineOSImageCreateParameters()
        {
            VirtualMachineOSImageCreateParameters parameters = new VirtualMachineOSImageCreateParameters();

            return(ConvertFromObjectsToArguments(new string[] { "Parameters" }, new object[] { parameters }));
        }