Example #1
0
        protected PSArgument[] CreateVirtualMachineOSImageReplicateParameters()
        {
            string imageName = string.Empty;
            VirtualMachineOSImageReplicateParameters parameters = new VirtualMachineOSImageReplicateParameters();

            return(ConvertFromObjectsToArguments(new string[] { "ImageName", "Parameters" }, new object[] { imageName, parameters }));
        }
Example #2
0
        protected void ExecuteVirtualMachineOSImageReplicateMethod(object[] invokeMethodInputParameters)
        {
            string imageName = (string)ParseParameter(invokeMethodInputParameters[0]);
            VirtualMachineOSImageReplicateParameters parameters = (VirtualMachineOSImageReplicateParameters)ParseParameter(invokeMethodInputParameters[1]);

            var result = VirtualMachineOSImageClient.Replicate(imageName, parameters);

            WriteObject(result);
        }
Example #3
0
 /// <summary>
 /// Replicate an OS image to multiple target locations. This operation
 /// is only for publishers. You have to be registered as image
 /// publisher with Windows Azure to be able to call this.
 /// </summary>
 /// <param name='operations'>
 /// Reference to the
 /// Microsoft.WindowsAzure.Management.Compute.IVirtualMachineOSImageOperations.
 /// </param>
 /// <param name='imageName'>
 /// Required. The name of the virtual machine OS image to replicate.
 /// </param>
 /// <param name='parameters'>
 /// Required. Parameters supplied to the Replicate Virtual Machine
 /// Image operation.
 /// </param>
 /// <returns>
 /// The response body contains the published name of the image.
 /// </returns>
 public static Task <VirtualMachineOSImageReplicateResponse> ReplicateAsync(this IVirtualMachineOSImageOperations operations, string imageName, VirtualMachineOSImageReplicateParameters parameters)
 {
     return(operations.ReplicateAsync(imageName, parameters, CancellationToken.None));
 }
Example #4
0
 /// <summary>
 /// Replicate an OS image to multiple target locations. This operation
 /// is only for publishers. You have to be registered as image
 /// publisher with Windows Azure to be able to call this.
 /// </summary>
 /// <param name='operations'>
 /// Reference to the
 /// Microsoft.WindowsAzure.Management.Compute.IVirtualMachineOSImageOperations.
 /// </param>
 /// <param name='imageName'>
 /// Required. The name of the virtual machine OS image to replicate.
 /// </param>
 /// <param name='parameters'>
 /// Required. Parameters supplied to the Replicate Virtual Machine
 /// Image operation.
 /// </param>
 /// <returns>
 /// The response body contains the published name of the image.
 /// </returns>
 public static VirtualMachineOSImageReplicateResponse Replicate(this IVirtualMachineOSImageOperations operations, string imageName, VirtualMachineOSImageReplicateParameters parameters)
 {
     return(Task.Factory.StartNew((object s) =>
     {
         return ((IVirtualMachineOSImageOperations)s).ReplicateAsync(imageName, parameters);
     }
                                  , operations, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default).Unwrap().GetAwaiter().GetResult());
 }
Example #5
0
        public void OSImage()
        {
            TestLogTracingInterceptor.Current.Start();
            using (var undoContext = UndoContext.Current)
            {
                undoContext.Start();
                var mgmt    = fixture.GetManagementClient();
                var compute = ComputeManagementTestUtilities.GetComputeManagementClient(fixture);
                var storage = fixture.GetStorageManagementClient();

                try
                {
                    string storageAccountName             = TestUtilities.GenerateName("rdfepir").ToLower();
                    var    osImageName                    = TestUtilities.GenerateName("osimage").ToLower();
                    var    osImageBlobName                = osImageName + ".vhd";
                    var    publicOSImageBlob_Linux_WestUS = new Uri("http://longlivedstoragerruswest.blob.core.test-cint.azure-test.net/vhdblobs/CoreOS-Stable-Generalized.30GB.vhd");
                    string location = "West US";

                    try
                    {
                        // **************
                        // SETUP
                        // **************
                        // Create storage account. Used to place os blobs.
                        storage.StorageAccounts.Create(
                            new StorageAccountCreateParameters
                        {
                            Location    = location,
                            Label       = storageAccountName,
                            Name        = storageAccountName,
                            AccountType = StorageAccountTypes.StandardGRS
                        });

                        // Copy public osimage blob into our storage account (needed for osimage create call to work).
                        var osImageBlobUri = Microsoft.Azure.Test.ComputeManagementTestUtilities.CopyPageBlobInStorage(
                            storageAccountName,
                            publicOSImageBlob_Linux_WestUS,
                            "osimages",
                            osImageBlobName);

                        // Create osimage from vhd in our storage account blob. Now we can create OSs from this image.
                        compute.VirtualMachineOSImages.Create(new VirtualMachineOSImageCreateParameters()
                        {
                            Name                = osImageName,
                            Label               = "test",
                            Description         = "test",
                            Eula                = "http://test.com",
                            SmallIconUri        = "test",
                            IconUri             = "test",
                            PrivacyUri          = new Uri("http://test.com/"),
                            ShowInGui           = false,
                            ImageFamily         = "test",
                            Language            = "test",
                            PublishedDate       = DateTime.Now,
                            RecommendedVMSize   = VirtualMachineRoleSize.Small,
                            OperatingSystemType = VirtualMachineVMImageOperatingSystemType.Windows,
                            IsPremium           = false,
                            MediaLinkUri        = osImageBlobUri,
                        });

                        // **************
                        // TESTS
                        // **************
                        var osImageParamater = new VirtualMachineOSImageReplicateParameters()
                        {
                            TargetLocations        = new[] { location },
                            ComputeImageAttributes = new ComputeImageAttributes()
                            {
                                Offer   = "TestOffer",
                                Sku     = "Standard",
                                Version = "1.0.0"
                            },
                            // Providing this should fail for a subscription that
                            // does not have image market place rights.
                            // Only one customer can hve image market place rights.
                            MarketplaceImageAttributes = new MarketplaceImageAttributes()
                            {
                                PublisherId = "publisherId",
                                Plan        = new Plan()
                                {
                                    Name      = "PlanName",
                                    Publisher = "PlanPublisher",
                                    Product   = "PlanProduct"
                                }
                            }
                        };

                        // Replicate    (check new contract with ComputeImageAttributes and MarketplaceImageAttributes is accepted - 200 OK)
                        var replicateResponse = compute.VirtualMachineOSImages.Replicate(osImageName, osImageParamater);

                        Assert.Equal(HttpStatusCode.OK, replicateResponse.StatusCode);
                        Assert.True(!string.IsNullOrEmpty(replicateResponse.RequestId));

                        // ListDetails  (check new contract with ComputeImageAttributes and MarketplaceImageAttributes is returned)
                        var osImage = compute.VirtualMachineOSImages.GetDetails(osImageName);

                        Assert.NotNull(osImage.ComputeImageAttributes);
                        Assert.Equal(osImageParamater.ComputeImageAttributes.Offer, osImage.ComputeImageAttributes.Offer);
                        Assert.Equal(osImageParamater.ComputeImageAttributes.Version, osImage.ComputeImageAttributes.Version);
                        Assert.Equal(osImageParamater.ComputeImageAttributes.Sku, osImage.ComputeImageAttributes.Sku);

                        Assert.NotNull(osImage.MarketplaceImageAttributes);
                        Assert.Equal(osImageParamater.MarketplaceImageAttributes.PublisherId, osImage.MarketplaceImageAttributes.PublisherId);
                        Assert.NotNull(osImage.MarketplaceImageAttributes.Plan);
                        Assert.Equal(osImageParamater.MarketplaceImageAttributes.Plan.Name, osImage.MarketplaceImageAttributes.Plan.Name);
                        Assert.Equal(osImageParamater.MarketplaceImageAttributes.Plan.Product, osImage.MarketplaceImageAttributes.Plan.Product);
                        Assert.Equal(osImageParamater.MarketplaceImageAttributes.Plan.Publisher, osImage.MarketplaceImageAttributes.Plan.Publisher);

                        // Share async    (check new async share succeeds)
                        var shareResponse = compute.VirtualMachineOSImages.Share(osImageName, "Private");

                        Assert.Equal(OperationStatus.Succeeded, shareResponse.Status);
                        Assert.True(!string.IsNullOrEmpty(shareResponse.RequestId));
                    }
                    finally
                    {
                        // CLEANUP
                        // Unreplicate os image
                        compute.VirtualMachineOSImages.Unreplicate(osImageName);

                        // Delete os image
                        compute.VirtualMachineOSImages.Delete(osImageName, true);

                        // Delete storage account
                        storage.StorageAccounts.Delete(storageAccountName);
                    }
                }
                finally
                {
                    undoContext.Dispose();
                    mgmt.Dispose();
                    compute.Dispose();
                    storage.Dispose();
                    TestLogTracingInterceptor.Current.Stop();
                }
            }
        }