netboxgo/virtual_machines.go
2021-11-29 11:38:01 +01:00

102 lines
2.9 KiB
Go

package netboxgo
import (
"context"
"fmt"
"net/http"
"time"
)
type VirtualMachinesService service
// NewVirtualMachine is used to create new VirtualizationVirtualMachines
type NewVirtualMachine struct {
ID int `json:"id"`
Name string `json:"name"`
Status struct {
Label string `json:"label"`
Value int `json:"value"`
} `json:"status"`
Site struct {
ID int `json:"id"`
URL string `json:"url"`
Name string `json:"name"`
Slug string `json:"slug"`
} `json:"site"`
Cluster struct {
ID int `json:"id"`
URL string `json:"url"`
Name string `json:"name"`
VirtualmachineCount int `json:"virtualmachine_count"`
} `json:"cluster"`
Role struct {
ID int `json:"id"`
URL string `json:"url"`
Name string `json:"name"`
Slug string `json:"slug"`
DeviceCount int `json:"device_count"`
VirtualmachineCount int `json:"virtualmachine_count"`
} `json:"role"`
Tenant struct {
ID int `json:"id"`
URL string `json:"url"`
Name string `json:"name"`
Slug string `json:"slug"`
} `json:"tenant"`
Platform struct {
ID int `json:"id"`
URL string `json:"url"`
Name string `json:"name"`
Slug string `json:"slug"`
DeviceCount int `json:"device_count"`
VirtualmachineCount int `json:"virtualmachine_count"`
} `json:"platform"`
PrimaryIP struct {
ID int `json:"id"`
URL string `json:"url"`
Family int `json:"family"`
Address string `json:"address"`
} `json:"primary_ip"`
PrimaryIP4 struct {
ID int `json:"id"`
URL string `json:"url"`
Family int `json:"family"`
Address string `json:"address"`
} `json:"primary_ip4"`
PrimaryIP6 struct {
ID int `json:"id"`
URL string `json:"url"`
Family int `json:"family"`
Address string `json:"address"`
} `json:"primary_ip6"`
Vcpus int `json:"vcpus"`
Memory int `json:"memory"`
Disk int `json:"disk"`
Comments string `json:"comments"`
LocalContextData string `json:"local_context_data"`
Tags []string `json:"tags"`
CustomFields interface{} `json:"custom_fields"`
ConfigContext interface{} `json:"config_context"`
Created string `json:"created"`
LastUpdated time.Time `json:"last_updated"`
}
const virtualMachinesPath = virtualizationPath + "/virtual-machines"
// Create a virtual-machine
func (s *VirtualMachinesService) Create(ctx context.Context, c *NewVirtualMachine) error {
var err error
var req *http.Request
req, err = s.client.newRequest(ctx, "POST", virtualMachinesPath, "", c)
if err != nil {
return fmt.Errorf("unable to create request: %w", err)
}
_, err = s.client.do(req, nil)
if err != nil {
return fmt.Errorf("unable to do request: %w", err)
}
return nil
}