github.com/wulonghui/docker@v1.8.0-rc2/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 "github.com/docker/docker/daemon/graphdriver/windows" 11 "github.com/docker/docker/pkg/archive" 12 "github.com/docker/docker/pkg/parsers" 13 "github.com/docker/docker/runconfig" 14 "github.com/docker/libnetwork" 15 "github.com/microsoft/hcsshim" 16 ) 17 18 const DefaultVirtualSwitch = "Virtual Switch" 19 20 func (daemon *Daemon) Changes(container *Container) ([]archive.Change, error) { 21 return daemon.driver.Changes(container.ID, container.ImageID) 22 } 23 24 func (daemon *Daemon) Diff(container *Container) (archive.Archive, error) { 25 return daemon.driver.Diff(container.ID, container.ImageID) 26 } 27 28 func parseSecurityOpt(container *Container, config *runconfig.HostConfig) error { 29 return nil 30 } 31 32 func (daemon *Daemon) createRootfs(container *Container) error { 33 // Step 1: create the container directory. 34 // This doubles as a barrier to avoid race conditions. 35 if err := os.Mkdir(container.root, 0700); err != nil { 36 return err 37 } 38 39 if wd, ok := daemon.driver.(*windows.WindowsGraphDriver); ok { 40 if container.ImageID != "" { 41 // Get list of paths to parent layers. 42 logrus.Debugln("createRootfs: Container has parent image:", container.ImageID) 43 img, err := daemon.graph.Get(container.ImageID) 44 if err != nil { 45 return err 46 } 47 48 ids, err := daemon.graph.ParentLayerIds(img) 49 if err != nil { 50 return err 51 } 52 logrus.Debugf("Got image ids: %d", len(ids)) 53 54 if err := hcsshim.CreateSandboxLayer(wd.Info(), container.ID, container.ImageID, wd.LayerIdsToPaths(ids)); err != nil { 55 return err 56 } 57 } else { 58 if err := daemon.driver.Create(container.ID, container.ImageID); err != nil { 59 return err 60 } 61 } 62 } else { 63 // Fall-back code path to allow the use of the VFS driver for development 64 if err := daemon.driver.Create(container.ID, container.ImageID); err != nil { 65 return err 66 } 67 68 } 69 return nil 70 } 71 72 func checkKernel() error { 73 return nil 74 } 75 76 func (daemon *Daemon) verifyContainerSettings(hostConfig *runconfig.HostConfig, config *runconfig.Config) ([]string, error) { 77 // TODO Windows. Verifications TBC 78 return nil, nil 79 } 80 81 // checkConfigOptions checks for mutually incompatible config options 82 func checkConfigOptions(config *Config) error { 83 return nil 84 } 85 86 // checkSystem validates platform-specific requirements 87 func checkSystem() error { 88 var dwVersion uint32 89 90 // TODO Windows. May need at some point to ensure have elevation and 91 // possibly LocalSystem. 92 93 // Validate the OS version. Note that docker.exe must be manifested for this 94 // call to return the correct version. 95 dwVersion, err := syscall.GetVersion() 96 if err != nil { 97 return fmt.Errorf("Failed to call GetVersion()") 98 } 99 if int(dwVersion&0xFF) < 10 { 100 return fmt.Errorf("This version of Windows does not support the docker daemon") 101 } 102 103 return nil 104 } 105 106 // configureKernelSecuritySupport configures and validate security support for the kernel 107 func configureKernelSecuritySupport(config *Config, driverName string) error { 108 return nil 109 } 110 111 func migrateIfDownlevel(driver graphdriver.Driver, root string) error { 112 return nil 113 } 114 115 func configureVolumes(config *Config) error { 116 // Windows does not support volumes at this time 117 return nil 118 } 119 120 func configureSysInit(config *Config) (string, error) { 121 // TODO Windows. 122 return os.Getenv("TEMP"), nil 123 } 124 125 func isBridgeNetworkDisabled(config *Config) bool { 126 return false 127 } 128 129 func initNetworkController(config *Config) (libnetwork.NetworkController, error) { 130 // Set the name of the virtual switch if not specified by -b on daemon start 131 if config.Bridge.VirtualSwitchName == "" { 132 config.Bridge.VirtualSwitchName = DefaultVirtualSwitch 133 } 134 return nil, nil 135 } 136 137 func (daemon *Daemon) RegisterLinks(container *Container, hostConfig *runconfig.HostConfig) error { 138 // TODO Windows. Factored out for network modes. There may be more 139 // refactoring required here. 140 141 if hostConfig == nil || hostConfig.Links == nil { 142 return nil 143 } 144 145 for _, l := range hostConfig.Links { 146 name, alias, err := parsers.ParseLink(l) 147 if err != nil { 148 return err 149 } 150 child, err := daemon.Get(name) 151 if err != nil { 152 //An error from daemon.Get() means this name could not be found 153 return fmt.Errorf("Could not get container for %s", name) 154 } 155 if err := daemon.RegisterLink(container, child, alias); err != nil { 156 return err 157 } 158 } 159 160 // After we load all the links into the daemon 161 // set them to nil on the hostconfig 162 hostConfig.Links = nil 163 if err := container.WriteHostConfig(); err != nil { 164 return err 165 } 166 return nil 167 }