From c5960a55a99c71a9dd056ea25dd7c1c182ef5570 Mon Sep 17 00:00:00 2001 From: Fabian Stamm Date: Sun, 6 Nov 2022 17:38:49 +0100 Subject: [PATCH] Switch from python to rust --- .dockerignore | 1 + .gitignore | 3 +- .tool-versions | 1 - Cargo.lock | 1023 ++++++++++++++++++++++ Cargo.toml | 17 + Dockerfile | 33 +- README.md | 6 - __pycache__/csi_pb2.cpython-310.pyc | Bin 31009 -> 0 bytes __pycache__/csi_pb2_grpc.cpython-310.pyc | Bin 15872 -> 0 bytes bin/build.sh | 3 - bin/gen-protos.sh | 3 - bin/push.sh | 3 - bin/test_part1.sh | 2 - build.rs | 4 + csi-spec | 2 +- main.py | 138 --- requirements.txt | 5 - src/main.rs | 454 ++++++++++ 18 files changed, 1525 insertions(+), 173 deletions(-) create mode 100644 .dockerignore delete mode 100644 .tool-versions create mode 100644 Cargo.lock create mode 100644 Cargo.toml delete mode 100644 README.md delete mode 100644 __pycache__/csi_pb2.cpython-310.pyc delete mode 100644 __pycache__/csi_pb2_grpc.cpython-310.pyc delete mode 100755 bin/build.sh delete mode 100755 bin/gen-protos.sh delete mode 100755 bin/push.sh delete mode 100755 bin/test_part1.sh create mode 100644 build.rs delete mode 100644 main.py delete mode 100644 requirements.txt create mode 100644 src/main.rs 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 e38a390561de09190b44288a07da7247f4d8a0bc..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 31009 zcmeHw33wdUm2OL|wIs`O%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!MCnEp%i~s4v|0$3+=$<1==&+TeSG+l6$4b&l$E` 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(()) +}