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)
| 72 | // "500": |
| 73 | // $ref: "#/responses/InternalServerError" |
| 74 | func 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 { |
nothing calls this directly
no test coverage detected
searching dependent graphs…