Пример #1
0
func (this FileStore) save(host *host.Host) error {

	if rpcClientDriver, ok := host.Driver.(rpc.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(this.getMachinesDir(), host.Name)

	if err := os.MkdirAll(hostpath, 0700); err != nil {
		return err
	}

	return this.saveToFile(data, filepath.Join(hostpath, "config.json"))

}
Пример #2
0
func (this FileStore) loadConfig(h *host.Host) (*host.Host, error) {
	data, err := ioutil.ReadFile(filepath.Join(this.getMachinesDir(), h.Name, "config.json"))

	// Remember the machine name so we don't have to pass it through each
	// struct in the migration.
	name := h.Name

	if err != nil {
		return &host.Host{Name: name}, err
	}

	if err := json.Unmarshal(data, h); err != nil {
		return &host.Host{Name: name}, err
	}

	h.Name = name

	return h, err
}