blob: 469923f7e9a1f65c4717d29ea190cae349af2644 [file] [log] [blame]
David K. Bainbridge215e0242017-09-05 23:18:24 -07001package container
2
3import (
4 "strings"
5)
6
7// IsBridge indicates whether container uses the bridge network stack
8// in windows it is given the name NAT
9func (n NetworkMode) IsBridge() bool {
10 return n == "nat"
11}
12
13// IsHost indicates whether container uses the host network stack.
14// returns false as this is not supported by windows
15func (n NetworkMode) IsHost() bool {
16 return false
17}
18
19// IsUserDefined indicates user-created network
20func (n NetworkMode) IsUserDefined() bool {
21 return !n.IsDefault() && !n.IsNone() && !n.IsBridge() && !n.IsContainer()
22}
23
24// IsHyperV indicates the use of a Hyper-V partition for isolation
25func (i Isolation) IsHyperV() bool {
26 return strings.ToLower(string(i)) == "hyperv"
27}
28
29// IsProcess indicates the use of process isolation
30func (i Isolation) IsProcess() bool {
31 return strings.ToLower(string(i)) == "process"
32}
33
34// IsValid indicates if an isolation technology is valid
35func (i Isolation) IsValid() bool {
36 return i.IsDefault() || i.IsHyperV() || i.IsProcess()
37}
38
39// NetworkName returns the name of the network stack.
40func (n NetworkMode) NetworkName() string {
41 if n.IsDefault() {
42 return "default"
43 } else if n.IsBridge() {
44 return "nat"
45 } else if n.IsNone() {
46 return "none"
47 } else if n.IsContainer() {
48 return "container"
49 } else if n.IsUserDefined() {
50 return n.UserDefined()
51 }
52
53 return ""
54}