|
| 1 | +using System; |
| 2 | +using System.Linq; |
| 3 | +using XenAPI; |
| 4 | + |
| 5 | + |
| 6 | +namespace GetVmRecords |
| 7 | +{ |
| 8 | + static class GetVariousRecords |
| 9 | + { |
| 10 | + public static void Run(Session session) |
| 11 | + { |
| 12 | + PrintTitle("Printing various records"); |
| 13 | + PrintHostRecords(session); |
| 14 | + PrintStorageRepositories(session); |
| 15 | + PrintVmRecords(session); |
| 16 | + PrintPhysicalNetworkInterfaces(session); |
| 17 | + } |
| 18 | + |
| 19 | + private static void PrintHostRecords(Session session) |
| 20 | + { |
| 21 | + PrintTitle("Hosts"); |
| 22 | + var hostRecords = Host.get_all_records(session); |
| 23 | + |
| 24 | + foreach (var hostRec in hostRecords) |
| 25 | + { |
| 26 | + var host = hostRec.Value; |
| 27 | + System.Console.WriteLine("Name: {0}", host.name_label); |
| 28 | + System.Console.WriteLine("Hostname: {0}", host.hostname); |
| 29 | + System.Console.WriteLine("Description: {0}", host.name_description); |
| 30 | + System.Console.WriteLine(); |
| 31 | + } |
| 32 | + } |
| 33 | + |
| 34 | + private static void PrintStorageRepositories(Session session) |
| 35 | + { |
| 36 | + PrintTitle("Storage Repositories"); |
| 37 | + var srRecords = SR.get_all_records(session); |
| 38 | + |
| 39 | + foreach (var srRec in srRecords) |
| 40 | + { |
| 41 | + var sr = srRec.Value; |
| 42 | + System.Console.WriteLine("Name: {0}", sr.name_label); |
| 43 | + System.Console.WriteLine("Description: {0}", sr.name_description); |
| 44 | + System.Console.WriteLine("Usage: {0:0.0}GB / {1:0.0}GB", sr.physical_utilisation / 1e9, sr.physical_size / 1e9); |
| 45 | + System.Console.WriteLine(); |
| 46 | + } |
| 47 | + } |
| 48 | + |
| 49 | + private static void PrintVmRecords(Session session) |
| 50 | + { |
| 51 | + PrintTitle("Virtual Machines"); |
| 52 | + |
| 53 | + var vmRecords = VM.get_all_records(session); |
| 54 | + foreach (var vmRec in vmRecords) |
| 55 | + { |
| 56 | + var vm = vmRec.Value; |
| 57 | + System.Console.WriteLine(vm.is_a_template ? "VM name: {0}" : "Template name {0}", vm.name_label); |
| 58 | + System.Console.WriteLine("Power state: {0}", vm.power_state); |
| 59 | + string ops = string.Join(",", vm.allowed_operations.Select(op => op.ToString())); |
| 60 | + System.Console.WriteLine("Allowed operations: {0}", ops); |
| 61 | + System.Console.WriteLine("vCPUs: {0}", vm.VCPUs_at_startup); |
| 62 | + System.Console.WriteLine(); |
| 63 | + } |
| 64 | + } |
| 65 | + |
| 66 | + private static void PrintPhysicalNetworkInterfaces(Session session) |
| 67 | + { |
| 68 | + PrintTitle("Physical network interfaces"); |
| 69 | + var pifRecords = PIF.get_all_records(session); |
| 70 | + |
| 71 | + foreach (var pifRec in pifRecords) |
| 72 | + { |
| 73 | + var pif = pifRec.Value; |
| 74 | + |
| 75 | + Host host = Host.get_record(session, pif.host); |
| 76 | + System.Console.WriteLine("Host: {0}", host.name_label); |
| 77 | + System.Console.WriteLine("IP: {0}", pif.IP); |
| 78 | + System.Console.WriteLine("MAC address: {0}", pif.MAC); |
| 79 | + System.Console.WriteLine(); |
| 80 | + } |
| 81 | + } |
| 82 | + |
| 83 | + private static void PrintTitle(string title) |
| 84 | + { |
| 85 | + System.Console.WriteLine(); |
| 86 | + System.Console.WriteLine("*** {0} ***", title); |
| 87 | + System.Console.WriteLine(); |
| 88 | + } |
| 89 | + } |
| 90 | +} |
0 commit comments