github.com/cloudbase/juju-core@v0.0.0-20140504232958-a7271ac7912f/cmd/juju/expose.go (about)

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