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

Side by Side Diff: provider/maas/environprovider.go

Issue 14644045: Use environment-uuid when interacting with MAAS
Patch Set: Use environment-uuid when interacting with MAAS Created 11 years, 5 months 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
OLDNEW
1 // Copyright 2013 Canonical Ltd. 1 // Copyright 2013 Canonical Ltd.
2 // Licensed under the AGPLv3, see LICENCE file for details. 2 // Licensed under the AGPLv3, see LICENCE file for details.
3 3
4 package maas 4 package maas
5 5
6 import ( 6 import (
7 "errors"
7 "os" 8 "os"
8 9
9 "launchpad.net/loggo" 10 "launchpad.net/loggo"
10 11
11 "launchpad.net/juju-core/environs" 12 "launchpad.net/juju-core/environs"
12 "launchpad.net/juju-core/environs/config" 13 "launchpad.net/juju-core/environs/config"
13 "launchpad.net/juju-core/instance" 14 "launchpad.net/juju-core/instance"
14 "launchpad.net/juju-core/juju/osenv" 15 "launchpad.net/juju-core/juju/osenv"
15 "launchpad.net/juju-core/utils" 16 "launchpad.net/juju-core/utils"
16 ) 17 )
(...skipping 13 matching lines...) Expand all
30 31
31 func (maasEnvironProvider) Open(cfg *config.Config) (environs.Environ, error) { 32 func (maasEnvironProvider) Open(cfg *config.Config) (environs.Environ, error) {
32 logger.Debugf("opening environment %q.", cfg.Name()) 33 logger.Debugf("opening environment %q.", cfg.Name())
33 env, err := NewEnviron(cfg) 34 env, err := NewEnviron(cfg)
34 if err != nil { 35 if err != nil {
35 return nil, err 36 return nil, err
36 } 37 }
37 return env, nil 38 return env, nil
38 } 39 }
39 40
41 var errUUIDAlreadySet = errors.New(
42 "environment-uuid is already set; this should not be set by hand")
43
40 func (p maasEnvironProvider) Prepare(cfg *config.Config) (environs.Environ, erro r) { 44 func (p maasEnvironProvider) Prepare(cfg *config.Config) (environs.Environ, erro r) {
41 » // TODO any attributes to prepare? 45 » attrs := cfg.UnknownAttrs()
thumper 2013/10/15 21:38:03 Didn't this bit land as r1984 on lp:juju-core?
46 » uuid, found := attrs["environment-uuid"]
47 » if found {
48 » » if uuid != "" {
49 » » » return nil, errUUIDAlreadySet
50 » » }
51 » } else {
52 » » uuid, err := utils.NewUUID()
53 » » if err != nil {
54 » » » return nil, err
55 » » }
56 » » attrs["environment-uuid"] = uuid.String()
57 » }
58 » cfg, err := cfg.Apply(attrs)
59 » if err != nil {
60 » » return nil, err
61 » }
42 return p.Open(cfg) 62 return p.Open(cfg)
43 } 63 }
44 64
45 // Boilerplate config YAML. Don't mess with the indentation or add newlines! 65 // Boilerplate config YAML. Don't mess with the indentation or add newlines!
46 var boilerplateYAML = ` 66 var boilerplateYAML = `
47 # https://juju.ubuntu.com/docs/config-maas.html 67 # https://juju.ubuntu.com/docs/config-maas.html
48 maas: 68 maas:
49 type: maas 69 type: maas
50 ·· 70 ··
51 # maas-server specifies the location of the MAAS server. It must 71 # maas-server specifies the location of the MAAS server. It must
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
88 108
89 // PublicAddress is specified in the EnvironProvider interface. 109 // PublicAddress is specified in the EnvironProvider interface.
90 func (prov maasEnvironProvider) PublicAddress() (string, error) { 110 func (prov maasEnvironProvider) PublicAddress() (string, error) {
91 return prov.hostname() 111 return prov.hostname()
92 } 112 }
93 113
94 // PrivateAddress is specified in the EnvironProvider interface. 114 // PrivateAddress is specified in the EnvironProvider interface.
95 func (prov maasEnvironProvider) PrivateAddress() (string, error) { 115 func (prov maasEnvironProvider) PrivateAddress() (string, error) {
96 return prov.hostname() 116 return prov.hostname()
97 } 117 }
OLDNEW

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