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

Side by Side Diff: juju/conn.go

Issue 7391051: juju: add NewConnFromState
Patch Set: juju: add NewConnFromState Created 12 years, 1 month 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') | juju/conn_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
1 package juju 1 package juju
2 2
3 import ( 3 import (
4 "crypto/sha256" 4 "crypto/sha256"
5 "encoding/hex" 5 "encoding/hex"
6 "fmt" 6 "fmt"
7 "io" 7 "io"
8 "io/ioutil" 8 "io/ioutil"
9 "launchpad.net/juju-core/charm" 9 "launchpad.net/juju-core/charm"
10 "launchpad.net/juju-core/environs" 10 "launchpad.net/juju-core/environs"
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
71 Environ: environ, 71 Environ: environ,
72 State: st, 72 State: st,
73 } 73 }
74 if err := conn.updateSecrets(); err != nil { 74 if err := conn.updateSecrets(); err != nil {
75 conn.Close() 75 conn.Close()
76 return nil, fmt.Errorf("unable to push secrets: %v", err) 76 return nil, fmt.Errorf("unable to push secrets: %v", err)
77 } 77 }
78 return conn, nil 78 return conn, nil
79 } 79 }
80 80
81 // NewConnFromState returns a Conn that uses an Environ
82 // made by reading the environment configuration.
83 // The resulting Conn uses the given State - closing
84 // it will close that State.
85 func NewConnFromState(st *state.State) (*Conn, error) {
86 cfg, err := st.EnvironConfig()
87 if err != nil {
88 return nil, err
89 }
90 environ, err := environs.New(cfg)
91 if err != nil {
92 return nil, err
93 }
94 return &Conn{
95 Environ: environ,
96 State: st,
97 }, nil
98 }
99
81 // NewConnFromName returns a Conn pointing at the environName environment, or th e 100 // NewConnFromName returns a Conn pointing at the environName environment, or th e
82 // default environment if not specified. 101 // default environment if not specified.
83 func NewConnFromName(environName string) (*Conn, error) { 102 func NewConnFromName(environName string) (*Conn, error) {
84 environ, err := environs.NewFromName(environName) 103 environ, err := environs.NewFromName(environName)
85 if err != nil { 104 if err != nil {
86 return nil, err 105 return nil, err
87 } 106 }
88 return NewConn(environ) 107 return NewConn(environ)
89 } 108 }
90 109
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after
300 } 319 }
301 if status != state.UnitError { 320 if status != state.UnitError {
302 return fmt.Errorf("unit %q is not in an error state", unit) 321 return fmt.Errorf("unit %q is not in an error state", unit)
303 } 322 }
304 mode := state.ResolvedNoHooks 323 mode := state.ResolvedNoHooks
305 if retryHooks { 324 if retryHooks {
306 mode = state.ResolvedRetryHooks 325 mode = state.ResolvedRetryHooks
307 } 326 }
308 return unit.SetResolved(mode) 327 return unit.SetResolved(mode)
309 } 328 }
OLDNEW
« no previous file with comments | « [revision details] ('k') | juju/conn_test.go » ('j') | no next file with comments »

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