~juju-qa/ubuntu/yakkety/juju/2.0-rc3-again

« back to all changes in this revision

Viewing changes to src/launchpad.net/juju-core/cmd/juju/expose.go

  • Committer: Package Import Robot
  • Author(s): James Page
  • Date: 2013-04-24 22:34:47 UTC
  • Revision ID: package-import@ubuntu.com-20130424223447-f0qdji7ubnyo0s71
Tags: upstream-1.10.0.1
ImportĀ upstreamĀ versionĀ 1.10.0.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
package main
 
2
 
 
3
import (
 
4
        "errors"
 
5
        "launchpad.net/juju-core/cmd"
 
6
        "launchpad.net/juju-core/juju"
 
7
        "launchpad.net/juju-core/state/api/params"
 
8
        "launchpad.net/juju-core/state/statecmd"
 
9
)
 
10
 
 
11
// ExposeCommand is responsible exposing services.
 
12
type ExposeCommand struct {
 
13
        EnvCommandBase
 
14
        ServiceName string
 
15
}
 
16
 
 
17
func (c *ExposeCommand) Info() *cmd.Info {
 
18
        return &cmd.Info{
 
19
                Name:    "expose",
 
20
                Args:    "<service>",
 
21
                Purpose: "expose a service",
 
22
        }
 
23
}
 
24
 
 
25
func (c *ExposeCommand) Init(args []string) error {
 
26
        if len(args) == 0 {
 
27
                return errors.New("no service name specified")
 
28
        }
 
29
        c.ServiceName = args[0]
 
30
        return cmd.CheckEmpty(args[1:])
 
31
}
 
32
 
 
33
// Run changes the juju-managed firewall to expose any
 
34
// ports that were also explicitly marked by units as open.
 
35
func (c *ExposeCommand) Run(_ *cmd.Context) error {
 
36
        conn, err := juju.NewConnFromName(c.EnvName)
 
37
        if err != nil {
 
38
                return err
 
39
        }
 
40
        defer conn.Close()
 
41
 
 
42
        params := params.ServiceExpose{
 
43
                ServiceName: c.ServiceName,
 
44
        }
 
45
        return statecmd.ServiceExpose(conn.State, params)
 
46
}