public void TestGetRegionGceManagedInstanceGroup() { var listResponse = new RegionInstanceGroupManagerList() { Items = new[] { FirstTestGroup, SecondTestGroup } }; Mock <RegionInstanceGroupManagersResource> instances = ServiceMock.Resource(s => s.RegionInstanceGroupManagers); instances.SetupRequest( item => item.List(FakeProjectId, FakeRegionName), listResponse); Pipeline.Commands.AddScript( $"Get-GceManagedInstanceGroup -Region {FakeRegionName}"); Collection <PSObject> results = Pipeline.Invoke(); Assert.AreEqual(results.Count, 2); InstanceGroupManager firstGroup = results[0]?.BaseObject as InstanceGroupManager; InstanceGroupManager secondGroup = results[1]?.BaseObject as InstanceGroupManager; Assert.IsNotNull(firstGroup); Assert.AreEqual(firstGroup.Name, FirstTestGroup.Name); Assert.IsNotNull(secondGroup); Assert.AreEqual(secondGroup.Name, SecondTestGroup.Name); }
public void TestWaitGceManagedInstanceGroupPipelineRegional() { var listResponse = new RegionInstanceGroupManagersListInstancesResponse() { ManagedInstances = new[] { FirstTestInstance, SecondTestInstance } }; string instanceGroupName = "RegionalInstanceGroup"; InstanceGroupManager regionalInstanceGroup = CreateRegionalInstanceGroup(instanceGroupName, FakeProjectId, FakeRegionName); string managedRegionVar = "managedRegion"; Pipeline.Runspace.SessionStateProxy.SetVariable(managedRegionVar, regionalInstanceGroup); Mock <RegionInstanceGroupManagersResource> instances = ServiceMock.Resource(s => s.RegionInstanceGroupManagers); instances.SetupRequest( item => item.ListManagedInstances(FakeProjectId, FakeRegionName, instanceGroupName), listResponse); Pipeline.Commands.AddScript( $"${managedRegionVar} | Wait-GceManagedInstanceGroup"); Pipeline.Invoke(); instances.VerifyAll(); }
public void TestRemoveGceManagedInstanceGroupPipelineZonal() { string instanceGroupName = "RegionalInstanceGroup"; string zoneLink = $"{ComputeHttpsLink}/projects/{FakeProjectId}/zones/{FakeZoneName}"; InstanceGroupManager regionalInstanceGroup = new InstanceGroupManager() { Name = instanceGroupName, Zone = zoneLink, SelfLink = $"{zoneLink}/instanceGroupManagers/{instanceGroupName}" }; string managedRegionVar = "managedRegion"; Pipeline.Runspace.SessionStateProxy.SetVariable(managedRegionVar, regionalInstanceGroup); Mock <InstanceGroupManagersResource> instances = ServiceMock.Resource(s => s.InstanceGroupManagers); instances.SetupRequest( item => item.Delete(FakeProjectId, FakeZoneName, instanceGroupName), DoneOperation); Pipeline.Commands.AddScript( $"${managedRegionVar} | Remove-GceManagedInstanceGroup"); Pipeline.Invoke(); instances.VerifyAll(); }
public void TestSetGceManagedInstanceGroupAbandonInstanceByRegion() { string instanceGroupName = FirstTestGroup.Name; string instanceUri = "uri"; Mock <RegionInstanceGroupManagersResource> instances = ServiceMock.Resource(s => s.RegionInstanceGroupManagers); instances.SetupRequest( item => item.AbandonInstances(It.IsAny <RegionInstanceGroupManagersAbandonInstancesRequest>(), FakeProjectId, FakeRegionName, instanceGroupName), DoneOperation); instances.SetupRequest( i => i.Get(FakeProjectId, FakeRegionName, instanceGroupName), FirstTestGroup); Pipeline.Commands.AddScript( $"Set-GceManagedInstanceGroup -Name {instanceGroupName} -Region {FakeRegionName}" + $" -Abandon -InstanceUri {instanceUri}"); Collection <PSObject> results = Pipeline.Invoke(); instances.Verify( resource => resource.AbandonInstances( It.Is <RegionInstanceGroupManagersAbandonInstancesRequest>(request => request.Instances.Count == 1 && request.Instances.Contains(instanceUri)), FakeProjectId, FakeRegionName, instanceGroupName), Times.Once); Assert.AreEqual(results.Count, 1); InstanceGroupManager createdInstance = results[0].BaseObject as InstanceGroupManager; Assert.AreEqual(createdInstance?.Name, instanceGroupName); }
public void TestSetGceManagedInstanceGroupResizeByRegion() { string instanceGroupName = FirstTestGroup.Name; int newSize = 5; Mock <RegionInstanceGroupManagersResource> instances = ServiceMock.Resource(s => s.RegionInstanceGroupManagers); instances.SetupRequest( item => item.Resize(FakeProjectId, FakeRegionName, instanceGroupName, newSize), DoneOperation); instances.SetupRequest( i => i.Get(FakeProjectId, FakeRegionName, instanceGroupName), FirstTestGroup); Pipeline.Commands.AddScript( $"Set-GceManagedInstanceGroup -Name {instanceGroupName} -Region {FakeRegionName}" + $" -Size {newSize}"); Collection <PSObject> results = Pipeline.Invoke(); instances.Verify( resource => resource.Resize( FakeProjectId, FakeRegionName, instanceGroupName, newSize), Times.Once); Assert.AreEqual(results.Count, 1); InstanceGroupManager createdInstance = results[0].BaseObject as InstanceGroupManager; Assert.AreEqual(createdInstance?.Name, instanceGroupName); }
public void TestAddGceManagedInstanceGroupDefault() { string instanceGroupName = FirstTestGroup.Name; Mock <InstanceGroupManagersResource> instances = ServiceMock.Resource(s => s.InstanceGroupManagers); instances.SetupRequest( item => item.Insert( It.Is <InstanceGroupManager>(manager => manager.Name == instanceGroupName), FakeProjectId, FakeZoneName), DoneOperation); instances.SetupRequest( i => i.Get(FakeProjectId, FakeZoneName, instanceGroupName), FirstTestGroup); Pipeline.Commands.AddScript( $"Add-GceManagedInstanceGroup -Name {instanceGroupName} " + $"-InstanceTemplate template -TargetSize 1"); Collection <PSObject> results = Pipeline.Invoke(); instances.Verify( resource => resource.Insert( It.Is <InstanceGroupManager>(manager => manager.Name == instanceGroupName), FakeProjectId, FakeZoneName), Times.Once); Assert.AreEqual(results.Count, 1); InstanceGroupManager createdInstance = results[0].BaseObject as InstanceGroupManager; Assert.AreEqual(createdInstance?.Name, instanceGroupName); }
public void TestAddGceManagedInstanceGroupByObjectWithRegionParam() { string managedRegionObject = "managedRegionObj"; string instanceGroupName = FirstTestGroup.Name; Pipeline.Runspace.SessionStateProxy.SetVariable(managedRegionObject, FirstTestGroup); Mock <RegionInstanceGroupManagersResource> instances = ServiceMock.Resource(s => s.RegionInstanceGroupManagers); instances.SetupRequest( item => item.Insert( It.Is <InstanceGroupManager>(manager => manager.Name == instanceGroupName), FakeProjectId, FakeRegionName), DoneOperation); instances.SetupRequest( i => i.Get(FakeProjectId, FakeRegionName, FirstTestGroup.Name), FirstTestGroup); Pipeline.Commands.AddScript( $"${managedRegionObject} | Add-GceManagedInstanceGroup -Region {FakeRegionName}"); Collection <PSObject> results = Pipeline.Invoke(); instances.Verify( resource => resource.Insert( It.Is <InstanceGroupManager>(manager => manager.Name == instanceGroupName), FakeProjectId, FakeRegionName), Times.Once); Assert.AreEqual(results.Count, 1); InstanceGroupManager createdInstance = results[0].BaseObject as InstanceGroupManager; Assert.AreEqual(createdInstance?.Name, instanceGroupName); }
public void TestAddGceManagedInstanceGroupByRegion() { string instanceGroupName = "instance-group"; string templateName = "instance-template"; Mock <RegionInstanceGroupManagersResource> instances = ServiceMock.Resource(s => s.RegionInstanceGroupManagers); instances.SetupRequest( item => item.Insert( It.Is <InstanceGroupManager>(manager => manager.Name == instanceGroupName), FakeProjectId, FakeRegionName), DoneOperation); instances.SetupRequest( i => i.Get(FakeProjectId, FakeRegionName, instanceGroupName), new InstanceGroupManager { Name = instanceGroupName }); Pipeline.Commands.AddScript($"Add-GceManagedInstanceGroup -Name {instanceGroupName} " + $"-InstanceTemplate {templateName} -TargetSize 1 -Region {FakeRegionName}"); Collection <PSObject> results = Pipeline.Invoke(); instances.Verify( resource => resource.Insert( It.Is <InstanceGroupManager>(manager => manager.Name == instanceGroupName), FakeProjectId, FakeRegionName), Times.Once); Assert.AreEqual(results.Count, 1); InstanceGroupManager createdInstance = results[0].BaseObject as InstanceGroupManager; Assert.AreEqual(createdInstance?.Name, instanceGroupName); }
public async stt::Task GetRequestObjectAsync() { moq::Mock <InstanceGroupManagers.InstanceGroupManagersClient> mockGrpcClient = new moq::Mock <InstanceGroupManagers.InstanceGroupManagersClient>(moq::MockBehavior.Strict); mockGrpcClient.Setup(x => x.CreateOperationsClientForZoneOperations()).Returns(new moq::Mock <lro::Operations.OperationsClient>().Object); GetInstanceGroupManagerRequest request = new GetInstanceGroupManagerRequest { Zone = "zone255f4ea8", Project = "projectaa6ff846", InstanceGroupManager = "instance_group_manager71b45dfc", }; InstanceGroupManager expectedResponse = new InstanceGroupManager { Id = 11672635353343658936UL, Kind = "kindf7aa39d9", Name = "name1c9368b0", Zone = "zone255f4ea8", CreationTimestamp = "creation_timestamp235e59a1", StatefulPolicy = new StatefulPolicy(), TargetSize = -93132225, InstanceGroup = "instance_group6bf5a5ef", Region = "regionedb20d96", Versions = { new InstanceGroupManagerVersion(), }, CurrentActions = new InstanceGroupManagerActionsSummary(), UpdatePolicy = new InstanceGroupManagerUpdatePolicy(), Status = new InstanceGroupManagerStatus(), Fingerprint = "fingerprint009e6052", InstanceTemplate = "instance_template6cae3083", TargetPools = { "target_pools6fc69e1f", }, BaseInstanceName = "base_instance_name7c1f304c", Description = "description2cf9da67", NamedPorts = { new NamedPort(), }, SelfLink = "self_link7e87f12d", AutoHealingPolicies = { new InstanceGroupManagerAutoHealingPolicy(), }, DistributionPolicy = new DistributionPolicy(), }; mockGrpcClient.Setup(x => x.GetAsync(request, moq::It.IsAny <grpccore::CallOptions>())).Returns(new grpccore::AsyncUnaryCall <InstanceGroupManager>(stt::Task.FromResult(expectedResponse), null, null, null, null)); InstanceGroupManagersClient client = new InstanceGroupManagersClientImpl(mockGrpcClient.Object, null); InstanceGroupManager responseCallSettings = await client.GetAsync(request, gaxgrpc::CallSettings.FromCancellationToken(st::CancellationToken.None)); xunit::Assert.Same(expectedResponse, responseCallSettings); InstanceGroupManager responseCancellationToken = await client.GetAsync(request, st::CancellationToken.None); xunit::Assert.Same(expectedResponse, responseCancellationToken); mockGrpcClient.VerifyAll(); }
public void TestGetGceManagedInstanceGroupByNameAndRegion() { string instanceGroupName = FirstTestGroup.Name; Mock <RegionInstanceGroupManagersResource> instances = ServiceMock.Resource(s => s.RegionInstanceGroupManagers); instances.SetupRequest( item => item.Get(FakeProjectId, FakeRegionName, instanceGroupName), FirstTestGroup); Pipeline.Commands.AddScript( $"Get-GceManagedInstanceGroup -Name {instanceGroupName} -Region {FakeRegionName}"); Collection <PSObject> results = Pipeline.Invoke(); Assert.AreEqual(results.Count, 1); InstanceGroupManager retrievedInstance = results[0].BaseObject as InstanceGroupManager; Assert.AreEqual(retrievedInstance?.Name, instanceGroupName); }
public void TestRemoveGceManagedInstanceGroupPipelineRegional() { string instanceGroupName = "RegionalInstanceGroup"; InstanceGroupManager regionalInstanceGroup = CreateRegionalInstanceGroup(instanceGroupName, FakeProjectId, FakeRegionName); string managedRegionVar = "managedRegion"; Pipeline.Runspace.SessionStateProxy.SetVariable(managedRegionVar, regionalInstanceGroup); Mock <RegionInstanceGroupManagersResource> instances = ServiceMock.Resource(s => s.RegionInstanceGroupManagers); instances.SetupRequest( item => item.Delete(FakeProjectId, FakeRegionName, instanceGroupName), DoneOperation); Pipeline.Commands.AddScript( $"${managedRegionVar} | Remove-GceManagedInstanceGroup"); Pipeline.Invoke(); instances.VerifyAll(); }
public void TestWaitGceManagedInstanceGroupPipelineZonal() { var listResponse = new InstanceGroupManagersListManagedInstancesResponse() { ManagedInstances = new[] { FirstTestInstance, SecondTestInstance } }; string instanceGroupName = "RegionalInstanceGroup"; string zoneLink = $"{ComputeHttpsLink}/projects/{FakeProjectId}/zones/{FakeZoneName}"; InstanceGroupManager regionalInstanceGroup = new InstanceGroupManager() { Name = instanceGroupName, Zone = zoneLink, SelfLink = $"{zoneLink}/instanceGroupManagers/{instanceGroupName}" }; string managedRegionVar = "managedRegion"; Pipeline.Runspace.SessionStateProxy.SetVariable(managedRegionVar, regionalInstanceGroup); Mock <InstanceGroupManagersResource> instances = ServiceMock.Resource(s => s.InstanceGroupManagers); instances.SetupRequest( item => item.ListManagedInstances(FakeProjectId, FakeZoneName, instanceGroupName), listResponse); Pipeline.Commands.AddScript( $"${managedRegionVar} | Wait-GceManagedInstanceGroup"); Pipeline.Invoke(); instances.VerifyAll(); }
protected override void ProcessRecord() { InstanceGroupManager manager; switch (ParameterSetName) { case ParameterSetNames.ByProperies: manager = new InstanceGroupManager { Name = Name, InstanceTemplate = InstanceTemplate, Zone = Zone, BaseInstanceName = BaseInstanceName ?? Name, Description = Description, TargetPools = TargetPool, NamedPorts = BuildNamedPorts(), TargetSize = TargetSize }; break; case ParameterSetNames.ByObject: manager = Object; break; default: throw UnknownParameterSetException; } InstanceGroupManagersResource.InsertRequest request = Service.InstanceGroupManagers.Insert(manager, Project, Zone); Operation operation = request.Execute(); AddZoneOperation(Project, Zone, operation, () => { WriteObject(Service.InstanceGroupManagers.Get(Project, Zone, manager.Name)); }); }
/// <summary> /// Updates a managed instance group using the information that you specify in the request. This operation is marked as DONE when the group is updated even if the instances in the group have not yet been updated. You must separately verify the status of the individual instances with the listmanagedinstances method. /// Documentation https://developers.google.com/compute/beta/reference/regionInstanceGroupManagers/update /// Generation Note: This does not always build corectly. Google needs to standardise things I need to figuer out which ones are wrong. /// </summary> /// <param name="service">Authenticated compute service.</param> /// <param name="project">Project ID for this request.</param> /// <param name="region">Name of the region scoping this request.</param> /// <param name="instanceGroupManager">The name of the instance group manager.</param> /// <param name="body">A valid compute beta body.</param> /// <returns>OperationResponse</returns> public static Operation Update(computeService service, string project, string region, string instanceGroupManager, InstanceGroupManager body) { try { // Initial validation. if (service == null) { throw new ArgumentNullException("service"); } if (body == null) { throw new ArgumentNullException("body"); } if (project == null) { throw new ArgumentNullException(project); } if (region == null) { throw new ArgumentNullException(region); } if (instanceGroupManager == null) { throw new ArgumentNullException(instanceGroupManager); } // Make the request. return(service.RegionInstanceGroupManagers.Update(body, project, region, instanceGroupManager).Execute()); } catch (Exception ex) { throw new Exception("Request RegionInstanceGroupManagers.Update failed.", ex); } }
/// <summary> /// Creates a managed instance group using the information that you specify in the request. After the group is created, it schedules an action to create instances in the group using the specified instance template. This operation is marked as DONE when the group is created even if the instances in the group have not yet been created. You must separately verify the status of the individual instances with the listmanagedinstances method.A regional managed instance group can contain up to 2000 instances. /// Documentation https://developers.google.com/compute/v1/reference/regionInstanceGroupManagers/insert /// Generation Note: This does not always build corectly. Google needs to standardise things I need to figuer out which ones are wrong. /// </summary> /// <param name="service">Authenticated Compute service.</param> /// <param name="project">Project ID for this request.</param> /// <param name="region">Name of the region scoping this request.</param> /// <param name="body">A valid Compute v1 body.</param> /// <param name="optional">Optional paramaters.</param> /// <returns>OperationResponse</returns> public static Operation Insert(ComputeService service, string project, string region, InstanceGroupManager body, RegionInstanceGroupManagersInsertOptionalParms optional = null) { try { // Initial validation. if (service == null) { throw new ArgumentNullException("service"); } if (body == null) { throw new ArgumentNullException("body"); } if (project == null) { throw new ArgumentNullException(project); } if (region == null) { throw new ArgumentNullException(region); } // Building the initial request. var request = service.RegionInstanceGroupManagers.Insert(body, project, region); // Applying optional parameters to the request. request = (RegionInstanceGroupManagersResource.InsertRequest)SampleHelpers.ApplyOptionalParms(request, optional); // Requesting data. return(request.Execute()); } catch (Exception ex) { throw new Exception("Request RegionInstanceGroupManagers.Insert failed.", ex); } }
/// <summary> /// Creates an instance group manager, as well as the instance group and the specified number of instances. /// Documentation https://developers.google.com/replicapool/v1beta2/reference/instanceGroupManagers/insert /// Generation Note: This does not always build corectly. Google needs to standardise things I need to figuer out which ones are wrong. /// </summary> /// <param name="service">Authenticated Replicapool service.</param> /// <param name="project">The Google Developers Console project name.</param> /// <param name="zone">The name of the zone in which the instance group manager resides.</param> /// <param name="size">Number of instances that should exist.</param> /// <param name="body">A valid Replicapool v1beta2 body.</param> /// <returns>OperationResponse</returns> public static Operation Insert(ReplicapoolService service, string project, string zone, int?size, InstanceGroupManager body) { try { // Initial validation. if (service == null) { throw new ArgumentNullException("service"); } if (body == null) { throw new ArgumentNullException("body"); } if (project == null) { throw new ArgumentNullException(project); } if (zone == null) { throw new ArgumentNullException(zone); } if (size == null) { throw new ArgumentNullException(size); } // Make the request. return(service.InstanceGroupManagers.Insert(body, project, zone, size).Execute()); } catch (Exception ex) { throw new Exception("Request InstanceGroupManagers.Insert failed.", ex); } }