github.com/zhuohuang-hust/src-cbuild@v0.0.0-20230105071821-c7aab3e7c840/api/types/container/hostconfig_windows.go (about)

     1  package container
     2  
     3  import (
     4  	"strings"
     5  )
     6  
     7  // IsDefault indicates whether container uses the default network stack.
     8  func (n NetworkMode) IsDefault() bool {
     9  	return n == "default"
    10  }
    11  
    12  // IsNone indicates whether container isn't using a network stack.
    13  func (n NetworkMode) IsNone() bool {
    14  	return n == "none"
    15  }
    16  
    17  // IsContainer indicates whether container uses a container network stack.
    18  // Returns false as windows doesn't support this mode
    19  func (n NetworkMode) IsContainer() bool {
    20  	return false
    21  }
    22  
    23  // IsBridge indicates whether container uses the bridge network stack
    24  // in windows it is given the name NAT
    25  func (n NetworkMode) IsBridge() bool {
    26  	return n == "nat"
    27  }
    28  
    29  // IsHost indicates whether container uses the host network stack.
    30  // returns false as this is not supported by windows
    31  func (n NetworkMode) IsHost() bool {
    32  	return false
    33  }
    34  
    35  // IsPrivate indicates whether container uses its private network stack.
    36  func (n NetworkMode) IsPrivate() bool {
    37  	return !(n.IsHost() || n.IsContainer())
    38  }
    39  
    40  // ConnectedContainer is the id of the container which network this container is connected to.
    41  // Returns blank string on windows
    42  func (n NetworkMode) ConnectedContainer() string {
    43  	return ""
    44  }
    45  
    46  // IsUserDefined indicates user-created network
    47  func (n NetworkMode) IsUserDefined() bool {
    48  	return !n.IsDefault() && !n.IsNone() && !n.IsBridge()
    49  }
    50  
    51  // IsHyperV indicates the use of a Hyper-V partition for isolation
    52  func (i Isolation) IsHyperV() bool {
    53  	return strings.ToLower(string(i)) == "hyperv"
    54  }
    55  
    56  // IsProcess indicates the use of process isolation
    57  func (i Isolation) IsProcess() bool {
    58  	return strings.ToLower(string(i)) == "process"
    59  }
    60  
    61  // IsValid indicates if an isolation technology is valid
    62  func (i Isolation) IsValid() bool {
    63  	return i.IsDefault() || i.IsHyperV() || i.IsProcess()
    64  }
    65  
    66  // NetworkName returns the name of the network stack.
    67  func (n NetworkMode) NetworkName() string {
    68  	if n.IsDefault() {
    69  		return "default"
    70  	} else if n.IsBridge() {
    71  		return "nat"
    72  	} else if n.IsNone() {
    73  		return "none"
    74  	} else if n.IsUserDefined() {
    75  		return n.UserDefined()
    76  	}
    77  
    78  	return ""
    79  }
    80  
    81  //UserDefined indicates user-created network
    82  func (n NetworkMode) UserDefined() string {
    83  	if n.IsUserDefined() {
    84  		return string(n)
    85  	}
    86  	return ""
    87  }