Esempio n. 1
0
// AddPendingResource sends the provided resource blob up to Juju
// without making it available yet. For example, AddPendingResource()
// is used before the service is deployed.
func (c Client) AddPendingResource(serviceID string, res charmresource.Resource, filename string, reader io.ReadSeeker) (pendingID string, err error) {
	ids, err := c.AddPendingResources(AddPendingResourcesArgs{
		ServiceID: serviceID,
		Resources: []charmresource.Resource{res},
	})
	if err != nil {
		return "", errors.Trace(err)
	}
	pendingID = ids[0]

	if reader != nil {
		uReq, err := api.NewUploadRequest(serviceID, res.Name, filename, reader)
		if err != nil {
			return "", errors.Trace(err)
		}
		uReq.PendingID = pendingID
		req, err := uReq.HTTPRequest()
		if err != nil {
			return "", errors.Trace(err)
		}

		var response api.UploadResult // ignored
		if err := c.doer.Do(req, reader, &response); err != nil {
			return "", errors.Trace(err)
		}
	}

	return pendingID, nil
}
Esempio n. 2
0
// Upload sends the provided resource blob up to Juju.
func (c Client) Upload(service, name, filename string, reader io.ReadSeeker) error {
	uReq, err := api.NewUploadRequest(service, name, filename, reader)
	if err != nil {
		return errors.Trace(err)
	}
	req, err := uReq.HTTPRequest()
	if err != nil {
		return errors.Trace(err)
	}

	var response api.UploadResult // ignored
	if err := c.doer.Do(req, reader, &response); err != nil {
		return errors.Trace(err)
	}

	return nil
}