~themue/juju-core/037-empty-strings-in-charm-config

« back to all changes in this revision

Viewing changes to environs/imagemetadata/boilerplate.go

  • Committer: Frank Mueller
  • Date: 2013-08-02 12:04:49 UTC
  • mfrom: (1567.1.18 juju-core)
  • Revision ID: frank.mueller@canonical.com-20130802120449-bdmjta1ppsgafwov
cmd/set: merged trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
8
8
        "fmt"
9
9
        "io/ioutil"
10
10
        "launchpad.net/juju-core/environs/config"
 
11
        "os"
 
12
        "path/filepath"
11
13
        "text/template"
12
14
        "time"
13
15
)
15
17
const (
16
18
        defaultIndexFileName = "index.json"
17
19
        defaultImageFileName = "imagemetadata.json"
 
20
        streamsDir           = "streams/v1"
18
21
)
19
22
 
 
23
// Boilerplate generates some basic simplestreams metadata using the specified cloud and image details.
 
24
// If name is non-empty, it will be used as a prefix for the names of the generated index and image files.
20
25
func Boilerplate(name, series string, im *ImageMetadata, cloudSpec *CloudSpec) ([]string, error) {
 
26
        return MakeBoilerplate(name, series, im, cloudSpec, true)
 
27
}
 
28
 
 
29
// MakeBoilerplate exists so it can be called by tests. See Boilerplate above. It provides an option to retain
 
30
// the streams directories when writing the generated metadata files.
 
31
func MakeBoilerplate(name, series string, im *ImageMetadata, cloudSpec *CloudSpec, flattenPath bool) ([]string, error) {
21
32
        indexFileName := defaultIndexFileName
22
33
        imageFileName := defaultImageFileName
23
34
        if name != "" {
30
41
                Arch:          im.Arch,
31
42
                Region:        cloudSpec.Region,
32
43
                URL:           cloudSpec.Endpoint,
33
 
                Path:          "streams/v1",
 
44
                Path:          streamsDir,
34
45
                ImageFileName: imageFileName,
35
46
                Updated:       now.Format(time.RFC1123Z),
36
47
                VersionKey:    now.Format("20060102"),
42
53
                return nil, fmt.Errorf("invalid series %q", series)
43
54
        }
44
55
 
 
56
        if !flattenPath {
 
57
                streamsPath := config.JujuHomePath(streamsDir)
 
58
                if err = os.MkdirAll(streamsPath, 0755); err != nil {
 
59
                        return nil, err
 
60
                }
 
61
                indexFileName = filepath.Join(streamsDir, indexFileName)
 
62
                imageFileName = filepath.Join(streamsDir, imageFileName)
 
63
        }
45
64
        err = writeJsonFile(imparams, indexFileName, indexBoilerplate)
46
65
        if err != nil {
47
66
                return nil, err
84
103
{
85
104
 "index": {
86
105
   "com.ubuntu.cloud:custom": {
87
 
    "updated": "{{.Updated}}",
88
 
    "clouds": [
89
 
     {
90
 
       "region": "{{.Region}}",
91
 
       "endpoint": "{{.URL}}"
92
 
     }
93
 
    ],
94
 
    "cloudname": "custom",
95
 
    "datatype": "image-ids",
96
 
    "format": "products:1.0",
97
 
    "products": [
98
 
      "com.ubuntu.cloud:server:{{.Version}}:{{.Arch}}"
99
 
    ],
100
 
    "path": "{{.Path}}/{{.ImageFileName}}"
 
106
     "updated": "{{.Updated}}",
 
107
     "clouds": [
 
108
       {
 
109
         "region": "{{.Region}}",
 
110
         "endpoint": "{{.URL}}"
 
111
       }
 
112
     ],
 
113
     "cloudname": "custom",
 
114
     "datatype": "image-ids",
 
115
     "format": "products:1.0",
 
116
     "products": [
 
117
       "com.ubuntu.cloud:server:{{.Version}}:{{.Arch}}"
 
118
     ],
 
119
     "path": "{{.Path}}/{{.ImageFileName}}"
101
120
   }
102
 
  },
103
 
  "updated": "{{.Updated}}",
104
 
  "format": "index:1.0"
 
121
 },
 
122
 "updated": "{{.Updated}}",
 
123
 "format": "index:1.0"
105
124
}
106
125
`
107
126