feat: basic volume plugin commands

This commit is contained in:
Nicolas Meienberger
2025-08-09 12:36:16 +02:00
parent 8d86f56b87
commit e7463d34ef
13 changed files with 222 additions and 9 deletions

View File

@@ -0,0 +1,17 @@
package driver
import (
"encoding/json"
"log"
"net/http"
)
func Activate(w http.ResponseWriter, r *http.Request) {
// Log the activation request
log.Printf("Received activation request: %s", r.URL.Path)
resp := map[string]any{
"Implements": []string{"VolumeDriver"},
}
_ = json.NewEncoder(w).Encode(resp)
}

25
internal/driver/create.go Normal file
View File

@@ -0,0 +1,25 @@
package driver
import (
"encoding/json"
"ironmount/internal/constants"
"net/http"
"os"
"path/filepath"
)
func Create(w http.ResponseWriter, r *http.Request) {
var req struct {
Name string
}
_ = json.NewDecoder(r.Body).Decode(&req)
volPath := filepath.Join(constants.VolumeRoot, req.Name)
if err := os.MkdirAll(volPath, 0755); err != nil {
_ = json.NewEncoder(w).Encode(map[string]string{"Err": err.Error()})
return
}
volumes[req.Name] = Volume{Name: req.Name, Path: volPath}
_ = json.NewEncoder(w).Encode(map[string]string{"Err": ""})
}

27
internal/driver/mount.go Normal file
View File

@@ -0,0 +1,27 @@
package driver
import (
"encoding/json"
"net/http"
)
func Mount(w http.ResponseWriter, r *http.Request) {
var req MountRequest
err := json.NewDecoder(r.Body).Decode(&req)
if err != nil {
http.Error(w, "Invalid request body", http.StatusBadRequest)
return
}
vol, ok := volumes[req.Name]
if !ok {
_ = json.NewEncoder(w).Encode(map[string]string{"Err": "volume not found"})
return
}
_ = json.NewEncoder(w).Encode(map[string]string{
"Mountpoint": vol.Path,
"Err": "",
})
}

22
internal/driver/path.go Normal file
View File

@@ -0,0 +1,22 @@
package driver
import (
"encoding/json"
"net/http"
)
func Path(w http.ResponseWriter, r *http.Request) {
var req PathRequest
_ = json.NewDecoder(r.Body).Decode(&req)
vol, ok := volumes[req.Name]
if !ok {
_ = json.NewEncoder(w).Encode(map[string]string{"Err": "volume not found"})
return
}
_ = json.NewEncoder(w).Encode(map[string]string{
"Mountpoint": vol.Path,
"Err": "",
})
}

14
internal/driver/remove.go Normal file
View File

@@ -0,0 +1,14 @@
package driver
import (
"encoding/json"
"net/http"
)
func Remove(w http.ResponseWriter, r *http.Request) {
var req RemoveRequest
_ = json.NewDecoder(r.Body).Decode(&req)
delete(volumes, req.Name)
_ = json.NewEncoder(w).Encode(map[string]string{"Err": ""})
}

8
internal/driver/state.go Normal file
View File

@@ -0,0 +1,8 @@
package driver
type Volume struct {
Name string
Path string
}
var volumes = map[string]Volume{}

22
internal/driver/type.go Normal file
View File

@@ -0,0 +1,22 @@
package driver
// CreateRequest is the JSON request for Create
type CreateRequest struct {
Name string
}
// RemoveRequest is the JSON request for Remove
type RemoveRequest struct {
Name string
}
// MountRequest is the JSON request for Mount
type MountRequest struct {
Name string
ID string
}
// PathRequest is the JSON request for Path
type PathRequest struct {
Name string
}

View File

@@ -0,0 +1,10 @@
package driver
import (
"encoding/json"
"net/http"
)
func Unmount(w http.ResponseWriter, r *http.Request) {
_ = json.NewEncoder(w).Encode(map[string]string{"Err": ""})
}