lxd/container_metadata.go
func containerMetadataTemplatesDelete(d *Daemon, r *http.Request) Response {
	project := projectParam(r)

	name := mux.Vars(r)["name"]

	// Handle requests targeted to a container on a different node
	response, err := ForwardedResponseIfContainerIsRemote(d, r, project, name)
	if err != nil {
		return SmartError(err)
	}
	if response != nil {
		return response
	}

	// Load the container
	c, err := containerLoadByProjectAndName(d.State(), project, name)
	if err != nil {
		return SmartError(err)
	}

	// Start the storage if needed
	ourStart, err := c.StorageStart()
	if err != nil {
		return SmartError(err)
	}
	if ourStart {
		defer c.StorageStop()
	}

	// Look at the request
	templateName := r.FormValue("path")
	if templateName == "" {
		return BadRequest(fmt.Errorf("missing path argument"))
	}

	templatePath, err := getContainerTemplatePath(c, templateName)
	if err != nil {
		return SmartError(err)
	}

	if !shared.PathExists(templatePath) {
		return NotFound(fmt.Errorf("Path '%s' not found", templatePath))
	}

	// Delete the template
	err = os.Remove(templatePath)
	if err != nil {
		return InternalError(err)
	}

	return EmptySyncResponse
}
func containerMetadataTemplatesDelete(d *Daemon, r *http.Request) Response {
	project := projectParam(r)

	name := mux.Vars(r)["name"]

	// Handle requests targeted to a container on a different node
	response, err := ForwardedResponseIfContainerIsRemote(d, r, project, name)
	if err != nil {
		return SmartError(err)
	}
	if response != nil {
		return response
	}

	// Load the container
	c, err := containerLoadByProjectAndName(d.State(), project, name)
	if err != nil {
		return SmartError(err)
	}

	// Start the storage if needed
	ourStart, err := c.StorageStart()
	if err != nil {
		return SmartError(err)
	}
	if ourStart {
		defer c.StorageStop()
	}

	// Look at the request
	templateName := r.FormValue("path")
	if templateName == "" {
		return BadRequest(fmt.Errorf("missing path argument"))
	}

	templatePath, err := getContainerTemplatePath(c, templateName)
	if err != nil {
		return SmartError(err)
	}

	if !shared.PathExists(templatePath) {
		return NotFound(fmt.Errorf("Path '%s' not found", templatePath))
	}

	// Delete the template
	err = os.Remove(templatePath)
	if err != nil {
		return InternalError(err)
	}

	return EmptySyncResponse
}
func containerMetadataTemplatesDelete ( d * Daemon , r * http . Request ) Response { project := projectParam ( r ) name := mux . Vars ( r ) [ " " ] // Handle requests targeted to a container on a different node response , err := ForwardedResponseIfContainerIsRemote ( d , r , project , name ) if err != nil { return SmartError ( err ) } if response != nil { return response } // Load the container c , err := containerLoadByProjectAndName ( d . State ( ) , project , name ) if err != nil { return SmartError ( err ) } // Start the storage if needed ourStart , err := c . StorageStart ( ) if err != nil { return SmartError ( err ) } if ourStart { defer c . StorageStop ( ) } // Look at the request templateName := r . FormValue ( " " ) if templateName == " " { return BadRequest ( fmt . Errorf ( " " ) ) } templatePath , err := getContainerTemplatePath ( c , templateName ) if err != nil { return SmartError ( err ) } if ! shared . PathExists ( templatePath ) { return NotFound ( fmt . Errorf ( " " , templatePath ) ) } // Delete the template err = os . Remove ( templatePath ) if err != nil { return InternalError ( err ) } return EmptySyncResponse }
// Delete a container template
Delete a container template