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

Side by Side Diff: container/container.go

Issue 6312044: container: new package
Patch Set: Created 5 years, 6 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:
View unified diff | Download patch
« no previous file with comments | « [revision details] ('k') | container/container_test.go » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 package container
2
3 import (
4 "fmt"
5 "launchpad.net/juju-core/juju/state"
6 "launchpad.net/juju-core/juju/upstart"
7 "os/exec"
8 "strings"
9 )
10
11 // Container contains running juju service units.
12 type Container interface {
13 Deploy() error
14 Destroy() error
15 }
16
17 // TODO:
18 //type lxc struct {
19 // name string
20 //}
21 //
22 //func LXC(args...) Container {
23 //}
24
25 type simple struct {
26 unit *state.Unit
27 }
28
29 func Simple(unit *state.Unit) Container {
30 return &simple{unit}
31 }
32
33 func deslash(s string) string {
34 return strings.Replace(s, "/", "-", -1)
35 }
36
37 func (s *simple) service() *upstart.Service {
38 return upstart.NewService(deslash(s.unit.Name()))
39 }
40
41 func (s *simple) Deploy() error {
42 exe, err := exec.LookPath("jujud")
43 if err != nil {
44 return fmt.Errorf("cannot find executable: %v", err)
45 }
46 conf := &upstart.Conf{
47 Service: *s.service(),
48 Desc: "juju unit agent for " + s.unit.Name(),
49 Cmd: exe + " unit --unit-name " + s.unit.Name(),
50 // TODO: Out
51 }
52 return conf.Install()
53 }
54
55 func (s *simple) Destroy() error {
56 // TODO what, if any, directory do we need to delete?
57 return s.service().Remove()
58 }
59
OLDNEW
« no previous file with comments | « [revision details] ('k') | container/container_test.go » ('j') | no next file with comments »

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