Ubuntu Pastebin

Paste from Mich at Fri, 19 Aug 2016 09:22:24 +0000

Download as text
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
// SetAPIHostPorts sets the addresses of the API server instances.              
// Each server is represented by one element in the top level slice.            
func (st *State) SetAPIHostPorts(netHostsPorts [][]network.HostPort) error {    
        controllers, closer := st.getCollection(controllersC)                   
        defer closer()                                                          
        doc := apiHostPortsDoc{                                                 
                APIHostPorts: fromNetworkHostsPorts(netHostsPorts),             
        }                                                                       
        buildTxn := func(attempt int) ([]txn.Op, error) {                       
                var existingDoc apiHostPortsDoc                                 
                err := controllers.Find(bson.D{{"_id", apiHostPortsKey}}).One(&existingDoc)
                if err != nil {                                                 
                        return nil, err                                         
                }                                                               
                op := txn.Op{                                                   
                        C:  controllersC,                                       
                        Id: apiHostPortsKey,                                    
                        Assert: bson.D{{                                        
                                "txn-revno", existingDoc.TxnRevno,              
                        }},                                                     
                }                                                               
                hostPorts := networkHostsPorts(existingDoc.APIHostPorts)        
                if !hostsPortsEqual(netHostsPorts, hostPorts) {                 
                        op.Update = bson.D{{                                    
                                "$set", bson.D{{"apihostports", doc.APIHostPorts}},
                        }}                                                      
                }                                                               
                return []txn.Op{op}, nil                                        
        }                                                                       
        if err := st.run(buildTxn); err != nil {                                
                return errors.Annotate(err, "cannot set API addresses")         
        }                                                                       
        logger.Debugf("setting API hostPorts: %v", netHostsPorts)               
        return nil  
Download as text