From 843db9e3ec1eaa629ce3826f12482b9ce9ce9dad Mon Sep 17 00:00:00 2001 From: Chewing_Bever Date: Sat, 18 Jun 2022 22:17:52 +0200 Subject: [PATCH] chore: added roadmap; started volume_list --- ROADMAP.md | 143 +++++++++++++++++++++++++++++++++++++++++++++++++++++ docker.v | 16 +++--- volumes.v | 33 +++++++++++++ 3 files changed, 184 insertions(+), 8 deletions(-) create mode 100644 ROADMAP.md create mode 100644 volumes.v diff --git a/ROADMAP.md b/ROADMAP.md new file mode 100644 index 0000000..69f4048 --- /dev/null +++ b/ROADMAP.md @@ -0,0 +1,143 @@ +# Roadmap + +This file keeps track of which parts of the Docker Engine API v1.41 are +currently supported. Note that in-development support is not listed here, so as +long as the full functionality isn't supported, it won't be noted. + +This list was taking from the [API +reference](https://docs.docker.com/engine/api/v1.41/). + +* Containers + - [ ] List containers + - [ ] Create a container + - [ ] Inspect a container + - [ ] List processes running inside a container + - [ ] Get container logs + - [ ] Get changes on a container’s filesystem + - [ ] Export a container + - [ ] Get container stats based on resource usage + - [ ] Resize a container TTY + - [ ] Start a container + - [ ] Stop a container + - [ ] Restart a container + - [ ] Kill a container + - [ ] Update a container + - [ ] Rename a container + - [ ] Pause a container + - [ ] Unpause a container + - [ ] Attach to a container + - [ ] Attach to a container via a websocket + - [ ] Wait for a container + - [ ] Remove a container + - [ ] Get information about files in a container + - [ ] Get an archive of a filesystem resource in a container + - [ ] Extract an archive of files or folders to a directory in a container + - [ ] Delete stopped containers + +* Images + - [ ] List images + - [ ] Build an image + - [ ] Delete builder cache + - [ ] Create an image + - [ ] Inspect an image + - [ ] Get the history of an image + - [ ] Push an image + - [ ] Tag an image + - [ ] Remove an image + - [ ] Search images + - [ ] Delete unused images + - [ ] Create a new image from a container + - [ ] Export an image + - [ ] Export several images + - [ ] Import images + +* Networks + - [ ] List networks + - [ ] Inspect a network + - [ ] Remove a network + - [ ] Create a network + - [ ] Connect a container to a network + - [ ] Disconnect a container from a network + - [ ] Delete unused networks + +* Volumes + - [ ] List volumes + - [ ] Create a volume + - [ ] Inspect a volume + - [ ] Remove a volume + - [ ] Delete unused volumes + +* Exec + - [ ] Create an exec instance + - [ ] Start an exec instance + - [ ] Resize an exec instance + - [ ] Inspect an exec instance + +* Swarm + - [ ] Inspect swarm + - [ ] Initialize a new swarm + - [ ] Join an existing swarm + - [ ] Leave a swarm + - [ ] Update a swarm + - [ ] Get the unlock key + - [ ] Unlock a locked manager + +* Nodes + - [ ] List nodes + - [ ] Inspect a node + - [ ] Delete a node + - [ ] Update a node + +* Services + - [ ] List services + - [ ] Create a service + - [ ] Inspect a service + - [ ] Delete a service + - [ ] Update a service + - [ ] Get service logs + +* Tasks + - [ ] List tasks + - [ ] Inspect a task + - [ ] Get task logs + +* Secrets + - [ ] List secrets + - [ ] Create a secret + - [ ] Inspect a secret + - [ ] Delete a secret + - [ ] Update a secret + +* Configs + - [ ] List configs + - [ ] Create a config + - [ ] Inspect a config + - [ ] Delete a config + - [ ] Update a config + +* Plugins + - [ ] List plugins + - [ ] Get plugin privileges + - [ ] Install a plugin + - [ ] Inspect a plugin + - [ ] Remove a plugin + - [ ] Enable a plugin + - [ ] Disable a plugin + - [ ] Upgrade a plugin + - [ ] Create a plugin + - [ ] Push a plugin + - [ ] Configure a plugin + +* System + - [ ] Check auth configuration + - [ ] Get system information + - [ ] Get version + - [ ] Ping + - [ ] Monitor events + - [ ] Get data usage information + +* Distribution + - [ ] Get image information from the registry + +* Session + - [ ] Initialize interactive session diff --git a/docker.v b/docker.v index f4bcf23..1784599 100644 --- a/docker.v +++ b/docker.v @@ -39,7 +39,7 @@ pub fn (mut d DockerConn) close() ? { } // send_request sends an HTTP request without body. -pub fn (mut d DockerConn) send_request(method http.Method, url urllib.URL) ? { +fn (mut d DockerConn) send_request(method http.Method, url urllib.URL) ? { req := '$method $url.request_uri() HTTP/1.1\nHost: localhost\n\n' d.socket.write_string(req)? @@ -49,7 +49,7 @@ pub fn (mut d DockerConn) send_request(method http.Method, url urllib.URL) ? { } // send_request_with_body sends an HTTP request with the given body. -pub fn (mut d DockerConn) send_request_with_body(method http.Method, url urllib.URL, content_type string, body string) ? { +fn (mut d DockerConn) send_request_with_body(method http.Method, url urllib.URL, content_type string, body string) ? { req := '$method $url.request_uri() HTTP/1.1\nHost: localhost\nContent-Type: $content_type\nContent-Length: $body.len\n\n$body\n\n' d.socket.write_string(req)? @@ -60,7 +60,7 @@ pub fn (mut d DockerConn) send_request_with_body(method http.Method, url urllib. // send_request_with_json is a convenience wrapper around // send_request_with_body that encodes the input as JSON. -pub fn (mut d DockerConn) send_request_with_json(method http.Method, url urllib.URL, data &T) ? { +fn (mut d DockerConn) send_request_with_json(method http.Method, url urllib.URL, data &T) ? { body := json.encode(data) return d.send_request_with_body(method, url, 'application/json', body) @@ -70,7 +70,7 @@ pub fn (mut d DockerConn) send_request_with_json(method http.Method, url urll // '\r\n\r\n', after which it parses the response as an HTTP response. // Importantly, this function never consumes the reader past the HTTP // separator, so the body can be read fully later on. -pub fn (mut d DockerConn) read_response_head() ?http.Response { +fn (mut d DockerConn) read_response_head() ?http.Response { mut res := []u8{} util.read_until_separator(mut d.reader, mut res, vdocker.http_separator)? @@ -80,7 +80,7 @@ pub fn (mut d DockerConn) read_response_head() ?http.Response { // read_response_body reads `length` bytes from the stream. It can be used when // the response encoding isn't chunked to fully read it. -pub fn (mut d DockerConn) read_response_body(length int) ?string { +fn (mut d DockerConn) read_response_body(length int) ?string { if length == 0 { return '' } @@ -101,7 +101,7 @@ pub fn (mut d DockerConn) read_response_body(length int) ?string { // read_response is a convenience function which always consumes the entire // response & returns it. It should only be used when we're certain that the // result isn't too large. -pub fn (mut d DockerConn) read_response() ?(http.Response, string) { +fn (mut d DockerConn) read_response() ?(http.Response, string) { head := d.read_response_head()? if head.header.get(http.CommonHeader.transfer_encoding) or { '' } == 'chunked' { @@ -121,7 +121,7 @@ pub fn (mut d DockerConn) read_response() ?(http.Response, string) { // get_chunked_response_reader returns a ChunkedResponseReader using the socket // as reader. -pub fn (mut d DockerConn) get_chunked_response_reader() &ChunkedResponseReader { +fn (mut d DockerConn) get_chunked_response_reader() &ChunkedResponseReader { r := new_chunked_response_reader(d.reader) return r @@ -129,7 +129,7 @@ pub fn (mut d DockerConn) get_chunked_response_reader() &ChunkedResponseReader { // get_stream_format_reader returns a StreamFormatReader using the socket as // reader. -pub fn (mut d DockerConn) get_stream_format_reader() &StreamFormatReader { +fn (mut d DockerConn) get_stream_format_reader() &StreamFormatReader { r := new_chunked_response_reader(d.reader) r2 := new_stream_format_reader(r) diff --git a/volumes.v b/volumes.v new file mode 100644 index 0000000..ae97db1 --- /dev/null +++ b/volumes.v @@ -0,0 +1,33 @@ +module vdocker + +import net.http { Method } +import net.urllib +import json +import time + +struct Volume { + name string [json: Name] + driver string [json: Driver] + mountpoint string [json: Mountpoint] + created_at time.Time [json: CreatedAt] +} + +struct VolumeListResponse { + volumes []Volume [json: Volumes] + warnings []string [json: Warnings] +} + +pub fn (mut d DockerConn) volume_list() ?VolumeListResponse { + d.send_request(Method.get, urllib.parse('/v1.41/volumes')?)? + head, body := d.read_response()? + + if head.status_code != 200 { + data := json.decode(DockerError, body)? + + return error(data.message) + } + + data := json.decode(VolumeListResponse, body)? + + return data +}