Beispiel #1
0
// Upload sends the backup archive to remote storage.
func (c *Client) Upload(archive io.Reader, meta params.BackupsMetadataResult) (string, error) {
	// Empty out some of the metadata.
	meta.ID = ""
	meta.Stored = time.Time{}

	// Send the request.
	_, resp, err := c.http.SendHTTPRequestReader("backups", archive, &meta, "juju-backup.tar.gz")
	if err != nil {
		return "", errors.Annotate(err, "while sending HTTP request")
	}

	// Handle the response.
	if resp.StatusCode == http.StatusOK {
		var result params.BackupsMetadataResult
		if err := apihttp.ExtractJSONResult(resp, &result); err != nil {
			return "", errors.Annotate(err, "while extracting result")
		}
		return result.ID, nil
	} else {
		failure, err := apihttp.ExtractAPIError(resp)
		if err != nil {
			return "", errors.Annotate(err, "while extracting failure")
		}
		return "", errors.Trace(failure)
	}
}
Beispiel #2
0
func (s *backupsSuite) TestCreateOkay(c *gc.C) {
	s.setBackups(c, s.meta, "")
	var args params.BackupsCreateArgs
	result, err := s.api.Create(args)
	c.Assert(err, gc.IsNil)
	var expected params.BackupsMetadataResult
	expected.UpdateFromMetadata(s.meta)

	c.Check(result, gc.DeepEquals, expected)
}
Beispiel #3
0
func (s *backupsSuite) TestCreateNotes(c *gc.C) {
	meta := s.newMeta("this backup is important")
	s.setBackups(c, meta, "")
	args := params.BackupsCreateArgs{
		Notes: "this backup is important",
	}
	result, err := s.api.Create(args)
	c.Assert(err, gc.IsNil)
	var expected params.BackupsMetadataResult
	expected.UpdateFromMetadata(meta)
	expected.Notes = "this backup is important"

	c.Check(result, gc.DeepEquals, expected)
}
Beispiel #4
0
// Upload sends the backup archive to remote storage.
func (c *Client) Upload(archive io.ReadSeeker, meta params.BackupsMetadataResult) (string, error) {
	// Empty out some of the metadata.
	meta.ID = ""
	meta.Stored = time.Time{}

	req, err := http.NewRequest("PUT", "/backups", nil)
	if err != nil {
		return "", errors.Trace(err)
	}
	body, contentType, err := httpattachment.NewBody(archive, meta, "juju-backup.tar.gz")
	if err != nil {
		return "", errors.Annotatef(err, "cannot create multipart body")
	}
	req.Header.Set("Content-Type", contentType)
	var result params.BackupsMetadataResult
	if err := c.client.Do(req, body, &result); err != nil {
		return "", errors.Trace(err)
	}
	return result.ID, nil
}
Beispiel #5
0
// ResultFromMetadata updates the result with the information in the
// metadata value.
func ResultFromMetadata(meta *backups.Metadata) params.BackupsMetadataResult {
	var result params.BackupsMetadataResult

	result.ID = meta.ID()

	result.Checksum = meta.Checksum()
	result.ChecksumFormat = meta.ChecksumFormat()
	result.Size = meta.Size()
	if meta.Stored() != nil {
		result.Stored = *(meta.Stored())
	}

	result.Started = meta.Started
	if meta.Finished != nil {
		result.Finished = *meta.Finished
	}
	result.Notes = meta.Notes

	result.Environment = meta.Origin.Environment
	result.Machine = meta.Origin.Machine
	result.Hostname = meta.Origin.Hostname
	result.Version = meta.Origin.Version

	return result
}
Beispiel #6
0
// ResultFromMetadata updates the result with the information in the
// metadata value.
func ResultFromMetadata(meta *backups.Metadata) params.BackupsMetadataResult {
	var result params.BackupsMetadataResult

	result.ID = meta.ID()

	result.Checksum = meta.Checksum()
	result.ChecksumFormat = meta.ChecksumFormat()
	result.Size = meta.Size()
	if meta.Stored() != nil {
		result.Stored = *(meta.Stored())
	}

	result.Started = meta.Started
	if meta.Finished != nil {
		result.Finished = *meta.Finished
	}
	result.Notes = meta.Notes

	result.Model = meta.Origin.Model
	result.Machine = meta.Origin.Machine
	result.Hostname = meta.Origin.Hostname
	result.Version = meta.Origin.Version
	result.Series = meta.Origin.Series

	// TODO(wallyworld) - remove these ASAP
	// These are only used by the restore CLI when re-bootstrapping.
	// We will use a better solution but the way restore currently
	// works, we need them and they are no longer available via
	// bootstrap config. We will need to ifx how re-bootstrap deals
	// with these keys to address the issue.
	result.CACert = meta.CACert
	result.CAPrivateKey = meta.CAPrivateKey

	return result
}