public async override void Execute()
        {
            #region SETUP
            ScenarioContext[] contexts = new ScenarioContext[] { new ScenarioContext(), new ScenarioContext("c9cbd920-c00c-427c-852b-8aaf38badaeb") };
            ParallelOptions   options  = new ParallelOptions
            {
                MaxDegreeOfParallelism = 1
            };

            Parallel.ForEach(contexts, options, context =>
            {
                var createMultipleVms = new CreateMultipleVms(context);
                createMultipleVms.Execute();
            });
            #endregion


            var client = new AzureResourceManagerClient();
            foreach (var sub in client.Subscriptions().List())
            {
                await foreach (var armResource in sub.ListVirtualMachinesByNameAsync("even"))
                {
                    var vmOperations = VirtualMachineOperations.FromGeneric(armResource);
                    Console.WriteLine($"Stopping {vmOperations.Id.Subscription} {vmOperations.Id.ResourceGroup} {vmOperations.Id.Name}");
                    vmOperations.PowerOff();
                    Console.WriteLine($"Starting {vmOperations.Id.Subscription} {vmOperations.Id.ResourceGroup} {vmOperations.Id.Name}");
                    vmOperations.PowerOn();
                }
            }
        }
        public async void ShutdownAsync()
        {
            var client = new AzureResourceManagerClient();

            await foreach (var subscription in client.Subscriptions().ListAsync())
            {
                await foreach (var armResource in subscription.ListVirtualMachinesByNameAsync("even"))
                {
                    var vmOperations = VirtualMachineOperations.FromGeneric(armResource);
                    await vmOperations.PowerOffAsync();

                    await vmOperations.PowerOnAsync();
                }
            }
        }
        public override void Execute()
        {
            AzureResourceManagerClientOptions options1 = new AzureResourceManagerClientOptions();
            AzureResourceManagerClientOptions options2 = new AzureResourceManagerClientOptions();
            var dummyPolicy1 = new dummyPolicy();
            var dummyPolicy2 = new dummyPolicy();

            options1.AddPolicy(dummyPolicy1, HttpPipelinePosition.PerCall);
            options2.AddPolicy(dummyPolicy2, HttpPipelinePosition.PerCall);
            var client1 = new AzureResourceManagerClient(options1);
            var client2 = new AzureResourceManagerClient(options2);

            foreach (var sub in client1.Subscriptions().List())
            {
                var x = sub;
            }

            Debug.Assert(dummyPolicy1.numMsgGot != dummyPolicy2.numMsgGot);
            Console.WriteLine("\nPASSED\n");
        }
Exemple #4
0
        public override void Execute()
        {
            var createMultipleVms = new CreateMultipleVms(Context);

            createMultipleVms.Execute();

            var client = new AzureResourceManagerClient();

            foreach (var sub in client.Subscriptions().List())
            {
                var vmList = sub.ListVirtualMachines();
                foreach (var vm in vmList.Where(armResource => armResource.Data.Name.Contains("-o")))
                {
                    Console.WriteLine($"In subscription list: Stopping {vm.Id}");
                    vm.PowerOff();
                    Console.WriteLine($"In subscription list: Starting {vm.Id}");
                    vm.PowerOn();
                }
            }

            var resourceGroup = new AzureResourceManagerClient().ResourceGroup(Context.SubscriptionId, Context.RgName);

            resourceGroup.VirtualMachines().List().Select(vm =>
            {
                var parts = vm.Id.Name.Split('-');
                var n     = Convert.ToInt32(parts[0].Last());
                return(vm, n);
            })
            .Where(tuple => tuple.n % 2 == 0)
            .ToList()
            .ForEach(tuple =>
            {
                Console.WriteLine($"In resource group list: Stopping {tuple.vm.Id.Name}");
                tuple.vm.PowerOff();
                Console.WriteLine($"In resource group list: Starting {tuple.vm.Id.Name}");
                tuple.vm.PowerOn();
            });
        }