Merge lp:~thumper/juju-core/move-params-port into lp:~go-bot/juju-core/trunk

Proposed by Tim Penhey
Status: Merged
Approved by: Tim Penhey
Approved revision: no longer in the source branch.
Merged at revision: 1290
Proposed branch: lp:~thumper/juju-core/move-params-port
Merge into: lp:~go-bot/juju-core/trunk
Prerequisite: lp:~thumper/juju-core/instance-id
Diff against target: 1406 lines (+171/-180)
18 files modified
environs/azure/environ.go (+3/-4)
environs/azure/instance.go (+3/-4)
environs/dummy/environs.go (+12/-13)
environs/ec2/ec2.go (+11/-12)
environs/interface.go (+3/-4)
environs/jujutest/livetests.go (+24/-25)
environs/maas/environ.go (+4/-5)
environs/maas/instance.go (+8/-9)
environs/openstack/provider.go (+10/-11)
instance/instance.go (+14/-5)
state/api/params/params.go (+2/-11)
state/api/params/params_test.go (+2/-1)
state/megawatcher_internal_test.go (+4/-4)
state/state_test.go (+4/-5)
state/unit.go (+9/-8)
state/unit_test.go (+7/-6)
worker/firewaller/firewaller.go (+17/-18)
worker/firewaller/firewaller_test.go (+34/-35)
To merge this branch: bzr merge lp:~thumper/juju-core/move-params-port
Reviewer Review Type Date Requested Status
Juju Engineering Pending
Review via email: mp+169711@code.launchpad.net

Commit message

Move params.Ports to the instance package

This removes the state/api/params dependency inside instance.
The instance package only imports standard libraries now.

https://codereview.appspot.com/10327043/

Description of the change

Move params.Ports to the instance package

This removes the state/api/params dependency inside instance.
The instance package only imports standard libraries now.

https://codereview.appspot.com/10327043/

To post a comment you must log in.
Revision history for this message
Tim Penhey (thumper) wrote :

Reviewers: mp+169711_code.launchpad.net,

Message:
Please take a look.

Description:
Move params.Ports to the instance package

This removes the state/api/params dependency inside instance.
The instance package only imports standard libraries now.

https://code.launchpad.net/~thumper/juju-core/move-params-port/+merge/169711

Requires:
https://code.launchpad.net/~thumper/juju-core/instance-id/+merge/169709

(do not edit description out of merge proposal)

Please review this at https://codereview.appspot.com/10327043/

Affected files:
   A [revision details]
   M environs/azure/environ.go
   M environs/azure/instance.go
   M environs/dummy/environs.go
   M environs/ec2/ec2.go
   M environs/interface.go
   M environs/jujutest/livetests.go
   M environs/maas/environ.go
   M environs/maas/instance.go
   M environs/openstack/provider.go
   M instance/instance.go
   M state/api/params/params.go
   M state/api/params/params_test.go
   M state/megawatcher_internal_test.go
   M state/state_test.go
   M state/unit.go
   M state/unit_test.go
   M worker/firewaller/firewaller.go
   M worker/firewaller/firewaller_test.go

Revision history for this message
Ian Booth (wallyworld) wrote :

LGTM

https://codereview.appspot.com/10327043/diff/1/environs/maas/instance.go
File environs/maas/instance.go (right):

https://codereview.appspot.com/10327043/diff/1/environs/maas/instance.go#newcode36
environs/maas/instance.go:36: func (this *maasInstance) DNSName()
(string, error) {
s/this/mi

https://codereview.appspot.com/10327043/

Revision history for this message
Tim Penhey (thumper) wrote :

On 2013/06/17 06:25:07, dfc wrote:
> Would you consider a type instead ?

> type Proto int

> const {
> TCP Proto = iota
> UDP
> }

> func (p Proto) String() string {
> switch p {
> case TCP: return "TCP"
> case UDP: return "UDP"
> default: return "unknown"
> }

Yes, but not in this branch.

The current changes here are very mechanical and limited in scope.

Changing the type of the protocol specifier would require more changes.

So, yes, I support this idea, just not right now.

https://codereview.appspot.com/10327043/

Revision history for this message
Go Bot (go-bot) wrote :

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'environs/azure/environ.go'
2--- environs/azure/environ.go 2013-06-17 21:41:29 +0000
3+++ environs/azure/environ.go 2013-06-17 21:41:30 +0000
4@@ -10,7 +10,6 @@
5 "launchpad.net/juju-core/instance"
6 "launchpad.net/juju-core/state"
7 "launchpad.net/juju-core/state/api"
8- "launchpad.net/juju-core/state/api/params"
9 )
10
11 type azureEnviron struct{}
12@@ -84,17 +83,17 @@
13 }
14
15 // OpenPorts is specified in the Environ interface.
16-func (env *azureEnviron) OpenPorts(ports []params.Port) error {
17+func (env *azureEnviron) OpenPorts(ports []instance.Port) error {
18 panic("unimplemented")
19 }
20
21 // ClosePorts is specified in the Environ interface.
22-func (env *azureEnviron) ClosePorts(ports []params.Port) error {
23+func (env *azureEnviron) ClosePorts(ports []instance.Port) error {
24 panic("unimplemented")
25 }
26
27 // Ports is specified in the Environ interface.
28-func (env *azureEnviron) Ports() ([]params.Port, error) {
29+func (env *azureEnviron) Ports() ([]instance.Port, error) {
30 panic("unimplemented")
31 }
32
33
34=== modified file 'environs/azure/instance.go'
35--- environs/azure/instance.go 2013-06-17 21:41:29 +0000
36+++ environs/azure/instance.go 2013-06-17 21:41:30 +0000
37@@ -5,7 +5,6 @@
38
39 import (
40 "launchpad.net/juju-core/instance"
41- "launchpad.net/juju-core/state/api/params"
42 )
43
44 type azureInstance struct{}
45@@ -29,16 +28,16 @@
46 }
47
48 // OpenPorts is specified in the Instance interface.
49-func (instance *azureInstance) OpenPorts(machineId string, ports []params.Port) error {
50+func (instance *azureInstance) OpenPorts(machineId string, ports []instance.Port) error {
51 panic("unimplemented")
52 }
53
54 // ClosePorts is specified in the Instance interface.
55-func (instance *azureInstance) ClosePorts(machineId string, ports []params.Port) error {
56+func (instance *azureInstance) ClosePorts(machineId string, ports []instance.Port) error {
57 panic("unimplemented")
58 }
59
60 // Ports is specified in the Instance interface.
61-func (instance *azureInstance) Ports(machineId string) ([]params.Port, error) {
62+func (instance *azureInstance) Ports(machineId string) ([]instance.Port, error) {
63 panic("unimplemented")
64 }
65
66=== modified file 'environs/dummy/environs.go'
67--- environs/dummy/environs.go 2013-06-17 21:41:29 +0000
68+++ environs/dummy/environs.go 2013-06-17 21:41:30 +0000
69@@ -34,7 +34,6 @@
70 "launchpad.net/juju-core/schema"
71 "launchpad.net/juju-core/state"
72 "launchpad.net/juju-core/state/api"
73- "launchpad.net/juju-core/state/api/params"
74 "launchpad.net/juju-core/state/apiserver"
75 "launchpad.net/juju-core/testing"
76 "launchpad.net/juju-core/utils"
77@@ -92,14 +91,14 @@
78 Env string
79 MachineId string
80 InstanceId instance.Id
81- Ports []params.Port
82+ Ports []instance.Port
83 }
84
85 type OpClosePorts struct {
86 Env string
87 MachineId string
88 InstanceId instance.Id
89- Ports []params.Port
90+ Ports []instance.Port
91 }
92
93 type OpPutFile struct {
94@@ -127,7 +126,7 @@
95 mu sync.Mutex
96 maxId int // maximum instance id allocated so far.
97 insts map[instance.Id]*dummyInstance
98- globalPorts map[params.Port]bool
99+ globalPorts map[instance.Port]bool
100 firewallMode config.FirewallMode
101 bootstrapped bool
102 storageDelay time.Duration
103@@ -229,7 +228,7 @@
104 name: name,
105 ops: ops,
106 insts: make(map[instance.Id]*dummyInstance),
107- globalPorts: make(map[params.Port]bool),
108+ globalPorts: make(map[instance.Port]bool),
109 firewallMode: fwmode,
110 }
111 s.storage = newStorage(s, "/"+name+"/private")
112@@ -562,7 +561,7 @@
113 i := &dummyInstance{
114 state: e.state,
115 id: instance.Id(fmt.Sprintf("%s-%d", e.state.name, e.state.maxId)),
116- ports: make(map[params.Port]bool),
117+ ports: make(map[instance.Port]bool),
118 machineId: machineId,
119 series: series,
120 }
121@@ -637,7 +636,7 @@
122 return insts, nil
123 }
124
125-func (e *environ) OpenPorts(ports []params.Port) error {
126+func (e *environ) OpenPorts(ports []instance.Port) error {
127 e.state.mu.Lock()
128 defer e.state.mu.Unlock()
129 if e.state.firewallMode != config.FwGlobal {
130@@ -650,7 +649,7 @@
131 return nil
132 }
133
134-func (e *environ) ClosePorts(ports []params.Port) error {
135+func (e *environ) ClosePorts(ports []instance.Port) error {
136 e.state.mu.Lock()
137 defer e.state.mu.Unlock()
138 if e.state.firewallMode != config.FwGlobal {
139@@ -663,7 +662,7 @@
140 return nil
141 }
142
143-func (e *environ) Ports() (ports []params.Port, err error) {
144+func (e *environ) Ports() (ports []instance.Port, err error) {
145 e.state.mu.Lock()
146 defer e.state.mu.Unlock()
147 if e.state.firewallMode != config.FwGlobal {
148@@ -683,7 +682,7 @@
149
150 type dummyInstance struct {
151 state *environState
152- ports map[params.Port]bool
153+ ports map[instance.Port]bool
154 id instance.Id
155 machineId string
156 series string
157@@ -702,7 +701,7 @@
158 return inst.DNSName()
159 }
160
161-func (inst *dummyInstance) OpenPorts(machineId string, ports []params.Port) error {
162+func (inst *dummyInstance) OpenPorts(machineId string, ports []instance.Port) error {
163 defer delay()
164 log.Infof("environs/dummy: openPorts %s, %#v", machineId, ports)
165 if inst.state.firewallMode != config.FwInstance {
166@@ -726,7 +725,7 @@
167 return nil
168 }
169
170-func (inst *dummyInstance) ClosePorts(machineId string, ports []params.Port) error {
171+func (inst *dummyInstance) ClosePorts(machineId string, ports []instance.Port) error {
172 defer delay()
173 if inst.state.firewallMode != config.FwInstance {
174 return fmt.Errorf("invalid firewall mode for closing ports on instance: %q",
175@@ -749,7 +748,7 @@
176 return nil
177 }
178
179-func (inst *dummyInstance) Ports(machineId string) (ports []params.Port, err error) {
180+func (inst *dummyInstance) Ports(machineId string) (ports []instance.Port, err error) {
181 defer delay()
182 if inst.state.firewallMode != config.FwInstance {
183 return nil, fmt.Errorf("invalid firewall mode for retrieving ports from instance: %q",
184
185=== modified file 'environs/ec2/ec2.go'
186--- environs/ec2/ec2.go 2013-06-17 21:41:29 +0000
187+++ environs/ec2/ec2.go 2013-06-17 21:41:30 +0000
188@@ -21,7 +21,6 @@
189 "launchpad.net/juju-core/log"
190 "launchpad.net/juju-core/state"
191 "launchpad.net/juju-core/state/api"
192- "launchpad.net/juju-core/state/api/params"
193 "launchpad.net/juju-core/utils"
194 "net/http"
195 "strings"
196@@ -601,7 +600,7 @@
197 return st.deleteAll()
198 }
199
200-func portsToIPPerms(ports []params.Port) []ec2.IPPerm {
201+func portsToIPPerms(ports []instance.Port) []ec2.IPPerm {
202 ipPerms := make([]ec2.IPPerm, len(ports))
203 for i, p := range ports {
204 ipPerms[i] = ec2.IPPerm{
205@@ -614,7 +613,7 @@
206 return ipPerms
207 }
208
209-func (e *environ) openPortsInGroup(name string, ports []params.Port) error {
210+func (e *environ) openPortsInGroup(name string, ports []instance.Port) error {
211 if len(ports) == 0 {
212 return nil
213 }
214@@ -644,7 +643,7 @@
215 return nil
216 }
217
218-func (e *environ) closePortsInGroup(name string, ports []params.Port) error {
219+func (e *environ) closePortsInGroup(name string, ports []instance.Port) error {
220 if len(ports) == 0 {
221 return nil
222 }
223@@ -659,7 +658,7 @@
224 return nil
225 }
226
227-func (e *environ) portsInGroup(name string) (ports []params.Port, err error) {
228+func (e *environ) portsInGroup(name string) (ports []instance.Port, err error) {
229 g := ec2.SecurityGroup{Name: name}
230 resp, err := e.ec2().SecurityGroups([]ec2.SecurityGroup{g}, nil)
231 if err != nil {
232@@ -674,7 +673,7 @@
233 continue
234 }
235 for i := p.FromPort; i <= p.ToPort; i++ {
236- ports = append(ports, params.Port{
237+ ports = append(ports, instance.Port{
238 Protocol: p.Protocol,
239 Number: i,
240 })
241@@ -684,7 +683,7 @@
242 return ports, nil
243 }
244
245-func (e *environ) OpenPorts(ports []params.Port) error {
246+func (e *environ) OpenPorts(ports []instance.Port) error {
247 if e.Config().FirewallMode() != config.FwGlobal {
248 return fmt.Errorf("invalid firewall mode for opening ports on environment: %q",
249 e.Config().FirewallMode())
250@@ -696,7 +695,7 @@
251 return nil
252 }
253
254-func (e *environ) ClosePorts(ports []params.Port) error {
255+func (e *environ) ClosePorts(ports []instance.Port) error {
256 if e.Config().FirewallMode() != config.FwGlobal {
257 return fmt.Errorf("invalid firewall mode for closing ports on environment: %q",
258 e.Config().FirewallMode())
259@@ -708,7 +707,7 @@
260 return nil
261 }
262
263-func (e *environ) Ports() ([]params.Port, error) {
264+func (e *environ) Ports() ([]instance.Port, error) {
265 if e.Config().FirewallMode() != config.FwGlobal {
266 return nil, fmt.Errorf("invalid firewall mode for retrieving ports from environment: %q",
267 e.Config().FirewallMode())
268@@ -767,7 +766,7 @@
269 return "juju-" + e.name
270 }
271
272-func (inst *ec2Instance) OpenPorts(machineId string, ports []params.Port) error {
273+func (inst *ec2Instance) OpenPorts(machineId string, ports []instance.Port) error {
274 if inst.e.Config().FirewallMode() != config.FwInstance {
275 return fmt.Errorf("invalid firewall mode for opening ports on instance: %q",
276 inst.e.Config().FirewallMode())
277@@ -780,7 +779,7 @@
278 return nil
279 }
280
281-func (inst *ec2Instance) ClosePorts(machineId string, ports []params.Port) error {
282+func (inst *ec2Instance) ClosePorts(machineId string, ports []instance.Port) error {
283 if inst.e.Config().FirewallMode() != config.FwInstance {
284 return fmt.Errorf("invalid firewall mode for closing ports on instance: %q",
285 inst.e.Config().FirewallMode())
286@@ -793,7 +792,7 @@
287 return nil
288 }
289
290-func (inst *ec2Instance) Ports(machineId string) ([]params.Port, error) {
291+func (inst *ec2Instance) Ports(machineId string) ([]instance.Port, error) {
292 if inst.e.Config().FirewallMode() != config.FwInstance {
293 return nil, fmt.Errorf("invalid firewall mode for retrieving ports from instance: %q",
294 inst.e.Config().FirewallMode())
295
296=== modified file 'environs/interface.go'
297--- environs/interface.go 2013-06-17 21:41:29 +0000
298+++ environs/interface.go 2013-06-17 21:41:30 +0000
299@@ -11,7 +11,6 @@
300 "launchpad.net/juju-core/instance"
301 "launchpad.net/juju-core/state"
302 "launchpad.net/juju-core/state/api"
303- "launchpad.net/juju-core/state/api/params"
304 )
305
306 // A EnvironProvider represents a computing and storage provider.
307@@ -172,17 +171,17 @@
308 // OpenPorts opens the given ports for the whole environment.
309 // Must only be used if the environment was setup with the
310 // FwGlobal firewall mode.
311- OpenPorts(ports []params.Port) error
312+ OpenPorts(ports []instance.Port) error
313
314 // ClosePorts closes the given ports for the whole environment.
315 // Must only be used if the environment was setup with the
316 // FwGlobal firewall mode.
317- ClosePorts(ports []params.Port) error
318+ ClosePorts(ports []instance.Port) error
319
320 // Ports returns the ports opened for the whole environment.
321 // Must only be used if the environment was setup with the
322 // FwGlobal firewall mode.
323- Ports() ([]params.Port, error)
324+ Ports() ([]instance.Port, error)
325
326 // Provider returns the EnvironProvider that created this Environ.
327 Provider() EnvironProvider
328
329=== modified file 'environs/jujutest/livetests.go'
330--- environs/jujutest/livetests.go 2013-06-17 21:41:29 +0000
331+++ environs/jujutest/livetests.go 2013-06-17 21:41:30 +0000
332@@ -19,7 +19,6 @@
333 "launchpad.net/juju-core/juju"
334 "launchpad.net/juju-core/juju/testing"
335 "launchpad.net/juju-core/state"
336- "launchpad.net/juju-core/state/api/params"
337 coretesting "launchpad.net/juju-core/testing"
338 "launchpad.net/juju-core/utils"
339 "launchpad.net/juju-core/version"
340@@ -175,70 +174,70 @@
341 defer t.Env.StopInstances([]instance.Instance{inst2})
342
343 // Open some ports and check they're there.
344- err = inst1.OpenPorts("1", []params.Port{{"udp", 67}, {"tcp", 45}})
345+ err = inst1.OpenPorts("1", []instance.Port{{"udp", 67}, {"tcp", 45}})
346 c.Assert(err, IsNil)
347 ports, err = inst1.Ports("1")
348 c.Assert(err, IsNil)
349- c.Assert(ports, DeepEquals, []params.Port{{"tcp", 45}, {"udp", 67}})
350+ c.Assert(ports, DeepEquals, []instance.Port{{"tcp", 45}, {"udp", 67}})
351 ports, err = inst2.Ports("2")
352 c.Assert(err, IsNil)
353 c.Assert(ports, HasLen, 0)
354
355- err = inst2.OpenPorts("2", []params.Port{{"tcp", 89}, {"tcp", 45}})
356+ err = inst2.OpenPorts("2", []instance.Port{{"tcp", 89}, {"tcp", 45}})
357 c.Assert(err, IsNil)
358
359 // Check there's no crosstalk to another machine
360 ports, err = inst2.Ports("2")
361 c.Assert(err, IsNil)
362- c.Assert(ports, DeepEquals, []params.Port{{"tcp", 45}, {"tcp", 89}})
363+ c.Assert(ports, DeepEquals, []instance.Port{{"tcp", 45}, {"tcp", 89}})
364 ports, err = inst1.Ports("1")
365 c.Assert(err, IsNil)
366- c.Assert(ports, DeepEquals, []params.Port{{"tcp", 45}, {"udp", 67}})
367+ c.Assert(ports, DeepEquals, []instance.Port{{"tcp", 45}, {"udp", 67}})
368
369 // Check that opening the same port again is ok.
370 oldPorts, err := inst2.Ports("2")
371 c.Assert(err, IsNil)
372- err = inst2.OpenPorts("2", []params.Port{{"tcp", 45}})
373+ err = inst2.OpenPorts("2", []instance.Port{{"tcp", 45}})
374 c.Assert(err, IsNil)
375 ports, err = inst2.Ports("2")
376 c.Assert(err, IsNil)
377 c.Assert(ports, DeepEquals, oldPorts)
378
379 // Check that opening the same port again and another port is ok.
380- err = inst2.OpenPorts("2", []params.Port{{"tcp", 45}, {"tcp", 99}})
381+ err = inst2.OpenPorts("2", []instance.Port{{"tcp", 45}, {"tcp", 99}})
382 c.Assert(err, IsNil)
383 ports, err = inst2.Ports("2")
384 c.Assert(err, IsNil)
385- c.Assert(ports, DeepEquals, []params.Port{{"tcp", 45}, {"tcp", 89}, {"tcp", 99}})
386+ c.Assert(ports, DeepEquals, []instance.Port{{"tcp", 45}, {"tcp", 89}, {"tcp", 99}})
387
388- err = inst2.ClosePorts("2", []params.Port{{"tcp", 45}, {"tcp", 99}})
389+ err = inst2.ClosePorts("2", []instance.Port{{"tcp", 45}, {"tcp", 99}})
390 c.Assert(err, IsNil)
391
392 // Check that we can close ports and that there's no crosstalk.
393 ports, err = inst2.Ports("2")
394 c.Assert(err, IsNil)
395- c.Assert(ports, DeepEquals, []params.Port{{"tcp", 89}})
396+ c.Assert(ports, DeepEquals, []instance.Port{{"tcp", 89}})
397 ports, err = inst1.Ports("1")
398 c.Assert(err, IsNil)
399- c.Assert(ports, DeepEquals, []params.Port{{"tcp", 45}, {"udp", 67}})
400+ c.Assert(ports, DeepEquals, []instance.Port{{"tcp", 45}, {"udp", 67}})
401
402 // Check that we can close multiple ports.
403- err = inst1.ClosePorts("1", []params.Port{{"tcp", 45}, {"udp", 67}})
404+ err = inst1.ClosePorts("1", []instance.Port{{"tcp", 45}, {"udp", 67}})
405 c.Assert(err, IsNil)
406 ports, err = inst1.Ports("1")
407 c.Assert(ports, HasLen, 0)
408
409 // Check that we can close ports that aren't there.
410- err = inst2.ClosePorts("2", []params.Port{{"tcp", 111}, {"udp", 222}})
411+ err = inst2.ClosePorts("2", []instance.Port{{"tcp", 111}, {"udp", 222}})
412 c.Assert(err, IsNil)
413 ports, err = inst2.Ports("2")
414- c.Assert(ports, DeepEquals, []params.Port{{"tcp", 89}})
415+ c.Assert(ports, DeepEquals, []instance.Port{{"tcp", 89}})
416
417 // Check errors when acting on environment.
418- err = t.Env.OpenPorts([]params.Port{{"tcp", 80}})
419+ err = t.Env.OpenPorts([]instance.Port{{"tcp", 80}})
420 c.Assert(err, ErrorMatches, `invalid firewall mode for opening ports on environment: "instance"`)
421
422- err = t.Env.ClosePorts([]params.Port{{"tcp", 80}})
423+ err = t.Env.ClosePorts([]instance.Port{{"tcp", 80}})
424 c.Assert(err, ErrorMatches, `invalid firewall mode for closing ports on environment: "instance"`)
425
426 _, err = t.Env.Ports()
427@@ -273,34 +272,34 @@
428 c.Assert(ports, HasLen, 0)
429 defer t.Env.StopInstances([]instance.Instance{inst2})
430
431- err = t.Env.OpenPorts([]params.Port{{"udp", 67}, {"tcp", 45}, {"tcp", 89}, {"tcp", 99}})
432+ err = t.Env.OpenPorts([]instance.Port{{"udp", 67}, {"tcp", 45}, {"tcp", 89}, {"tcp", 99}})
433 c.Assert(err, IsNil)
434
435 ports, err = t.Env.Ports()
436 c.Assert(err, IsNil)
437- c.Assert(ports, DeepEquals, []params.Port{{"tcp", 45}, {"tcp", 89}, {"tcp", 99}, {"udp", 67}})
438+ c.Assert(ports, DeepEquals, []instance.Port{{"tcp", 45}, {"tcp", 89}, {"tcp", 99}, {"udp", 67}})
439
440 // Check closing some ports.
441- err = t.Env.ClosePorts([]params.Port{{"tcp", 99}, {"udp", 67}})
442+ err = t.Env.ClosePorts([]instance.Port{{"tcp", 99}, {"udp", 67}})
443 c.Assert(err, IsNil)
444
445 ports, err = t.Env.Ports()
446 c.Assert(err, IsNil)
447- c.Assert(ports, DeepEquals, []params.Port{{"tcp", 45}, {"tcp", 89}})
448+ c.Assert(ports, DeepEquals, []instance.Port{{"tcp", 45}, {"tcp", 89}})
449
450 // Check that we can close ports that aren't there.
451- err = t.Env.ClosePorts([]params.Port{{"tcp", 111}, {"udp", 222}})
452+ err = t.Env.ClosePorts([]instance.Port{{"tcp", 111}, {"udp", 222}})
453 c.Assert(err, IsNil)
454
455 ports, err = t.Env.Ports()
456 c.Assert(err, IsNil)
457- c.Assert(ports, DeepEquals, []params.Port{{"tcp", 45}, {"tcp", 89}})
458+ c.Assert(ports, DeepEquals, []instance.Port{{"tcp", 45}, {"tcp", 89}})
459
460 // Check errors when acting on instances.
461- err = inst1.OpenPorts("1", []params.Port{{"tcp", 80}})
462+ err = inst1.OpenPorts("1", []instance.Port{{"tcp", 80}})
463 c.Assert(err, ErrorMatches, `invalid firewall mode for opening ports on instance: "global"`)
464
465- err = inst1.ClosePorts("1", []params.Port{{"tcp", 80}})
466+ err = inst1.ClosePorts("1", []instance.Port{{"tcp", 80}})
467 c.Assert(err, ErrorMatches, `invalid firewall mode for closing ports on instance: "global"`)
468
469 _, err = inst1.Ports("1")
470
471=== modified file 'environs/maas/environ.go'
472--- environs/maas/environ.go 2013-06-17 21:41:29 +0000
473+++ environs/maas/environ.go 2013-06-17 21:41:30 +0000
474@@ -17,7 +17,6 @@
475 "launchpad.net/juju-core/log"
476 "launchpad.net/juju-core/state"
477 "launchpad.net/juju-core/state/api"
478- "launchpad.net/juju-core/state/api/params"
479 "launchpad.net/juju-core/utils"
480 "net/url"
481 "sync"
482@@ -490,19 +489,19 @@
483 }
484
485 // MAAS does not do firewalling so these port methods do nothing.
486-func (*maasEnviron) OpenPorts([]params.Port) error {
487+func (*maasEnviron) OpenPorts([]instance.Port) error {
488 log.Debugf("environs/maas: unimplemented OpenPorts() called")
489 return nil
490 }
491
492-func (*maasEnviron) ClosePorts([]params.Port) error {
493+func (*maasEnviron) ClosePorts([]instance.Port) error {
494 log.Debugf("environs/maas: unimplemented ClosePorts() called")
495 return nil
496 }
497
498-func (*maasEnviron) Ports() ([]params.Port, error) {
499+func (*maasEnviron) Ports() ([]instance.Port, error) {
500 log.Debugf("environs/maas: unimplemented Ports() called")
501- return []params.Port{}, nil
502+ return []instance.Port{}, nil
503 }
504
505 func (*maasEnviron) Provider() environs.EnvironProvider {
506
507=== modified file 'environs/maas/instance.go'
508--- environs/maas/instance.go 2013-06-17 21:41:29 +0000
509+++ environs/maas/instance.go 2013-06-17 21:41:30 +0000
510@@ -7,7 +7,6 @@
511 "launchpad.net/gomaasapi"
512 "launchpad.net/juju-core/instance"
513 "launchpad.net/juju-core/log"
514- "launchpad.net/juju-core/state/api/params"
515 )
516
517 type maasInstance struct {
518@@ -34,32 +33,32 @@
519 return nil
520 }
521
522-func (instance *maasInstance) DNSName() (string, error) {
523- hostname, err := (*instance.maasObject).GetField("hostname")
524+func (mi *maasInstance) DNSName() (string, error) {
525+ hostname, err := (*mi.maasObject).GetField("hostname")
526 if err != nil {
527 return "", err
528 }
529 return hostname, nil
530 }
531
532-func (instance *maasInstance) WaitDNSName() (string, error) {
533+func (mi *maasInstance) WaitDNSName() (string, error) {
534 // A MAAS nodes gets his DNS name when it's created. WaitDNSName,
535 // (same as DNSName) just returns the hostname of the node.
536- return instance.DNSName()
537+ return mi.DNSName()
538 }
539
540 // MAAS does not do firewalling so these port methods do nothing.
541-func (instance *maasInstance) OpenPorts(machineId string, ports []params.Port) error {
542+func (mi *maasInstance) OpenPorts(machineId string, ports []instance.Port) error {
543 log.Debugf("environs/maas: unimplemented OpenPorts() called")
544 return nil
545 }
546
547-func (instance *maasInstance) ClosePorts(machineId string, ports []params.Port) error {
548+func (mi *maasInstance) ClosePorts(machineId string, ports []instance.Port) error {
549 log.Debugf("environs/maas: unimplemented ClosePorts() called")
550 return nil
551 }
552
553-func (instance *maasInstance) Ports(machineId string) ([]params.Port, error) {
554+func (mi *maasInstance) Ports(machineId string) ([]instance.Port, error) {
555 log.Debugf("environs/maas: unimplemented Ports() called")
556- return []params.Port{}, nil
557+ return []instance.Port{}, nil
558 }
559
560=== modified file 'environs/openstack/provider.go'
561--- environs/openstack/provider.go 2013-06-17 21:41:29 +0000
562+++ environs/openstack/provider.go 2013-06-17 21:41:30 +0000
563@@ -27,7 +27,6 @@
564 "launchpad.net/juju-core/log"
565 "launchpad.net/juju-core/state"
566 "launchpad.net/juju-core/state/api"
567- "launchpad.net/juju-core/state/api/params"
568 "launchpad.net/juju-core/utils"
569 "net/http"
570 "strconv"
571@@ -354,7 +353,7 @@
572
573 // TODO: following 30 lines nearly verbatim from environs/ec2
574
575-func (inst *openstackInstance) OpenPorts(machineId string, ports []params.Port) error {
576+func (inst *openstackInstance) OpenPorts(machineId string, ports []instance.Port) error {
577 if inst.e.Config().FirewallMode() != config.FwInstance {
578 return fmt.Errorf("invalid firewall mode for opening ports on instance: %q",
579 inst.e.Config().FirewallMode())
580@@ -367,7 +366,7 @@
581 return nil
582 }
583
584-func (inst *openstackInstance) ClosePorts(machineId string, ports []params.Port) error {
585+func (inst *openstackInstance) ClosePorts(machineId string, ports []instance.Port) error {
586 if inst.e.Config().FirewallMode() != config.FwInstance {
587 return fmt.Errorf("invalid firewall mode for closing ports on instance: %q",
588 inst.e.Config().FirewallMode())
589@@ -380,7 +379,7 @@
590 return nil
591 }
592
593-func (inst *openstackInstance) Ports(machineId string) ([]params.Port, error) {
594+func (inst *openstackInstance) Ports(machineId string) ([]instance.Port, error) {
595 if inst.e.Config().FirewallMode() != config.FwInstance {
596 return nil, fmt.Errorf("invalid firewall mode for retrieving ports from instance: %q",
597 inst.e.Config().FirewallMode())
598@@ -1001,7 +1000,7 @@
599 return filter
600 }
601
602-func (e *environ) openPortsInGroup(name string, ports []params.Port) error {
603+func (e *environ) openPortsInGroup(name string, ports []instance.Port) error {
604 novaclient := e.nova()
605 group, err := novaclient.SecurityGroupByName(name)
606 if err != nil {
607@@ -1023,7 +1022,7 @@
608 return nil
609 }
610
611-func (e *environ) closePortsInGroup(name string, ports []params.Port) error {
612+func (e *environ) closePortsInGroup(name string, ports []instance.Port) error {
613 if len(ports) == 0 {
614 return nil
615 }
616@@ -1050,14 +1049,14 @@
617 return nil
618 }
619
620-func (e *environ) portsInGroup(name string) (ports []params.Port, err error) {
621+func (e *environ) portsInGroup(name string) (ports []instance.Port, err error) {
622 group, err := e.nova().SecurityGroupByName(name)
623 if err != nil {
624 return nil, err
625 }
626 for _, p := range (*group).Rules {
627 for i := *p.FromPort; i <= *p.ToPort; i++ {
628- ports = append(ports, params.Port{
629+ ports = append(ports, instance.Port{
630 Protocol: *p.IPProtocol,
631 Number: i,
632 })
633@@ -1069,7 +1068,7 @@
634
635 // TODO: following 30 lines nearly verbatim from environs/ec2
636
637-func (e *environ) OpenPorts(ports []params.Port) error {
638+func (e *environ) OpenPorts(ports []instance.Port) error {
639 if e.Config().FirewallMode() != config.FwGlobal {
640 return fmt.Errorf("invalid firewall mode for opening ports on environment: %q",
641 e.Config().FirewallMode())
642@@ -1081,7 +1080,7 @@
643 return nil
644 }
645
646-func (e *environ) ClosePorts(ports []params.Port) error {
647+func (e *environ) ClosePorts(ports []instance.Port) error {
648 if e.Config().FirewallMode() != config.FwGlobal {
649 return fmt.Errorf("invalid firewall mode for closing ports on environment: %q",
650 e.Config().FirewallMode())
651@@ -1093,7 +1092,7 @@
652 return nil
653 }
654
655-func (e *environ) Ports() ([]params.Port, error) {
656+func (e *environ) Ports() ([]instance.Port, error) {
657 if e.Config().FirewallMode() != config.FwGlobal {
658 return nil, fmt.Errorf("invalid firewall mode for retrieving ports from environment: %q",
659 e.Config().FirewallMode())
660
661=== modified file 'instance/instance.go'
662--- instance/instance.go 2013-06-17 21:41:29 +0000
663+++ instance/instance.go 2013-06-17 21:41:30 +0000
664@@ -5,8 +5,7 @@
665
666 import (
667 "errors"
668-
669- "launchpad.net/juju-core/state/api/params"
670+ "fmt"
671 )
672
673 var ErrNoDNSName = errors.New("DNS name not allocated")
674@@ -15,6 +14,16 @@
675 // instance (physical or virtual machine allocated in the provider).
676 type Id string
677
678+// Port identifies a network port number for a particular protocol.
679+type Port struct {
680+ Protocol string
681+ Number int
682+}
683+
684+func (p Port) String() string {
685+ return fmt.Sprintf("%s:%d", p.Protocol, p.Number)
686+}
687+
688 // Instance represents the the realization of a machine in state.
689 type Instance interface {
690 // Id returns a provider-generated identifier for the Instance.
691@@ -31,14 +40,14 @@
692
693 // OpenPorts opens the given ports on the instance, which
694 // should have been started with the given machine id.
695- OpenPorts(machineId string, ports []params.Port) error
696+ OpenPorts(machineId string, ports []Port) error
697
698 // ClosePorts closes the given ports on the instance, which
699 // should have been started with the given machine id.
700- ClosePorts(machineId string, ports []params.Port) error
701+ ClosePorts(machineId string, ports []Port) error
702
703 // Ports returns the set of ports open on the instance, which
704 // should have been started with the given machine id.
705 // The ports are returned as sorted by state.SortPorts.
706- Ports(machineId string) ([]params.Port, error)
707+ Ports(machineId string) ([]Port, error)
708 }
709
710=== modified file 'state/api/params/params.go'
711--- state/api/params/params.go 2013-06-12 18:19:17 +0000
712+++ state/api/params/params.go 2013-06-17 21:41:30 +0000
713@@ -9,6 +9,7 @@
714 "fmt"
715 "launchpad.net/juju-core/charm"
716 "launchpad.net/juju-core/constraints"
717+ "launchpad.net/juju-core/instance"
718 )
719
720 // Error holds the error result of a single operation.
721@@ -280,16 +281,6 @@
722 CharmURL string
723 }
724
725-// Port identifies a network port number for a particular protocol.
726-type Port struct {
727- Protocol string
728- Number int
729-}
730-
731-func (p Port) String() string {
732- return fmt.Sprintf("%s:%d", p.Protocol, p.Number)
733-}
734-
735 // Delta holds details of a change to the environment.
736 type Delta struct {
737 // If Removed is true, the entity has been removed;
738@@ -435,7 +426,7 @@
739 PublicAddress string
740 PrivateAddress string
741 MachineId string
742- Ports []Port
743+ Ports []instance.Port
744 Status Status
745 StatusInfo string
746 }
747
748=== modified file 'state/api/params/params_test.go'
749--- state/api/params/params_test.go 2013-06-11 00:58:34 +0000
750+++ state/api/params/params_test.go 2013-06-17 21:41:30 +0000
751@@ -8,6 +8,7 @@
752 . "launchpad.net/gocheck"
753 "launchpad.net/juju-core/charm"
754 "launchpad.net/juju-core/constraints"
755+ "launchpad.net/juju-core/instance"
756 "launchpad.net/juju-core/state"
757 "launchpad.net/juju-core/state/api/params"
758 "testing"
759@@ -63,7 +64,7 @@
760 Service: "Shazam",
761 Series: "precise",
762 CharmURL: "cs:~user/precise/wordpress-42",
763- Ports: []params.Port{
764+ Ports: []instance.Port{
765 {
766 Protocol: "http",
767 Number: 80},
768
769=== modified file 'state/megawatcher_internal_test.go'
770--- state/megawatcher_internal_test.go 2013-06-17 21:41:29 +0000
771+++ state/megawatcher_internal_test.go 2013-06-17 21:41:30 +0000
772@@ -130,7 +130,7 @@
773 Service: wordpress.Name(),
774 Series: m.Series(),
775 MachineId: m.Id(),
776- Ports: []params.Port{},
777+ Ports: []instance.Port{},
778 Status: params.StatusPending,
779 })
780 pairs := map[string]string{"name": fmt.Sprintf("bar %d", i)}
781@@ -176,7 +176,7 @@
782 Name: fmt.Sprintf("logging/%d", i),
783 Service: "logging",
784 Series: "series",
785- Ports: []params.Port{},
786+ Ports: []instance.Port{},
787 Status: params.StatusPending,
788 })
789 }
790@@ -340,7 +340,7 @@
791 PublicAddress: "public",
792 PrivateAddress: "private",
793 MachineId: "0",
794- Ports: []params.Port{{"tcp", 12345}},
795+ Ports: []instance.Port{{"tcp", 12345}},
796 Status: params.StatusError,
797 StatusInfo: "failure",
798 },
799@@ -372,7 +372,7 @@
800 Service: "wordpress",
801 Series: "series",
802 PublicAddress: "public",
803- Ports: []params.Port{{"udp", 17070}},
804+ Ports: []instance.Port{{"udp", 17070}},
805 Status: params.StatusError,
806 StatusInfo: "another failure",
807 },
808
809=== modified file 'state/state_test.go'
810--- state/state_test.go 2013-06-17 21:41:29 +0000
811+++ state/state_test.go 2013-06-17 21:41:30 +0000
812@@ -13,7 +13,6 @@
813 "launchpad.net/juju-core/errors"
814 "launchpad.net/juju-core/instance"
815 "launchpad.net/juju-core/state"
816- "launchpad.net/juju-core/state/api/params"
817 "launchpad.net/juju-core/testing"
818 "net/url"
819 "sort"
820@@ -903,15 +902,15 @@
821 }
822
823 var sortPortsTests = []struct {
824- have, want []params.Port
825+ have, want []instance.Port
826 }{
827- {nil, []params.Port{}},
828- {[]params.Port{{"b", 1}, {"a", 99}, {"a", 1}}, []params.Port{{"a", 1}, {"a", 99}, {"b", 1}}},
829+ {nil, []instance.Port{}},
830+ {[]instance.Port{{"b", 1}, {"a", 99}, {"a", 1}}, []instance.Port{{"a", 1}, {"a", 99}, {"b", 1}}},
831 }
832
833 func (*StateSuite) TestSortPorts(c *C) {
834 for _, t := range sortPortsTests {
835- p := make([]params.Port, len(t.have))
836+ p := make([]instance.Port, len(t.have))
837 copy(p, t.have)
838 state.SortPorts(p)
839 c.Check(p, DeepEquals, t.want)
840
841=== modified file 'state/unit.go'
842--- state/unit.go 2013-06-12 00:02:00 +0000
843+++ state/unit.go 2013-06-17 21:41:30 +0000
844@@ -10,6 +10,7 @@
845 "labix.org/v2/mgo/txn"
846 "launchpad.net/juju-core/charm"
847 "launchpad.net/juju-core/errors"
848+ "launchpad.net/juju-core/instance"
849 "launchpad.net/juju-core/state/api/params"
850 "launchpad.net/juju-core/state/presence"
851 "launchpad.net/juju-core/utils"
852@@ -67,7 +68,7 @@
853 MachineId string
854 Resolved ResolvedMode
855 Tools *Tools `bson:",omitempty"`
856- Ports []params.Port
857+ Ports []instance.Port
858 Life Life
859 TxnRevno int64 `bson:"txn-revno"`
860 PasswordHash string
861@@ -472,7 +473,7 @@
862
863 // OpenPort sets the policy of the port with protocol and number to be opened.
864 func (u *Unit) OpenPort(protocol string, number int) (err error) {
865- port := params.Port{Protocol: protocol, Number: number}
866+ port := instance.Port{Protocol: protocol, Number: number}
867 defer utils.ErrorContextf(&err, "cannot open port %v for unit %q", port, u)
868 ops := []txn.Op{{
869 C: u.st.units.Name,
870@@ -498,7 +499,7 @@
871
872 // ClosePort sets the policy of the port with protocol and number to be closed.
873 func (u *Unit) ClosePort(protocol string, number int) (err error) {
874- port := params.Port{Protocol: protocol, Number: number}
875+ port := instance.Port{Protocol: protocol, Number: number}
876 defer utils.ErrorContextf(&err, "cannot close port %v for unit %q", port, u)
877 ops := []txn.Op{{
878 C: u.st.units.Name,
879@@ -510,7 +511,7 @@
880 if err != nil {
881 return onAbort(err, errDead)
882 }
883- newPorts := make([]params.Port, 0, len(u.doc.Ports))
884+ newPorts := make([]instance.Port, 0, len(u.doc.Ports))
885 for _, p := range u.doc.Ports {
886 if p != port {
887 newPorts = append(newPorts, p)
888@@ -521,8 +522,8 @@
889 }
890
891 // OpenedPorts returns a slice containing the open ports of the unit.
892-func (u *Unit) OpenedPorts() []params.Port {
893- ports := append([]params.Port{}, u.doc.Ports...)
894+func (u *Unit) OpenedPorts() []instance.Port {
895+ ports := append([]instance.Port{}, u.doc.Ports...)
896 SortPorts(ports)
897 return ports
898 }
899@@ -1008,7 +1009,7 @@
900 return nil
901 }
902
903-type portSlice []params.Port
904+type portSlice []instance.Port
905
906 func (p portSlice) Len() int { return len(p) }
907 func (p portSlice) Swap(i, j int) { p[i], p[j] = p[j], p[i] }
908@@ -1023,6 +1024,6 @@
909
910 // SortPorts sorts the given ports, first by protocol,
911 // then by number.
912-func SortPorts(ports []params.Port) {
913+func SortPorts(ports []instance.Port) {
914 sort.Sort(portSlice(ports))
915 }
916
917=== modified file 'state/unit_test.go'
918--- state/unit_test.go 2013-06-11 00:58:34 +0000
919+++ state/unit_test.go 2013-06-17 21:41:30 +0000
920@@ -7,6 +7,7 @@
921 . "launchpad.net/gocheck"
922 "launchpad.net/juju-core/charm"
923 "launchpad.net/juju-core/errors"
924+ "launchpad.net/juju-core/instance"
925 "launchpad.net/juju-core/state"
926 "launchpad.net/juju-core/state/api/params"
927 "sort"
928@@ -635,14 +636,14 @@
929 err := s.unit.OpenPort("tcp", 80)
930 c.Assert(err, IsNil)
931 open := s.unit.OpenedPorts()
932- c.Assert(open, DeepEquals, []params.Port{
933+ c.Assert(open, DeepEquals, []instance.Port{
934 {"tcp", 80},
935 })
936
937 err = s.unit.OpenPort("udp", 53)
938 c.Assert(err, IsNil)
939 open = s.unit.OpenedPorts()
940- c.Assert(open, DeepEquals, []params.Port{
941+ c.Assert(open, DeepEquals, []instance.Port{
942 {"tcp", 80},
943 {"udp", 53},
944 })
945@@ -650,7 +651,7 @@
946 err = s.unit.OpenPort("tcp", 53)
947 c.Assert(err, IsNil)
948 open = s.unit.OpenedPorts()
949- c.Assert(open, DeepEquals, []params.Port{
950+ c.Assert(open, DeepEquals, []instance.Port{
951 {"tcp", 53},
952 {"tcp", 80},
953 {"udp", 53},
954@@ -659,7 +660,7 @@
955 err = s.unit.OpenPort("tcp", 443)
956 c.Assert(err, IsNil)
957 open = s.unit.OpenedPorts()
958- c.Assert(open, DeepEquals, []params.Port{
959+ c.Assert(open, DeepEquals, []instance.Port{
960 {"tcp", 53},
961 {"tcp", 80},
962 {"tcp", 443},
963@@ -669,7 +670,7 @@
964 err = s.unit.ClosePort("tcp", 80)
965 c.Assert(err, IsNil)
966 open = s.unit.OpenedPorts()
967- c.Assert(open, DeepEquals, []params.Port{
968+ c.Assert(open, DeepEquals, []instance.Port{
969 {"tcp", 53},
970 {"tcp", 443},
971 {"udp", 53},
972@@ -678,7 +679,7 @@
973 err = s.unit.ClosePort("tcp", 80)
974 c.Assert(err, IsNil)
975 open = s.unit.OpenedPorts()
976- c.Assert(open, DeepEquals, []params.Port{
977+ c.Assert(open, DeepEquals, []instance.Port{
978 {"tcp", 53},
979 {"tcp", 443},
980 {"udp", 53},
981
982=== modified file 'worker/firewaller/firewaller.go'
983--- worker/firewaller/firewaller.go 2013-06-17 21:41:29 +0000
984+++ worker/firewaller/firewaller.go 2013-06-17 21:41:30 +0000
985@@ -11,7 +11,6 @@
986 "launchpad.net/juju-core/instance"
987 "launchpad.net/juju-core/log"
988 "launchpad.net/juju-core/state"
989- "launchpad.net/juju-core/state/api/params"
990 "launchpad.net/juju-core/state/watcher"
991 "launchpad.net/juju-core/worker"
992 "launchpad.net/tomb"
993@@ -32,7 +31,7 @@
994 serviceds map[string]*serviceData
995 exposedChange chan *exposedChange
996 globalMode bool
997- globalPortRef map[params.Port]int
998+ globalPortRef map[instance.Port]int
999 }
1000
1001 // NewFirewaller returns a new Firewaller.
1002@@ -67,7 +66,7 @@
1003 }
1004 if fw.environ.Config().FirewallMode() == config.FwGlobal {
1005 fw.globalMode = true
1006- fw.globalPortRef = make(map[params.Port]int)
1007+ fw.globalPortRef = make(map[instance.Port]int)
1008 }
1009 for {
1010 select {
1011@@ -136,7 +135,7 @@
1012 fw: fw,
1013 id: id,
1014 unitds: make(map[string]*unitData),
1015- ports: make([]params.Port, 0),
1016+ ports: make([]instance.Port, 0),
1017 }
1018 m, err := machined.machine()
1019 if errors.IsNotFoundError(err) {
1020@@ -195,7 +194,7 @@
1021 unitd.serviced = fw.serviceds[serviceName]
1022 unitd.serviced.unitds[unitName] = unitd
1023
1024- ports := make([]params.Port, len(unitd.ports))
1025+ ports := make([]instance.Port, len(unitd.ports))
1026 copy(ports, unitd.ports)
1027
1028 go unitd.watchLoop(ports)
1029@@ -224,7 +223,7 @@
1030 if err != nil {
1031 return err
1032 }
1033- collector := make(map[params.Port]bool)
1034+ collector := make(map[instance.Port]bool)
1035 for _, unitd := range fw.unitds {
1036 if unitd.serviced.exposed {
1037 for _, port := range unitd.ports {
1038@@ -232,7 +231,7 @@
1039 }
1040 }
1041 }
1042- wantedPorts := []params.Port{}
1043+ wantedPorts := []instance.Port{}
1044 for port := range collector {
1045 wantedPorts = append(wantedPorts, port)
1046 }
1047@@ -365,7 +364,7 @@
1048 // flushMachine opens and closes ports for the passed machine.
1049 func (fw *Firewaller) flushMachine(machined *machineData) error {
1050 // Gather ports to open and close.
1051- ports := map[params.Port]bool{}
1052+ ports := map[instance.Port]bool{}
1053 for _, unitd := range machined.unitds {
1054 if unitd.serviced.exposed {
1055 for _, port := range unitd.ports {
1056@@ -373,7 +372,7 @@
1057 }
1058 }
1059 }
1060- want := []params.Port{}
1061+ want := []instance.Port{}
1062 for port := range ports {
1063 want = append(want, port)
1064 }
1065@@ -389,9 +388,9 @@
1066 // flushGlobalPorts opens and closes global ports in the environment.
1067 // It keeps a reference count for ports so that only 0-to-1 and 1-to-0 events
1068 // modify the environment.
1069-func (fw *Firewaller) flushGlobalPorts(rawOpen, rawClose []params.Port) error {
1070+func (fw *Firewaller) flushGlobalPorts(rawOpen, rawClose []instance.Port) error {
1071 // Filter which ports are really to open or close.
1072- var toOpen, toClose []params.Port
1073+ var toOpen, toClose []instance.Port
1074 for _, port := range rawOpen {
1075 if fw.globalPortRef[port] == 0 {
1076 toOpen = append(toOpen, port)
1077@@ -426,7 +425,7 @@
1078 }
1079
1080 // flushGlobalPorts opens and closes ports global on the machine.
1081-func (fw *Firewaller) flushInstancePorts(machined *machineData, toOpen, toClose []params.Port) error {
1082+func (fw *Firewaller) flushInstancePorts(machined *machineData, toOpen, toClose []instance.Port) error {
1083 // If there's nothing to do, do nothing.
1084 // This is important because when a machine is first created,
1085 // it will have no instance id but also no open ports -
1086@@ -583,7 +582,7 @@
1087 fw *Firewaller
1088 id string
1089 unitds map[string]*unitData
1090- ports []params.Port
1091+ ports []instance.Port
1092 }
1093
1094 func (md *machineData) machine() (*state.Machine, error) {
1095@@ -624,7 +623,7 @@
1096 // portsChange contains the changed ports for one specific unit.
1097 type portsChange struct {
1098 unitd *unitData
1099- ports []params.Port
1100+ ports []instance.Port
1101 }
1102
1103 // unitData holds unit details and watches port changes.
1104@@ -634,11 +633,11 @@
1105 unit *state.Unit
1106 serviced *serviceData
1107 machined *machineData
1108- ports []params.Port
1109+ ports []instance.Port
1110 }
1111
1112 // watchLoop watches the unit for port changes.
1113-func (ud *unitData) watchLoop(latestPorts []params.Port) {
1114+func (ud *unitData) watchLoop(latestPorts []instance.Port) {
1115 defer ud.tomb.Done()
1116 w := ud.unit.Watch()
1117 defer watcher.Stop(w, &ud.tomb)
1118@@ -673,7 +672,7 @@
1119
1120 // samePorts returns whether old and new contain the same set of ports.
1121 // Both old and new must be sorted.
1122-func samePorts(old, new []params.Port) bool {
1123+func samePorts(old, new []instance.Port) bool {
1124 if len(old) != len(new) {
1125 return false
1126 }
1127@@ -747,7 +746,7 @@
1128 }
1129
1130 // diff returns all the ports that exist in A but not B.
1131-func diff(A, B []params.Port) (missing []params.Port) {
1132+func diff(A, B []instance.Port) (missing []instance.Port) {
1133 next:
1134 for _, a := range A {
1135 for _, b := range B {
1136
1137=== modified file 'worker/firewaller/firewaller_test.go'
1138--- worker/firewaller/firewaller_test.go 2013-06-14 01:23:48 +0000
1139+++ worker/firewaller/firewaller_test.go 2013-06-17 21:41:30 +0000
1140@@ -10,7 +10,6 @@
1141 "launchpad.net/juju-core/instance"
1142 "launchpad.net/juju-core/juju/testing"
1143 "launchpad.net/juju-core/state"
1144- "launchpad.net/juju-core/state/api/params"
1145 coretesting "launchpad.net/juju-core/testing"
1146 "launchpad.net/juju-core/worker"
1147 "launchpad.net/juju-core/worker/firewaller"
1148@@ -33,7 +32,7 @@
1149
1150 // assertPorts retrieves the open ports of the instance and compares them
1151 // to the expected.
1152-func (s *FirewallerSuite) assertPorts(c *C, inst instance.Instance, machineId string, expected []params.Port) {
1153+func (s *FirewallerSuite) assertPorts(c *C, inst instance.Instance, machineId string, expected []instance.Port) {
1154 s.State.StartSync()
1155 start := time.Now()
1156 for {
1157@@ -59,7 +58,7 @@
1158
1159 // assertEnvironPorts retrieves the open ports of environment and compares them
1160 // to the expected.
1161-func (s *FirewallerSuite) assertEnvironPorts(c *C, expected []params.Port) {
1162+func (s *FirewallerSuite) assertEnvironPorts(c *C, expected []instance.Port) {
1163 s.State.StartSync()
1164 start := time.Now()
1165 for {
1166@@ -179,12 +178,12 @@
1167 err = u.OpenPort("tcp", 8080)
1168 c.Assert(err, IsNil)
1169
1170- s.assertPorts(c, inst, m.Id(), []params.Port{{"tcp", 80}, {"tcp", 8080}})
1171+ s.assertPorts(c, inst, m.Id(), []instance.Port{{"tcp", 80}, {"tcp", 8080}})
1172
1173 err = u.ClosePort("tcp", 80)
1174 c.Assert(err, IsNil)
1175
1176- s.assertPorts(c, inst, m.Id(), []params.Port{{"tcp", 8080}})
1177+ s.assertPorts(c, inst, m.Id(), []instance.Port{{"tcp", 8080}})
1178 }
1179
1180 func (s *FirewallerSuite) TestMultipleExposedServices(c *C) {
1181@@ -213,15 +212,15 @@
1182 err = u2.OpenPort("tcp", 3306)
1183 c.Assert(err, IsNil)
1184
1185- s.assertPorts(c, inst1, m1.Id(), []params.Port{{"tcp", 80}, {"tcp", 8080}})
1186- s.assertPorts(c, inst2, m2.Id(), []params.Port{{"tcp", 3306}})
1187+ s.assertPorts(c, inst1, m1.Id(), []instance.Port{{"tcp", 80}, {"tcp", 8080}})
1188+ s.assertPorts(c, inst2, m2.Id(), []instance.Port{{"tcp", 3306}})
1189
1190 err = u1.ClosePort("tcp", 80)
1191 c.Assert(err, IsNil)
1192 err = u2.ClosePort("tcp", 3306)
1193 c.Assert(err, IsNil)
1194
1195- s.assertPorts(c, inst1, m1.Id(), []params.Port{{"tcp", 8080}})
1196+ s.assertPorts(c, inst1, m1.Id(), []instance.Port{{"tcp", 8080}})
1197 s.assertPorts(c, inst2, m2.Id(), nil)
1198 }
1199
1200@@ -242,12 +241,12 @@
1201 inst2 := s.startInstance(c, m2)
1202 err = u2.OpenPort("tcp", 80)
1203 c.Assert(err, IsNil)
1204- s.assertPorts(c, inst2, m2.Id(), []params.Port{{"tcp", 80}})
1205+ s.assertPorts(c, inst2, m2.Id(), []instance.Port{{"tcp", 80}})
1206
1207 inst1 := s.startInstance(c, m1)
1208 err = u1.OpenPort("tcp", 8080)
1209 c.Assert(err, IsNil)
1210- s.assertPorts(c, inst1, m1.Id(), []params.Port{{"tcp", 8080}})
1211+ s.assertPorts(c, inst1, m1.Id(), []instance.Port{{"tcp", 8080}})
1212 }
1213
1214 func (s *FirewallerSuite) TestMultipleUnits(c *C) {
1215@@ -269,8 +268,8 @@
1216 err = u2.OpenPort("tcp", 80)
1217 c.Assert(err, IsNil)
1218
1219- s.assertPorts(c, inst1, m1.Id(), []params.Port{{"tcp", 80}})
1220- s.assertPorts(c, inst2, m2.Id(), []params.Port{{"tcp", 80}})
1221+ s.assertPorts(c, inst1, m1.Id(), []instance.Port{{"tcp", 80}})
1222+ s.assertPorts(c, inst2, m2.Id(), []instance.Port{{"tcp", 80}})
1223
1224 err = u1.ClosePort("tcp", 80)
1225 c.Assert(err, IsNil)
1226@@ -301,7 +300,7 @@
1227 fw := firewaller.NewFirewaller(s.State)
1228 defer func() { c.Assert(fw.Stop(), IsNil) }()
1229
1230- s.assertPorts(c, inst, m.Id(), []params.Port{{"tcp", 80}, {"tcp", 8080}})
1231+ s.assertPorts(c, inst, m.Id(), []instance.Port{{"tcp", 80}, {"tcp", 8080}})
1232
1233 err = svc.SetExposed()
1234 c.Assert(err, IsNil)
1235@@ -331,7 +330,7 @@
1236 err = u.OpenPort("tcp", 80)
1237 c.Assert(err, IsNil)
1238
1239- s.assertPorts(c, inst, m.Id(), []params.Port{{"tcp", 80}})
1240+ s.assertPorts(c, inst, m.Id(), []instance.Port{{"tcp", 80}})
1241 }
1242
1243 func (s *FirewallerSuite) TestStartWithUnexposedService(c *C) {
1244@@ -357,7 +356,7 @@
1245 // Expose service.
1246 err = svc.SetExposed()
1247 c.Assert(err, IsNil)
1248- s.assertPorts(c, inst, m.Id(), []params.Port{{"tcp", 80}})
1249+ s.assertPorts(c, inst, m.Id(), []instance.Port{{"tcp", 80}})
1250 }
1251
1252 func (s *FirewallerSuite) TestSetClearExposedService(c *C) {
1253@@ -381,7 +380,7 @@
1254 err = svc.SetExposed()
1255 c.Assert(err, IsNil)
1256
1257- s.assertPorts(c, inst, m.Id(), []params.Port{{"tcp", 80}, {"tcp", 8080}})
1258+ s.assertPorts(c, inst, m.Id(), []instance.Port{{"tcp", 80}, {"tcp", 8080}})
1259
1260 // ClearExposed closes the ports again.
1261 err = svc.ClearExposed()
1262@@ -409,8 +408,8 @@
1263 err = u2.OpenPort("tcp", 80)
1264 c.Assert(err, IsNil)
1265
1266- s.assertPorts(c, inst1, m1.Id(), []params.Port{{"tcp", 80}})
1267- s.assertPorts(c, inst2, m2.Id(), []params.Port{{"tcp", 80}})
1268+ s.assertPorts(c, inst1, m1.Id(), []instance.Port{{"tcp", 80}})
1269+ s.assertPorts(c, inst2, m2.Id(), []instance.Port{{"tcp", 80}})
1270
1271 // Remove unit.
1272 err = u1.EnsureDead()
1273@@ -419,7 +418,7 @@
1274 c.Assert(err, IsNil)
1275
1276 s.assertPorts(c, inst1, m1.Id(), nil)
1277- s.assertPorts(c, inst2, m2.Id(), []params.Port{{"tcp", 80}})
1278+ s.assertPorts(c, inst2, m2.Id(), []instance.Port{{"tcp", 80}})
1279 }
1280
1281 func (s *FirewallerSuite) TestRemoveService(c *C) {
1282@@ -436,7 +435,7 @@
1283 err = u.OpenPort("tcp", 80)
1284 c.Assert(err, IsNil)
1285
1286- s.assertPorts(c, inst, m.Id(), []params.Port{{"tcp", 80}})
1287+ s.assertPorts(c, inst, m.Id(), []instance.Port{{"tcp", 80}})
1288
1289 // Remove service.
1290 err = u.EnsureDead()
1291@@ -472,8 +471,8 @@
1292 err = u2.OpenPort("tcp", 3306)
1293 c.Assert(err, IsNil)
1294
1295- s.assertPorts(c, inst1, m1.Id(), []params.Port{{"tcp", 80}})
1296- s.assertPorts(c, inst2, m2.Id(), []params.Port{{"tcp", 3306}})
1297+ s.assertPorts(c, inst1, m1.Id(), []instance.Port{{"tcp", 80}})
1298+ s.assertPorts(c, inst2, m2.Id(), []instance.Port{{"tcp", 3306}})
1299
1300 // Remove services.
1301 err = u2.EnsureDead()
1302@@ -508,7 +507,7 @@
1303 err = u.OpenPort("tcp", 80)
1304 c.Assert(err, IsNil)
1305
1306- s.assertPorts(c, inst, m.Id(), []params.Port{{"tcp", 80}})
1307+ s.assertPorts(c, inst, m.Id(), []instance.Port{{"tcp", 80}})
1308
1309 // Remove unit and service, also tested without. Has no effect.
1310 err = u.EnsureDead()
1311@@ -541,7 +540,7 @@
1312 err = u.OpenPort("tcp", 80)
1313 c.Assert(err, IsNil)
1314
1315- s.assertPorts(c, inst, m.Id(), []params.Port{{"tcp", 80}})
1316+ s.assertPorts(c, inst, m.Id(), []instance.Port{{"tcp", 80}})
1317
1318 // Remove unit.
1319 err = u.EnsureDead()
1320@@ -591,17 +590,17 @@
1321 err = u2.OpenPort("tcp", 80)
1322 c.Assert(err, IsNil)
1323
1324- s.assertEnvironPorts(c, []params.Port{{"tcp", 80}, {"tcp", 8080}})
1325+ s.assertEnvironPorts(c, []instance.Port{{"tcp", 80}, {"tcp", 8080}})
1326
1327 // Closing a port opened by a different unit won't touch the environment.
1328 err = u1.ClosePort("tcp", 80)
1329 c.Assert(err, IsNil)
1330- s.assertEnvironPorts(c, []params.Port{{"tcp", 80}, {"tcp", 8080}})
1331+ s.assertEnvironPorts(c, []instance.Port{{"tcp", 80}, {"tcp", 8080}})
1332
1333 // Closing a port used just once changes the environment.
1334 err = u1.ClosePort("tcp", 8080)
1335 c.Assert(err, IsNil)
1336- s.assertEnvironPorts(c, []params.Port{{"tcp", 80}})
1337+ s.assertEnvironPorts(c, []instance.Port{{"tcp", 80}})
1338
1339 // Closing the last port also modifies the environment.
1340 err = u2.ClosePort("tcp", 80)
1341@@ -636,7 +635,7 @@
1342 // Expose service.
1343 err = svc.SetExposed()
1344 c.Assert(err, IsNil)
1345- s.assertEnvironPorts(c, []params.Port{{"tcp", 80}})
1346+ s.assertEnvironPorts(c, []instance.Port{{"tcp", 80}})
1347 }
1348
1349 func (s *FirewallerSuite) TestGlobalModeRestart(c *C) {
1350@@ -659,7 +658,7 @@
1351 err = u.OpenPort("tcp", 8080)
1352 c.Assert(err, IsNil)
1353
1354- s.assertEnvironPorts(c, []params.Port{{"tcp", 80}, {"tcp", 8080}})
1355+ s.assertEnvironPorts(c, []instance.Port{{"tcp", 80}, {"tcp", 8080}})
1356
1357 // Stop firewall and close one and open a different port.
1358 err = fw.Stop()
1359@@ -674,7 +673,7 @@
1360 fw = firewaller.NewFirewaller(s.State)
1361 defer func() { c.Assert(fw.Stop(), IsNil) }()
1362
1363- s.assertEnvironPorts(c, []params.Port{{"tcp", 80}, {"tcp", 8888}})
1364+ s.assertEnvironPorts(c, []instance.Port{{"tcp", 80}, {"tcp", 8888}})
1365 }
1366
1367 func (s *FirewallerSuite) TestGlobalModeRestartUnexposedService(c *C) {
1368@@ -697,7 +696,7 @@
1369 err = u.OpenPort("tcp", 8080)
1370 c.Assert(err, IsNil)
1371
1372- s.assertEnvironPorts(c, []params.Port{{"tcp", 80}, {"tcp", 8080}})
1373+ s.assertEnvironPorts(c, []instance.Port{{"tcp", 80}, {"tcp", 8080}})
1374
1375 // Stop firewall and clear exposed flag on service.
1376 err = fw.Stop()
1377@@ -733,7 +732,7 @@
1378 err = u1.OpenPort("tcp", 8080)
1379 c.Assert(err, IsNil)
1380
1381- s.assertEnvironPorts(c, []params.Port{{"tcp", 80}, {"tcp", 8080}})
1382+ s.assertEnvironPorts(c, []instance.Port{{"tcp", 80}, {"tcp", 8080}})
1383
1384 // Stop firewall and add another service using the port.
1385 err = fw.Stop()
1386@@ -753,17 +752,17 @@
1387 fw = firewaller.NewFirewaller(s.State)
1388 defer func() { c.Assert(fw.Stop(), IsNil) }()
1389
1390- s.assertEnvironPorts(c, []params.Port{{"tcp", 80}, {"tcp", 8080}})
1391+ s.assertEnvironPorts(c, []instance.Port{{"tcp", 80}, {"tcp", 8080}})
1392
1393 // Closing a port opened by a different unit won't touch the environment.
1394 err = u1.ClosePort("tcp", 80)
1395 c.Assert(err, IsNil)
1396- s.assertEnvironPorts(c, []params.Port{{"tcp", 80}, {"tcp", 8080}})
1397+ s.assertEnvironPorts(c, []instance.Port{{"tcp", 80}, {"tcp", 8080}})
1398
1399 // Closing a port used just once changes the environment.
1400 err = u1.ClosePort("tcp", 8080)
1401 c.Assert(err, IsNil)
1402- s.assertEnvironPorts(c, []params.Port{{"tcp", 80}})
1403+ s.assertEnvironPorts(c, []instance.Port{{"tcp", 80}})
1404
1405 // Closing the last port also modifies the environment.
1406 err = u2.ClosePort("tcp", 80)

Subscribers

People subscribed via source and target branches

to status/vote changes: