/// <summary> /// Create/register a new extension. If the extension is already present/registered, updates the registration with the /// provided values. /// </summary> /// <param name="bearerToken">Authorization bearer token</param> /// <param name="virtualMachineExtension">The prepopulated Virtual Machine Extension object.</param> /// <returns>VMExtension object if successful, else NULL</returns> public static async Task <VMExtension?> CreateOrUpdate(string bearerToken, VMExtension virtualMachineExtension) { if (string.IsNullOrWhiteSpace(bearerToken)) { throw new ArgumentNullException(nameof(virtualMachineExtension)); } if (virtualMachineExtension == null) { throw new ArgumentNullException(nameof(virtualMachineExtension)); } RestApiResponse response = await RestApiClient.PUT( bearerToken, $"https://management.azure.com/{virtualMachineExtension.ResourceId[1..]}",
public void GetBatchComputeNodeExtensionTest() { string extensionName = "testExtension"; string publisher = "testPublisher"; string type = "testType"; // Setup cmdlet to get a compute node by id BatchAccountContext context = BatchTestHelpers.CreateBatchContextWithKeys(); cmdlet.BatchContext = context; cmdlet.PoolId = "testPool"; cmdlet.ComputeNodeId = "testComputeNode"; cmdlet.Name = extensionName; VMExtension extension = new VMExtension(extensionName, publisher, type); // Build an extension instead of querying the service on a Get ComputeNodeExtension call AzureOperationResponse <ProxyModels.NodeVMExtension, ProxyModels.ComputeNodeExtensionGetHeaders> response = BatchTestHelpers.CreateComputeNodeExtensionGetResponse(extension); RequestInterceptor interceptor = BatchTestHelpers.CreateFakeServiceResponseInterceptor < ProxyModels.ComputeNodeExtensionGetOptions, AzureOperationResponse <ProxyModels.NodeVMExtension, ProxyModels.ComputeNodeExtensionGetHeaders> >(response); cmdlet.AdditionalBehaviors = new List <BatchClientBehavior>() { interceptor }; // Setup the cmdlet to write pipeline output to a list that can be examined later List <PSNodeVMExtension> pipeline = new List <PSNodeVMExtension>(); commandRuntimeMock.Setup(r => r.WriteObject(It.IsAny <PSNodeVMExtension>())).Callback <object>(c => pipeline.Add((PSNodeVMExtension)c)); cmdlet.ExecuteCmdlet(); // Verify that the cmdlet wrote the compute node returned from the OM to the pipeline Assert.Single(pipeline); PSVMExtension pipelineExtension = pipeline[0].VmExtension; Assert.NotNull(pipelineExtension); Assert.Equal("testExtension", pipelineExtension.Name); Assert.Equal("testPublisher", pipelineExtension.Publisher); Assert.Equal("testType", pipelineExtension.Type); }
public void GetBatchComputeNodeExtensionODataTest() { string extensionName = "testExtension"; string publisher = "testPublisher"; string type = "testType"; // Setup cmdlet to get a compute node by id BatchAccountContext context = BatchTestHelpers.CreateBatchContextWithKeys(); cmdlet.BatchContext = context; cmdlet.PoolId = "testPool"; cmdlet.ComputeNodeId = "testComputeNode"; cmdlet.Name = extensionName; cmdlet.Select = "ExtensionName,Publisher"; VMExtension extension = new VMExtension(extensionName, publisher, type); // Fetch the OData clauses off the request. The OData clauses are applied after user provided RequestInterceptors, so a ResponseInterceptor is used. AzureOperationResponse <ProxyModels.NodeVMExtension, ProxyModels.ComputeNodeExtensionGetHeaders> getResponse = BatchTestHelpers.CreateComputeNodeExtensionGetResponse(extension); RequestInterceptor requestInterceptor = BatchTestHelpers.CreateFakeServiceResponseInterceptor < ProxyModels.ComputeNodeExtensionGetOptions, AzureOperationResponse <ProxyModels.NodeVMExtension, ProxyModels.ComputeNodeExtensionGetHeaders> >(getResponse); string requestSelect = null; ResponseInterceptor responseInterceptor = new ResponseInterceptor((response, request) => { ProxyModels.ComputeNodeExtensionGetOptions options = (ProxyModels.ComputeNodeExtensionGetOptions)request.Options; requestSelect = options.Select; return(Task.FromResult(response)); }); cmdlet.AdditionalBehaviors = new List <BatchClientBehavior>() { requestInterceptor, responseInterceptor }; cmdlet.ExecuteCmdlet(); Assert.Equal(cmdlet.Select, requestSelect); }
private void AssertSame(VMExtension expected, VMExtension given, bool resourceToo = true) { if (resourceToo) { AssertSameResource(expected, given); } if (expected == null) { Assert.Null(given); } else { Assert.NotNull(given); Assert.Equal(expected.ComputeRole, given.ComputeRole); Assert.Equal(expected.IsSystemExtension, given.IsSystemExtension); Assert.Equal(expected.ProvisioningState, given.ProvisioningState); Assert.Equal(expected.SupportMultipleExtensions, given.SupportMultipleExtensions); Assert.Equal(expected.VmOsType, given.VmOsType); Assert.Equal(expected.VmScaleSetEnabled, given.VmScaleSetEnabled); } }
private void ValidateVMExtension(VMExtension image) { //AssertValidResource(image); Assert.NotNull(image); }