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

Function instanceDebugRepairPost

cmd/incusd/instance_debug.go:183–235  ·  view source on GitHub ↗

swagger:operation GET /1.0/instances/{name}/debug/repair instances instance_debug_repair_post Trigger a repair action on the instance. Runs an internal repair action on the instance. --- parameters: - in: path name: name description: Instance name type: string required:

(d *Daemon, r *http.Request)

Source from the content-addressed store, hash-verified

181// "500":
182// $ref: "#/responses/InternalServerError"
183func instanceDebugRepairPost(d *Daemon, r *http.Request) response.Response {
184 s := d.State()
185
186 projectName := request.ProjectParam(r)
187 name, err := pathVar(r, "name")
188 if err != nil {
189 return response.SmartError(err)
190 }
191
192 if internalInstance.IsSnapshot(name) {
193 return response.BadRequest(errors.New("Invalid instance name"))
194 }
195
196 // Handle requests targeted to an instance on a different node
197 resp, err := forwardedResponseIfInstanceIsRemote(s, r, projectName, name)
198 if err != nil {
199 return response.SmartError(err)
200 }
201
202 if resp != nil {
203 return resp
204 }
205
206 // Parse the request.
207 req := api.InstanceDebugRepairPost{}
208
209 err = json.NewDecoder(r.Body).Decode(&req)
210 if err != nil {
211 return response.BadRequest(err)
212 }
213
214 // Validate the repair action.
215 if !slices.Contains([]string{"rebuild-config-volume"}, req.Action) {
216 return response.BadRequest(fmt.Errorf("Invalid repair action %q", req.Action))
217 }
218
219 // Load the instance.
220 inst, err := instance.LoadByProjectAndName(s, projectName, name)
221 if err != nil {
222 return response.SmartError(err)
223 }
224
225 // Running the action.
226 switch req.Action {
227 case "rebuild-config-volume":
228 err := instanceDebugRepairRebuildConfigVolume(s, inst)
229 if err != nil {
230 return response.SmartError(err)
231 }
232 }
233
234 return response.EmptySyncResponse
235}
236
237func instanceDebugRepairRebuildConfigVolume(s *state.State, inst instance.Instance) error {
238 // Initial validation.

Callers

nothing calls this directly

Calls 11

ProjectParamFunction · 0.92
SmartErrorFunction · 0.92
BadRequestFunction · 0.92
LoadByProjectAndNameFunction · 0.92
pathVarFunction · 0.85
ErrorfMethod · 0.80
StateMethod · 0.65
IsSnapshotMethod · 0.65
ContainsMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…