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

Side by Side Diff: state/networks.go

Issue 77270046: state: Add networks doc for services
Patch Set: state: Add networks doc for services Created 11 years 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') | state/open.go » ('j') | state/open.go » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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 }
OLDNEW
« no previous file with comments | « [revision details] ('k') | state/open.go » ('j') | state/open.go » ('J')

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