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

« back to all changes in this revision

Viewing changes to src/github.com/juju/juju/state/backups/metadata.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:
13
13
        "time"
14
14
 
15
15
        "github.com/juju/errors"
 
16
        jujuversion "github.com/juju/juju/version"
16
17
        "github.com/juju/utils/filestorage"
17
 
 
18
 
        "github.com/juju/juju/version"
 
18
        "github.com/juju/version"
19
19
)
20
20
 
21
21
// checksumFormat identifies how to interpret the checksum for a backup
56
56
 
57
57
        // Started records when the backup was started.
58
58
        Started time.Time
 
59
 
59
60
        // Finished records when the backup was complete.
60
61
        Finished *time.Time
 
62
 
61
63
        // Origin identifies where the backup was created.
62
64
        Origin Origin
 
65
 
63
66
        // Notes is an optional user-supplied annotation.
64
67
        Notes string
 
68
 
 
69
        // TODO(wallyworld) - remove these ASAP
 
70
        // These are only used by the restore CLI when re-bootstrapping.
 
71
        // We will use a better solution but the way restore currently
 
72
        // works, we need them and they are no longer available via
 
73
        // bootstrap config. We will need to ifx how re-bootstrap deals
 
74
        // with these keys to address the issue.
 
75
 
 
76
        // CACert is the controller CA certificate.
 
77
        CACert string
 
78
 
 
79
        // CAPrivateKey is the controller CA private key.
 
80
        CAPrivateKey string
65
81
}
66
82
 
67
83
// NewMetadata returns a new Metadata for a state backup archive.  Only
71
87
                FileMetadata: filestorage.NewMetadata(),
72
88
                Started:      time.Now().UTC(),
73
89
                Origin: Origin{
74
 
                        Version: version.Current,
 
90
                        Version: jujuversion.Current,
75
91
                },
76
92
        }
77
93
}
92
108
        meta.Origin.Model = db.ModelTag().Id()
93
109
        meta.Origin.Machine = machine
94
110
        meta.Origin.Hostname = hostname
 
111
 
 
112
        si, err := db.StateServingInfo()
 
113
        if err != nil {
 
114
                return nil, errors.Annotate(err, "could not get server secrets")
 
115
        }
 
116
        cfg, err := db.ModelConfig()
 
117
        if err != nil {
 
118
                return nil, errors.Annotate(err, "could not get model config")
 
119
        }
 
120
        meta.CACert, _ = cfg.CACert()
 
121
        meta.CAPrivateKey = si.CAPrivateKey
95
122
        return meta, nil
96
123
}
97
124
 
134
161
        Machine     string
135
162
        Hostname    string
136
163
        Version     version.Number
 
164
 
 
165
        CACert       string
 
166
        CAPrivateKey string
137
167
}
138
168
 
139
169
// TODO(ericsnow) Move AsJSONBuffer to filestorage.Metadata.
147
177
                ChecksumFormat: m.ChecksumFormat(),
148
178
                Size:           m.Size(),
149
179
 
150
 
                Started:     m.Started,
151
 
                Notes:       m.Notes,
152
 
                Environment: m.Origin.Model,
153
 
                Machine:     m.Origin.Machine,
154
 
                Hostname:    m.Origin.Hostname,
155
 
                Version:     m.Origin.Version,
 
180
                Started:      m.Started,
 
181
                Notes:        m.Notes,
 
182
                Environment:  m.Origin.Model,
 
183
                Machine:      m.Origin.Machine,
 
184
                Hostname:     m.Origin.Hostname,
 
185
                Version:      m.Origin.Version,
 
186
                CACert:       m.CACert,
 
187
                CAPrivateKey: m.CAPrivateKey,
156
188
        }
157
189
 
158
190
        stored := m.Stored()
202
234
                Version:  flat.Version,
203
235
        }
204
236
 
 
237
        // TODO(wallyworld) - put these in a separate file.
 
238
        meta.CACert = flat.CACert
 
239
        meta.CAPrivateKey = flat.CAPrivateKey
 
240
 
205
241
        return meta, nil
206
242
}
207
243