client/lxd_containers.go
func (r *ProtocolLXD) CreateContainerFile(containerName string, path string, args ContainerFileArgs) error {
	if args.Type == "directory" {
		if !r.HasExtension("directory_manipulation") {
			return fmt.Errorf("The server is missing the required \"directory_manipulation\" API extension")
		}
	}

	if args.Type == "symlink" {
		if !r.HasExtension("file_symlinks") {
			return fmt.Errorf("The server is missing the required \"file_symlinks\" API extension")
		}
	}

	if args.WriteMode == "append" {
		if !r.HasExtension("file_append") {
			return fmt.Errorf("The server is missing the required \"file_append\" API extension")
		}
	}

	// Prepare the HTTP request
	requestURL := fmt.Sprintf("%s/1.0/containers/%s/files?path=%s", r.httpHost, url.QueryEscape(containerName), url.QueryEscape(path))

	requestURL, err := r.setQueryAttributes(requestURL)
	if err != nil {
		return err
	}

	req, err := http.NewRequest("POST", requestURL, args.Content)
	if err != nil {
		return err
	}

	// Set the user agent
	if r.httpUserAgent != "" {
		req.Header.Set("User-Agent", r.httpUserAgent)
	}

	// Set the various headers
	if args.UID > -1 {
		req.Header.Set("X-LXD-uid", fmt.Sprintf("%d", args.UID))
	}

	if args.GID > -1 {
		req.Header.Set("X-LXD-gid", fmt.Sprintf("%d", args.GID))
	}

	if args.Mode > -1 {
		req.Header.Set("X-LXD-mode", fmt.Sprintf("%04o", args.Mode))
	}

	if args.Type != "" {
		req.Header.Set("X-LXD-type", args.Type)
	}

	if args.WriteMode != "" {
		req.Header.Set("X-LXD-write", args.WriteMode)
	}

	// Send the request
	resp, err := r.do(req)
	if err != nil {
		return err
	}

	// Check the return value for a cleaner error
	_, _, err = lxdParseResponse(resp)
	if err != nil {
		return err
	}

	return nil
}
func (r *ProtocolLXD) CreateContainerFile(containerName string, path string, args ContainerFileArgs) error {
	if args.Type == "directory" {
		if !r.HasExtension("directory_manipulation") {
			return fmt.Errorf("The server is missing the required \"directory_manipulation\" API extension")
		}
	}

	if args.Type == "symlink" {
		if !r.HasExtension("file_symlinks") {
			return fmt.Errorf("The server is missing the required \"file_symlinks\" API extension")
		}
	}

	if args.WriteMode == "append" {
		if !r.HasExtension("file_append") {
			return fmt.Errorf("The server is missing the required \"file_append\" API extension")
		}
	}

	// Prepare the HTTP request
	requestURL := fmt.Sprintf("%s/1.0/containers/%s/files?path=%s", r.httpHost, url.QueryEscape(containerName), url.QueryEscape(path))

	requestURL, err := r.setQueryAttributes(requestURL)
	if err != nil {
		return err
	}

	req, err := http.NewRequest("POST", requestURL, args.Content)
	if err != nil {
		return err
	}

	// Set the user agent
	if r.httpUserAgent != "" {
		req.Header.Set("User-Agent", r.httpUserAgent)
	}

	// Set the various headers
	if args.UID > -1 {
		req.Header.Set("X-LXD-uid", fmt.Sprintf("%d", args.UID))
	}

	if args.GID > -1 {
		req.Header.Set("X-LXD-gid", fmt.Sprintf("%d", args.GID))
	}

	if args.Mode > -1 {
		req.Header.Set("X-LXD-mode", fmt.Sprintf("%04o", args.Mode))
	}

	if args.Type != "" {
		req.Header.Set("X-LXD-type", args.Type)
	}

	if args.WriteMode != "" {
		req.Header.Set("X-LXD-write", args.WriteMode)
	}

	// Send the request
	resp, err := r.do(req)
	if err != nil {
		return err
	}

	// Check the return value for a cleaner error
	_, _, err = lxdParseResponse(resp)
	if err != nil {
		return err
	}

	return nil
}
func ( r * ProtocolLXD ) CreateContainerFile ( containerName string , path string , args ContainerFileArgs ) error { if args . Type == " " { if ! r . HasExtension ( " " ) { return fmt . Errorf ( " \" \" " ) } } if args . Type == " " { if ! r . HasExtension ( " " ) { return fmt . Errorf ( " \" \" " ) } } if args . WriteMode == " " { if ! r . HasExtension ( " " ) { return fmt . Errorf ( " \" \" " ) } } // Prepare the HTTP request requestURL := fmt . Sprintf ( " " , r . httpHost , url . QueryEscape ( containerName ) , url . QueryEscape ( path ) ) requestURL , err := r . setQueryAttributes ( requestURL ) if err != nil { return err } req , err := http . NewRequest ( " " , requestURL , args . Content ) if err != nil { return err } // Set the user agent if r . httpUserAgent != " " { req . Header . Set ( " " , r . httpUserAgent ) } // Set the various headers if args . UID > - 1 { req . Header . Set ( " " , fmt . Sprintf ( " " , args . UID ) ) } if args . GID > - 1 { req . Header . Set ( " " , fmt . Sprintf ( " " , args . GID ) ) } if args . Mode > - 1 { req . Header . Set ( " " , fmt . Sprintf ( " " , args . Mode ) ) } if args . Type != " " { req . Header . Set ( " " , args . Type ) } if args . WriteMode != " " { req . Header . Set ( " " , args . WriteMode ) } // Send the request resp , err := r . do ( req ) if err != nil { return err } // Check the return value for a cleaner error _ , _ , err = lxdParseResponse ( resp ) if err != nil { return err } return nil }
// CreateContainerFile tells LXD to create a file in the container
CreateContainerFile tells LXD to create a file in the container