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

« back to all changes in this revision

Viewing changes to src/launchpad.net/juju-core/worker/uniter/context.go

  • Committer: Package Import Robot
  • Author(s): James Page
  • Date: 2013-07-11 17:18:27 UTC
  • mfrom: (1.1.1)
  • Revision ID: package-import@ubuntu.com-20130711171827-vjqkg40r0dlf7ys2
Tags: 1.11.2-0ubuntu1
* New upstream release.
* Make juju-core the default juju (LP: #1190634):
  - d/control: Add virtual package juju -> juju-core.
  - d/juju-core.postinst.in: Bump priority of alternatives over that of
    python juju packages.
* Enable for all architectures (LP: #1172505):
  - d/control: Version BD on golang-go to >= 2:1.1.1 to ensure CGO
    support for non-x86 archs, make juju-core Arch: any.
  - d/README.source: Dropped - no longer required.
* d/watch: Updated for new upstream tarball naming.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// Copyright 2012, 2013 Canonical Ltd.
 
2
// Licensed under the AGPLv3, see LICENCE file for details.
 
3
 
1
4
package uniter
2
5
 
3
6
import (
4
7
        "bufio"
5
8
        "fmt"
6
9
        "io"
 
10
        "launchpad.net/juju-core/charm"
7
11
        "launchpad.net/juju-core/log"
8
12
        "launchpad.net/juju-core/state"
9
13
        "launchpad.net/juju-core/worker/uniter/jujuc"
11
15
        "os/exec"
12
16
        "path/filepath"
13
17
        "sort"
 
18
        "strings"
14
19
        "sync"
15
20
        "time"
16
21
)
19
24
type HookContext struct {
20
25
        unit *state.Unit
21
26
 
22
 
        // config holds the service configuration.
23
 
        config map[string]interface{}
 
27
        // configSettings holds the service configuration.
 
28
        configSettings charm.Settings
24
29
 
25
30
        // id identifies the context.
26
31
        id string
41
46
        // relations contains the context for every relation the unit is a member
42
47
        // of, keyed on relation id.
43
48
        relations map[int]*ContextRelation
 
49
 
 
50
        // apiAddrs contains the API server addresses.
 
51
        apiAddrs []string
44
52
}
45
53
 
46
54
func NewHookContext(unit *state.Unit, id, uuid string, relationId int,
47
 
        remoteUnitName string, relations map[int]*ContextRelation) *HookContext {
 
55
        remoteUnitName string, relations map[int]*ContextRelation,
 
56
        apiAddrs []string) *HookContext {
48
57
        return &HookContext{
49
58
                unit:           unit,
50
59
                id:             id,
52
61
                relationId:     relationId,
53
62
                remoteUnitName: remoteUnitName,
54
63
                relations:      relations,
 
64
                apiAddrs:       apiAddrs,
55
65
        }
56
66
}
57
67
 
75
85
        return ctx.unit.ClosePort(protocol, port)
76
86
}
77
87
 
78
 
func (ctx *HookContext) Config() (map[string]interface{}, error) {
79
 
        if ctx.config == nil {
 
88
func (ctx *HookContext) ConfigSettings() (charm.Settings, error) {
 
89
        if ctx.configSettings == nil {
80
90
                var err error
81
 
                ctx.config, err = ctx.unit.ServiceConfig()
 
91
                ctx.configSettings, err = ctx.unit.ConfigSettings()
82
92
                if err != nil {
83
93
                        return nil, err
84
94
                }
85
95
        }
86
 
        return ctx.config, nil
 
96
        result := charm.Settings{}
 
97
        for name, value := range ctx.configSettings {
 
98
                result[name] = value
 
99
        }
 
100
        return result, nil
87
101
}
88
102
 
89
103
func (ctx *HookContext) HookRelation() (jujuc.ContextRelation, bool) {
120
134
                "JUJU_AGENT_SOCKET=" + socketPath,
121
135
                "JUJU_UNIT_NAME=" + ctx.unit.Name(),
122
136
                "JUJU_ENV_UUID=" + ctx.uuid,
 
137
                "JUJU_API_ADDRESSES=" + strings.Join(ctx.apiAddrs, " "),
123
138
        }
124
139
        if r, found := ctx.HookRelation(); found {
125
140
                vars = append(vars, "JUJU_RELATION="+r.Name())