Bladeren bron

Vendor jhowardmsft/opengcs v0.0.4

Signed-off-by: John Howard <jhoward@microsoft.com>
John Howard 8 jaren geleden
bovenliggende
commit
c75db46d5b
2 gewijzigde bestanden met toevoegingen van 38 en 35 verwijderingen
  1. 1 1
      vendor.conf
  2. 37 34
      vendor/github.com/jhowardmsft/opengcs/gogcs/client/config.go

+ 1 - 1
vendor.conf

@@ -8,7 +8,7 @@ github.com/docker/libtrust 9cbd2a1374f46905c68a4eb3694a130610adc62a
 github.com/go-check/check 4ed411733c5785b40214c70bce814c3a3a689609 https://github.com/cpuguy83/check.git
 github.com/gorilla/context v1.1
 github.com/gorilla/mux v1.1
-github.com/jhowardmsft/opengcs v0.0.3
+github.com/jhowardmsft/opengcs v0.0.4
 github.com/kr/pty 5cf931ef8f
 github.com/mattn/go-shellwords v1.0.3
 github.com/tchap/go-patricia v2.2.6

+ 37 - 34
vendor/github.com/jhowardmsft/opengcs/gogcs/client/config.go

@@ -51,12 +51,11 @@ const (
 // must be in the same directory.
 //
 // VHD is the priority.
-//
-// All paths are full host path-names.
 type Config struct {
-	Kernel            string            // Kernel for Utility VM (embedded in a UEFI bootloader)
-	Initrd            string            // Initrd image for Utility VM
-	Vhdx              string            // VHD for booting the utility VM
+	KirdPath          string            // Path to where kernel/initrd are found (defaults to c:\program files\lcow)
+	KernelFile        string            // Kernel for Utility VM (embedded in a UEFI bootloader) - does NOT include full path, just filename
+	InitrdFile        string            // Initrd image for Utility VM - does NOT include full path, just filename
+	Vhdx              string            // VHD for booting the utility VM - is a full path
 	Name              string            // Name of the utility VM
 	RequestedMode     Mode              // What mode is preferred when validating
 	ActualMode        Mode              // What mode was obtained during validation
@@ -67,12 +66,6 @@ type Config struct {
 // GenerateDefault generates a default config from a set of options
 // If baseDir is not supplied, defaults to $env:ProgramFiles\lcow
 func (config *Config) GenerateDefault(options []string) error {
-	baseDir := filepath.Join(os.Getenv("ProgramFiles"), "lcow")
-
-	if _, err := os.Stat(baseDir); os.IsNotExist(err) {
-		return fmt.Errorf("opengcs: cannot create default utility VM configuration as directory '%s' was not found", baseDir)
-	}
-
 	if config.UvmTimeoutSeconds < 0 {
 		return fmt.Errorf("opengcs: cannot generate a config when supplied a negative utility VM timeout")
 	}
@@ -93,18 +86,16 @@ func (config *Config) GenerateDefault(options []string) error {
 		}
 	}
 
-	config.Vhdx = filepath.Join(baseDir, `uvm.vhdx`)
-	config.Kernel = filepath.Join(baseDir, `bootx64.efi`)
-	config.Initrd = filepath.Join(baseDir, `initrd.img`)
-
 	for _, v := range options {
 		opt := strings.SplitN(v, "=", 2)
 		if len(opt) == 2 {
 			switch strings.ToLower(opt[0]) {
+			case "opengcskirdpath":
+				config.KirdPath = opt[1]
 			case "opengcskernel":
-				config.Kernel = opt[1]
+				config.KernelFile = opt[1]
 			case "opengcsinitrd":
-				config.Initrd = opt[1]
+				config.InitrdFile = opt[1]
 			case "opengcsvhdx":
 				config.Vhdx = opt[1]
 			case "opengcstimeoutsecs":
@@ -119,6 +110,20 @@ func (config *Config) GenerateDefault(options []string) error {
 		}
 	}
 
+	if config.KirdPath == "" {
+		config.KirdPath = filepath.Join(os.Getenv("ProgramFiles"), "lcow")
+	}
+
+	if config.Vhdx == "" {
+		config.Vhdx = filepath.Join(config.KirdPath, `uvm.vhdx`)
+	}
+	if config.KernelFile == "" {
+		config.KernelFile = `bootx64.efi`
+	}
+	if config.InitrdFile == "" {
+		config.InitrdFile = `initrd.img`
+	}
+
 	// Which timeout are we going to take? If not through option or environment,
 	// then use the default constant, otherwise the maximum of the option or
 	// environment supplied setting. A requested on in the config supplied
@@ -143,7 +148,7 @@ func (config *Config) validate() error {
 	if config.RequestedMode == ModeRequestVhdx && config.Vhdx == "" {
 		return fmt.Errorf("opengcs: config is invalid - request for VHDX mode did not supply a VHDX")
 	}
-	if config.RequestedMode == ModeRequestKernelInitrd && (config.Kernel == "" || config.Initrd == "") {
+	if config.RequestedMode == ModeRequestKernelInitrd && (config.KernelFile == "" || config.InitrdFile == "") {
 		return fmt.Errorf("opengcs: config is invalid - request for Kernel+Initrd mode must supply both kernel and initrd")
 	}
 
@@ -160,22 +165,23 @@ func (config *Config) validate() error {
 	}
 
 	// So must be kernel+initrd, or auto where we fallback as the VHDX doesn't exist
-	if config.Initrd == "" || config.Kernel == "" {
+	if config.InitrdFile == "" || config.KernelFile == "" {
 		if config.RequestedMode == ModeRequestKernelInitrd {
 			return fmt.Errorf("opengcs: both initrd and kernel options for utility VM boot must be supplied")
 		}
 		return fmt.Errorf("opengcs: configuration is invalid")
 	}
-	if _, err := os.Stat(config.Kernel); os.IsNotExist(err) {
-		return fmt.Errorf("opengcs: kernel '%s' was not found", config.Kernel)
-	}
-	if _, err := os.Stat(config.Initrd); os.IsNotExist(err) {
-		return fmt.Errorf("opengcs: initrd '%s' was not found", config.Initrd)
+
+	// Move to validation
+	//if _, err := os.Stat(baseDir); os.IsNotExist(err) {
+	//	return fmt.Errorf("opengcs: cannot create default utility VM configuration as directory '%s' was not found", baseDir)
+	//}
+
+	if _, err := os.Stat(filepath.Join(config.KirdPath, config.KernelFile)); os.IsNotExist(err) {
+		return fmt.Errorf("opengcs: kernel '%s' was not found", filepath.Join(config.KirdPath, config.KernelFile))
 	}
-	dk, _ := filepath.Split(config.Kernel)
-	di, _ := filepath.Split(config.Initrd)
-	if dk != di {
-		return fmt.Errorf("initrd '%s' and kernel '%s' must be located in the same directory", config.Initrd, config.Kernel)
+	if _, err := os.Stat(filepath.Join(config.KirdPath, config.InitrdFile)); os.IsNotExist(err) {
+		return fmt.Errorf("opengcs: initrd '%s' was not found", filepath.Join(config.KirdPath, config.InitrdFile))
 	}
 
 	config.ActualMode = ModeActualKernelInitrd
@@ -203,13 +209,10 @@ func (config *Config) Create() error {
 			ImagePath: config.Vhdx,
 		}
 	} else {
-		// TODO @jhowardmsft - with a platform change that is in-flight, remove ImagePath for
-		// initrd/kernel boot. Current platform requires it.
-		dir, _ := filepath.Split(config.Initrd)
 		configuration.HvRuntime = &hcsshim.HvRuntime{
-			ImagePath:       dir,
-			LinuxInitrdPath: config.Initrd,
-			LinuxKernelPath: config.Kernel,
+			ImagePath:       config.KirdPath,
+			LinuxInitrdFile: config.InitrdFile,
+			LinuxKernelFile: config.KernelFile,
 		}
 	}