/// <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();
 }
 /// <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);
 }
        protected override void OnProcessRecord()
        {
            ServiceManagementProfile.Initialize();

            if (string.Equals(ParameterSetName, VMImageParamSet, StringComparison.OrdinalIgnoreCase))
            {
                var osDiskConfig = DiskConfig == null ? null : DiskConfig.OSDiskConfiguration;
                var dataDiskConfigs = DiskConfig == 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<VirtualMachineOSImageCreateResponse, OSImageContext>(response, s));
            }
        }
        protected PSArgument[] CreateVirtualMachineOSImageCreateParameters()
        {
            VirtualMachineOSImageCreateParameters parameters = new VirtualMachineOSImageCreateParameters();

            return ConvertFromObjectsToArguments(new string[] { "Parameters" }, new object[] { parameters });
        }
Exemplo n.º 5
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));
            }
        }