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

Side by Side Diff: environs/openstack/config.go

Issue 6874049: Add more OpenStack provider implementation (Closed)
Patch Set: Add more OpenStack provider implementation Created 11 years, 3 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
« no previous file with comments | « [revision details] ('k') | environs/openstack/config_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 openstack 1 package openstack
2 2
3 import ( 3 import (
4 "fmt" 4 "fmt"
5 "launchpad.net/goose/identity"
5 "launchpad.net/juju-core/environs/config" 6 "launchpad.net/juju-core/environs/config"
6 "launchpad.net/juju-core/schema" 7 "launchpad.net/juju-core/schema"
7 "net/url" 8 "net/url"
8 "os" 9 "os"
9 ) 10 )
10 11
11 var configChecker = schema.StrictFieldMap( 12 var configChecker = schema.StrictFieldMap(
12 schema.Fields{ 13 schema.Fields{
13 "username": schema.String(), 14 "username": schema.String(),
14 "password": schema.String(), 15 "password": schema.String(),
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
70 return nil, err 71 return nil, err
71 } 72 }
72 ecfg := &environConfig{cfg, v.(map[string]interface{})} 73 ecfg := &environConfig{cfg, v.(map[string]interface{})}
73 74
74 if ecfg.authURL() != "" { 75 if ecfg.authURL() != "" {
75 parts, err := url.Parse(ecfg.authURL()) 76 parts, err := url.Parse(ecfg.authURL())
76 if err != nil || parts.Host == "" || parts.Scheme == "" { 77 if err != nil || parts.Host == "" || parts.Scheme == "" {
77 return nil, fmt.Errorf("invalid auth-url value %q", ecfg .authURL()) 78 return nil, fmt.Errorf("invalid auth-url value %q", ecfg .authURL())
78 } 79 }
79 } 80 }
80
81 if ecfg.username() == "" || ecfg.password() == "" || ecfg.tenantName() = = "" || ecfg.authURL() == "" { 81 if ecfg.username() == "" || ecfg.password() == "" || ecfg.tenantName() = = "" || ecfg.authURL() == "" {
82 » » // TODO(dimitern): get goose client to handle this 82 » » cred, err := identity.CompleteCredentialsFromEnv()
83 » » auth, ok := getEnvAuth() 83 » » if err != nil {
84 » » if !ok { 84 » » » return nil, err
85 » » » return nil, fmt.Errorf("OpenStack environment has no use rname, password, tenant-name, or auth-url")
86 } 85 }
87 » » ecfg.attrs["username"] = auth.username 86 » » ecfg.attrs["username"] = cred.User
88 » » ecfg.attrs["password"] = auth.password 87 » » ecfg.attrs["password"] = cred.Secrets
89 » » ecfg.attrs["tenant-name"] = auth.tenantName 88 » » ecfg.attrs["tenant-name"] = cred.TenantName
90 » » ecfg.attrs["auth-url"] = auth.authURL 89 » » ecfg.attrs["auth-url"] = cred.URL
91 } 90 }
92 // We cannot validate the region name, since each OS installation 91 // We cannot validate the region name, since each OS installation
93 // can have its own region names - only after authentication the 92 // can have its own region names - only after authentication the
94 // region names are known (from the service endpoints) 93 // region names are known (from the service endpoints)
95 if ecfg.region() == "" { 94 if ecfg.region() == "" {
96 region := os.Getenv("OS_REGION_NAME") 95 region := os.Getenv("OS_REGION_NAME")
97 if region != "" { 96 if region != "" {
98 ecfg.attrs["region"] = region 97 ecfg.attrs["region"] = region
99 } else { 98 } else {
100 return nil, fmt.Errorf("OpenStack environment has no reg ion") 99 return nil, fmt.Errorf("OpenStack environment has no reg ion")
(...skipping 13 matching lines...) Expand all
114 switch cfg.FirewallMode() { 113 switch cfg.FirewallMode() {
115 case config.FwDefault: 114 case config.FwDefault:
116 ecfg.attrs["firewall-mode"] = config.FwInstance 115 ecfg.attrs["firewall-mode"] = config.FwInstance
117 case config.FwInstance, config.FwGlobal: 116 case config.FwInstance, config.FwGlobal:
118 default: 117 default:
119 return nil, fmt.Errorf("unsupported firewall mode: %q", cfg.Fire wallMode()) 118 return nil, fmt.Errorf("unsupported firewall mode: %q", cfg.Fire wallMode())
120 } 119 }
121 120
122 return cfg.Apply(ecfg.attrs) 121 return cfg.Apply(ecfg.attrs)
123 } 122 }
124
125 // TODO(dimitern): temporarily here, until goose client handles this
126 type envAuth struct {
127 username, password, tenantName, authURL string
128 }
129
130 func getEnvAuth() (auth envAuth, ok bool) {
131 auth = envAuth{
132 username: os.Getenv("OS_USERNAME"),
133 password: os.Getenv("OS_PASSWORD"),
134 tenantName: os.Getenv("OS_TENANT_NAME"),
135 authURL: os.Getenv("OS_AUTH_URL"),
136 }
137 if auth.username == "" || auth.password == "" || auth.tenantName == "" | | auth.authURL == "" {
138 return auth, false
139 }
140 return auth, true
141 }
OLDNEW
« no previous file with comments | « [revision details] ('k') | environs/openstack/config_test.go » ('j') | no next file with comments »

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