github.com/mattyw/juju@v0.0.0-20140610034352-732aecd63861/cmd/juju/endpoint.go (about)

     1  // Copyright 2013 Canonical Ltd.
     2  // Licensed under the AGPLv3, see LICENCE file for details.
     3  
     4  package main
     5  
     6  import (
     7  	"launchpad.net/gnuflag"
     8  
     9  	"github.com/juju/juju/cmd"
    10  	"github.com/juju/juju/cmd/envcmd"
    11  	"github.com/juju/juju/juju"
    12  )
    13  
    14  // EndpointCommand returns the API endpoints
    15  type EndpointCommand struct {
    16  	envcmd.EnvCommandBase
    17  	out     cmd.Output
    18  	refresh bool
    19  }
    20  
    21  const endpointDoc = `
    22  Returns a list of the API servers formatted as host:port
    23  Default output format returns an api server per line.
    24  
    25  Examples:
    26    $ juju api-endpoints
    27    10.0.3.1:17070
    28    $
    29  `
    30  
    31  func (c *EndpointCommand) Info() *cmd.Info {
    32  	return &cmd.Info{
    33  		Name:    "api-endpoints",
    34  		Args:    "",
    35  		Purpose: "Print the API server addresses",
    36  		Doc:     endpointDoc,
    37  	}
    38  }
    39  
    40  func (c *EndpointCommand) SetFlags(f *gnuflag.FlagSet) {
    41  	c.out.AddFlags(f, "smart", cmd.DefaultFormatters)
    42  	f.BoolVar(&c.refresh, "refresh", false, "connect to the API to ensure up-to-date endpoint locations")
    43  }
    44  
    45  // Print out the addresses of the API server endpoints.
    46  func (c *EndpointCommand) Run(ctx *cmd.Context) error {
    47  	apiendpoint, err := juju.APIEndpointForEnv(c.EnvName, c.refresh)
    48  	if err != nil {
    49  		return err
    50  	}
    51  	return c.out.Write(ctx, apiendpoint.Addresses)
    52  }