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

« back to all changes in this revision

Viewing changes to src/github.com/juju/juju/cmd/juju/backups/restore.go

  • Committer: Nicholas Skaggs
  • Date: 2016-09-30 14:39:30 UTC
  • mfrom: (1.8.1)
  • Revision ID: nicholas.skaggs@canonical.com-20160930143930-vwwhrefh6ftckccy
import upstream

Show diffs side-by-side

added added

removed removed

Lines of Context:
48
48
// it is invoked with "juju restore-backup".
49
49
type restoreCommand struct {
50
50
        CommandBase
51
 
        constraints constraints.Value
52
 
        filename    string
53
 
        backupId    string
54
 
        bootstrap   bool
55
 
        buildAgent  bool
 
51
        constraints    constraints.Value
 
52
        constraintsStr string
 
53
        filename       string
 
54
        backupId       string
 
55
        bootstrap      bool
 
56
        buildAgent     bool
56
57
 
57
58
        newAPIClientFunc         func() (RestoreAPI, error)
58
59
        newEnvironFunc           func(environs.OpenParams) (environs.Environ, error)
59
 
        getRebootstrapParamsFunc func(string, *params.BackupsMetadataResult) (*restoreBootstrapParams, error)
 
60
        getRebootstrapParamsFunc func(*cmd.Context, string, *params.BackupsMetadataResult) (*restoreBootstrapParams, error)
60
61
        getArchiveFunc           func(string) (ArchiveReader, *params.BackupsMetadataResult, error)
61
62
        waitForAgentFunc         func(ctx *cmd.Context, c *modelcmd.ModelCommandBase, controllerName, hostedModelName string) error
62
63
}
105
106
// SetFlags handles known option flags.
106
107
func (c *restoreCommand) SetFlags(f *gnuflag.FlagSet) {
107
108
        c.CommandBase.SetFlags(f)
108
 
        f.Var(constraints.ConstraintsValue{Target: &c.constraints},
109
 
                "constraints", "set model constraints")
110
 
 
 
109
        f.StringVar(&c.constraintsStr, "constraints", "", "set model constraints")
111
110
        f.BoolVar(&c.bootstrap, "b", false, "Bootstrap a new state machine")
112
111
        f.StringVar(&c.filename, "file", "", "Provide a file to be used as the backup.")
113
112
        f.StringVar(&c.backupId, "id", "", "Provide the name of the backup to be restored")
147
146
// getRebootstrapParams returns the params for rebootstrapping the
148
147
// specified controller.
149
148
func (c *restoreCommand) getRebootstrapParams(
150
 
        controllerName string, meta *params.BackupsMetadataResult,
 
149
        ctx *cmd.Context, controllerName string, meta *params.BackupsMetadataResult,
151
150
) (*restoreBootstrapParams, error) {
152
151
        // TODO(axw) delete this and -b. We will update bootstrap with a flag
153
152
        // to specify a restore file. When we do that, we'll need to extract
160
159
        if err != nil {
161
160
                return nil, errors.Trace(err)
162
161
        }
163
 
        config, params, err := modelcmd.NewGetBootstrapConfigParamsFunc(store)(controllerName)
 
162
        config, params, err := modelcmd.NewGetBootstrapConfigParamsFunc(ctx, store)(controllerName)
164
163
        if err != nil {
165
164
                return nil, errors.Trace(err)
166
165
        }
219
218
// rebootstrap will bootstrap a new server in safe-mode (not killing any other agent)
220
219
// if there is no current server available to restore to.
221
220
func (c *restoreCommand) rebootstrap(ctx *cmd.Context, meta *params.BackupsMetadataResult) error {
222
 
        params, err := c.getRebootstrapParamsFunc(c.ControllerName(), meta)
 
221
        params, err := c.getRebootstrapParamsFunc(ctx, c.ControllerName(), meta)
223
222
        if err != nil {
224
223
                return errors.Trace(err)
225
224
        }
367
366
 
368
367
// Run is the entry point for this command.
369
368
func (c *restoreCommand) Run(ctx *cmd.Context) error {
 
369
        var err error
 
370
        c.constraints, err = common.ParseConstraints(ctx, c.constraintsStr)
 
371
        if err != nil {
 
372
                return err
 
373
        }
 
374
 
370
375
        if c.Log != nil {
371
376
                if err := c.Log.Start(ctx); err != nil {
372
377
                        return err