~juju-qa/ubuntu/xenial/juju/xenial-2.0-beta3

« back to all changes in this revision

Viewing changes to src/github.com/juju/juju/resource/resourceadapters/deploy.go

  • Committer: Martin Packman
  • Date: 2016-03-30 19:31:08 UTC
  • mfrom: (1.1.41)
  • Revision ID: martin.packman@canonical.com-20160330193108-h9iz3ak334uk0z5r
Merge new upstream source 2.0~beta3

Show diffs side-by-side

added added

removed removed

Lines of Context:
4
4
package resourceadapters
5
5
 
6
6
import (
 
7
        "strconv"
 
8
 
7
9
        "github.com/juju/errors"
 
10
        "gopkg.in/juju/charm.v6-unstable"
8
11
        charmresource "gopkg.in/juju/charm.v6-unstable/resource"
 
12
        "gopkg.in/macaroon.v1"
9
13
 
10
14
        "github.com/juju/juju/api"
 
15
        "github.com/juju/juju/resource/api/client"
11
16
        "github.com/juju/juju/resource/cmd"
12
17
)
13
18
 
14
19
// DeployResources uploads the bytes for the given files to the server and
15
20
// creates pending resource metadata for the all resource mentioned in the
16
21
// metadata. It returns a map of resource name to pending resource IDs.
17
 
func DeployResources(serviceID string, files map[string]string, resources map[string]charmresource.Meta, conn api.Connection) (ids map[string]string, err error) {
 
22
func DeployResources(serviceID string, cURL *charm.URL, csMac *macaroon.Macaroon, filesAndRevisions map[string]string, resources map[string]charmresource.Meta, conn api.Connection) (ids map[string]string, err error) {
18
23
        client, err := newAPIClient(conn)
19
24
        if err != nil {
20
25
                return nil, errors.Trace(err)
21
26
        }
22
27
 
23
 
        ids, err = cmd.DeployResources(serviceID, files, resources, client)
 
28
        filenames := make(map[string]string)
 
29
        revisions := make(map[string]int)
 
30
        for name, val := range filesAndRevisions {
 
31
                rev, err := strconv.Atoi(val)
 
32
                if err != nil {
 
33
                        filenames[name] = val
 
34
                } else {
 
35
                        revisions[name] = rev
 
36
                }
 
37
        }
 
38
 
 
39
        ids, err = cmd.DeployResources(cmd.DeployResourcesArgs{
 
40
                ServiceID:          serviceID,
 
41
                CharmURL:           cURL,
 
42
                CharmStoreMacaroon: csMac,
 
43
                Filenames:          filenames,
 
44
                Revisions:          revisions,
 
45
                ResourcesMeta:      resources,
 
46
                Client:             &deployClient{client},
 
47
        })
24
48
        if err != nil {
25
49
                return nil, errors.Trace(err)
26
50
        }
27
51
        return ids, nil
28
52
}
 
53
 
 
54
type deployClient struct {
 
55
        *client.Client
 
56
}
 
57
 
 
58
// AddPendingResources adds pending metadata for store-based resources.
 
59
func (cl *deployClient) AddPendingResources(serviceID string, cURL *charm.URL, csMac *macaroon.Macaroon, resources []charmresource.Resource) ([]string, error) {
 
60
        return cl.Client.AddPendingResources(client.AddPendingResourcesArgs{
 
61
                ServiceID:          serviceID,
 
62
                CharmURL:           cURL,
 
63
                CharmStoreMacaroon: csMac,
 
64
                Resources:          resources,
 
65
        })
 
66
}