github.com/mattyw/juju@v0.0.0-20140610034352-732aecd63861/state/charm.go (about)

     1  // Copyright 2012, 2013 Canonical Ltd.
     2  // Licensed under the AGPLv3, see LICENCE file for details.
     3  
     4  package state
     5  
     6  import (
     7  	"net/url"
     8  
     9  	"github.com/juju/juju/charm"
    10  )
    11  
    12  // charmDoc represents the internal state of a charm in MongoDB.
    13  type charmDoc struct {
    14  	URL           *charm.URL `bson:"_id"`
    15  	Meta          *charm.Meta
    16  	Config        *charm.Config
    17  	Actions       *charm.Actions
    18  	BundleURL     *url.URL
    19  	BundleSha256  string
    20  	PendingUpload bool
    21  	Placeholder   bool
    22  }
    23  
    24  // Charm represents the state of a charm in the environment.
    25  type Charm struct {
    26  	st  *State
    27  	doc charmDoc
    28  }
    29  
    30  func newCharm(st *State, cdoc *charmDoc) (*Charm, error) {
    31  	return &Charm{st: st, doc: *cdoc}, nil
    32  }
    33  
    34  func (c *Charm) String() string {
    35  	return c.doc.URL.String()
    36  }
    37  
    38  // URL returns the URL that identifies the charm.
    39  func (c *Charm) URL() *charm.URL {
    40  	clone := *c.doc.URL
    41  	return &clone
    42  }
    43  
    44  // Revision returns the monotonically increasing charm
    45  // revision number.
    46  func (c *Charm) Revision() int {
    47  	return c.doc.URL.Revision
    48  }
    49  
    50  // Meta returns the metadata of the charm.
    51  func (c *Charm) Meta() *charm.Meta {
    52  	return c.doc.Meta
    53  }
    54  
    55  // Config returns the configuration of the charm.
    56  func (c *Charm) Config() *charm.Config {
    57  	return c.doc.Config
    58  }
    59  
    60  // Actions returns the actions definition of the charm.
    61  func (c *Charm) Actions() *charm.Actions {
    62  	return c.doc.Actions
    63  }
    64  
    65  // BundleURL returns the url to the charm bundle in
    66  // the provider storage.
    67  func (c *Charm) BundleURL() *url.URL {
    68  	return c.doc.BundleURL
    69  }
    70  
    71  // BundleSha256 returns the SHA256 digest of the charm bundle bytes.
    72  func (c *Charm) BundleSha256() string {
    73  	return c.doc.BundleSha256
    74  }
    75  
    76  // IsUploaded returns whether the charm has been uploaded to the
    77  // provider storage.
    78  func (c *Charm) IsUploaded() bool {
    79  	return !c.doc.PendingUpload
    80  }
    81  
    82  // IsPlaceholder returns whether the charm record is just a placeholder
    83  // rather than representing a deployed charm.
    84  func (c *Charm) IsPlaceholder() bool {
    85  	return c.doc.Placeholder
    86  }