Skip to content

Commit

Permalink
Added apply network command
Browse files Browse the repository at this point in the history
Allows network configurations to be applied through the Proxmox api
  • Loading branch information
dandyrow committed Oct 17, 2022
1 parent 51b045d commit ff715ce
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
11 changes: 11 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -708,6 +708,17 @@ func main() {
failError(config.CreateNetwork(c))
log.Printf("Network %s has been created\n", config.Iface)

case "applyNetwork":
if len(flag.Args()) < 2 {
failError(fmt.Errorf("error: Proxmox node name required"))
}
node := flag.Args()[1]
exitStatus, err := c.ApplyNetwork(node)
if err != nil {
failError(fmt.Errorf("error: %+v\n api error: %s", err, exitStatus))
}
log.Printf("Network configuration on node %s has been applied\n", node)

default:
fmt.Printf("unknown action, try start|stop vmid\n")
}
Expand Down
8 changes: 8 additions & 0 deletions proxmox/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -1828,6 +1828,14 @@ func (client *Client) CreateNetwork(node string, params map[string]interface{})
return
}

func (client Client) ApplyNetwork(node string) (exitStatus string, err error) {
paramMap := map[string]interface{}{
"node": node,
}

return client.UpdateItemWithTask(paramMap, "/nodes/"+node+"/network")
}

// Shared
func (c *Client) GetItemConfigMapStringInterface(url, text, message string) (map[string]interface{}, error) {
data, err := c.GetItemConfig(url, text, message)
Expand Down

0 comments on commit ff715ce

Please sign in to comment.