Пример #1
0
        public override void Execute()
        {
            var createVm = new CreateSingleVmExample(Context);

            createVm.Execute();

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

            foreach (var genericOp in rgOp.VirtualMachines().ListByName(Context.VmName))
            {
                Console.WriteLine($"Deleting {genericOp.Id}");
                genericOp.Delete();
            }

            try
            {
                var vmOp = rgOp.VirtualMachine(Context.VmName);
                Console.WriteLine($"Trying to get {vmOp.Id}");
                var response = vmOp.Get();
            }
            catch (RequestFailedException e) when(e.Status == 404)
            {
                Console.WriteLine("Got 404 returned as expected");
                return;
            }

            throw new InvalidOperationException("Failed");
        }
Пример #2
0
        public override void Execute()
        {
            var createVm = new CreateSingleVmExample(Context);

            createVm.Execute();

            var rgOp = new AzureResourceManagerClient().ResourceGroup(Context.SubscriptionId, Context.RgName);
            var vmOp = rgOp.VirtualMachine(Context.VmName);

            var vm = vmOp.Get().Value;

            Console.WriteLine($"Adding tags to {vm.Data.Name}");
            vm.StartAddTag("tagkey", "tagvalue");
        }
        public override void Execute()
        {
            var createVm = new CreateSingleVmExample(Context);

            createVm.Execute();

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

            foreach (var genericOp in rgOp.VirtualMachines().ListByName(Context.VmName))
            {
                Console.WriteLine($"Adding tag to {genericOp.Id}");
                genericOp.StartAddTag("tagKey", "tagVaue");
            }

            var vmOp = rgOp.VirtualMachine(Context.VmName);

            Console.WriteLine($"Getting {vmOp.Id}");
            var vm = vmOp.Get().Value;

            if (!vm.Data.Tags.ContainsKey("tagKey"))
            {
                throw new InvalidOperationException("Failed");
            }
        }