launchpad.net/~rogpeppe/juju-core/500-errgo-fix@v0.0.0-20140213181702-000000002356/provider/manual/config.go (about)

     1  // Copyright 2013 Canonical Ltd.
     2  // Licensed under the AGPLv3, see LICENCE file for details.
     3  
     4  package manual
     5  
     6  import (
     7  	"fmt"
     8  
     9  	"launchpad.net/juju-core/environs/config"
    10  	"launchpad.net/juju-core/schema"
    11  )
    12  
    13  const defaultStoragePort = 8040
    14  
    15  var (
    16  	configFields = schema.Fields{
    17  		"bootstrap-host":    schema.String(),
    18  		"bootstrap-user":    schema.String(),
    19  		"storage-listen-ip": schema.String(),
    20  		"storage-port":      schema.Int(),
    21  		"storage-auth-key":  schema.String(),
    22  		"use-sshstorage":    schema.Bool(),
    23  	}
    24  	configDefaults = schema.Defaults{
    25  		"bootstrap-user":    "",
    26  		"storage-listen-ip": "",
    27  		"storage-port":      defaultStoragePort,
    28  		"use-sshstorage":    true,
    29  	}
    30  )
    31  
    32  type environConfig struct {
    33  	*config.Config
    34  	attrs map[string]interface{}
    35  }
    36  
    37  func newEnvironConfig(config *config.Config, attrs map[string]interface{}) *environConfig {
    38  	return &environConfig{Config: config, attrs: attrs}
    39  }
    40  
    41  func (c *environConfig) useSSHStorage() bool {
    42  	// Prior to 1.17.3, the use-sshstorage attribute
    43  	// did not exist. We take non-existence to be
    44  	// equivalent to false.
    45  	useSSHStorage, _ := c.attrs["use-sshstorage"].(bool)
    46  	return useSSHStorage
    47  }
    48  
    49  func (c *environConfig) bootstrapHost() string {
    50  	return c.attrs["bootstrap-host"].(string)
    51  }
    52  
    53  func (c *environConfig) bootstrapUser() string {
    54  	return c.attrs["bootstrap-user"].(string)
    55  }
    56  
    57  func (c *environConfig) storageListenIPAddress() string {
    58  	return c.attrs["storage-listen-ip"].(string)
    59  }
    60  
    61  func (c *environConfig) storagePort() int {
    62  	return int(c.attrs["storage-port"].(int64))
    63  }
    64  
    65  func (c *environConfig) storageAuthKey() string {
    66  	return c.attrs["storage-auth-key"].(string)
    67  }
    68  
    69  // storageAddr returns an address for connecting to the
    70  // bootstrap machine's localstorage.
    71  func (c *environConfig) storageAddr() string {
    72  	return fmt.Sprintf("%s:%d", c.bootstrapHost(), c.storagePort())
    73  }
    74  
    75  // storageListenAddr returns an address for the bootstrap
    76  // machine to listen on for its localstorage.
    77  func (c *environConfig) storageListenAddr() string {
    78  	return fmt.Sprintf("%s:%d", c.storageListenIPAddress(), c.storagePort())
    79  }