mirror of
https://github.com/nicotsx/ironmount.git
synced 2025-12-10 12:10:51 +01:00
feat: basic volume plugin commands
This commit is contained in:
3
internal/constants/constants.go
Normal file
3
internal/constants/constants.go
Normal file
@@ -0,0 +1,3 @@
|
||||
package constants
|
||||
|
||||
var VolumeRoot = "/tmp/ironmount"
|
||||
17
internal/driver/activate.go
Normal file
17
internal/driver/activate.go
Normal 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
25
internal/driver/create.go
Normal 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
27
internal/driver/mount.go
Normal 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
22
internal/driver/path.go
Normal 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
14
internal/driver/remove.go
Normal 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
8
internal/driver/state.go
Normal 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
22
internal/driver/type.go
Normal 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
|
||||
}
|
||||
10
internal/driver/unmount.go
Normal file
10
internal/driver/unmount.go
Normal 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": ""})
|
||||
}
|
||||
Reference in New Issue
Block a user