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

Function instanceMetadataGet

cmd/incusd/instance_metadata.go:74–145  ·  view source on GitHub ↗

swagger:operation GET /1.0/instances/{name}/metadata instances instance_metadata_get Get the instance image metadata Gets the image metadata for the instance. --- produces: - application/json parameters: - in: path name: name description: Instance name type: string

(d *Daemon, r *http.Request)

Source from the content-addressed store, hash-verified

72// "500":
73// $ref: "#/responses/InternalServerError"
74func instanceMetadataGet(d *Daemon, r *http.Request) response.Response {
75 s := d.State()
76
77 projectName := request.ProjectParam(r)
78 name, err := pathVar(r, "name")
79 if err != nil {
80 return response.SmartError(err)
81 }
82
83 if internalInstance.IsSnapshot(name) {
84 return response.BadRequest(errors.New("Invalid instance name"))
85 }
86
87 // Handle requests targeted to a container on a different node
88 resp, err := forwardedResponseIfInstanceIsRemote(s, r, projectName, name)
89 if err != nil {
90 return response.SmartError(err)
91 }
92
93 if resp != nil {
94 return resp
95 }
96
97 // Load the container
98 c, err := instance.LoadByProjectAndName(s, projectName, name)
99 if err != nil {
100 return response.SmartError(err)
101 }
102
103 // Start the storage if needed
104 pool, err := storagePools.LoadByInstance(s, c)
105 if err != nil {
106 return response.SmartError(err)
107 }
108
109 _, err = storagePools.InstanceMount(pool, c, nil)
110 if err != nil {
111 return response.SmartError(err)
112 }
113
114 defer logger.WarnOnError(func() error { return storagePools.InstanceUnmount(pool, c, nil) }, "Failed to unmount instance")
115
116 // If missing, just return empty result
117 metadataPath := filepath.Join(c.Path(), "metadata.yaml")
118 if !util.PathExists(metadataPath) {
119 return response.SyncResponse(true, api.ImageMetadata{})
120 }
121
122 // Read the metadata
123 metadataFile, err := os.Open(metadataPath)
124 if err != nil {
125 return response.InternalError(err)
126 }
127
128 defer logger.WarnOnError(metadataFile.Close, "Failed to close metadata file")
129
130 data, err := io.ReadAll(metadataFile)
131 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
PathExistsFunction · 0.92
SyncResponseFunction · 0.92
InternalErrorFunction · 0.92
CreateRequestorFunction · 0.92
SyncResponseETagFunction · 0.92
pathVarFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…