Пример #1
0
func (s Filestore) Save(host *host.Host) error {
	if serialDriver, ok := host.Driver.(*drivers.SerialDriver); ok {
		// Unwrap Driver
		host.Driver = serialDriver.Driver

		// Re-wrap Driver when done
		defer func() {
			host.Driver = serialDriver
		}()
	}

	// TODO: Does this belong here?
	if rpcClientDriver, ok := host.Driver.(*rpcdriver.RPCClientDriver); ok {
		data, err := rpcClientDriver.GetConfigRaw()
		if err != nil {
			return fmt.Errorf("Error getting raw config for driver: %s", err)
		}
		host.RawDriver = data
	}

	data, err := json.MarshalIndent(host, "", "    ")
	if err != nil {
		return err
	}

	hostPath := filepath.Join(s.getMachinesDir(), host.Name)

	// Ensure that the directory we want to save to exists.
	if err := os.MkdirAll(hostPath, 0700); err != nil {
		return err
	}

	return s.saveToFile(data, filepath.Join(hostPath, "config.json"))
}
Пример #2
0
func (f *fakeLibMachineAPI) Create(h *host.Host) error {
	if f.driverName == "amazonec2" {
		f.ec2Driver = h.Driver.(*amazonec2.Driver)
	}
	h.Driver = &fakedriver.Driver{
		MockName:  h.Name,
		MockState: state.Running,
		MockIP:    "192.168.10.3",
	}
	f.Save(h)
	return nil
}
Пример #3
0
func (ps PluginStore) Save(host *host.Host) error {
	if serialDriver, ok := host.Driver.(*drivers.SerialDriver); ok {
		// Unwrap Driver
		host.Driver = serialDriver.Driver

		// Re-wrap Driver when done
		defer func() {
			host.Driver = serialDriver
		}()
	}

	// TODO: Does this belong here?
	if rpcClientDriver, ok := host.Driver.(*rpcdriver.RPCClientDriver); ok {
		data, err := rpcClientDriver.GetConfigRaw()
		if err != nil {
			return fmt.Errorf("Error getting raw config for driver: %s", err)
		}
		host.RawDriver = data
	}

	return ps.Filestore.Save(host)
}