github.com/chenchun/docker@v1.3.2-0.20150629222414-20467faf132b/daemon/daemon_windows.go (about)

     1  package daemon
     2  
     3  import (
     4  	"fmt"
     5  	"os"
     6  	"runtime"
     7  	"syscall"
     8  
     9  	"github.com/docker/docker/daemon/graphdriver"
    10  	"github.com/docker/docker/pkg/archive"
    11  	"github.com/docker/docker/pkg/parsers"
    12  	"github.com/docker/docker/runconfig"
    13  	"github.com/docker/libnetwork"
    14  )
    15  
    16  func (daemon *Daemon) Changes(container *Container) ([]archive.Change, error) {
    17  	return daemon.driver.Changes(container.ID, container.ImageID)
    18  }
    19  
    20  func (daemon *Daemon) Diff(container *Container) (archive.Archive, error) {
    21  	return daemon.driver.Diff(container.ID, container.ImageID)
    22  }
    23  
    24  func parseSecurityOpt(container *Container, config *runconfig.HostConfig) error {
    25  	return nil
    26  }
    27  
    28  func (daemon *Daemon) createRootfs(container *Container) error {
    29  	// Step 1: create the container directory.
    30  	// This doubles as a barrier to avoid race conditions.
    31  	if err := os.Mkdir(container.root, 0700); err != nil {
    32  		return err
    33  	}
    34  	if err := daemon.driver.Create(container.ID, container.ImageID); err != nil {
    35  		return err
    36  	}
    37  	return nil
    38  }
    39  
    40  func checkKernel() error {
    41  	return nil
    42  }
    43  
    44  func (daemon *Daemon) verifyContainerSettings(hostConfig *runconfig.HostConfig, config *runconfig.Config) ([]string, error) {
    45  	// TODO Windows. Verifications TBC
    46  	return nil, nil
    47  }
    48  
    49  // checkConfigOptions checks for mutually incompatible config options
    50  func checkConfigOptions(config *Config) error {
    51  	return nil
    52  }
    53  
    54  // checkSystem validates the system is supported and we have sufficient privileges
    55  func checkSystem() error {
    56  	var dwVersion uint32
    57  
    58  	// TODO Windows. Once daemon is running on Windows, move this code back to
    59  	// NewDaemon() in daemon.go, and extend the check to support Windows.
    60  	if runtime.GOOS != "linux" && runtime.GOOS != "windows" {
    61  		return ErrSystemNotSupported
    62  	}
    63  
    64  	// TODO Windows. May need at some point to ensure have elevation and
    65  	// possibly LocalSystem.
    66  
    67  	// Validate the OS version. Note that docker.exe must be manifested for this
    68  	// call to return the correct version.
    69  	dwVersion, err := syscall.GetVersion()
    70  	if err != nil {
    71  		return fmt.Errorf("Failed to call GetVersion()")
    72  	}
    73  	if int(dwVersion&0xFF) < 10 {
    74  		return fmt.Errorf("This version of Windows does not support the docker daemon")
    75  	}
    76  
    77  	return nil
    78  }
    79  
    80  // configureKernelSecuritySupport configures and validate security support for the kernel
    81  func configureKernelSecuritySupport(config *Config, driverName string) error {
    82  	return nil
    83  }
    84  
    85  func migrateIfDownlevel(driver graphdriver.Driver, root string) error {
    86  	return nil
    87  }
    88  
    89  func configureVolumes(config *Config) error {
    90  	// Windows does not support volumes at this time
    91  	return nil
    92  }
    93  
    94  func configureSysInit(config *Config) (string, error) {
    95  	// TODO Windows.
    96  	return os.Getenv("TEMP"), nil
    97  }
    98  
    99  func isNetworkDisabled(config *Config) bool {
   100  	return false
   101  }
   102  
   103  func initNetworkController(config *Config) (libnetwork.NetworkController, error) {
   104  	// TODO Windows
   105  	return nil, nil
   106  }
   107  
   108  func (daemon *Daemon) RegisterLinks(container *Container, hostConfig *runconfig.HostConfig) error {
   109  	// TODO Windows. Factored out for network modes. There may be more
   110  	// refactoring required here.
   111  
   112  	if hostConfig == nil || hostConfig.Links == nil {
   113  		return nil
   114  	}
   115  
   116  	for _, l := range hostConfig.Links {
   117  		name, alias, err := parsers.ParseLink(l)
   118  		if err != nil {
   119  			return err
   120  		}
   121  		child, err := daemon.Get(name)
   122  		if err != nil {
   123  			//An error from daemon.Get() means this name could not be found
   124  			return fmt.Errorf("Could not get container for %s", name)
   125  		}
   126  		if err := daemon.RegisterLink(container, child, alias); err != nil {
   127  			return err
   128  		}
   129  	}
   130  
   131  	// After we load all the links into the daemon
   132  	// set them to nil on the hostconfig
   133  	hostConfig.Links = nil
   134  	if err := container.WriteHostConfig(); err != nil {
   135  		return err
   136  	}
   137  	return nil
   138  }