~ubuntu-branches/ubuntu/trusty/juju-core/trusty-proposed

« back to all changes in this revision

Viewing changes to src/launchpad.net/juju-core/provider/manual/config.go

  • Committer: Package Import Robot
  • Author(s): James Page
  • Date: 2014-02-03 09:22:46 UTC
  • mfrom: (1.1.17)
  • Revision ID: package-import@ubuntu.com-20140203092246-e03vg402vztzo4qa
Tags: 1.17.2-0ubuntu1
New upstream release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
        }
 
23
        configDefaults = schema.Defaults{
 
24
                "bootstrap-user":    "",
 
25
                "storage-listen-ip": "",
 
26
                "storage-port":      defaultStoragePort,
 
27
        }
 
28
)
 
29
 
 
30
type environConfig struct {
 
31
        *config.Config
 
32
        attrs map[string]interface{}
 
33
}
 
34
 
 
35
func newEnvironConfig(config *config.Config, attrs map[string]interface{}) *environConfig {
 
36
        return &environConfig{Config: config, attrs: attrs}
 
37
}
 
38
 
 
39
func (c *environConfig) bootstrapHost() string {
 
40
        return c.attrs["bootstrap-host"].(string)
 
41
}
 
42
 
 
43
func (c *environConfig) bootstrapUser() string {
 
44
        return c.attrs["bootstrap-user"].(string)
 
45
}
 
46
 
 
47
func (c *environConfig) storageListenIPAddress() string {
 
48
        return c.attrs["storage-listen-ip"].(string)
 
49
}
 
50
 
 
51
func (c *environConfig) storagePort() int {
 
52
        return int(c.attrs["storage-port"].(int64))
 
53
}
 
54
 
 
55
func (c *environConfig) storageAuthKey() string {
 
56
        return c.attrs["storage-auth-key"].(string)
 
57
}
 
58
 
 
59
// storageAddr returns an address for connecting to the
 
60
// bootstrap machine's localstorage.
 
61
func (c *environConfig) storageAddr() string {
 
62
        return fmt.Sprintf("%s:%d", c.bootstrapHost(), c.storagePort())
 
63
}
 
64
 
 
65
// storageListenAddr returns an address for the bootstrap
 
66
// machine to listen on for its localstorage.
 
67
func (c *environConfig) storageListenAddr() string {
 
68
        return fmt.Sprintf("%s:%d", c.storageListenIPAddress(), c.storagePort())
 
69
}