LEFT | RIGHT |
1 // Stub provider for OpenStack, using goose will be implemented here | 1 // Stub provider for OpenStack, using goose will be implemented here |
2 | 2 |
3 package openstack | 3 package openstack |
4 | 4 |
5 import ( | 5 import ( |
6 "fmt" | 6 "fmt" |
7 "io/ioutil" | 7 "io/ioutil" |
8 "launchpad.net/goose/client" | 8 "launchpad.net/goose/client" |
9 "launchpad.net/goose/identity" | 9 "launchpad.net/goose/identity" |
10 "launchpad.net/goose/nova" | 10 "launchpad.net/goose/nova" |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
85 } | 85 } |
86 | 86 |
87 var _ environs.Environ = (*environ)(nil) | 87 var _ environs.Environ = (*environ)(nil) |
88 | 88 |
89 type instance struct { | 89 type instance struct { |
90 e *environ | 90 e *environ |
91 *nova.Entity | 91 *nova.Entity |
92 } | 92 } |
93 | 93 |
94 func (inst *instance) String() string { | 94 func (inst *instance) String() string { |
95 » return inst.Id() | 95 » return inst.Entity.Id |
96 } | 96 } |
97 | 97 |
98 var _ environs.Instance = (*instance)(nil) | 98 var _ environs.Instance = (*instance)(nil) |
99 | 99 |
100 func (inst *instance) Id() string { | 100 func (inst *instance) Id() state.InstanceId { |
101 » return inst.Entity.Id | 101 » return state.InstanceId(inst.Entity.Id) |
102 } | 102 } |
103 | 103 |
104 func (inst *instance) DNSName() (string, error) { | 104 func (inst *instance) DNSName() (string, error) { |
105 panic("DNSName not implemented") | 105 panic("DNSName not implemented") |
106 } | 106 } |
107 | 107 |
108 func (inst *instance) WaitDNSName() (string, error) { | 108 func (inst *instance) WaitDNSName() (string, error) { |
109 panic("WaitDNSName not implemented") | 109 panic("WaitDNSName not implemented") |
110 } | 110 } |
111 | 111 |
112 func (inst *instance) OpenPorts(machineId int, ports []state.Port) error { | 112 func (inst *instance) OpenPorts(machineId string, ports []state.Port) error { |
113 panic("OpenPorts not implemented") | 113 panic("OpenPorts not implemented") |
114 } | 114 } |
115 | 115 |
116 func (inst *instance) ClosePorts(machineId int, ports []state.Port) error { | 116 func (inst *instance) ClosePorts(machineId string, ports []state.Port) error { |
117 panic("ClosePorts not implemented") | 117 panic("ClosePorts not implemented") |
118 } | 118 } |
119 | 119 |
120 func (inst *instance) Ports(machineId int) ([]state.Port, error) { | 120 func (inst *instance) Ports(machineId string) ([]state.Port, error) { |
121 panic("Ports not implemented") | 121 panic("Ports not implemented") |
122 } | 122 } |
123 | 123 |
124 func (e *environ) ecfg() *environConfig { | 124 func (e *environ) ecfg() *environConfig { |
125 e.ecfgMutex.Lock() | 125 e.ecfgMutex.Lock() |
126 ecfg := e.ecfgUnlocked | 126 ecfg := e.ecfgUnlocked |
127 e.ecfgMutex.Unlock() | 127 e.ecfgMutex.Unlock() |
128 return ecfg | 128 return ecfg |
129 } | 129 } |
130 | 130 |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
175 TenantName: ecfg.tenantName(), | 175 TenantName: ecfg.tenantName(), |
176 URL: ecfg.authURL(), | 176 URL: ecfg.authURL(), |
177 } | 177 } |
178 // TODO: do not hard code authentication type | 178 // TODO: do not hard code authentication type |
179 client := client.NewClient(cred, identity.AuthUserPass) | 179 client := client.NewClient(cred, identity.AuthUserPass) |
180 e.novaUnlocked = nova.New(client) | 180 e.novaUnlocked = nova.New(client) |
181 e.swiftUnlocked = swift.New(client) | 181 e.swiftUnlocked = swift.New(client) |
182 return nil | 182 return nil |
183 } | 183 } |
184 | 184 |
185 func (e *environ) StartInstance(machineId int, info *state.Info, tools *state.To
ols) (environs.Instance, error) { | 185 func (e *environ) StartInstance(machineId string, info *state.Info, tools *state
.Tools) (environs.Instance, error) { |
186 panic("StartInstance not implemented") | 186 panic("StartInstance not implemented") |
187 } | 187 } |
188 | 188 |
189 func (e *environ) StopInstances([]environs.Instance) error { | 189 func (e *environ) StopInstances([]environs.Instance) error { |
190 panic("StopInstances not implemented") | 190 panic("StopInstances not implemented") |
191 } | 191 } |
192 | 192 |
193 func (e *environ) Instances(ids []string) ([]environs.Instance, error) { | 193 func (e *environ) Instances(ids []state.InstanceId) ([]environs.Instance, error)
{ |
| 194 » // TODO FIXME Instances must somehow be tagged to be part of the environ
ment. |
| 195 » // This is returning *all* instances, which means it's impossible to hav
e two different |
| 196 » // environments on the same account. |
194 if len(ids) == 0 { | 197 if len(ids) == 0 { |
195 return nil, nil | 198 return nil, nil |
196 } | 199 } |
197 insts := make([]environs.Instance, len(ids)) | 200 insts := make([]environs.Instance, len(ids)) |
198 » servers, err := e.nova().ListServers() | 201 » servers, err := e.nova().ListServers(nil) |
199 if err != nil { | 202 if err != nil { |
200 return nil, err | 203 return nil, err |
201 } | 204 } |
202 for i, id := range ids { | 205 for i, id := range ids { |
203 » » for j, _ := range *servers { | 206 » » for j, _ := range servers { |
204 » » » if (*servers)[j].Id == id { | 207 » » » if servers[j].Id == string(id) { |
205 » » » » insts[i] = &instance{e, &(*servers)[j]} | 208 » » » » insts[i] = &instance{e, &servers[j]} |
206 } | 209 } |
207 } | 210 } |
208 } | 211 } |
209 return insts, nil | 212 return insts, nil |
210 } | 213 } |
211 | 214 |
212 func (e *environ) AllInstances() (insts []environs.Instance, err error) { | 215 func (e *environ) AllInstances() (insts []environs.Instance, err error) { |
| 216 // TODO FIXME Instances must somehow be tagged to be part of the environ
ment. |
| 217 // This is returning *all* instances, which means it's impossible to hav
e two different |
| 218 // environments on the same account. |
213 // TODO: add filtering to exclude deleted images etc | 219 // TODO: add filtering to exclude deleted images etc |
214 » servers, err := e.nova().ListServers() | 220 » servers, err := e.nova().ListServers(nil) |
215 » if err != nil { | 221 » if err != nil { |
216 » » return nil, err | 222 » » return nil, err |
217 » } | 223 » } |
218 » for _, server := range *servers { | 224 » for _, server := range servers { |
219 var s = server | 225 var s = server |
220 insts = append(insts, &instance{e, &s}) | 226 insts = append(insts, &instance{e, &s}) |
221 } | 227 } |
222 return insts, err | 228 return insts, err |
223 } | 229 } |
224 | 230 |
225 func (e *environ) Storage() environs.Storage { | 231 func (e *environ) Storage() environs.Storage { |
226 panic("Storage not implemented") | 232 panic("Storage not implemented") |
227 } | 233 } |
228 | 234 |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
281 if err != nil { | 287 if err != nil { |
282 continue | 288 continue |
283 } | 289 } |
284 return strings.TrimSpace(string(data)), nil | 290 return strings.TrimSpace(string(data)), nil |
285 } | 291 } |
286 if err != nil { | 292 if err != nil { |
287 return "", fmt.Errorf("cannot get %q: %v", uri, err) | 293 return "", fmt.Errorf("cannot get %q: %v", uri, err) |
288 } | 294 } |
289 return | 295 return |
290 } | 296 } |
LEFT | RIGHT |