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")) }
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) }