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

     1  // Copyright 2018 Canonical Ltd.
     2  // Licensed under the AGPLv3, see LICENCE file for details.
     3  
     4  // Package bundle provides access to the bundle api facade.
     5  // This facade contains api calls that are specific to bundles.
     6  
     7  package bundle
     8  
     9  import (
    10  	"github.com/juju/errors"
    11  	"github.com/juju/loggo"
    12  
    13  	"github.com/juju/juju/api/base"
    14  	"github.com/juju/juju/apiserver/params"
    15  )
    16  
    17  var logger = loggo.GetLogger("juju.api.bundle")
    18  
    19  // Client allows access to the bundle API end point.
    20  type Client struct {
    21  	base.ClientFacade
    22  	facade base.FacadeCaller
    23  }
    24  
    25  // NewClient creates a new client for accessing the bundle api.
    26  func NewClient(st base.APICallCloser) *Client {
    27  	frontend, backend := base.NewClientFacade(st, "Bundle")
    28  	return &Client{
    29  		ClientFacade: frontend,
    30  		facade:       backend}
    31  }
    32  
    33  // ExportBundle exports the current model configuration.
    34  func (c *Client) ExportBundle() (string, error) {
    35  	var result params.StringResult
    36  	if bestVer := c.BestAPIVersion(); bestVer < 2 {
    37  		return "", errors.Errorf("this controller version does not support bundle export feature.")
    38  	}
    39  
    40  	if err := c.facade.FacadeCall("ExportBundle", nil, &result); err != nil {
    41  		return "", errors.Trace(err)
    42  	}
    43  
    44  	if result.Error != nil {
    45  		return "", errors.Trace(result.Error)
    46  	}
    47  
    48  	return result.Result, nil
    49  }