github.com/niedbalski/juju@v0.0.0-20190215020005-8ff100488e47/api/uniter/lxdprofile.go (about)

     1  // Copyright 2018 Canonical Ltd.
     2  // Licensed under the AGPLv3, see LICENCE file for details.
     3  
     4  package uniter
     5  
     6  import (
     7  	"github.com/juju/errors"
     8  	names "gopkg.in/juju/names.v2"
     9  
    10  	"github.com/juju/juju/api/base"
    11  	apiwatcher "github.com/juju/juju/api/watcher"
    12  	"github.com/juju/juju/apiserver/params"
    13  	"github.com/juju/juju/core/watcher"
    14  )
    15  
    16  // LXDProfileAPI provides common agent-side API functions
    17  type LXDProfileAPI struct {
    18  	facade base.FacadeCaller
    19  	tag    names.Tag
    20  }
    21  
    22  // NewLXDProfileAPI creates a LXDProfileAPI on the specified facade,
    23  // and uses this name when calling through the caller.
    24  func NewLXDProfileAPI(facade base.FacadeCaller, tag names.Tag) *LXDProfileAPI {
    25  	return &LXDProfileAPI{facade: facade, tag: tag}
    26  }
    27  
    28  // WatchLXDProfileUpgradeNotifications returns a StringsWatcher for observing the state of
    29  // a LXD profile upgrade
    30  func (u *LXDProfileAPI) WatchLXDProfileUpgradeNotifications(applicationName string) (watcher.StringsWatcher, error) {
    31  	var results params.StringsWatchResults
    32  	args := params.LXDProfileUpgrade{
    33  		Entities:        []params.Entity{{Tag: u.tag.String()}},
    34  		ApplicationName: applicationName,
    35  	}
    36  	err := u.facade.FacadeCall("WatchLXDProfileUpgradeNotifications", args, &results)
    37  	if err != nil {
    38  		return nil, err
    39  	}
    40  	if len(results.Results) != 1 {
    41  		return nil, errors.Errorf("expected 1 result, got %d", len(results.Results))
    42  	}
    43  	result := results.Results[0]
    44  	if result.Error != nil {
    45  		return nil, result.Error
    46  	}
    47  	w := apiwatcher.NewStringsWatcher(u.facade.RawAPICaller(), result)
    48  	return w, nil
    49  }
    50  
    51  // RemoveUpgradeCharmProfileData removes the lxd profile status instance data
    52  // for a machine
    53  func (u *LXDProfileAPI) RemoveUpgradeCharmProfileData() error {
    54  	var results params.ErrorResults
    55  	args := params.Entities{
    56  		Entities: []params.Entity{{Tag: u.tag.String()}},
    57  	}
    58  
    59  	err := u.facade.FacadeCall("RemoveUpgradeCharmProfileData", args, &results)
    60  	if err != nil {
    61  		return err
    62  	}
    63  	return results.OneError()
    64  }