-
Notifications
You must be signed in to change notification settings - Fork 44
/
HostNetworkingService.cs
74 lines (62 loc) · 2.75 KB
/
HostNetworkingService.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
using System.ComponentModel;
using Microsoft.Windows.ComputeVirtualization.Schema;
namespace Microsoft.Windows.ComputeVirtualization
{
public class HostNetworkingService
{
/// <summary>
/// Helper function to call into HNS to update/query a single network.
/// </summary>
/// <param name="method">The request method type</param>
/// <param name="path">The path of the request</param>
/// <param name="request">The request data</param>
/// <returns>The queried network.</returns>
public static HNSNetwork HNSNetworkRequest(string method, string path, string request, IHns hns = null)
{
string result;
(hns ?? HnsFactory.GetHns()).Call(method, "/networks/" + path, request, out result);
var response = JsonHelper.FromJson<Schema.HNSSingleNetworkResponse>(result);
if (!response.Success)
{
throw new Win32Exception(response.Error);
}
return response.Output;
}
/// <summary>
/// Helper function to call into HNS to query the list of available networks.
/// </summary>
/// <param name="method">The request method type</param>
/// <param name="path">The path of the request</param>
/// <param name="request">The request data</param>
/// <returns>The filtered list of networks.</returns>
public static HNSNetwork[] HNSListNetworkRequest(string method, string path, string request, IHns hns = null)
{
string result;
(hns ?? HnsFactory.GetHns()).Call(method, "/networks/" + path, request, out result);
var response = JsonHelper.FromJson<Schema.HNSNetworkResponse>(result);
if (!response.Success)
{
throw new Win32Exception(response.Error);
}
return response.Output;
}
/// <summary>
/// Helper function to call into HNS to modify/query a network endpoint.
/// </summary>
/// <param name="method">The request method type</param>
/// <param name="path">The path of the request</param>
/// <param name="request">The request data</param>
/// <returns>The queried endpoint.</returns>
public static HNSEndpoint HNSEndpointRequest(string method, string path, string request, IHns hns = null)
{
string result;
(hns ?? HnsFactory.GetHns()).Call(method, "/endpoints/" + path, request, out result);
var response = JsonHelper.FromJson<Schema.HNSEndpointResponse>(result);
if (!response.Success)
{
throw new Win32Exception(response.Error);
}
return response.Output;
}
}
}