diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..9f97022 --- /dev/null +++ b/.dockerignore @@ -0,0 +1 @@ +target/ \ No newline at end of file diff --git a/.gitignore b/.gitignore index 00219ef..9f97022 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1 @@ -csi_pb2.py -csi_pb2_grpc.py +target/ \ No newline at end of file diff --git a/.tool-versions b/.tool-versions deleted file mode 100644 index 85cfd4b..0000000 --- a/.tool-versions +++ /dev/null @@ -1 +0,0 @@ -python 3.10.5 diff --git a/Cargo.lock b/Cargo.lock new file mode 100644 index 0000000..f295d7f --- /dev/null +++ b/Cargo.lock @@ -0,0 +1,1023 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "anyhow" +version = "1.0.66" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "216261ddc8289130e551ddcd5ce8a064710c0d064a4d2895c67151c92b5443f6" + +[[package]] +name = "async-stream" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dad5c83079eae9969be7fadefe640a1c566901f05ff91ab221de4b6f68d9507e" +dependencies = [ + "async-stream-impl", + "futures-core", +] + +[[package]] +name = "async-stream-impl" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "10f203db73a71dfa2fb6dd22763990fa26f3d2625a6da2da900d23b87d26be27" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "async-trait" +version = "0.1.58" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e805d94e6b5001b651426cf4cd446b1ab5f319d27bab5c644f61de0a804360c" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "autocfg" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" + +[[package]] +name = "axum" +version = "0.5.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "acee9fd5073ab6b045a275b3e709c163dd36c90685219cb21804a147b58dba43" +dependencies = [ + "async-trait", + "axum-core", + "bitflags", + "bytes", + "futures-util", + "http", + "http-body", + "hyper", + "itoa", + "matchit", + "memchr", + "mime", + "percent-encoding", + "pin-project-lite", + "serde", + "sync_wrapper", + "tokio", + "tower", + "tower-http", + "tower-layer", + "tower-service", +] + +[[package]] +name = "axum-core" +version = "0.2.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "37e5939e02c56fecd5c017c37df4238c0a839fa76b7f97acdd7efb804fd181cc" +dependencies = [ + "async-trait", + "bytes", + "futures-util", + "http", + "http-body", + "mime", + "tower-layer", + "tower-service", +] + +[[package]] +name = "base64" +version = "0.13.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9e1b586273c5702936fe7b7d6896644d8be71e6314cfe09d3167c95f712589e8" + +[[package]] +name = "bitflags" +version = "1.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" + +[[package]] +name = "bytes" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec8a7b6a70fde80372154c65702f00a0f56f3e1c36abbc6c440484be248856db" + +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + +[[package]] +name = "either" +version = "1.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "90e5c1c8368803113bf0c9584fc495a58b86dc8a29edbf8fe877d21d9507e797" + +[[package]] +name = "fastrand" +version = "1.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a7a407cfaa3385c4ae6b23e84623d48c2798d06e3e6a1878f7f59f17b3f86499" +dependencies = [ + "instant", +] + +[[package]] +name = "fixedbitset" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0ce7134b9999ecaf8bcd65542e436736ef32ddca1b3e06094cb6ec5755203b80" + +[[package]] +name = "fnv" +version = "1.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" + +[[package]] +name = "futures-channel" +version = "0.3.25" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "52ba265a92256105f45b719605a571ffe2d1f0fea3807304b522c1d778f79eed" +dependencies = [ + "futures-core", +] + +[[package]] +name = "futures-core" +version = "0.3.25" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "04909a7a7e4633ae6c4a9ab280aeb86da1236243a77b694a49eacd659a4bd3ac" + +[[package]] +name = "futures-sink" +version = "0.3.25" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "39c15cf1a4aa79df40f1bb462fb39676d0ad9e366c2a33b590d7c66f4f81fcf9" + +[[package]] +name = "futures-task" +version = "0.3.25" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2ffb393ac5d9a6eaa9d3fdf37ae2776656b706e200c8e16b1bdb227f5198e6ea" + +[[package]] +name = "futures-util" +version = "0.3.25" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "197676987abd2f9cadff84926f410af1c183608d36641465df73ae8211dc65d6" +dependencies = [ + "futures-core", + "futures-task", + "pin-project-lite", + "pin-utils", +] + +[[package]] +name = "getrandom" +version = "0.2.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c05aeb6a22b8f62540c194aac980f2115af067bfe15a0734d7277a768d396b31" +dependencies = [ + "cfg-if", + "libc", + "wasi", +] + +[[package]] +name = "gluster-dir-csi" +version = "0.1.0" +dependencies = [ + "hostname", + "prost", + "prost-types", + "tokio", + "tokio-stream", + "tonic", + "tonic-build", +] + +[[package]] +name = "h2" +version = "0.3.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5f9f29bc9dda355256b2916cf526ab02ce0aeaaaf2bad60d65ef3f12f11dd0f4" +dependencies = [ + "bytes", + "fnv", + "futures-core", + "futures-sink", + "futures-util", + "http", + "indexmap", + "slab", + "tokio", + "tokio-util", + "tracing", +] + +[[package]] +name = "hashbrown" +version = "0.12.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888" + +[[package]] +name = "heck" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2540771e65fc8cb83cd6e8a237f70c319bd5c29f78ed1084ba5d50eeac86f7f9" + +[[package]] +name = "hermit-abi" +version = "0.1.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "62b467343b94ba476dcb2500d242dadbb39557df889310ac77c5d99100aaac33" +dependencies = [ + "libc", +] + +[[package]] +name = "hostname" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c731c3e10504cc8ed35cfe2f1db4c9274c3d35fa486e3b31df46f068ef3e867" +dependencies = [ + "libc", + "match_cfg", + "winapi", +] + +[[package]] +name = "http" +version = "0.2.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "75f43d41e26995c17e71ee126451dd3941010b0514a81a9d11f3b341debc2399" +dependencies = [ + "bytes", + "fnv", + "itoa", +] + +[[package]] +name = "http-body" +version = "0.4.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d5f38f16d184e36f2408a55281cd658ecbd3ca05cce6d6510a176eca393e26d1" +dependencies = [ + "bytes", + "http", + "pin-project-lite", +] + +[[package]] +name = "http-range-header" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0bfe8eed0a9285ef776bb792479ea3834e8b94e13d615c2f66d03dd50a435a29" + +[[package]] +name = "httparse" +version = "1.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d897f394bad6a705d5f4104762e116a75639e470d80901eed05a860a95cb1904" + +[[package]] +name = "httpdate" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c4a1e36c821dbe04574f602848a19f742f4fb3c98d40449f11bcad18d6b17421" + +[[package]] +name = "hyper" +version = "0.14.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "abfba89e19b959ca163c7752ba59d737c1ceea53a5d31a149c805446fc958064" +dependencies = [ + "bytes", + "futures-channel", + "futures-core", + "futures-util", + "h2", + "http", + "http-body", + "httparse", + "httpdate", + "itoa", + "pin-project-lite", + "socket2", + "tokio", + "tower-service", + "tracing", + "want", +] + +[[package]] +name = "hyper-timeout" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bbb958482e8c7be4bc3cf272a766a2b0bf1a6755e7a6ae777f017a31d11b13b1" +dependencies = [ + "hyper", + "pin-project-lite", + "tokio", + "tokio-io-timeout", +] + +[[package]] +name = "indexmap" +version = "1.9.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "10a35a97730320ffe8e2d410b5d3b69279b98d2c14bdb8b70ea89ecf7888d41e" +dependencies = [ + "autocfg", + "hashbrown", +] + +[[package]] +name = "instant" +version = "0.1.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7a5bbe824c507c5da5956355e86a746d82e0e1464f65d862cc5e71da70e94b2c" +dependencies = [ + "cfg-if", +] + +[[package]] +name = "itertools" +version = "0.10.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b0fd2260e829bddf4cb6ea802289de2f86d6a7a690192fbe91b3f46e0f2c8473" +dependencies = [ + "either", +] + +[[package]] +name = "itoa" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4217ad341ebadf8d8e724e264f13e593e0648f5b3e94b3896a5df283be015ecc" + +[[package]] +name = "lazy_static" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" + +[[package]] +name = "libc" +version = "0.2.137" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fc7fcc620a3bff7cdd7a365be3376c97191aeaccc2a603e600951e452615bf89" + +[[package]] +name = "log" +version = "0.4.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "abb12e687cfb44aa40f41fc3978ef76448f9b6038cad6aef4259d3c095a2382e" +dependencies = [ + "cfg-if", +] + +[[package]] +name = "match_cfg" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ffbee8634e0d45d258acb448e7eaab3fce7a0a467395d4d9f228e3c1f01fb2e4" + +[[package]] +name = "matchit" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "73cbba799671b762df5a175adf59ce145165747bb891505c43d09aefbbf38beb" + +[[package]] +name = "memchr" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d" + +[[package]] +name = "mime" +version = "0.3.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2a60c7ce501c71e03a9c9c0d35b861413ae925bd979cc7a4e30d060069aaac8d" + +[[package]] +name = "mio" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e5d732bc30207a6423068df043e3d02e0735b155ad7ce1a6f76fe2baa5b158de" +dependencies = [ + "libc", + "log", + "wasi", + "windows-sys", +] + +[[package]] +name = "multimap" +version = "0.8.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e5ce46fe64a9d73be07dcbe690a38ce1b293be448fd8ce1e6c1b8062c9f72c6a" + +[[package]] +name = "num_cpus" +version = "1.14.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f6058e64324c71e02bc2b150e4f3bc8286db6c83092132ffa3f6b1eab0f9def5" +dependencies = [ + "hermit-abi", + "libc", +] + +[[package]] +name = "once_cell" +version = "1.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "86f0b0d4bf799edbc74508c1e8bf170ff5f41238e5f8225603ca7caaae2b7860" + +[[package]] +name = "percent-encoding" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "478c572c3d73181ff3c2539045f6eb99e5491218eae919370993b890cdbdd98e" + +[[package]] +name = "petgraph" +version = "0.6.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6d5014253a1331579ce62aa67443b4a658c5e7dd03d4bc6d302b94474888143" +dependencies = [ + "fixedbitset", + "indexmap", +] + +[[package]] +name = "pin-project" +version = "1.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ad29a609b6bcd67fee905812e544992d216af9d755757c05ed2d0e15a74c6ecc" +dependencies = [ + "pin-project-internal", +] + +[[package]] +name = "pin-project-internal" +version = "1.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "069bdb1e05adc7a8990dce9cc75370895fbe4e3d58b9b73bf1aee56359344a55" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "pin-project-lite" +version = "0.2.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e0a7ae3ac2f1173085d398531c705756c94a4c56843785df85a60c1a0afac116" + +[[package]] +name = "pin-utils" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" + +[[package]] +name = "ppv-lite86" +version = "0.2.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de" + +[[package]] +name = "prettyplease" +version = "0.1.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c142c0e46b57171fe0c528bee8c5b7569e80f0c17e377cd0e30ea57dbc11bb51" +dependencies = [ + "proc-macro2", + "syn", +] + +[[package]] +name = "proc-macro2" +version = "1.0.47" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5ea3d908b0e36316caf9e9e2c4625cdde190a7e6f440d794667ed17a1855e725" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "prost" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a0841812012b2d4a6145fae9a6af1534873c32aa67fff26bd09f8fa42c83f95a" +dependencies = [ + "bytes", + "prost-derive", +] + +[[package]] +name = "prost-build" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1d8b442418ea0822409d9e7d047cbf1e7e9e1760b172bf9982cf29d517c93511" +dependencies = [ + "bytes", + "heck", + "itertools", + "lazy_static", + "log", + "multimap", + "petgraph", + "prettyplease", + "prost", + "prost-types", + "regex", + "syn", + "tempfile", + "which", +] + +[[package]] +name = "prost-derive" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "164ae68b6587001ca506d3bf7f1000bfa248d0e1217b618108fba4ec1d0cc306" +dependencies = [ + "anyhow", + "itertools", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "prost-types" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "747761bc3dc48f9a34553bf65605cf6cb6288ba219f3450b4275dbd81539551a" +dependencies = [ + "bytes", + "prost", +] + +[[package]] +name = "quote" +version = "1.0.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bbe448f377a7d6961e30f5955f9b8d106c3f5e449d493ee1b125c1d43c2b5179" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "rand" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" +dependencies = [ + "libc", + "rand_chacha", + "rand_core", +] + +[[package]] +name = "rand_chacha" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" +dependencies = [ + "ppv-lite86", + "rand_core", +] + +[[package]] +name = "rand_core" +version = "0.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" +dependencies = [ + "getrandom", +] + +[[package]] +name = "redox_syscall" +version = "0.2.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fb5a58c1855b4b6819d59012155603f0b22ad30cad752600aadfcb695265519a" +dependencies = [ + "bitflags", +] + +[[package]] +name = "regex" +version = "1.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e076559ef8e241f2ae3479e36f97bd5741c0330689e217ad51ce2c76808b868a" +dependencies = [ + "regex-syntax", +] + +[[package]] +name = "regex-syntax" +version = "0.6.28" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "456c603be3e8d448b072f410900c09faf164fbce2d480456f50eea6e25f9c848" + +[[package]] +name = "remove_dir_all" +version = "0.5.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3acd125665422973a33ac9d3dd2df85edad0f4ae9b00dafb1a05e43a9f5ef8e7" +dependencies = [ + "winapi", +] + +[[package]] +name = "serde" +version = "1.0.147" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d193d69bae983fc11a79df82342761dfbf28a99fc8d203dca4c3c1b590948965" + +[[package]] +name = "slab" +version = "0.4.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4614a76b2a8be0058caa9dbbaf66d988527d86d003c11a94fbd335d7661edcef" +dependencies = [ + "autocfg", +] + +[[package]] +name = "socket2" +version = "0.4.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "02e2d2db9033d13a1567121ddd7a095ee144db4e1ca1b1bda3419bc0da294ebd" +dependencies = [ + "libc", + "winapi", +] + +[[package]] +name = "syn" +version = "1.0.103" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a864042229133ada95abf3b54fdc62ef5ccabe9515b64717bcb9a1919e59445d" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "sync_wrapper" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "20518fe4a4c9acf048008599e464deb21beeae3d3578418951a189c235a7a9a8" + +[[package]] +name = "tempfile" +version = "3.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5cdb1ef4eaeeaddc8fbd371e5017057064af0911902ef36b39801f67cc6d79e4" +dependencies = [ + "cfg-if", + "fastrand", + "libc", + "redox_syscall", + "remove_dir_all", + "winapi", +] + +[[package]] +name = "tokio" +version = "1.21.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a9e03c497dc955702ba729190dc4aac6f2a0ce97f913e5b1b5912fc5039d9099" +dependencies = [ + "autocfg", + "bytes", + "libc", + "memchr", + "mio", + "num_cpus", + "pin-project-lite", + "socket2", + "tokio-macros", + "winapi", +] + +[[package]] +name = "tokio-io-timeout" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "30b74022ada614a1b4834de765f9bb43877f910cc8ce4be40e89042c9223a8bf" +dependencies = [ + "pin-project-lite", + "tokio", +] + +[[package]] +name = "tokio-macros" +version = "1.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9724f9a975fb987ef7a3cd9be0350edcbe130698af5b8f7a631e23d42d052484" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "tokio-stream" +version = "0.1.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d660770404473ccd7bc9f8b28494a811bc18542b915c0855c51e8f419d5223ce" +dependencies = [ + "futures-core", + "pin-project-lite", + "tokio", +] + +[[package]] +name = "tokio-util" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0bb2e075f03b3d66d8d8785356224ba688d2906a371015e225beeb65ca92c740" +dependencies = [ + "bytes", + "futures-core", + "futures-sink", + "pin-project-lite", + "tokio", + "tracing", +] + +[[package]] +name = "tonic" +version = "0.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "55b9af819e54b8f33d453655bef9b9acc171568fb49523078d0cc4e7484200ec" +dependencies = [ + "async-stream", + "async-trait", + "axum", + "base64", + "bytes", + "futures-core", + "futures-util", + "h2", + "http", + "http-body", + "hyper", + "hyper-timeout", + "percent-encoding", + "pin-project", + "prost", + "prost-derive", + "tokio", + "tokio-stream", + "tokio-util", + "tower", + "tower-layer", + "tower-service", + "tracing", + "tracing-futures", +] + +[[package]] +name = "tonic-build" +version = "0.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "48c6fd7c2581e36d63388a9e04c350c21beb7a8b059580b2e93993c526899ddc" +dependencies = [ + "prettyplease", + "proc-macro2", + "prost-build", + "quote", + "syn", +] + +[[package]] +name = "tower" +version = "0.4.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b8fa9be0de6cf49e536ce1851f987bd21a43b771b09473c3549a6c853db37c1c" +dependencies = [ + "futures-core", + "futures-util", + "indexmap", + "pin-project", + "pin-project-lite", + "rand", + "slab", + "tokio", + "tokio-util", + "tower-layer", + "tower-service", + "tracing", +] + +[[package]] +name = "tower-http" +version = "0.3.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c530c8675c1dbf98facee631536fa116b5fb6382d7dd6dc1b118d970eafe3ba" +dependencies = [ + "bitflags", + "bytes", + "futures-core", + "futures-util", + "http", + "http-body", + "http-range-header", + "pin-project-lite", + "tower", + "tower-layer", + "tower-service", +] + +[[package]] +name = "tower-layer" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c20c8dbed6283a09604c3e69b4b7eeb54e298b8a600d4d5ecb5ad39de609f1d0" + +[[package]] +name = "tower-service" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6bc1c9ce2b5135ac7f93c72918fc37feb872bdc6a5533a8b85eb4b86bfdae52" + +[[package]] +name = "tracing" +version = "0.1.37" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ce8c33a8d48bd45d624a6e523445fd21ec13d3653cd51f681abf67418f54eb8" +dependencies = [ + "cfg-if", + "log", + "pin-project-lite", + "tracing-attributes", + "tracing-core", +] + +[[package]] +name = "tracing-attributes" +version = "0.1.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4017f8f45139870ca7e672686113917c71c7a6e02d4924eda67186083c03081a" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "tracing-core" +version = "0.1.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "24eb03ba0eab1fd845050058ce5e616558e8f8d8fca633e6b163fe25c797213a" +dependencies = [ + "once_cell", +] + +[[package]] +name = "tracing-futures" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "97d095ae15e245a057c8e8451bab9b3ee1e1f68e9ba2b4fbc18d0ac5237835f2" +dependencies = [ + "pin-project", + "tracing", +] + +[[package]] +name = "try-lock" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "59547bce71d9c38b83d9c0e92b6066c4253371f15005def0c30d9657f50c7642" + +[[package]] +name = "unicode-ident" +version = "1.0.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6ceab39d59e4c9499d4e5a8ee0e2735b891bb7308ac83dfb4e80cad195c9f6f3" + +[[package]] +name = "want" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1ce8a968cb1cd110d136ff8b819a556d6fb6d919363c61534f6860c7eb172ba0" +dependencies = [ + "log", + "try-lock", +] + +[[package]] +name = "wasi" +version = "0.11.0+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" + +[[package]] +name = "which" +version = "4.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1c831fbbee9e129a8cf93e7747a82da9d95ba8e16621cae60ec2cdc849bacb7b" +dependencies = [ + "either", + "libc", + "once_cell", +] + +[[package]] +name = "winapi" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" +dependencies = [ + "winapi-i686-pc-windows-gnu", + "winapi-x86_64-pc-windows-gnu", +] + +[[package]] +name = "winapi-i686-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" + +[[package]] +name = "winapi-x86_64-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" + +[[package]] +name = "windows-sys" +version = "0.42.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5a3e1820f08b8513f676f7ab6c1f99ff312fb97b553d30ff4dd86f9f15728aa7" +dependencies = [ + "windows_aarch64_gnullvm", + "windows_aarch64_msvc", + "windows_i686_gnu", + "windows_i686_msvc", + "windows_x86_64_gnu", + "windows_x86_64_gnullvm", + "windows_x86_64_msvc", +] + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.42.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "41d2aa71f6f0cbe00ae5167d90ef3cfe66527d6f613ca78ac8024c3ccab9a19e" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.42.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dd0f252f5a35cac83d6311b2e795981f5ee6e67eb1f9a7f64eb4500fbc4dcdb4" + +[[package]] +name = "windows_i686_gnu" +version = "0.42.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fbeae19f6716841636c28d695375df17562ca208b2b7d0dc47635a50ae6c5de7" + +[[package]] +name = "windows_i686_msvc" +version = "0.42.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "84c12f65daa39dd2babe6e442988fc329d6243fdce47d7d2d155b8d874862246" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.42.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bf7b1b21b5362cbc318f686150e5bcea75ecedc74dd157d874d754a2ca44b0ed" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.42.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09d525d2ba30eeb3297665bd434a54297e4170c7f1a44cad4ef58095b4cd2028" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.42.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f40009d85759725a34da6d89a94e63d7bdc50a862acf0dbc7c8e488f1edcb6f5" diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..55d67fc --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,17 @@ +[package] +name = "gluster-dir-csi" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +tonic = "0.8" +prost = "0.11" +tokio = { version = "1.0", features = ["macros", "rt-multi-thread"] } +tokio-stream = { version = "0.1", features = ["net"] } +hostname = "0.3.1" +prost-types = "0.11.2" + +[build-dependencies] +tonic-build = "0.8" \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index d653c02..fcf091b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,12 +1,27 @@ -FROM python:3.10-slim-bullseye +FROM docker.io/rust:1.65.0-slim-bullseye as builder RUN apt-get update -yq && \ - apt-get install -y --no-install-recommends glusterfs-client + apt install -y --no-install-recommends \ + build-essential \ + libssl-dev \ + pkg-config \ + protobuf-compiler \ + libprotobuf-dev + + +WORKDIR /src +COPY . . + +RUN cargo build --release + +FROM docker.io/debian:bullseye-slim + +RUN apt-get update -yq && \ + apt-get install -y --no-install-recommends glusterfs-client htop + +COPY --from=builder /src/target/release/gluster-dir-csi /usr/local/bin/gluster-dir-csi + +ENTRYPOINT ["/usr/local/bin/gluster-dir-csi"] + + -COPY requirements.txt / -RUN pip install --upgrade pip -RUN pip install -r /requirements.txt -RUN pip3 install -r /requirements.txt -COPY *.py / -RUN mkdir /csi -CMD python3 -u /main.py diff --git a/README.md b/README.md deleted file mode 100644 index d98a68a..0000000 --- a/README.md +++ /dev/null @@ -1,6 +0,0 @@ -# Intro - -This is a super alpha implementation that supports the CSI spec for directories on a gluster volume. -Each top level directory is treated as a volume. - -Currently tested on hashicorp nomad. diff --git a/__pycache__/csi_pb2.cpython-310.pyc b/__pycache__/csi_pb2.cpython-310.pyc deleted file mode 100644 index e38a390..0000000 Binary files a/__pycache__/csi_pb2.cpython-310.pyc and /dev/null differ diff --git a/__pycache__/csi_pb2_grpc.cpython-310.pyc b/__pycache__/csi_pb2_grpc.cpython-310.pyc deleted file mode 100644 index 4f56426..0000000 Binary files a/__pycache__/csi_pb2_grpc.cpython-310.pyc and /dev/null differ diff --git a/bin/build.sh b/bin/build.sh deleted file mode 100755 index b2565c3..0000000 --- a/bin/build.sh +++ /dev/null @@ -1,3 +0,0 @@ -#!/usr/bin/env bash - -docker build -t ahelberg/gluster-dir-csi . diff --git a/bin/gen-protos.sh b/bin/gen-protos.sh deleted file mode 100755 index b484485..0000000 --- a/bin/gen-protos.sh +++ /dev/null @@ -1,3 +0,0 @@ -#!/usr/bin/env bash - -python -m grpc_tools.protoc -Icsi-spec/ --python_out=. --grpc_python_out=. csi-spec/csi.proto diff --git a/bin/push.sh b/bin/push.sh deleted file mode 100755 index 516d449..0000000 --- a/bin/push.sh +++ /dev/null @@ -1,3 +0,0 @@ -#!/usr/bin/env bash - -docker push ahelberg/gluster-dir-csi diff --git a/bin/test_part1.sh b/bin/test_part1.sh deleted file mode 100755 index 7abb078..0000000 --- a/bin/test_part1.sh +++ /dev/null @@ -1,2 +0,0 @@ -#!/usr/bin/env bash -./build.sh && docker run --rm -ti --privileged -v "$PWD/docker-csi:/csi" ahelberg/gluster-dir-csi diff --git a/build.rs b/build.rs new file mode 100644 index 0000000..e2a18d6 --- /dev/null +++ b/build.rs @@ -0,0 +1,4 @@ +fn main() -> Result<(), Box> { + tonic_build::compile_protos("csi-spec/csi.proto")?; + Ok(()) +} diff --git a/csi-spec b/csi-spec index ad238e5..1de425b 160000 --- a/csi-spec +++ b/csi-spec @@ -1 +1 @@ -Subproject commit ad238e5cad5a27188fcdae1ff3ace3f612638ca5 +Subproject commit 1de425b860085fa0e987d8ece6fe36ed47cdebb3 diff --git a/main.py b/main.py deleted file mode 100644 index e7f3f6d..0000000 --- a/main.py +++ /dev/null @@ -1,138 +0,0 @@ -from concurrent import futures - -import logging - -import socket -import os - -import grpc -import csi_pb2 -import csi_pb2_grpc - -import subprocess - - -gluster_host = os.environ["GLUSTER_HOST"] -gluster_volume = os.environ["GLUSTER_VOLUME"] - -csi_sock_full_path = os.environ.get("CSI_PATH", "/csi/") + "csi.sock" - - -def unmount(path): - print("Unmounting", path) - return subprocess.run(["umount", path]) - - -def mount(volume, path): - print("Mounting", volume, "at", path) - p = subprocess.run(["mount", "-t", "glusterfs", "%s:/%s/%s" % - (gluster_host, gluster_volume, volume), path]) - if p.returncode == 0: - return True - - # Might be a stale mount, unmount and try again - if p.returncode == 32: - return True - - print("Mounting failed with return code:", p.returncode) - return p - - -class Identity(csi_pb2_grpc.Identity): - - def GetPluginInfo(self, request, context): - return csi_pb2.GetPluginInfoResponse(name='gluster-dir-csi', vendor_version="1") - - def Probe(self, request, context): - return csi_pb2.ProbeResponse() - - def GetPluginCapabilities(self, request, context): - return csi_pb2.GetPluginCapabilitiesResponse( - capabilities=[ - csi_pb2.PluginCapability( - service=csi_pb2.PluginCapability.Service( - type=csi_pb2.PluginCapability.Service.Type.CONTROLLER_SERVICE) - ) - ]) - - -class Controller(csi_pb2_grpc.Controller): - - def ControllerGetCapabilities(self, request, context): - return csi_pb2.ControllerGetCapabilitiesResponse(capabilities=[ - csi_pb2.ControllerServiceCapability(rpc=csi_pb2.ControllerServiceCapability.RPC( - type=csi_pb2.ControllerServiceCapability.RPC.Type.CREATE_DELETE_VOLUME)), - ]) - - def CreateVolume(self, request, context): - name = request.name - print("CreateVolume", name) - p = subprocess.run(["mkdir", "-p", "/mnt/main/%s" % name]) - volume = csi_pb2.Volume(volume_id=name) - return csi_pb2.CreateVolumeResponse(volume=volume) - - -class Node(csi_pb2_grpc.Node): - - def NodeGetInfo(self, request, context): - node_id = os.getenv("HOSTNAME") - return csi_pb2.NodeGetInfoResponse(node_id=node_id) - - def NodeGetCapabilities(self, request, context): - return csi_pb2.NodeGetCapabilitiesResponse(capabilities=[ - csi_pb2.NodeServiceCapability(rpc=csi_pb2.NodeServiceCapability.RPC( - type=csi_pb2.NodeServiceCapability.RPC.Type.STAGE_UNSTAGE_VOLUME)) - ]) - - def NodePublishVolume(self, request, context): - volume_id = request.volume_id - path = request.target_path - print("Node Publish Volume", path) - p = subprocess.run(["mkdir", "-p", path], check=True) - res = mount(volume_id, path) - if res is True: - return csi_pb2.NodePublishVolumeResponse() - print(res) - - def NodeUnpublishVolume(self, request, context): - path = request.target_path - print("NodeUnpublishVolume", path) - p = subprocess.run(["umount", path]) - return csi_pb2.NodeUnpublishVolumeResponse() - - def NodeStageVolume(self, request, context): - volume_id = request.volume_id - path = request.staging_target_path - print("Node Stage Volume", path) - res = mount(volume_id, path) - if res is True: - return csi_pb2.NodeStageVolumeResponse() - print(res) - - def NodeUnstageVolume(self, request, context): - path = request.staging_target_path - print("NodeUnstageVolume", path) - p = subprocess.run(["umount", path]) - return csi_pb2.NodeUnstageVolumeResponse() - - -def serve(): - server = grpc.server(futures.ThreadPoolExecutor(max_workers=10)) - csi_pb2_grpc.add_IdentityServicer_to_server(Identity(), server) - csi_pb2_grpc.add_ControllerServicer_to_server(Controller(), server) - csi_pb2_grpc.add_NodeServicer_to_server(Node(), server) - - print("About to start listening on", csi_sock_full_path) - server.add_insecure_port(f'unix://%s' % csi_sock_full_path) - server.start() - print("Waiting for termination") - server.wait_for_termination() - - -if __name__ == '__main__': - p = subprocess.run(["mkdir", "-p", "/mnt/main"]) - p = subprocess.run(["mount", "-t", "glusterfs", "%s:/%s" % - (gluster_host, gluster_volume), "/mnt/main"], check=True) - - logging.basicConfig() - serve() diff --git a/requirements.txt b/requirements.txt deleted file mode 100644 index 5c38c41..0000000 --- a/requirements.txt +++ /dev/null @@ -1,5 +0,0 @@ -grpcio==1.47.0 -grpcio-tools==1.47.0 -protobuf==3.20.1 -googleapis-common-protos==1.53.0 -six==1.16.0 diff --git a/src/main.rs b/src/main.rs new file mode 100644 index 0000000..55385f9 --- /dev/null +++ b/src/main.rs @@ -0,0 +1,454 @@ +use std::io::Error; +use std::process::Command; + +use tonic::{transport::Server, Request, Response, Status}; + +pub mod csi { + tonic::include_proto!("csi.v1"); +} + +use tokio::net::UnixListener; +use tokio_stream::wrappers::UnixListenerStream; + +use csi::controller_server::{Controller, ControllerServer}; +use csi::identity_server::{Identity, IdentityServer}; +use csi::node_server::{Node, NodeServer}; + +fn mount_volume(volume_id: String, target_path: String) -> Result<(), Status> { + std::fs::create_dir_all(&target_path).unwrap(); + + // Mount gluster volume to target path + let output = std::process::Command::new("mount") + .arg("-t") + .arg("glusterfs") + .arg(format!( + "{}:/{}/{}", + std::env::var("GLUSTER_HOST").unwrap(), + std::env::var("GLUSTER_VOLUME").unwrap(), + volume_id + )) + .arg(&target_path) + .output() + .expect("failed to execute process"); + + // Check if mount was successful + // Code 0 means success + // Code 32 means already mounted + if output.status.code() != Some(0) && output.status.code() != Some(32) { + println!( + "Mount failed with code: {:?} {}", + output.status.code(), + String::from_utf8_lossy(&output.stderr) + ); + + return Err(Status::internal(format!( + "Mount failed with code: {:?}", + output.status.code(), + ))); + } + + return Ok(()); +} + +fn unmount_volume(target_path: String) -> Result<(), Status> { + // Unmount gluster volume + let output = std::process::Command::new("umount") + .arg("-l") //TODO: Think about this + .arg(target_path) + .output() + .expect("failed to execute process"); + + // Check if unmount was successful + // Code 0 means success + // Code 32 means already unmounted + if output.status.code() != Some(0) && output.status.code() != Some(32) { + println!( + "Unmount failed with code: {:?} {}", + output.status.code(), + String::from_utf8_lossy(&output.stderr) + ); + + return Err(Status::internal(format!( + "Unmount failed with code: {:?}", + output.status.code(), + ))); + } + + return Ok(()); +} + +#[derive(Debug, Default)] +struct GlusterNode {} + +#[tonic::async_trait] +impl Node for GlusterNode { + async fn node_get_info( + &self, + request: Request, + ) -> Result, Status> { + println!("Got a request: {:?}", request); + + // Get hostname of system + let hostname = hostname::get().unwrap().into_string().unwrap(); + + let reply = csi::NodeGetInfoResponse { + node_id: hostname, + max_volumes_per_node: 0, + accessible_topology: None, + }; + Ok(Response::new(reply)) + } + + async fn node_get_capabilities( + &self, + request: Request, + ) -> Result, Status> { + println!("Got a request: {:?}", request); + + let reply = csi::NodeGetCapabilitiesResponse { + capabilities: vec![csi::NodeServiceCapability { + r#type: Some(csi::node_service_capability::Type::Rpc( + csi::node_service_capability::Rpc { + r#type: csi::node_service_capability::rpc::Type::StageUnstageVolume as i32, + }, + )), + }], + }; + Ok(Response::new(reply)) + } + + async fn node_publish_volume( + &self, + request: Request, + ) -> Result, Status> { + println!("Got a request: {:?}", request); + + let volume_id = request.get_ref().volume_id.clone(); + let target_path = request.get_ref().target_path.clone(); + + // Mount gluster volume to target path + mount_volume(volume_id, target_path)?; + + let reply = csi::NodePublishVolumeResponse {}; + Ok(Response::new(reply)) + } + + async fn node_unpublish_volume( + &self, + request: Request, + ) -> Result, Status> { + println!("Got a request: {:?}", request); + + let target_path = request.get_ref().target_path.clone(); + + // Unmount gluster volume + unmount_volume(target_path)?; + + let reply = csi::NodeUnpublishVolumeResponse {}; + Ok(Response::new(reply)) + } + + async fn node_stage_volume( + &self, + request: Request, + ) -> Result, Status> { + println!("Got a request: {:?}", request); + + let volume_id = request.get_ref().volume_id.clone(); + let target_path = request.get_ref().staging_target_path.clone(); + + // Mount gluster volume to target path + mount_volume(volume_id, target_path)?; + + let reply = csi::NodeStageVolumeResponse {}; + Ok(Response::new(reply)) + } + + async fn node_unstage_volume( + &self, + request: Request, + ) -> Result, Status> { + println!("Got a request: {:?}", request); + + let target_path = request.get_ref().staging_target_path.clone(); + + // Unmount gluster volume + unmount_volume(target_path)?; + + let reply = csi::NodeUnstageVolumeResponse {}; + Ok(Response::new(reply)) + } + + async fn node_expand_volume( + &self, + request: Request, + ) -> Result, Status> { + println!("Got a request: {:?}", request); + + Err(Status::unimplemented("Not implemented")) + } + + async fn node_get_volume_stats( + &self, + request: Request, + ) -> Result, Status> { + println!("Got a request: {:?}", request); + + Err(Status::unimplemented("Not implemented")) + } +} + +#[derive(Debug, Default)] +struct GlusterController {} + +#[tonic::async_trait] +impl Controller for GlusterController { + async fn controller_get_capabilities( + &self, + request: Request, + ) -> Result, Status> { + println!("Got a request: {:?}", request); + + // Return CREATE_DELETE_VOLUME capability + let reply = csi::ControllerGetCapabilitiesResponse { + capabilities: vec![csi::ControllerServiceCapability { + r#type: Some(csi::controller_service_capability::Type::Rpc( + csi::controller_service_capability::Rpc { + r#type: csi::controller_service_capability::rpc::Type::CreateDeleteVolume + as i32, + }, + )), + }], + }; + + Ok(Response::new(reply)) + } + + async fn create_volume( + &self, + request: Request, + ) -> Result, Status> { + println!("Got a request: {:?}", request); + + let name = request.into_inner().name; + + std::fs::create_dir_all(std::path::Path::new("/mnt/main/").join(&name))?; + + let reply = csi::CreateVolumeResponse { + volume: Some(csi::Volume { + capacity_bytes: 0, + volume_id: name, + volume_context: Default::default(), + content_source: None, + accessible_topology: Default::default(), + }), + }; + Ok(Response::new(reply)) + } + + async fn delete_volume( + &self, + request: Request, + ) -> Result, Status> { + println!("Got a request: {:?}", request); + + // let name = request.into_inner().volume_id; + + // std::fs::remove_dir_all(std::path::Path::new("/mnt/glusterfs").join(&name))?; + + let reply = csi::DeleteVolumeResponse {}; + Ok(Response::new(reply)) + } + + async fn controller_publish_volume( + &self, + request: Request, + ) -> Result, Status> { + println!("Got a request: {:?}", request); + + Err(Status::unimplemented("not implemented")) + } + + async fn controller_unpublish_volume( + &self, + request: Request, + ) -> Result, Status> { + println!("Got a request: {:?}", request); + + Err(Status::unimplemented("not implemented")) + } + + async fn validate_volume_capabilities( + &self, + request: Request, + ) -> Result, Status> { + println!("Got a request: {:?}", request); + + Err(Status::unimplemented("not implemented")) + } + + async fn list_volumes( + &self, + request: Request, + ) -> Result, Status> { + println!("Got a request: {:?}", request); + + Err(Status::unimplemented("not implemented")) + } + + async fn get_capacity( + &self, + request: Request, + ) -> Result, Status> { + println!("Got a request: {:?}", request); + + Err(Status::unimplemented("not implemented")) + } + + async fn controller_get_volume( + &self, + request: Request, + ) -> Result, Status> { + println!("Got a request: {:?}", request); + + Err(Status::unimplemented("not implemented")) + } + + async fn create_snapshot( + &self, + request: Request, + ) -> Result, Status> { + println!("Got a request: {:?}", request); + + Err(Status::unimplemented("not implemented")) + } + + async fn delete_snapshot( + &self, + request: Request, + ) -> Result, Status> { + println!("Got a request: {:?}", request); + + Err(Status::unimplemented("not implemented")) + } + + async fn list_snapshots( + &self, + request: Request, + ) -> Result, Status> { + println!("Got a request: {:?}", request); + + Err(Status::unimplemented("not implemented")) + } + + async fn controller_expand_volume( + &self, + request: Request, + ) -> Result, Status> { + println!("Got a request: {:?}", request); + + Err(Status::unimplemented("not implemented")) + } +} + +#[derive(Debug, Default)] +struct GlusterIdentity {} + +#[tonic::async_trait] +impl Identity for GlusterIdentity { + async fn get_plugin_info( + &self, + request: Request, + ) -> Result, Status> { + println!("Got a request: {:?}", request); + + let reply = csi::GetPluginInfoResponse { + name: "glusterf-dir-csi".to_string(), + vendor_version: "0.1.0".to_string(), + ..Default::default() + }; + + Ok(Response::new(reply)) + } + + async fn get_plugin_capabilities( + &self, + request: Request, + ) -> Result, Status> { + println!("Got a request: {:?}", request); + + let reply = csi::GetPluginCapabilitiesResponse { + capabilities: vec![csi::PluginCapability { + r#type: Some(csi::plugin_capability::Type::Service( + csi::plugin_capability::Service { + r#type: csi::plugin_capability::service::Type::ControllerService as i32, + }, + )), + }], + }; + + Ok(Response::new(reply)) + } + + async fn probe( + &self, + request: Request, + ) -> Result, Status> { + println!("Got a request: {:?}", request); + + let reply = csi::ProbeResponse { ready: Some(true) }; + + Ok(Response::new(reply)) + } +} + +#[tokio::main] +async fn main() -> Result<(), Box> { + std::fs::create_dir_all("/mnt/main")?; + // Mount glusterfs main + let res = Command::new("mount") + .arg("-t") + .arg("glusterfs") + .arg(format!( + "{}:{}/", + std::env::var("GLUSTER_HOST")?, + std::env::var("GLUSTER_VOLUME")? + )) + .arg("/mnt/main") + .output() + .expect("failed to mount glusterfs"); + + if res.status.success() { + println!("Glusterfs mounted"); + } else { + println!( + "Glusterfs mount failed: {}", + String::from_utf8_lossy(&res.stderr) + ); + return Err("Glusterfs mount failed".into()); + } + + let identity = GlusterIdentity::default(); + let controller = GlusterController::default(); + let node = GlusterNode::default(); + + println!("Starting server..."); + let csi_sock_base = std::env::var("CSI_PATH") + .or_else(|_| Ok::("/csi/".to_owned())) + .unwrap(); + + std::fs::create_dir_all(&csi_sock_base)?; + let csi_sock: String = csi_sock_base + "csi.sock"; + + let uds = UnixListener::bind(csi_sock)?; + let uds_stream = UnixListenerStream::new(uds); + + Server::builder() + .add_service(IdentityServer::new(identity)) + .add_service(ControllerServer::new(controller)) + .add_service(NodeServer::new(node)) + .serve_with_incoming(uds_stream) + .await?; + + Ok(()) +}