github.com/axw/juju@v0.0.0-20161005053422-4bd6544d08d4/tools/lxdclient/client_serverconfig.go (about) 1 // Copyright 2015 Canonical Ltd. 2 // Licensed under the AGPLv3, see LICENCE file for details. 3 4 // +build go1.3 5 6 package lxdclient 7 8 import ( 9 "github.com/juju/errors" 10 "github.com/lxc/lxd" 11 "github.com/lxc/lxd/shared" 12 ) 13 14 type rawServerConfigClient interface { 15 SetServerConfig(key string, value string) (*lxd.Response, error) 16 17 WaitForSuccess(waitURL string) error 18 ServerStatus() (*shared.ServerState, error) 19 } 20 21 type serverConfigClient struct { 22 raw rawServerConfigClient 23 } 24 25 // SetConfig sets the given value in the server's config. 26 func (c serverConfigClient) SetConfig(key, value string) error { 27 resp, err := c.raw.SetServerConfig(key, value) 28 if err != nil { 29 return errors.Trace(err) 30 } 31 32 if resp.Operation != "" { 33 if err := c.raw.WaitForSuccess(resp.Operation); err != nil { 34 // TODO(ericsnow) Handle different failures (from the async 35 // operation) differently? 36 return errors.Trace(err) 37 } 38 } 39 40 return nil 41 } 42 43 func (c serverConfigClient) ServerStatus() (*shared.ServerState, error) { 44 return c.raw.ServerStatus() 45 }