protected void ExecuteExtensionImageRegisterMethod(object[] invokeMethodInputParameters) { ExtensionImageRegisterParameters parameters = (ExtensionImageRegisterParameters)ParseParameter(invokeMethodInputParameters[0]); var result = ExtensionImageClient.Register(parameters); WriteObject(result); }
public void CanRegisterUpdateAndUnregisterExtensionImage() { TestLogTracingInterceptor.Current.Start(); using (var undoContext = UndoContext.Current) { undoContext.Start(); var mgmt = fixture.GetManagementClient(); var compute = fixture.GetComputeManagementClient(); var storage = fixture.GetStorageManagementClient(); string versionStr = "74.59.0.0"; string verUpdtStr = "74.60.0.0"; const string publicSchemaStr = @"<?xml version=""1.0"" encoding=""utf-8""?>" + @"<xs:schema attributeFormDefault=""unqualified""" + @" elementFormDefault=""qualified""" + @" xmlns:xs=""http://www.w3.org/2001/XMLSchema"">" + @" <xs:element name=""PublicConfig"">" + @" <xs:complexType>" + @" <xs:sequence>" + @" <xs:element name=""UserName"" type=""xs:string"" />" + @" </xs:sequence>" + @" </xs:complexType>" + @" </xs:element>" + @"</xs:schema>"; const string privateSchemaStr = @"<?xml version=""1.0"" encoding=""utf-8""?>" + @"<xs:schema attributeFormDefault=""unqualified""" + @" elementFormDefault=""qualified""" + @" xmlns:xs=""http://www.w3.org/2001/XMLSchema"">" + @" <xs:element name=""PrivateConfig"">" + @" <xs:complexType>" + @" <xs:sequence>" + @" <xs:element name=""Password"" type=""xs:string"" />" + @" </xs:sequence>" + @" </xs:complexType>" + @" </xs:element>" + @"</xs:schema>"; const string sampleConfigStr = "TestSampleConfig"; try { string storageName = TestUtilities.GenerateName("teststorage"); string providerName = TestUtilities.GenerateName("testprovider"); string extensionName = TestUtilities.GenerateName("testextension"); string location = mgmt.GetDefaultLocation("Storage", "Compute"); const string usWestLocStr = "West US"; if (mgmt.Locations.List().Any( c => string.Equals(c.Name, usWestLocStr, StringComparison.OrdinalIgnoreCase))) { location = usWestLocStr; } // create a storage account var storageAccountResult = storage.StorageAccounts.Create( new StorageAccountCreateParameters { Location = location, Name = storageName, AccountType = "Standard_LRS" }); // get the storage account var keyResult = storage.StorageAccounts.GetKeys(storageName); // build the connection string const string containerStr = "ext"; Uri blobUri = StorageTestUtilities.UploadFileToBlobStorage(storageName, containerStr, @".\RemoteAccessPlugin.zip"); bool isPublisher = false; const string errorCodeStr = "ForbiddenError"; try { var parameters = new ExtensionImageRegisterParameters { ProviderNameSpace = providerName, Type = extensionName, Version = versionStr, HostingResources = "VmRole", MediaLink = blobUri, Label = providerName, Description = providerName, BlockRoleUponFailure = false, Certificate = new ExtensionCertificateConfiguration { StoreLocation = "LocalMachine", StoreName = "My", ThumbprintAlgorithm = "sha1", ThumbprintRequired = true }, LocalResources = new List <ExtensionLocalResourceConfiguration> { new ExtensionLocalResourceConfiguration { Name = "Test1", SizeInMB = 100 }, new ExtensionLocalResourceConfiguration { Name = "Test2", SizeInMB = 200 } }, DisallowMajorVersionUpgrade = true, SampleConfig = sampleConfigStr, PublishedDate = DateTime.Now, Eula = new Uri("http://test.com"), PrivacyUri = new Uri("http://test.com"), HomepageUri = new Uri("http://test.com"), IsInternalExtension = true, PrivateConfigurationSchema = privateSchemaStr, PublicConfigurationSchema = publicSchemaStr, ExtensionEndpoints = new ExtensionEndpointConfiguration { InputEndpoints = new List <ExtensionEndpointConfiguration.InputEndpoint> { new ExtensionEndpointConfiguration.InputEndpoint { Name = "Test1", Port = 1111, LocalPort = "*", Protocol = "tcp" }, new ExtensionEndpointConfiguration.InputEndpoint { Name = "Test2", Port = 2222, LocalPort = "22222", Protocol = "tcp" } }, InternalEndpoints = new List <ExtensionEndpointConfiguration.InternalEndpoint> { new ExtensionEndpointConfiguration.InternalEndpoint { Name = "Test1", Port = 1111, Protocol = "tcp" }, new ExtensionEndpointConfiguration.InternalEndpoint { Name = "Test2", Port = 2222, Protocol = "tcp" }, }, InstanceInputEndpoints = new List <ExtensionEndpointConfiguration.InstanceInputEndpoint> { new ExtensionEndpointConfiguration.InstanceInputEndpoint { Name = "Test1", Protocol = "tcp", LocalPort = "111", FixedPortMin = 100, FixedPortMax = 1000 }, new ExtensionEndpointConfiguration.InstanceInputEndpoint { Name = "Test2", Protocol = "tcp", LocalPort = "22", FixedPortMin = 2000, FixedPortMax = 10000 } } }, IsJsonExtension = false, CompanyName = providerName, SupportedOS = ExtensionImageSupportedOperatingSystemType.Windows, Regions = usWestLocStr, }; compute.ExtensionImages.Register(parameters); isPublisher = true; bool found = false; const int maxRetryTimes = 60; int retryTime = 0; VirtualMachineExtensionListResponse.ResourceExtension ext = null; while (!found && retryTime < maxRetryTimes) { Thread.Sleep(TimeSpan.FromMinutes(1.0)); ext = compute.VirtualMachineExtensions .ListVersions(providerName, extensionName) .FirstOrDefault(e => string.Equals(e.Version, versionStr)); if (ext != null) { found = true; } retryTime++; } if (found) { Assert.True(ext != null); Assert.Equal <string>(ext.Name, parameters.Type); Assert.Equal <string>(ext.Publisher, parameters.ProviderNameSpace); Assert.Equal <string>(ext.Description, parameters.Description); Assert.Equal <string>(ext.SampleConfig, parameters.SampleConfig); Assert.Equal <string>(ext.PrivateConfigurationSchema, parameters.PrivateConfigurationSchema); Assert.Equal <string>(ext.PublicConfigurationSchema, parameters.PublicConfigurationSchema); Assert.Equal <string>(ext.Eula.ToString(), parameters.Eula.ToString()); Assert.Equal <string>(ext.PrivacyUri.ToString(), parameters.PrivacyUri.ToString()); Assert.Equal <string>(ext.HomepageUri.ToString(), parameters.HomepageUri.ToString()); Assert.Equal <bool?>(ext.IsInternalExtension, parameters.IsInternalExtension); Assert.Equal <bool?>(ext.DisallowMajorVersionUpgrade, parameters.DisallowMajorVersionUpgrade); Assert.Equal <bool?>(ext.IsInternalExtension, parameters.IsInternalExtension); Assert.Equal <string>(ext.CompanyName, parameters.CompanyName); Assert.Equal <string>(ext.SupportedOS, parameters.SupportedOS); Assert.True(parameters.IsJsonExtension != null && !parameters.IsJsonExtension.Value && (ext.IsJsonExtension == null || !ext.IsJsonExtension.Value)); } } catch (CloudException e) { Assert.True(!isPublisher && e != null && e.Error.Code.Equals(errorCodeStr)); } try { var parameters = new ExtensionImageUpdateParameters { ProviderNameSpace = providerName, Type = extensionName, Version = verUpdtStr, HostingResources = "VmRole", MediaLink = blobUri, Label = providerName, Description = providerName, BlockRoleUponFailure = false, Certificate = new ExtensionCertificateConfiguration { StoreLocation = "LocalMachine", StoreName = "My", ThumbprintAlgorithm = "sha1", ThumbprintRequired = true }, LocalResources = new List <ExtensionLocalResourceConfiguration> { new ExtensionLocalResourceConfiguration { Name = "Test1", SizeInMB = 100 }, new ExtensionLocalResourceConfiguration { Name = "Test2", SizeInMB = 200 } }, DisallowMajorVersionUpgrade = true, SampleConfig = sampleConfigStr, PublishedDate = DateTime.Now, Eula = new Uri("http://test.com"), PrivacyUri = new Uri("http://test.com"), HomepageUri = new Uri("http://test.com"), IsInternalExtension = true, PrivateConfigurationSchema = privateSchemaStr, PublicConfigurationSchema = publicSchemaStr, ExtensionEndpoints = new ExtensionEndpointConfiguration { InputEndpoints = new List <ExtensionEndpointConfiguration.InputEndpoint> { new ExtensionEndpointConfiguration.InputEndpoint { Name = "Test1", Port = 1111, LocalPort = "11111", Protocol = "tcp" }, new ExtensionEndpointConfiguration.InputEndpoint { Name = "Test2", Port = 2222, LocalPort = "*", Protocol = "tcp" } }, InternalEndpoints = new List <ExtensionEndpointConfiguration.InternalEndpoint> { new ExtensionEndpointConfiguration.InternalEndpoint { Name = "Test1", Port = 1111, Protocol = "tcp" }, new ExtensionEndpointConfiguration.InternalEndpoint { Name = "Test2", Port = 2222, Protocol = "tcp" } }, InstanceInputEndpoints = new List <ExtensionEndpointConfiguration.InstanceInputEndpoint> { new ExtensionEndpointConfiguration.InstanceInputEndpoint { Name = "Test1", Protocol = "tcp", LocalPort = "11", FixedPortMin = 100, FixedPortMax = 1000 }, new ExtensionEndpointConfiguration.InstanceInputEndpoint { Name = "Test2", Protocol = "tcp", LocalPort = "22", FixedPortMin = 2000, FixedPortMax = 10000 } } }, IsJsonExtension = false, CompanyName = providerName, SupportedOS = ExtensionImageSupportedOperatingSystemType.Windows, Regions = usWestLocStr, }; compute.ExtensionImages.Update(parameters); bool found = false; const int maxRetryTimes = 60; int retryTime = 0; VirtualMachineExtensionListResponse.ResourceExtension ext = null; while (!found && retryTime < maxRetryTimes) { Thread.Sleep(TimeSpan.FromMinutes(1.0)); ext = compute.VirtualMachineExtensions .ListVersions(providerName, extensionName) .FirstOrDefault(e => string.Equals(e.Version, verUpdtStr)); if (ext != null) { found = true; } retryTime++; } if (found) { Assert.True(ext != null); Assert.Equal <string>(ext.Name, parameters.Type); Assert.Equal <string>(ext.Publisher, parameters.ProviderNameSpace); Assert.Equal <string>(ext.Description, parameters.Description); Assert.Equal <string>(ext.PrivateConfigurationSchema, parameters.PrivateConfigurationSchema); Assert.Equal <string>(ext.PublicConfigurationSchema, parameters.PublicConfigurationSchema); Assert.Equal <string>(ext.Eula.ToString(), parameters.Eula.ToString()); Assert.Equal <string>(ext.PrivacyUri.ToString(), parameters.PrivacyUri.ToString()); Assert.Equal <string>(ext.HomepageUri.ToString(), parameters.HomepageUri.ToString()); Assert.Equal <bool?>(ext.IsInternalExtension, parameters.IsInternalExtension); Assert.Equal <bool?>(ext.DisallowMajorVersionUpgrade, parameters.DisallowMajorVersionUpgrade); Assert.Equal <bool?>(ext.IsInternalExtension, parameters.IsInternalExtension); Assert.Equal <string>(ext.CompanyName, parameters.CompanyName); Assert.Equal <string>(ext.SupportedOS, parameters.SupportedOS); Assert.True(parameters.IsJsonExtension != null && !parameters.IsJsonExtension.Value && (ext.IsJsonExtension == null || !ext.IsJsonExtension.Value)); } } catch (CloudException e) { Assert.True(!isPublisher && e != null && e.Error.Code.Equals(errorCodeStr)); } try { compute.ExtensionImages.Unregister( providerName, extensionName, versionStr); compute.ExtensionImages.Unregister( providerName, extensionName, verUpdtStr); } catch (CloudException e) { Assert.True(!isPublisher && e != null && e.Error.Code.Equals(errorCodeStr)); } // List Publisher Extensions try { compute.HostedServices.ListPublisherExtensions(); } catch (CloudException e) { Assert.True(!isPublisher && e != null && e.Error.Code.Equals(errorCodeStr)); } } finally { undoContext.Dispose(); mgmt.Dispose(); compute.Dispose(); storage.Dispose(); TestLogTracingInterceptor.Current.Stop(); } } }
protected PSArgument[] CreateExtensionImageRegisterParameters() { ExtensionImageRegisterParameters parameters = new ExtensionImageRegisterParameters(); return(ConvertFromObjectsToArguments(new string[] { "Parameters" }, new object[] { parameters })); }
/// <summary> /// Register a new extension. An extension is identified by the /// combination of its ProviderNamespace and Type (case-sensitive /// string). It is not allowed to register an extension with the same /// identity (i.e. combination of ProviderNamespace and Type) of an /// already-registered extension. To register new version of an /// existing extension, the Update Extension API should be used. /// </summary> /// <param name='operations'> /// Reference to the /// Microsoft.WindowsAzure.Management.Compute.IExtensionImageOperations. /// </param> /// <param name='parameters'> /// Required. Parameters supplied to the Register Virtual Machine /// Extension Image operation. /// </param> /// <returns> /// A standard service response including an HTTP status code and /// request ID. /// </returns> public static Task <AzureOperationResponse> BeginRegisteringAsync(this IExtensionImageOperations operations, ExtensionImageRegisterParameters parameters) { return(operations.BeginRegisteringAsync(parameters, CancellationToken.None)); }
/// <summary> /// Register a new extension. An extension is identified by the /// combination of its ProviderNamespace and Type (case-sensitive /// string). It is not allowed to register an extension with the same /// identity (i.e. combination of ProviderNamespace and Type) of an /// already-registered extension. To register new version of an /// existing extension, the Update Extension API should be used. /// </summary> /// <param name='operations'> /// Reference to the /// Microsoft.WindowsAzure.Management.Compute.IExtensionImageOperations. /// </param> /// <param name='parameters'> /// Required. Parameters supplied to the Register Virtual Machine /// Extension Image operation. /// </param> /// <returns> /// A standard service response including an HTTP status code and /// request ID. /// </returns> public static AzureOperationResponse BeginRegistering(this IExtensionImageOperations operations, ExtensionImageRegisterParameters parameters) { return(Task.Factory.StartNew((object s) => { return ((IExtensionImageOperations)s).BeginRegisteringAsync(parameters); } , operations, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default).Unwrap().GetAwaiter().GetResult()); }
/// <summary> /// Register a new extension. An extension is identified by the /// combination of its ProviderNamespace and Type (case-sensitive /// string). It is not allowed to register an extension with the same /// identity (i.e. combination of ProviderNamespace and Type) of an /// already-registered extension. To register new version of an /// existing extension, the Update Extension API should be used. /// </summary> /// <param name='operations'> /// Reference to the /// Microsoft.WindowsAzure.Management.Compute.IExtensionImageOperations. /// </param> /// <param name='parameters'> /// Required. Parameters supplied to the Register Virtual Machine /// Extension Image operation. /// </param> /// <returns> /// The response body contains the status of the specified asynchronous /// operation, indicating whether it has succeeded, is inprogress, or /// has failed. Note that this status is distinct from the HTTP status /// code returned for the Get Operation Status operation itself. If /// the asynchronous operation succeeded, the response body includes /// the HTTP status code for the successful request. If the /// asynchronous operation failed, the response body includes the HTTP /// status code for the failed request and error information regarding /// the failure. /// </returns> public static Task <OperationStatusResponse> RegisterAsync(this IExtensionImageOperations operations, ExtensionImageRegisterParameters parameters) { return(operations.RegisterAsync(parameters, CancellationToken.None)); }