github.com/psychoss/docker@v1.9.0/daemon/daemon_windows.go (about)

     1  package daemon
     2  
     3  import (
     4  	"fmt"
     5  	"os"
     6  	"syscall"
     7  
     8  	"github.com/Sirupsen/logrus"
     9  	"github.com/docker/docker/daemon/graphdriver"
    10  	// register the windows graph driver
    11  	_ "github.com/docker/docker/daemon/graphdriver/windows"
    12  	"github.com/docker/docker/pkg/parsers"
    13  	"github.com/docker/docker/runconfig"
    14  	"github.com/docker/libnetwork"
    15  )
    16  
    17  const (
    18  	defaultVirtualSwitch = "Virtual Switch"
    19  	platformSupported    = true
    20  	windowsMinCPUShares  = 1
    21  	windowsMaxCPUShares  = 9
    22  )
    23  
    24  func parseSecurityOpt(container *Container, config *runconfig.HostConfig) error {
    25  	return nil
    26  }
    27  
    28  func setupInitLayer(initLayer string, rootUID, rootGID int) error {
    29  	return nil
    30  }
    31  
    32  func checkKernel() error {
    33  	return nil
    34  }
    35  
    36  // adaptContainerSettings is called during container creation to modify any
    37  // settings necessary in the HostConfig structure.
    38  func (daemon *Daemon) adaptContainerSettings(hostConfig *runconfig.HostConfig, adjustCPUShares bool) {
    39  	if hostConfig == nil {
    40  		return
    41  	}
    42  
    43  	if hostConfig.CPUShares < 0 {
    44  		logrus.Warnf("Changing requested CPUShares of %d to minimum allowed of %d", hostConfig.CPUShares, windowsMinCPUShares)
    45  		hostConfig.CPUShares = windowsMinCPUShares
    46  	} else if hostConfig.CPUShares > windowsMaxCPUShares {
    47  		logrus.Warnf("Changing requested CPUShares of %d to maximum allowed of %d", hostConfig.CPUShares, windowsMaxCPUShares)
    48  		hostConfig.CPUShares = windowsMaxCPUShares
    49  	}
    50  }
    51  
    52  // verifyPlatformContainerSettings performs platform-specific validation of the
    53  // hostconfig and config structures.
    54  func verifyPlatformContainerSettings(daemon *Daemon, hostConfig *runconfig.HostConfig, config *runconfig.Config) ([]string, error) {
    55  	return nil, nil
    56  }
    57  
    58  // checkConfigOptions checks for mutually incompatible config options
    59  func checkConfigOptions(config *Config) error {
    60  	return nil
    61  }
    62  
    63  // checkSystem validates platform-specific requirements
    64  func checkSystem() error {
    65  	var dwVersion uint32
    66  
    67  	// TODO Windows. May need at some point to ensure have elevation and
    68  	// possibly LocalSystem.
    69  
    70  	// Validate the OS version. Note that docker.exe must be manifested for this
    71  	// call to return the correct version.
    72  	dwVersion, err := syscall.GetVersion()
    73  	if err != nil {
    74  		return fmt.Errorf("Failed to call GetVersion()")
    75  	}
    76  	if int(dwVersion&0xFF) < 10 {
    77  		return fmt.Errorf("This version of Windows does not support the docker daemon")
    78  	}
    79  
    80  	return nil
    81  }
    82  
    83  // configureKernelSecuritySupport configures and validate security support for the kernel
    84  func configureKernelSecuritySupport(config *Config, driverName string) error {
    85  	return nil
    86  }
    87  
    88  func migrateIfDownlevel(driver graphdriver.Driver, root string) error {
    89  	return nil
    90  }
    91  
    92  func configureSysInit(config *Config, rootUID, rootGID int) (string, error) {
    93  	// TODO Windows.
    94  	return os.Getenv("TEMP"), nil
    95  }
    96  
    97  func isBridgeNetworkDisabled(config *Config) bool {
    98  	return false
    99  }
   100  
   101  func (daemon *Daemon) initNetworkController(config *Config) (libnetwork.NetworkController, error) {
   102  	// Set the name of the virtual switch if not specified by -b on daemon start
   103  	if config.Bridge.VirtualSwitchName == "" {
   104  		config.Bridge.VirtualSwitchName = defaultVirtualSwitch
   105  	}
   106  	return nil, nil
   107  }
   108  
   109  // registerLinks sets up links between containers and writes the
   110  // configuration out for persistence.
   111  func (daemon *Daemon) registerLinks(container *Container, hostConfig *runconfig.HostConfig) error {
   112  	// TODO Windows. Factored out for network modes. There may be more
   113  	// refactoring required here.
   114  
   115  	if hostConfig == nil || hostConfig.Links == nil {
   116  		return nil
   117  	}
   118  
   119  	for _, l := range hostConfig.Links {
   120  		name, alias, err := parsers.ParseLink(l)
   121  		if err != nil {
   122  			return err
   123  		}
   124  		child, err := daemon.Get(name)
   125  		if err != nil {
   126  			//An error from daemon.Get() means this name could not be found
   127  			return fmt.Errorf("Could not get container for %s", name)
   128  		}
   129  		if err := daemon.registerLink(container, child, alias); err != nil {
   130  			return err
   131  		}
   132  	}
   133  
   134  	// After we load all the links into the daemon
   135  	// set them to nil on the hostconfig
   136  	hostConfig.Links = nil
   137  	if err := container.writeHostConfig(); err != nil {
   138  		return err
   139  	}
   140  	return nil
   141  }
   142  
   143  func (daemon *Daemon) newBaseContainer(id string) Container {
   144  	return Container{
   145  		CommonContainer: CommonContainer{
   146  			ID:           id,
   147  			State:        NewState(),
   148  			execCommands: newExecStore(),
   149  			root:         daemon.containerRoot(id),
   150  		},
   151  	}
   152  }
   153  
   154  func (daemon *Daemon) cleanupMounts() error {
   155  	return nil
   156  }