MCPcopy
hub / github.com/lxc/incus / instanceMetadataTemplatesGet

Function instanceMetadataTemplatesGet

cmd/incusd/instance_metadata.go:430–547  ·  view source on GitHub ↗

swagger:operation GET /1.0/instances/{name}/metadata/templates instances instance_metadata_templates_get Get the template file names or a specific If no path specified, returns a list of template file names. If a path is specified, returns the file content. --- produces: - application/jso

(d *Daemon, r *http.Request)

Source from the content-addressed store, hash-verified

428// "500":
429// $ref: "#/responses/InternalServerError"
430func instanceMetadataTemplatesGet(d *Daemon, r *http.Request) response.Response {
431 s := d.State()
432
433 projectName := request.ProjectParam(r)
434 name, err := pathVar(r, "name")
435 if err != nil {
436 return response.SmartError(err)
437 }
438
439 if internalInstance.IsSnapshot(name) {
440 return response.BadRequest(errors.New("Invalid instance name"))
441 }
442
443 // Handle requests targeted to a container on a different node
444 resp, err := forwardedResponseIfInstanceIsRemote(s, r, projectName, name)
445 if err != nil {
446 return response.SmartError(err)
447 }
448
449 if resp != nil {
450 return resp
451 }
452
453 // Load the container
454 c, err := instance.LoadByProjectAndName(s, projectName, name)
455 if err != nil {
456 return response.SmartError(err)
457 }
458
459 // Start the storage if needed
460 pool, err := storagePools.LoadByInstance(s, c)
461 if err != nil {
462 return response.SmartError(err)
463 }
464
465 _, err = storagePools.InstanceMount(pool, c, nil)
466 if err != nil {
467 return response.SmartError(err)
468 }
469
470 defer logger.WarnOnError(func() error { return storagePools.InstanceUnmount(pool, c, nil) }, "Failed to unmount instance")
471
472 // Confine all template access to the instance directory.
473 root, err := os.OpenRoot(c.Path())
474 if err != nil {
475 return response.SmartError(err)
476 }
477
478 defer logger.WarnOnError(root.Close, "Failed to close instance root")
479
480 // Look at the request
481 templateName := r.FormValue("path")
482 if templateName == "" {
483 templates := []string{}
484
485 // List templates
486 entries, err := fs.ReadDir(root.FS(), "templates")
487 if err != nil {

Callers

nothing calls this directly

Calls 15

ProjectParamFunction · 0.92
SmartErrorFunction · 0.92
BadRequestFunction · 0.92
LoadByProjectAndNameFunction · 0.92
WarnOnErrorFunction · 0.92
SyncResponseFunction · 0.92
InternalErrorFunction · 0.92
NotFoundFunction · 0.92
SafeCopyFunction · 0.92
CreateRequestorFunction · 0.92
FileResponseFunction · 0.92
pathVarFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…