~themue/pyjuju/go-state-add-relation

« back to all changes in this revision

Viewing changes to environs/dummy/environs.go

  • Committer: Roger Peppe
  • Date: 2012-05-01 07:22:35 UTC
  • mfrom: (130.3.13 go-dummy-upload)
  • Revision ID: roger.peppe@canonical.com-20120501072235-whz9cxgoq1jrahab
juju: add code for building and uploading juju client

R=fwereade, niemeyer
CC=
https://codereview.appspot.com/6128046

Show diffs side-by-side

added added

removed removed

Lines of Context:
9
9
        "launchpad.net/juju/go/environs"
10
10
        "launchpad.net/juju/go/schema"
11
11
        "launchpad.net/juju/go/state"
12
 
        "launchpad.net/juju/go/version"
13
12
        "sync"
14
13
)
15
14
 
16
15
type Operation struct {
17
 
        Kind        OperationKind
18
 
        EnvironName string
 
16
        Kind OperationKind
 
17
        Env  string
19
18
}
20
19
 
21
20
// Operation represents an action on the dummy provider.
27
26
        OpDestroy
28
27
        OpStartInstance
29
28
        OpStopInstances
 
29
        OpPutFile
30
30
)
31
31
 
32
32
var kindNames = []string{
35
35
        OpDestroy:       "OpDestroy",
36
36
        OpStartInstance: "OpStartInstance",
37
37
        OpStopInstances: "OpStopInstances",
 
38
        OpPutFile:       "OpPutFile",
38
39
}
39
40
 
40
41
func (k OperationKind) String() string {
165
166
        if e.broken {
166
167
                return errBroken
167
168
        }
168
 
        e.ops <- Operation{OpBootstrap, e.name}
 
169
        e.ops <- Operation{Kind: OpBootstrap, Env: e.name}
169
170
        e.state.mu.Lock()
170
171
        defer e.state.mu.Unlock()
171
172
        if e.state.bootstrapped {
187
188
        if e.broken {
188
189
                return errBroken
189
190
        }
190
 
        e.ops <- Operation{OpDestroy, e.name}
 
191
        e.ops <- Operation{Kind: OpDestroy, Env: e.name}
191
192
        e.state.mu.Lock()
192
193
        e.state.bootstrapped = false
193
194
        e.state.mu.Unlock()
198
199
        if e.broken {
199
200
                return nil, errBroken
200
201
        }
201
 
        e.ops <- Operation{OpStartInstance, e.name}
 
202
        e.ops <- Operation{Kind: OpStartInstance, Env: e.name}
202
203
        e.state.mu.Lock()
203
204
        defer e.state.mu.Unlock()
204
205
        i := &instance{
213
214
        if e.broken {
214
215
                return errBroken
215
216
        }
216
 
        e.ops <- Operation{OpStopInstances, e.name}
 
217
        e.ops <- Operation{Kind: OpStopInstances, Env: e.name}
217
218
        e.state.mu.Lock()
218
219
        defer e.state.mu.Unlock()
219
220
        for _, i := range is {
250
251
        if e.broken {
251
252
                return errBroken
252
253
        }
 
254
        e.ops <- Operation{Kind: OpPutFile, Env: e.name}
253
255
        var buf bytes.Buffer
254
256
        _, err := io.Copy(&buf, r)
255
257
        if err != nil {
261
263
        return nil
262
264
}
263
265
 
264
 
func (*environ) UploadTools(r io.Reader, length int64, version version.Version) error {
265
 
        return fmt.Errorf("dummy environment does not support executable upload")
266
 
}
267
 
 
268
266
func (e *environ) GetFile(name string) (io.ReadCloser, error) {
269
267
        if e.broken {
270
268
                return nil, errBroken
303
301
func (m *instance) WaitDNSName() (string, error) {
304
302
        return m.DNSName()
305
303
}
 
304
 
 
305
// notifyCloser sends on the notify channel when
 
306
// it's closed.
 
307
type notifyCloser struct {
 
308
        io.Reader
 
309
        notify chan bool
 
310
}
 
311
 
 
312
func (r *notifyCloser) Close() error {
 
313
        r.notify <- true
 
314
        return nil
 
315
}