Compare commits
5 Commits
0d5b7b6939
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
77571e8062 | ||
|
|
7a4b283ebe | ||
|
|
3f546053f7 | ||
|
|
393306de12 | ||
|
|
8d19fbd549 |
@@ -2,3 +2,52 @@
|
|||||||
|
|
||||||
- Go 1.21+
|
- Go 1.21+
|
||||||
- GNU Make (for build automation)
|
- GNU Make (for build automation)
|
||||||
|
|
||||||
|
## Patterns
|
||||||
|
|
||||||
|
### Instance-scoped Commands
|
||||||
|
|
||||||
|
CLI commands that operate on a specific Wild Cloud instance should follow this pattern:
|
||||||
|
|
||||||
|
```go
|
||||||
|
// In cmd/utility.go
|
||||||
|
var dashboardTokenCmd = &cobra.Command{
|
||||||
|
Use: "token",
|
||||||
|
Short: "Get dashboard token",
|
||||||
|
RunE: func(cmd *cobra.Command, args []string) error {
|
||||||
|
// 1. Get instance from CLI context
|
||||||
|
instanceName, err := getInstanceName()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// 2. Call instance-scoped API endpoint with instance in URL
|
||||||
|
resp, err := apiClient.Get(fmt.Sprintf("/api/v1/instances/%s/utilities/dashboard/token", instanceName))
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// 3. Process response
|
||||||
|
data := resp.GetMap("data")
|
||||||
|
if data == nil {
|
||||||
|
return fmt.Errorf("no data in response")
|
||||||
|
}
|
||||||
|
|
||||||
|
token, ok := data["token"].(string)
|
||||||
|
if !ok {
|
||||||
|
return fmt.Errorf("no token in response")
|
||||||
|
}
|
||||||
|
|
||||||
|
// 4. Display result
|
||||||
|
fmt.Println(token)
|
||||||
|
return nil
|
||||||
|
},
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Key Principles
|
||||||
|
|
||||||
|
1. **Get instance from context**: Use `getInstanceName()` to get the current instance from CLI context
|
||||||
|
2. **Instance in URL path**: Include the instance name in the API endpoint URL path
|
||||||
|
3. **Stateless API calls**: Don't rely on server-side session state - pass instance explicitly
|
||||||
|
4. **Handle errors gracefully**: Return clear error messages if instance is not set or API call fails
|
||||||
|
|||||||
105
cmd/iso.go
105
cmd/iso.go
@@ -26,9 +26,9 @@ var (
|
|||||||
var isoListCmd = &cobra.Command{
|
var isoListCmd = &cobra.Command{
|
||||||
Use: "list",
|
Use: "list",
|
||||||
Short: "List all downloaded ISO images",
|
Short: "List all downloaded ISO images",
|
||||||
Long: `List all downloaded ISO images across all schematics with their versions and platforms.`,
|
Long: `List all downloaded ISO images with their schematic IDs, versions, and platforms.`,
|
||||||
RunE: func(cmd *cobra.Command, args []string) error {
|
RunE: func(cmd *cobra.Command, args []string) error {
|
||||||
resp, err := apiClient.Get("/api/v1/assets")
|
resp, err := apiClient.Get("/api/v1/pxe/assets")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -37,9 +37,9 @@ var isoListCmd = &cobra.Command{
|
|||||||
return printJSON(resp.Data)
|
return printJSON(resp.Data)
|
||||||
}
|
}
|
||||||
|
|
||||||
schematics := resp.GetArray("schematics")
|
assets := resp.GetArray("assets")
|
||||||
if len(schematics) == 0 {
|
if len(assets) == 0 {
|
||||||
fmt.Println("No ISOs found")
|
fmt.Println("No assets found")
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -48,22 +48,21 @@ var isoListCmd = &cobra.Command{
|
|||||||
SchematicID string
|
SchematicID string
|
||||||
Version string
|
Version string
|
||||||
Platform string
|
Platform string
|
||||||
Path string
|
|
||||||
Size int64
|
Size int64
|
||||||
}
|
}
|
||||||
var isos []isoInfo
|
var isos []isoInfo
|
||||||
|
|
||||||
for _, schematic := range schematics {
|
for _, asset := range assets {
|
||||||
if m, ok := schematic.(map[string]interface{}); ok {
|
if m, ok := asset.(map[string]interface{}); ok {
|
||||||
schematicID := fmt.Sprintf("%v", m["schematic_id"])
|
schematicID := fmt.Sprintf("%v", m["schematic_id"])
|
||||||
assets := m["assets"]
|
version := fmt.Sprintf("%v", m["version"])
|
||||||
if assetsList, ok := assets.([]interface{}); ok {
|
assetsList := m["assets"]
|
||||||
for _, asset := range assetsList {
|
if assetsArray, ok := assetsList.([]interface{}); ok {
|
||||||
if assetMap, ok := asset.(map[string]interface{}); ok {
|
for _, assetItem := range assetsArray {
|
||||||
|
if assetMap, ok := assetItem.(map[string]interface{}); ok {
|
||||||
if assetType, _ := assetMap["type"].(string); assetType == "iso" {
|
if assetType, _ := assetMap["type"].(string); assetType == "iso" {
|
||||||
if downloaded, _ := assetMap["downloaded"].(bool); downloaded {
|
if downloaded, _ := assetMap["downloaded"].(bool); downloaded {
|
||||||
path := fmt.Sprintf("%v", assetMap["path"])
|
path := fmt.Sprintf("%v", assetMap["path"])
|
||||||
version := extractVersion(path)
|
|
||||||
platform := extractPlatform(path)
|
platform := extractPlatform(path)
|
||||||
size := int64(0)
|
size := int64(0)
|
||||||
if s, ok := assetMap["size"].(float64); ok {
|
if s, ok := assetMap["size"].(float64); ok {
|
||||||
@@ -74,7 +73,6 @@ var isoListCmd = &cobra.Command{
|
|||||||
SchematicID: schematicID,
|
SchematicID: schematicID,
|
||||||
Version: version,
|
Version: version,
|
||||||
Platform: platform,
|
Platform: platform,
|
||||||
Path: path,
|
|
||||||
Size: size,
|
Size: size,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@@ -90,11 +88,11 @@ var isoListCmd = &cobra.Command{
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Printf("%-10s %-10s %-66s %-10s\n", "VERSION", "PLATFORM", "SCHEMATIC ID", "SIZE")
|
fmt.Printf("%-66s %-10s %-10s %-10s\n", "SCHEMATIC ID", "VERSION", "PLATFORM", "SIZE")
|
||||||
fmt.Println("--------------------------------------------------------------------------------------------------------")
|
fmt.Println("--------------------------------------------------------------------------------------------------------")
|
||||||
for _, iso := range isos {
|
for _, iso := range isos {
|
||||||
sizeMB := float64(iso.Size) / 1024 / 1024
|
sizeMB := float64(iso.Size) / 1024 / 1024
|
||||||
fmt.Printf("%-10s %-10s %-66s %.2f MB\n", iso.Version, iso.Platform, iso.SchematicID, sizeMB)
|
fmt.Printf("%-66s %-10s %-10s %.2f MB\n", iso.SchematicID, iso.Version, iso.Platform, sizeMB)
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
@@ -112,7 +110,6 @@ The ISO can be used to boot bare metal machines.`,
|
|||||||
version := args[1]
|
version := args[1]
|
||||||
|
|
||||||
payload := map[string]interface{}{
|
payload := map[string]interface{}{
|
||||||
"version": version,
|
|
||||||
"platform": isoPlatform,
|
"platform": isoPlatform,
|
||||||
"asset_types": []string{"iso"},
|
"asset_types": []string{"iso"},
|
||||||
}
|
}
|
||||||
@@ -121,12 +118,13 @@ The ISO can be used to boot bare metal machines.`,
|
|||||||
payload["force"] = true
|
payload["force"] = true
|
||||||
}
|
}
|
||||||
|
|
||||||
resp, err := apiClient.Post(fmt.Sprintf("/api/v1/assets/%s/download", schematicID), payload)
|
resp, err := apiClient.Post(fmt.Sprintf("/api/v1/pxe/assets/%s/%s/download", schematicID, version), payload)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Printf("Downloading ISO for schematic: %s\n", schematicID)
|
fmt.Printf("Downloading ISO:\n")
|
||||||
|
fmt.Printf(" Schematic: %s\n", schematicID)
|
||||||
fmt.Printf(" Version: %s\n", version)
|
fmt.Printf(" Version: %s\n", version)
|
||||||
fmt.Printf(" Platform: %s\n", isoPlatform)
|
fmt.Printf(" Platform: %s\n", isoPlatform)
|
||||||
|
|
||||||
@@ -139,17 +137,18 @@ The ISO can be used to boot bare metal machines.`,
|
|||||||
}
|
}
|
||||||
|
|
||||||
var isoDeleteCmd = &cobra.Command{
|
var isoDeleteCmd = &cobra.Command{
|
||||||
Use: "delete <schematic-id>",
|
Use: "delete <schematic-id> <version>",
|
||||||
Short: "Delete a schematic and all its assets",
|
Short: "Delete an asset and all its files",
|
||||||
Long: `Delete a schematic and all its downloaded assets including ISOs.
|
Long: `Delete a specific schematic@version asset and all its downloaded files including ISOs.
|
||||||
This operation cannot be undone.`,
|
This operation cannot be undone.`,
|
||||||
Args: cobra.ExactArgs(1),
|
Args: cobra.ExactArgs(2),
|
||||||
RunE: func(cmd *cobra.Command, args []string) error {
|
RunE: func(cmd *cobra.Command, args []string) error {
|
||||||
schematicID := args[0]
|
schematicID := args[0]
|
||||||
|
version := args[1]
|
||||||
|
|
||||||
// Prompt for confirmation unless --force is used
|
// Prompt for confirmation unless --force is used
|
||||||
if !isoForce {
|
if !isoForce {
|
||||||
fmt.Printf("Are you sure you want to delete schematic %s and all its assets? (yes/no): ", schematicID)
|
fmt.Printf("Are you sure you want to delete %s@%s and all its assets? (yes/no): ", schematicID, version)
|
||||||
reader := bufio.NewReader(cmd.InOrStdin())
|
reader := bufio.NewReader(cmd.InOrStdin())
|
||||||
response, err := reader.ReadString('\n')
|
response, err := reader.ReadString('\n')
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -162,12 +161,12 @@ This operation cannot be undone.`,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
resp, err := apiClient.Delete(fmt.Sprintf("/api/v1/assets/%s", schematicID))
|
resp, err := apiClient.Delete(fmt.Sprintf("/api/v1/pxe/assets/%s/%s", schematicID, version))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Printf("Schematic deleted: %s\n", schematicID)
|
fmt.Printf("Asset deleted: %s@%s\n", schematicID, version)
|
||||||
if msg := resp.GetString("message"); msg != "" {
|
if msg := resp.GetString("message"); msg != "" {
|
||||||
fmt.Printf("Status: %s\n", msg)
|
fmt.Printf("Status: %s\n", msg)
|
||||||
}
|
}
|
||||||
@@ -177,13 +176,14 @@ This operation cannot be undone.`,
|
|||||||
}
|
}
|
||||||
|
|
||||||
var isoInfoCmd = &cobra.Command{
|
var isoInfoCmd = &cobra.Command{
|
||||||
Use: "info <schematic-id>",
|
Use: "info <schematic-id> <version>",
|
||||||
Short: "Show detailed information about ISOs for a schematic",
|
Short: "Show detailed information about a specific asset",
|
||||||
Args: cobra.ExactArgs(1),
|
Args: cobra.ExactArgs(2),
|
||||||
RunE: func(cmd *cobra.Command, args []string) error {
|
RunE: func(cmd *cobra.Command, args []string) error {
|
||||||
schematicID := args[0]
|
schematicID := args[0]
|
||||||
|
version := args[1]
|
||||||
|
|
||||||
resp, err := apiClient.Get(fmt.Sprintf("/api/v1/assets/%s", schematicID))
|
resp, err := apiClient.Get(fmt.Sprintf("/api/v1/pxe/assets/%s/%s", schematicID, version))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -194,25 +194,15 @@ var isoInfoCmd = &cobra.Command{
|
|||||||
|
|
||||||
fmt.Printf("Schematic ID: %s\n", resp.GetString("schematic_id"))
|
fmt.Printf("Schematic ID: %s\n", resp.GetString("schematic_id"))
|
||||||
fmt.Printf("Version: %s\n", resp.GetString("version"))
|
fmt.Printf("Version: %s\n", resp.GetString("version"))
|
||||||
|
fmt.Printf("Path: %s\n", resp.GetString("path"))
|
||||||
if instances := resp.GetArray("instances"); len(instances) > 0 {
|
|
||||||
fmt.Printf("\nInstances using this schematic:\n")
|
|
||||||
for _, inst := range instances {
|
|
||||||
fmt.Printf(" - %s\n", inst)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if assets := resp.GetArray("assets"); len(assets) > 0 {
|
if assets := resp.GetArray("assets"); len(assets) > 0 {
|
||||||
fmt.Println("\nISO Images:")
|
fmt.Println("\nAssets:")
|
||||||
hasISO := false
|
|
||||||
for _, asset := range assets {
|
for _, asset := range assets {
|
||||||
if a, ok := asset.(map[string]interface{}); ok {
|
if a, ok := asset.(map[string]interface{}); ok {
|
||||||
if assetType, _ := a["type"].(string); assetType == "iso" {
|
assetType, _ := a["type"].(string)
|
||||||
hasISO = true
|
|
||||||
downloaded, _ := a["downloaded"].(bool)
|
downloaded, _ := a["downloaded"].(bool)
|
||||||
path := fmt.Sprintf("%v", a["path"])
|
path := fmt.Sprintf("%v", a["path"])
|
||||||
version := extractVersion(path)
|
|
||||||
platform := extractPlatform(path)
|
|
||||||
|
|
||||||
if downloaded {
|
if downloaded {
|
||||||
size := int64(0)
|
size := int64(0)
|
||||||
@@ -220,38 +210,29 @@ var isoInfoCmd = &cobra.Command{
|
|||||||
size = int64(s)
|
size = int64(s)
|
||||||
}
|
}
|
||||||
sizeMB := float64(size) / 1024 / 1024
|
sizeMB := float64(size) / 1024 / 1024
|
||||||
fmt.Printf(" ✓ %s / %s (%.2f MB)\n", version, platform, sizeMB)
|
|
||||||
|
if assetType == "iso" {
|
||||||
|
platform := extractPlatform(path)
|
||||||
|
fmt.Printf(" ✓ ISO (%s): %.2f MB\n", platform, sizeMB)
|
||||||
|
} else {
|
||||||
|
fmt.Printf(" ✓ %s: %.2f MB\n", assetType, sizeMB)
|
||||||
|
}
|
||||||
fmt.Printf(" Path: %s\n", path)
|
fmt.Printf(" Path: %s\n", path)
|
||||||
} else {
|
} else {
|
||||||
fmt.Printf(" ✗ Not downloaded\n")
|
fmt.Printf(" ✗ %s: Not downloaded\n", assetType)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if !hasISO {
|
|
||||||
fmt.Println(" No ISO images found")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
// extractVersion extracts version from ISO filename (e.g., "talos-v1.11.2-metal-amd64.iso" -> "v1.11.2")
|
// extractPlatform extracts platform from filename (e.g., "metal-amd64.iso" -> "amd64")
|
||||||
func extractVersion(path string) string {
|
|
||||||
filename := filepath.Base(path)
|
|
||||||
re := regexp.MustCompile(`talos-(v\d+\.\d+\.\d+)-metal`)
|
|
||||||
matches := re.FindStringSubmatch(filename)
|
|
||||||
if len(matches) > 1 {
|
|
||||||
return matches[1]
|
|
||||||
}
|
|
||||||
return "unknown"
|
|
||||||
}
|
|
||||||
|
|
||||||
// extractPlatform extracts platform from ISO filename (e.g., "talos-v1.11.2-metal-amd64.iso" -> "amd64")
|
|
||||||
func extractPlatform(path string) string {
|
func extractPlatform(path string) string {
|
||||||
filename := filepath.Base(path)
|
filename := filepath.Base(path)
|
||||||
re := regexp.MustCompile(`-(amd64|arm64)\.iso$`)
|
re := regexp.MustCompile(`-(amd64|arm64)\.`)
|
||||||
matches := re.FindStringSubmatch(filename)
|
matches := re.FindStringSubmatch(filename)
|
||||||
if len(matches) > 1 {
|
if len(matches) > 1 {
|
||||||
return matches[1]
|
return matches[1]
|
||||||
|
|||||||
127
cmd/node.go
127
cmd/node.go
@@ -1,7 +1,11 @@
|
|||||||
package cmd
|
package cmd
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"os"
|
||||||
|
"os/signal"
|
||||||
|
"syscall"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
@@ -14,27 +18,83 @@ var nodeCmd = &cobra.Command{
|
|||||||
}
|
}
|
||||||
|
|
||||||
var nodeDiscoverCmd = &cobra.Command{
|
var nodeDiscoverCmd = &cobra.Command{
|
||||||
Use: "discover <ip>...",
|
Use: "discover [subnet]",
|
||||||
Short: "Discover nodes on network",
|
Short: "Discover nodes on network",
|
||||||
Long: "Discover nodes on the network by scanning the provided IP addresses or ranges",
|
Long: `Discover nodes on the network by scanning a subnet or auto-detecting local networks.
|
||||||
Args: cobra.MinimumNArgs(1),
|
|
||||||
|
If a subnet is provided (e.g., 192.168.1.0/24), only that subnet will be scanned.
|
||||||
|
If no subnet is provided, all local networks will be automatically detected and scanned.
|
||||||
|
|
||||||
|
Examples:
|
||||||
|
wild node discover # Auto-detect local networks
|
||||||
|
wild node discover 192.168.1.0/24 # Scan specific subnet`,
|
||||||
|
Args: cobra.MaximumNArgs(1),
|
||||||
RunE: func(cmd *cobra.Command, args []string) error {
|
RunE: func(cmd *cobra.Command, args []string) error {
|
||||||
inst, err := getInstanceName()
|
inst, err := getInstanceName()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Printf("Starting discovery for %d IP(s)...\n", len(args))
|
// Check if --cancel flag is set
|
||||||
_, err = apiClient.Post(fmt.Sprintf("/api/v1/instances/%s/nodes/discover", inst), map[string]interface{}{
|
shouldCancel, _ := cmd.Flags().GetBool("cancel")
|
||||||
"ip_list": args,
|
if shouldCancel {
|
||||||
})
|
// Cancel any running discovery first
|
||||||
|
_, err := apiClient.Post(fmt.Sprintf("/api/v1/instances/%s/discovery/cancel", inst), nil)
|
||||||
|
if err != nil {
|
||||||
|
// Ignore error if no discovery is running
|
||||||
|
fmt.Println("No active discovery to cancel, starting new discovery...")
|
||||||
|
} else {
|
||||||
|
fmt.Println("Cancelled previous discovery, starting new discovery...")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Build request body
|
||||||
|
body := map[string]interface{}{}
|
||||||
|
if len(args) > 0 {
|
||||||
|
body["subnet"] = args[0]
|
||||||
|
fmt.Printf("Starting discovery for subnet %s...\n", args[0])
|
||||||
|
} else {
|
||||||
|
fmt.Println("Starting discovery (auto-detecting local networks)...")
|
||||||
|
}
|
||||||
|
|
||||||
|
_, err = apiClient.Post(fmt.Sprintf("/api/v1/instances/%s/nodes/discover", inst), body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Set up signal handling for Ctrl-C
|
||||||
|
ctx, cancel := context.WithCancel(context.Background())
|
||||||
|
defer cancel()
|
||||||
|
|
||||||
|
sigChan := make(chan os.Signal, 1)
|
||||||
|
signal.Notify(sigChan, os.Interrupt, syscall.SIGTERM)
|
||||||
|
|
||||||
|
// Handle signals in a goroutine
|
||||||
|
go func() {
|
||||||
|
<-sigChan
|
||||||
|
fmt.Println("\n\nCancelling discovery...")
|
||||||
|
cancel()
|
||||||
|
|
||||||
|
// Call cancel API
|
||||||
|
_, err := apiClient.Post(fmt.Sprintf("/api/v1/instances/%s/discovery/cancel", inst), nil)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Printf("Failed to cancel discovery: %v\n", err)
|
||||||
|
} else {
|
||||||
|
fmt.Println("Discovery cancelled successfully")
|
||||||
|
}
|
||||||
|
os.Exit(0)
|
||||||
|
}()
|
||||||
|
|
||||||
// Poll for completion
|
// Poll for completion
|
||||||
fmt.Println("Scanning nodes...")
|
fmt.Println("Scanning nodes... (Press Ctrl-C to cancel)")
|
||||||
|
ticker := time.NewTicker(500 * time.Millisecond)
|
||||||
|
defer ticker.Stop()
|
||||||
|
|
||||||
for {
|
for {
|
||||||
|
select {
|
||||||
|
case <-ctx.Done():
|
||||||
|
return nil
|
||||||
|
case <-ticker.C:
|
||||||
resp, err := apiClient.Get(fmt.Sprintf("/api/v1/instances/%s/discovery", inst))
|
resp, err := apiClient.Get(fmt.Sprintf("/api/v1/instances/%s/discovery", inst))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@@ -49,21 +109,29 @@ var nodeDiscoverCmd = &cobra.Command{
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Printf("\nFound %d node(s):\n\n", len(nodesFound))
|
fmt.Printf("\nFound %d node(s) in maintenance mode:\n\n", len(nodesFound))
|
||||||
fmt.Printf("%-15s %-12s %-10s\n", "IP", "INTERFACE", "VERSION")
|
fmt.Printf("%-15s %-15s %-15s\n", "IP", "VERSION", "HOSTNAME")
|
||||||
fmt.Println("-----------------------------------------------")
|
fmt.Println("-----------------------------------------------------")
|
||||||
for _, node := range nodesFound {
|
for _, node := range nodesFound {
|
||||||
if m, ok := node.(map[string]interface{}); ok {
|
if m, ok := node.(map[string]interface{}); ok {
|
||||||
fmt.Printf("%-15s %-12s %-10s\n",
|
version := m["version"]
|
||||||
m["ip"], m["interface"], m["version"])
|
if version == nil {
|
||||||
|
version = ""
|
||||||
|
}
|
||||||
|
hostname := m["hostname"]
|
||||||
|
if hostname == nil {
|
||||||
|
hostname = ""
|
||||||
|
}
|
||||||
|
fmt.Printf("%-15s %-15s %-15s\n",
|
||||||
|
m["ip"], version, hostname)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Still running, wait a bit
|
// Still running, show progress
|
||||||
fmt.Print(".")
|
fmt.Print(".")
|
||||||
time.Sleep(500 * time.Millisecond)
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
@@ -431,6 +499,31 @@ You can use it manually to update templates.`,
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var nodeCancelDiscoveryCmd = &cobra.Command{
|
||||||
|
Use: "cancel-discovery",
|
||||||
|
Short: "Cancel active node discovery",
|
||||||
|
Long: `Cancel an active node discovery operation.
|
||||||
|
|
||||||
|
Use this if discovery gets stuck or you want to stop a running scan.
|
||||||
|
|
||||||
|
Example:
|
||||||
|
wild node cancel-discovery`,
|
||||||
|
RunE: func(cmd *cobra.Command, args []string) error {
|
||||||
|
inst, err := getInstanceName()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
_, err = apiClient.Post(fmt.Sprintf("/api/v1/instances/%s/discovery/cancel", inst), nil)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
fmt.Println("Discovery cancelled successfully")
|
||||||
|
return nil
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
var nodeDeleteCmd = &cobra.Command{
|
var nodeDeleteCmd = &cobra.Command{
|
||||||
Use: "delete <hostname>",
|
Use: "delete <hostname>",
|
||||||
Short: "Delete a node",
|
Short: "Delete a node",
|
||||||
@@ -453,6 +546,7 @@ var nodeDeleteCmd = &cobra.Command{
|
|||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
nodeCmd.AddCommand(nodeDiscoverCmd)
|
nodeCmd.AddCommand(nodeDiscoverCmd)
|
||||||
|
nodeCmd.AddCommand(nodeCancelDiscoveryCmd)
|
||||||
nodeCmd.AddCommand(nodeDetectCmd)
|
nodeCmd.AddCommand(nodeDetectCmd)
|
||||||
nodeCmd.AddCommand(nodeListCmd)
|
nodeCmd.AddCommand(nodeListCmd)
|
||||||
nodeCmd.AddCommand(nodeShowCmd)
|
nodeCmd.AddCommand(nodeShowCmd)
|
||||||
@@ -462,6 +556,9 @@ func init() {
|
|||||||
nodeCmd.AddCommand(nodeFetchTemplatesCmd)
|
nodeCmd.AddCommand(nodeFetchTemplatesCmd)
|
||||||
nodeCmd.AddCommand(nodeDeleteCmd)
|
nodeCmd.AddCommand(nodeDeleteCmd)
|
||||||
|
|
||||||
|
// Add flags to node discover command
|
||||||
|
nodeDiscoverCmd.Flags().Bool("cancel", false, "Cancel any running discovery before starting")
|
||||||
|
|
||||||
// Add flags to node add command
|
// Add flags to node add command
|
||||||
nodeAddCmd.Flags().String("target-ip", "", "Target IP address for production")
|
nodeAddCmd.Flags().String("target-ip", "", "Target IP address for production")
|
||||||
nodeAddCmd.Flags().String("current-ip", "", "Current IP address (for maintenance mode)")
|
nodeAddCmd.Flags().String("current-ip", "", "Current IP address (for maintenance mode)")
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ var operationGetCmd = &cobra.Command{
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
resp, err := apiClient.Get(fmt.Sprintf("/api/v1/operations/%s?instance=%s", args[0], inst))
|
resp, err := apiClient.Get(fmt.Sprintf("/api/v1/instances/%s/operations/%s", inst, args[0]))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -43,7 +43,12 @@ var operationListCmd = &cobra.Command{
|
|||||||
Use: "list",
|
Use: "list",
|
||||||
Short: "List operations",
|
Short: "List operations",
|
||||||
RunE: func(cmd *cobra.Command, args []string) error {
|
RunE: func(cmd *cobra.Command, args []string) error {
|
||||||
resp, err := apiClient.Get("/api/v1/operations")
|
inst, err := getInstanceName()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
resp, err := apiClient.Get(fmt.Sprintf("/api/v1/instances/%s/operations", inst))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -90,7 +95,7 @@ func streamOperationOutput(opID string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Connect to SSE stream
|
// Connect to SSE stream
|
||||||
url := fmt.Sprintf("%s/api/v1/operations/%s/stream?instance=%s", baseURL, opID, inst)
|
url := fmt.Sprintf("%s/api/v1/instances/%s/operations/%s/stream", baseURL, inst, opID)
|
||||||
client := sse.NewClient(url)
|
client := sse.NewClient(url)
|
||||||
events := make(chan *sse.Event)
|
events := make(chan *sse.Event)
|
||||||
|
|
||||||
@@ -105,7 +110,7 @@ func streamOperationOutput(opID string) error {
|
|||||||
ticker := time.NewTicker(500 * time.Millisecond)
|
ticker := time.NewTicker(500 * time.Millisecond)
|
||||||
defer ticker.Stop()
|
defer ticker.Stop()
|
||||||
for range ticker.C {
|
for range ticker.C {
|
||||||
resp, err := apiClient.Get(fmt.Sprintf("/api/v1/operations/%s?instance=%s", opID, inst))
|
resp, err := apiClient.Get(fmt.Sprintf("/api/v1/instances/%s/operations/%s", inst, opID))
|
||||||
if err == nil {
|
if err == nil {
|
||||||
status := resp.GetString("status")
|
status := resp.GetString("status")
|
||||||
if status == "completed" || status == "failed" {
|
if status == "completed" || status == "failed" {
|
||||||
|
|||||||
@@ -38,7 +38,11 @@ var dashboardTokenCmd = &cobra.Command{
|
|||||||
Use: "token",
|
Use: "token",
|
||||||
Short: "Get dashboard token",
|
Short: "Get dashboard token",
|
||||||
RunE: func(cmd *cobra.Command, args []string) error {
|
RunE: func(cmd *cobra.Command, args []string) error {
|
||||||
resp, err := apiClient.Get("/api/v1/utilities/dashboard/token")
|
instanceName, err := getInstanceName()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
resp, err := apiClient.Get(fmt.Sprintf("/api/v1/instances/%s/utilities/dashboard/token", instanceName))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -68,7 +72,12 @@ var nodeIPCmd = &cobra.Command{
|
|||||||
Use: "node-ip",
|
Use: "node-ip",
|
||||||
Short: "Get control plane IP",
|
Short: "Get control plane IP",
|
||||||
RunE: func(cmd *cobra.Command, args []string) error {
|
RunE: func(cmd *cobra.Command, args []string) error {
|
||||||
resp, err := apiClient.Get("/api/v1/utilities/controlplane/ip")
|
inst, err := getInstanceName()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
resp, err := apiClient.Get(fmt.Sprintf("/api/v1/instances/%s/utilities/controlplane/ip", inst))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,7 +24,9 @@ var versionCmd = &cobra.Command{
|
|||||||
|
|
||||||
// If connected to daemon, show cluster versions
|
// If connected to daemon, show cluster versions
|
||||||
if apiClient != nil {
|
if apiClient != nil {
|
||||||
resp, err := apiClient.Get("/api/v1/utilities/version")
|
inst, err := getInstanceName()
|
||||||
|
if err == nil {
|
||||||
|
resp, err := apiClient.Get(fmt.Sprintf("/api/v1/instances/%s/utilities/version", inst))
|
||||||
if err == nil {
|
if err == nil {
|
||||||
if k8s, ok := resp.Data["kubernetes"].(string); ok {
|
if k8s, ok := resp.Data["kubernetes"].(string); ok {
|
||||||
fmt.Printf("Kubernetes: %s\n", k8s)
|
fmt.Printf("Kubernetes: %s\n", k8s)
|
||||||
@@ -34,5 +36,6 @@ var versionCmd = &cobra.Command{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user