Skip to content
This repository was archived by the owner on Feb 19, 2025. It is now read-only.

Commit 821c7ad

Browse files
committed
Consolidation of the C# sample code.
Signed-off-by: Konstantina Chremmou <[email protected]>
1 parent dbb6f5b commit 821c7ad

File tree

13 files changed

+230
-639
lines changed

13 files changed

+230
-639
lines changed

csharp/README.dist

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,9 @@ B. To build the source code:
7171
3. You should now be ready to build the source code.
7272

7373
C. To run the examples:
74-
1. Copy CookComputing.XmlRpcV2.dll from the bin folder into the samples folder
75-
at the same level as the XenSdkSample.sln file.
74+
1. Copy XenServer.dll and CookComputing.XmlRpcV2.dll from the bin folder into
75+
the samples folder at the same level as the XenSdkSample.csproj file.
7676
2. Open XenSdkSample.sln inside Visual Studio (2013 or greater).
7777
3. You should now be ready to compile the solution and run the examples.
78-
Each of the solution projects is a console application expecting the parameters
78+
The solution project is a console application expecting the parameters
7979
<host> <username> <password> to be passed to its Main method.
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
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+
}

csharp/samples/GetVariousRecords/GetVariousRecords.csproj

Lines changed: 0 additions & 92 deletions
This file was deleted.

csharp/samples/GetVariousRecords/Program.cs

Lines changed: 0 additions & 180 deletions
This file was deleted.

0 commit comments

Comments
 (0)