1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
|
// Copyright 2013 Canonical Ltd.
// Licensed under the AGPLv3, see LICENCE file for details.
package environs
import (
"fmt"
"io"
"strings"
"launchpad.net/juju-core/errors"
"launchpad.net/juju-core/log"
"launchpad.net/juju-core/utils"
)
// EmptyStorage holds a StorageReader object that contains no files and
// offers no URLs.
var EmptyStorage StorageReader = emptyStorage{}
type emptyStorage struct{}
// File named `verificationFilename` in the storage will contain
// `verificationContent`. This is also used to differentiate between
// Python Juju and juju-core environments, so change the content with
// care (and update CheckEnvironment below when you do that).
const verificationFilename string = "bootstrap-verify"
const verificationContent = "juju-core storage writing verified: ok\n"
var VerifyStorageError error = fmt.Errorf(
"provider storage is not writable")
func (s emptyStorage) Get(name string) (io.ReadCloser, error) {
return nil, errors.NotFoundf("file %q", name)
}
func (s emptyStorage) URL(name string) (string, error) {
return "", fmt.Errorf("file %q not found", name)
}
// ConsistencyStrategy is specified in the StorageReader interface.
func (s emptyStorage) ConsistencyStrategy() utils.AttemptStrategy {
return utils.AttemptStrategy{}
}
func (s emptyStorage) List(prefix string) ([]string, error) {
return nil, nil
}
func VerifyStorage(storage Storage) error {
reader := strings.NewReader(verificationContent)
err := storage.Put(verificationFilename, reader,
int64(len(verificationContent)))
if err != nil {
log.Debugf(
"environs: failed to write bootstrap-verify file: %v",
err)
return VerifyStorageError
}
return nil
}
|