Esempio n. 1
0
        /// <summary>
        /// Find a container network that uses a NAT for connectivity.
        /// </summary>
        /// <returns>The ID of the network.</returns>
        public static Guid FindNatNetwork(IHns hns = null)
        {
            string result;

            (hns ?? HnsFactory.GetHns()).Call("GET", "/networks/", "", out result);
            var response = JsonHelper.FromJson <Schema.HNSNetworkResponse>(result);

            if (!response.Success)
            {
                throw new Win32Exception(response.Error);
            }

            string networkId = null;

            foreach (var network in response.Output)
            {
                if (network.Type == Schema.NetworkMode.NAT)
                {
                    networkId = network.ID;
                    break;
                }
            }

            if (networkId == null)
            {
                throw new Exception("could not find NAT network");
            }

            return(Guid.Parse(networkId));
        }
        /// <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);
        }