~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/destroyrelation.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
        "fmt"
 
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
// DestroyRelationCommand causes an existing service relation to be shut down.
 
12
type DestroyRelationCommand struct {
 
13
        EnvCommandBase
 
14
        Endpoints []string
 
15
}
 
16
 
 
17
func (c *DestroyRelationCommand) Info() *cmd.Info {
 
18
        return &cmd.Info{
 
19
                Name:    "destroy-relation",
 
20
                Args:    "<service1>[:<relation name1>] <service2>[:<relation name2>]",
 
21
                Purpose: "destroy a relation between two services",
 
22
                Aliases: []string{"remove-relation"},
 
23
        }
 
24
}
 
25
 
 
26
func (c *DestroyRelationCommand) Init(args []string) error {
 
27
        if len(args) != 2 {
 
28
                return fmt.Errorf("a relation must involve two services")
 
29
        }
 
30
        c.Endpoints = args
 
31
        return nil
 
32
}
 
33
 
 
34
func (c *DestroyRelationCommand) Run(_ *cmd.Context) error {
 
35
        conn, err := juju.NewConnFromName(c.EnvName)
 
36
        if err != nil {
 
37
                return err
 
38
        }
 
39
        defer conn.Close()
 
40
 
 
41
        params := params.DestroyRelation{
 
42
                Endpoints: c.Endpoints,
 
43
        }
 
44
        return statecmd.DestroyRelation(conn.State, params)
 
45
}