~nskaggs/+junk/xenial-test

« back to all changes in this revision

Viewing changes to src/github.com/juju/juju/tools/lxdclient/client_serverconfig.go

  • Committer: Nicholas Skaggs
  • Date: 2016-10-24 20:56:05 UTC
  • Revision ID: nicholas.skaggs@canonical.com-20161024205605-z8lta0uvuhtxwzwl
Initi with beta15

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
}