1
// Copyright 2015 Canonical Ltd.
2
// Licensed under the AGPLv3, see LICENCE file for details.
9
"github.com/juju/errors"
13
type rawProfileClient interface {
14
ProfileCreate(name string) error
15
ListProfiles() ([]string, error)
16
SetProfileConfigItem(profile, key, value string) error
17
GetProfileConfig(profile string) (map[string]string, error)
18
ProfileDelete(profile string) error
19
ProfileDeviceAdd(profile, devname, devtype string, props []string) (*lxd.Response, error)
22
type profileClient struct {
26
// ProfileDelete deletes an existing profile. No check is made to
27
// verify the profile exists.
28
func (p profileClient) ProfileDelete(profile string) error {
29
if err := p.raw.ProfileDelete(profile); err != nil {
30
return errors.Trace(err)
35
// ProfileDeviceAdd adds a profile device, such as a disk or a nic, to
36
// the specified profile. No check is made to verify the profile
38
func (p profileClient) ProfileDeviceAdd(profile, devname, devtype string, props []string) (*lxd.Response, error) {
39
resp, err := p.raw.ProfileDeviceAdd(profile, devname, devtype, props)
41
return resp, errors.Trace(err)
46
// CreateProfile attempts to create a new lxc profile and set the given config.
47
func (p profileClient) CreateProfile(name string, config map[string]string) error {
48
if err := p.raw.ProfileCreate(name); err != nil {
49
//TODO(wwitzel3) use HasProfile to generate a more useful AlreadyExists error
50
return errors.Trace(err)
53
for k, v := range config {
54
if err := p.raw.SetProfileConfigItem(name, k, v); err != nil {
55
return errors.Trace(err)
61
// HasProfile returns true/false if the profile exists.
62
func (p profileClient) HasProfile(name string) (bool, error) {
63
profiles, err := p.raw.ListProfiles()
65
return false, errors.Trace(err)
67
for _, profile := range profiles {
75
// SetProfileConfigItem updates the given profile config key to the given value.
76
func (p profileClient) SetProfileConfigItem(profile, key, value string) error {
77
if err := p.raw.SetProfileConfigItem(profile, key, value); err != nil {
78
return errors.Trace(err)
83
// GetProfileConfig returns a map with all keys and values for the given
85
func (p profileClient) GetProfileConfig(profile string) (map[string]string, error) {
86
config, err := p.raw.GetProfileConfig(profile)
88
return nil, errors.Trace(err)