David K. Bainbridge | 215e024 | 2017-09-05 23:18:24 -0700 | [diff] [blame] | 1 | package container |
| 2 | |
| 3 | import ( |
| 4 | "strings" |
| 5 | ) |
| 6 | |
| 7 | // IsBridge indicates whether container uses the bridge network stack |
| 8 | // in windows it is given the name NAT |
| 9 | func (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 |
| 15 | func (n NetworkMode) IsHost() bool { |
| 16 | return false |
| 17 | } |
| 18 | |
| 19 | // IsUserDefined indicates user-created network |
| 20 | func (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 |
| 25 | func (i Isolation) IsHyperV() bool { |
| 26 | return strings.ToLower(string(i)) == "hyperv" |
| 27 | } |
| 28 | |
| 29 | // IsProcess indicates the use of process isolation |
| 30 | func (i Isolation) IsProcess() bool { |
| 31 | return strings.ToLower(string(i)) == "process" |
| 32 | } |
| 33 | |
| 34 | // IsValid indicates if an isolation technology is valid |
| 35 | func (i Isolation) IsValid() bool { |
| 36 | return i.IsDefault() || i.IsHyperV() || i.IsProcess() |
| 37 | } |
| 38 | |
| 39 | // NetworkName returns the name of the network stack. |
| 40 | func (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 | } |