github.com/DaoCloud/dao@v0.0.0-20161212064103-c3dbfd13ee36/container/container_windows.go (about)

     1  // +build windows
     2  
     3  package container
     4  
     5  import (
     6  	"fmt"
     7  	"os"
     8  	"path/filepath"
     9  
    10  	"github.com/docker/docker/utils"
    11  	"github.com/docker/docker/volume"
    12  	containertypes "github.com/docker/engine-api/types/container"
    13  )
    14  
    15  // Container holds fields specific to the Windows implementation. See
    16  // CommonContainer for standard fields common to all containers.
    17  type Container struct {
    18  	CommonContainer
    19  
    20  	HostnamePath   string
    21  	HostsPath      string
    22  	ResolvConfPath string
    23  	// Fields below here are platform specific.
    24  }
    25  
    26  // ExitStatus provides exit reasons for a container.
    27  type ExitStatus struct {
    28  	// The exit code with which the container exited.
    29  	ExitCode int
    30  }
    31  
    32  // CreateDaemonEnvironment creates a new environment variable slice for this container.
    33  func (container *Container) CreateDaemonEnvironment(linkedEnv []string) []string {
    34  	// because the env on the container can override certain default values
    35  	// we need to replace the 'env' keys where they match and append anything
    36  	// else.
    37  	return utils.ReplaceOrAppendEnvValues(linkedEnv, container.Config.Env)
    38  }
    39  
    40  // UnmountIpcMounts unmount Ipc related mounts.
    41  // This is a NOOP on windows.
    42  func (container *Container) UnmountIpcMounts(unmount func(pth string) error) {
    43  }
    44  
    45  // IpcMounts returns the list of Ipc related mounts.
    46  func (container *Container) IpcMounts() []Mount {
    47  	return nil
    48  }
    49  
    50  // UnmountVolumes explicitly unmounts volumes from the container.
    51  func (container *Container) UnmountVolumes(forceSyscall bool, volumeEventLog func(name, action string, attributes map[string]string)) error {
    52  	return nil
    53  }
    54  
    55  // TmpfsMounts returns the list of tmpfs mounts
    56  func (container *Container) TmpfsMounts() []Mount {
    57  	var mounts []Mount
    58  	return mounts
    59  }
    60  
    61  // UpdateContainer updates configuration of a container
    62  func (container *Container) UpdateContainer(hostConfig *containertypes.HostConfig) error {
    63  	container.Lock()
    64  	defer container.Unlock()
    65  	resources := hostConfig.Resources
    66  	if resources.BlkioWeight != 0 || resources.CPUShares != 0 ||
    67  		resources.CPUPeriod != 0 || resources.CPUQuota != 0 ||
    68  		resources.CpusetCpus != "" || resources.CpusetMems != "" ||
    69  		resources.Memory != 0 || resources.MemorySwap != 0 ||
    70  		resources.MemoryReservation != 0 || resources.KernelMemory != 0 {
    71  		return fmt.Errorf("Resource updating isn't supported on Windows")
    72  	}
    73  	// update HostConfig of container
    74  	if hostConfig.RestartPolicy.Name != "" {
    75  		container.HostConfig.RestartPolicy = hostConfig.RestartPolicy
    76  	}
    77  	return nil
    78  }
    79  
    80  // appendNetworkMounts appends any network mounts to the array of mount points passed in.
    81  // Windows does not support network mounts (not to be confused with SMB network mounts), so
    82  // this is a no-op.
    83  func appendNetworkMounts(container *Container, volumeMounts []volume.MountPoint) ([]volume.MountPoint, error) {
    84  	return volumeMounts, nil
    85  }
    86  
    87  // cleanResourcePath cleans a resource path by removing C:\ syntax, and prepares
    88  // to combine with a volume path
    89  func cleanResourcePath(path string) string {
    90  	if len(path) >= 2 {
    91  		c := path[0]
    92  		if path[1] == ':' && ('a' <= c && c <= 'z' || 'A' <= c && c <= 'Z') {
    93  			path = path[2:]
    94  		}
    95  	}
    96  	return filepath.Join(string(os.PathSeparator), path)
    97  }
    98  
    99  // BuildHostnameFile writes the container's hostname file.
   100  func (container *Container) BuildHostnameFile() error {
   101  	return nil
   102  }
   103  
   104  // canMountFS determines if the file system for the container
   105  // can be mounted locally. In the case of Windows, this is not possible
   106  // for Hyper-V containers during WORKDIR execution for example.
   107  func (container *Container) canMountFS() bool {
   108  	return !containertypes.Isolation.IsHyperV(container.HostConfig.Isolation)
   109  }