Beispiel #1
0
func (h *Host) LoadConfig() error {
	data, err := ioutil.ReadFile(filepath.Join(h.StorePath, "config.json"))
	if err != nil {
		return err
	}

	// First pass: find the driver name and load the driver
	var hostMetadata HostMetadata
	if err := json.Unmarshal(data, &hostMetadata); err != nil {
		return err
	}

	meta := FillNestedHostMetadata(&hostMetadata)

	authOptions := meta.HostOptions.AuthOptions

	driver, err := drivers.NewDriver(hostMetadata.DriverName, h.Name, h.StorePath, authOptions.CaCertPath, authOptions.PrivateKeyPath)
	if err != nil {
		return err
	}

	h.Driver = driver

	// Second pass: unmarshal driver config into correct driver
	if err := json.Unmarshal(data, &h); err != nil {
		return err
	}

	return nil
}
Beispiel #2
0
func (h *Host) LoadConfig() error {
	data, err := ioutil.ReadFile(filepath.Join(h.storePath, "config.json"))
	if err != nil {
		return err
	}

	// First pass: find the driver name and load the driver
	var config hostConfig
	if err := json.Unmarshal(data, &config); err != nil {
		return err
	}

	driver, err := drivers.NewDriver(config.DriverName, h.storePath)
	if err != nil {
		return err
	}
	h.Driver = driver

	// Second pass: unmarshal driver config into correct driver
	if err := json.Unmarshal(data, &h); err != nil {
		return err
	}

	return nil
}
Beispiel #3
0
func NewHost(name, driverName, storePath string) (*Host, error) {
	driver, err := drivers.NewDriver(driverName, storePath)
	if err != nil {
		return nil, err
	}
	return &Host{
		Name:       name,
		DriverName: driverName,
		Driver:     driver,
		storePath:  storePath,
	}, nil
}
Beispiel #4
0
func NewHost(name, driverName string, hostOptions *HostOptions) (*Host, error) {
	authOptions := hostOptions.AuthOptions
	storePath := filepath.Join(utils.GetMachineDir(), name)
	driver, err := drivers.NewDriver(driverName, name, storePath, authOptions.CaCertPath, authOptions.PrivateKeyPath)
	if err != nil {
		return nil, err
	}
	return &Host{
		Name:        name,
		DriverName:  driverName,
		Driver:      driver,
		StorePath:   storePath,
		HostOptions: hostOptions,
	}, nil
}
Beispiel #5
0
func NewHost(name, driverName, StorePath, caCert, privateKey string, engineOptions *engine.EngineOptions, swarmOptions *swarm.SwarmOptions) (*Host, error) {
	driver, err := drivers.NewDriver(driverName, name, StorePath, caCert, privateKey)
	if err != nil {
		return nil, err
	}
	return &Host{
		Name:           name,
		DriverName:     driverName,
		Driver:         driver,
		CaCertPath:     caCert,
		PrivateKeyPath: privateKey,
		EngineOptions:  engineOptions,
		SwarmOptions:   swarmOptions,
		StorePath:      StorePath,
	}, nil
}
Beispiel #6
0
func MigrateHost(h *Host, data []byte) (*Host, error) {
	migratedHostMetadata, err := getMigratedHostMetadata(data)
	if err != nil {
		return &Host{}, err
	}

	authOptions := migratedHostMetadata.HostOptions.AuthOptions

	driver, err := drivers.NewDriver(
		migratedHostMetadata.DriverName,
		h.Name,
		h.StorePath,
		authOptions.CaCertPath,
		authOptions.PrivateKeyPath,
	)
	if err != nil {
		return &Host{}, err
	}

	for h.ConfigVersion = migratedHostMetadata.ConfigVersion; h.ConfigVersion < version.ConfigVersion; h.ConfigVersion++ {
		switch h.ConfigVersion {
		case 0:
			hostV0 := &HostV0{
				Driver: driver,
			}
			if err := json.Unmarshal(data, &hostV0); err != nil {
				return &Host{}, fmt.Errorf("Error unmarshalling host config version 0: %s", err)
			}
			h = MigrateHostV0ToHostV1(hostV0)
		default:
		}
	}

	h.Driver = driver
	if err := json.Unmarshal(data, &h); err != nil {
		return &Host{}, fmt.Errorf("Error unmarshalling most recent host version: %s", err)
	}

	return h, nil
}