Left: | ||
Right: |
OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2014 Canonical Ltd. | |
2 // Licensed under the AGPLv3, see LICENCE file for details. | |
3 | |
4 package state | |
5 | |
6 import ( | |
7 "labix.org/v2/mgo" | |
8 "labix.org/v2/mgo/txn" | |
9 | |
10 "launchpad.net/juju-core/errors" | |
11 ) | |
12 | |
13 // serviceNetworksDoc represents the network restrictions for a service | |
dimitern
2014/03/21 14:21:56
Since we'll be using this for services, machines a
gz
2014/03/21 15:46:00
What exactly does "make it non-service-specific" e
gz
2014/03/21 16:31:05
Done.
| |
14 type serviceNetworksDoc struct { | |
15 NetworksToInclude *[]string | |
16 NetworksToExclude *[]string | |
17 } | |
18 | |
19 func newServiceNetworksDoc(includeNetworks, excludeNetworks []string) serviceNet worksDoc { | |
20 return serviceNetworksDoc{ | |
21 NetworksToInclude: &includeNetworks, | |
22 NetworksToExclude: &excludeNetworks, | |
23 } | |
24 } | |
25 | |
26 func createServiceNetworksOp(st *State, id string, includeNetworks, excludeNetwo rks []string) txn.Op { | |
27 return txn.Op{ | |
28 C: st.serviceNetworks.Name, | |
29 Id: id, | |
30 Assert: txn.DocMissing, | |
31 Insert: newServiceNetworksDoc(includeNetworks, excludeNetworks), | |
32 } | |
33 } | |
34 | |
35 // While networks are immutable, there is no setServiceNetworksOp function | |
dimitern
2014/03/21 14:21:56
No need to mention this for now - I'd just drop it
gz
2014/03/21 16:31:05
Keeping, just because I'll forget why otherwise, e
| |
36 | |
37 func removeServiceNetworksOp(st *State, id string) txn.Op { | |
38 return txn.Op{ | |
39 C: st.serviceNetworks.Name, | |
40 Id: id, | |
41 Remove: true, | |
42 } | |
43 } | |
44 | |
45 func readServiceNetworks(st *State, id string) (includeNetworks, excludeNetworks []string, err error) { | |
46 doc := serviceNetworksDoc{} | |
47 if err = st.serviceNetworks.FindId(id).One(&doc); err == mgo.ErrNotFound { | |
48 err = errors.NotFoundf("service networks") | |
49 } else if err == nil { | |
50 includeNetworks = *doc.NetworksToInclude | |
51 excludeNetworks = *doc.NetworksToExclude | |
52 } | |
53 return includeNetworks, excludeNetworks, err | |
54 } | |
OLD | NEW |