Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(535)

Delta Between Two Patch Sets: cmd/jujud/provisioning.go

Issue 6203083: jujud: add primordial provisioning agent (Closed)
Left Patch Set: jujud: add primordial provisioning agent Created 12 years, 10 months ago
Right Patch Set: jujud: add primordial provisioning agent Created 12 years, 10 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « cmd/jujud/machines.go ('k') | state/state.go » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
1 package main 1 package main
2 2
3 import ( 3 import (
4 "launchpad.net/gnuflag" 4 "launchpad.net/gnuflag"
5 "launchpad.net/juju/go/cmd" 5 "launchpad.net/juju/go/cmd"
6 "launchpad.net/juju/go/log" 6 "launchpad.net/juju/go/log"
7 "launchpad.net/juju/go/state" 7 "launchpad.net/juju/go/state"
8 » "os" 8
9 » // register providers
10 » _ "launchpad.net/juju/go/environs/dummy"
11 » _ "launchpad.net/juju/go/environs/ec2"
9 ) 12 )
10 13
11 // ProvisioningAgent is a cmd.Command responsible for running a provisioning age nt. 14 // ProvisioningAgent is a cmd.Command responsible for running a provisioning age nt.
12 type ProvisioningAgent struct { 15 type ProvisioningAgent struct {
13 Conf AgentConf 16 Conf AgentConf
14 } 17 }
15 18
16 // Info returns usage information for the command. 19 // Info returns usage information for the command.
17 func (a *ProvisioningAgent) Info() *cmd.Info { 20 func (a *ProvisioningAgent) Info() *cmd.Info {
18 return &cmd.Info{"provisioning", "", "run a juju provisioning agent", "" } 21 return &cmd.Info{"provisioning", "", "run a juju provisioning agent", "" }
19 } 22 }
20 23
21 // Init initializes the command for running. 24 // Init initializes the command for running.
22 func (a *ProvisioningAgent) Init(f *gnuflag.FlagSet, args []string) error { 25 func (a *ProvisioningAgent) Init(f *gnuflag.FlagSet, args []string) error {
23 a.Conf.addFlags(f) 26 a.Conf.addFlags(f)
24 if err := f.Parse(true, args); err != nil { 27 if err := f.Parse(true, args); err != nil {
25 return err 28 return err
26 } 29 }
27 return a.Conf.checkArgs(f.Args()) 30 return a.Conf.checkArgs(f.Args())
28 } 31 }
29 32
30 func (a *ProvisioningAgent) MustOpenState() *state.State { 33 // Run runs a provisioning agent.
34 func (a *ProvisioningAgent) Run(_ *cmd.Context) error {
31 state, err := state.Open(&a.Conf.StateInfo) 35 state, err := state.Open(&a.Conf.StateInfo)
32 if err != nil { 36 if err != nil {
33 » » log.Printf("failed to connect to zookeeper: %v", err) 37 » » return err
34 » » os.Exit(1)
fwereade 2012/05/18 09:08:25 I'd prefer not to jump across layers like this...
35 } 38 }
36 return state
37 }
38 39
39 // Run runs a provisioning agent. 40 » env, err := NewProxyEnviron(state)
40 func (a *ProvisioningAgent) Run(_ *cmd.Context) error { 41 » if err != nil {
41 » state := a.MustOpenState() 42 » » return err
43 » }
44 » machines := NewMachines(env)
45 » watcher := state.WatchMachines()
42 46
43 envwatcher := state.WatchEnvrionConfig()
fwereade 2012/05/18 09:08:25 s/WatchEnvrionConfig/WatchEnvironConfig/ ...and p
44 ps := NewProviderService(envwatcher, &a.Conf.StateInfo)
45
46 machines := state.WatchMachines()
47 for { 47 for {
48 » » changes, ok := <-machines.Changes() 48 » » select {
49 » » if !ok { 49 » » case changes, ok := <-watcher.Changes():
50 » » » break 50 » » » if !ok {
51 » » } 51 » » » » log.Printf("Machines watcher has shutdown")
52 » » for _, added := range changes.Added { 52 » » » » break
53 » » » ps.AddMachine(added) 53 » » » }
54 » » } 54 » » » for _, added := range changes.Added {
55 » » for _, deleted := range changes.Deleted { 55 » » » » log.Printf("provisioning: machine %d added", add ed.Id())
56 » » » ps.RemoveMachine(deleted) 56 » » » » machines.StartMachine(added.Id())
57 » » » }
58 » » » for _, deleted := range changes.Deleted {
59 » » » » log.Printf("provisioning: machine %d deleted", d eleted.Id())
60 » » » » machines.StopMachine(deleted.Id())
61 » » » }
57 } 62 }
58 } 63 }
59 » return nil 64 » return watcher.Stop()
60 } 65 }
LEFTRIGHT

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b