github.com/altoros/juju-vmware@v0.0.0-20150312064031-f19ae857ccca/agent/export_test.go (about)

     1  // Copyright 2013 Canonical Ltd.
     2  // Licensed under the AGPLv3, see LICENCE file for details.
     3  
     4  package agent
     5  
     6  import (
     7  	"fmt"
     8  	"os"
     9  
    10  	"github.com/juju/juju/state/multiwatcher"
    11  )
    12  
    13  func Password(config Config) string {
    14  	c := config.(*configInternal)
    15  	if c.stateDetails == nil {
    16  		return c.apiDetails.password
    17  	}
    18  	return c.stateDetails.password
    19  }
    20  
    21  func PatchConfig(config Config, fieldName string, value interface{}) error {
    22  	conf := config.(*configInternal)
    23  	switch fieldName {
    24  	case "DataDir":
    25  		conf.dataDir = value.(string)
    26  	case "LogDir":
    27  		conf.logDir = value.(string)
    28  	case "Jobs":
    29  		conf.jobs = value.([]multiwatcher.MachineJob)[:]
    30  	case "DeleteValues":
    31  		for _, key := range value.([]string) {
    32  			delete(conf.values, key)
    33  		}
    34  	case "Values":
    35  		for key, val := range value.(map[string]string) {
    36  			if conf.values == nil {
    37  				conf.values = make(map[string]string)
    38  			}
    39  			conf.values[key] = val
    40  		}
    41  	default:
    42  		return fmt.Errorf("unknown field %q", fieldName)
    43  	}
    44  	conf.configFilePath = ConfigPath(conf.dataDir, conf.tag)
    45  	return nil
    46  }
    47  
    48  func ConfigFileExists(config Config) bool {
    49  	conf := config.(*configInternal)
    50  	_, err := os.Lstat(conf.configFilePath)
    51  	return err == nil
    52  }
    53  
    54  var MachineJobFromParams = machineJobFromParams