private async Task ExecuteAsync() { // Update Tag for a known resource var rgOp = new AzureResourceManagerClient().GetResourceGroupOperations(Context.SubscriptionId, Context.RgName); var vmOp = rgOp.GetVirtualMachineOperations(Context.VmName); Console.WriteLine($"Adding tags to {vmOp.Id.Name}"); var vm = (await vmOp.StartAddTag("key1", "value1").WaitForCompletionAsync()).Value; Debug.Assert(vm.Data.Tags.Where(x => x.Key.StartsWith("key")).Count() == 1); DumpDictionary(vm.Data.Tags); vm = (await vm.StartAddTag("key2", "value2").WaitForCompletionAsync()).Value; Debug.Assert(vm.Data.Tags.Where(x => x.Key.StartsWith("key")).Count() == 2); DumpDictionary(vm.Data.Tags); vm = (await(await vmOp.StartAddTagAsync("key3", "value3")).WaitForCompletionAsync()).Value; Debug.Assert(vm.Data.Tags.Where(x => x.Key.StartsWith("key")).Count() == 3); DumpDictionary(vm.Data.Tags); vm = (await vm.StartAddTagAsync("key4", "value4")).WaitForCompletionAsync().Result.Value; Debug.Assert(vm.Data.Tags.Where(x => x.Key.StartsWith("key")).Count() == 4); DumpDictionary(vm.Data.Tags); }
public override void Execute() { var createVm = new CreateSingleVmExample(Context); createVm.Execute(); var rgOp = new AzureResourceManagerClient().GetResourceGroupOperations(Context.SubscriptionId, Context.RgName); foreach (var genericOp in rgOp.GetVirtualMachineContainer().ListByName(Context.VmName)) { Console.WriteLine($"Deleting {genericOp.Id}"); genericOp.Delete(); } try { var vmOp = rgOp.GetVirtualMachineOperations(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"); } throw new InvalidOperationException("Failed"); }
public override void Execute() { var createVm = new CreateSingleVmExample(Context); createVm.Execute(); var client = new AzureResourceManagerClient(); var subscription = client.GetSubscriptionOperations(Context.SubscriptionId); var resourceGroup = subscription.GetResourceGroupOperations(Context.RgName); var vmId = resourceGroup.GetVirtualMachineOperations(Context.VmName).Id; var vnId = resourceGroup.GetVirtualNetworkOperations(Context.VmName + "_vnet").Id; var subnetId = resourceGroup.GetVirtualNetworkOperations(Context.VmName + "_vnet").GetSubnetOperations(Context.SubnetName).Id; var asId = resourceGroup.GetAvailabilitySetOperations(Context.VmName + "_aSet").Id; var nsgId = resourceGroup.GetNetworkSecurityGroupOperations(Context.NsgName).Id; var niId = resourceGroup.GetNetworkInterfaceOperations(Context.VmName + "_nic").Id; var vmOps = client.GetVirtualMachineOperations(vmId); Console.WriteLine("\nclient.GetVirtualMachineOperations(vmResourceId)"); vmOps.PowerOff(); Console.WriteLine("Option 1 vm is " + vmOps.Get().Value.Data.InstanceView.Statuses.Last().Code); vmOps.PowerOn(); Console.WriteLine("Option 1 vm is " + vmOps.Get().Value.Data.InstanceView.Statuses.Last().Code); var subnetOps = client.GetSubnetOperations(subnetId); Console.WriteLine("Option 1 subnet is " + subnetOps.Id); var vnOps = client.GetVirtualNetworkOperations(vnId); var nsgOps = client.GetNetworkSecurityGroupOperations(nsgId); var niOps = client.GetNetworkInterfaceOperations(niId); var asOps = client.GetAvailabilitySetOperations(asId); Console.WriteLine(vnOps.Id); Console.WriteLine(nsgOps.Id); Console.WriteLine(niOps.Id); Console.WriteLine(asOps.Id); Console.WriteLine("Demo complete"); }
public override void Execute() { var createVm = new CreateSingleVmExample(Context); createVm.Execute(); var rgOp = new AzureResourceManagerClient().GetResourceGroupOperations(Context.SubscriptionId, Context.RgName); foreach (var genericOp in rgOp.GetVirtualMachineContainer().ListByName(Context.VmName)) { Console.WriteLine($"Adding tag to {genericOp.Id}"); genericOp.StartAddTag("tagKey", "tagVaue"); } var vmOp = rgOp.GetVirtualMachineOperations(Context.VmName); Console.WriteLine($"Getting {vmOp.Id}"); var vm = vmOp.Get().Value; if (!vm.Data.Tags.ContainsKey("tagKey")) { throw new InvalidOperationException("Failed"); } }