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();
                }
            }
        }
Пример #2
0
        public override void Execute()
        {
            var createMultipleVms = new CreateMultipleVms(Context);

            createMultipleVms.Execute();

            var rg = new AzureResourceManagerClient().ResourceGroup(Context.SubscriptionId, Context.RgName).Get().Value;

            //set tags on random vms
            Random rand = new Random(Environment.TickCount);

            foreach (var generic in rg.VirtualMachines().ListByName(Environment.UserName))
            {
                var vm = VirtualMachineOperations.FromGeneric(generic);
                if (rand.NextDouble() > 0.5)
                {
                    Console.WriteLine("adding tag to {0}", vm.Id.Name);
                    vm.StartAddTag("tagkey", "tagvalue");
                }
            }

            var filteredList = rg.VirtualMachines().List().Where(vm =>
            {
                string value;
                return(vm.Data.Tags.TryGetValue("tagkey", out value) && value == "tagvalue");
            });

            foreach (var vm in filteredList)
            {
                Console.WriteLine("--------Stopping VM {0}--------", vm.Id.Name);
                vm.PowerOff();
                Console.WriteLine("--------Starting VM {0}--------", vm.Id.Name);
                vm.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();
                }
            }
        }
Пример #4
0
        public override void Execute()
        {
            var createMultipleVms = new CreateMultipleVms(Context);

            createMultipleVms.Execute();

            var sub = new AzureResourceManagerClient().GetSubscriptionOperations(Context.SubscriptionId);

            foreach (var armResource in sub.ListVirtualMachinesByName("-e"))
            {
                var vmOperations = VirtualMachineOperations.FromGeneric(armResource);
                Console.WriteLine($"Stopping {armResource.Id.ResourceGroup} : {armResource.Id.Name}");
                vmOperations.PowerOff();
                Console.WriteLine($"Starting {armResource.Id.ResourceGroup} : {armResource.Id.Name}");
                vmOperations.PowerOn();
            }
        }