Newer
Older
import (
netbox "code.fbi.h-da.de/danet/gosdn/internal/netboxapi"
)
// Hilfsfunktion
func Int32Ptr(i int32) *int32 {
return &i
}
func Int64Ptr(i int64) *int64 {
return &i
}
func StringPtr(s string) *string {
return &s
}
// createDevice creates a device in NetBox
func CreateDevice(name string, deviceTypeID, roleID, siteID int32, serial, description, status string) *netbox.WritableDeviceWithConfigContextRequest {
// /dcim/device-types/ Gerätetyp
device := &netbox.WritableDeviceWithConfigContextRequest{
Name: *netbox.NewNullableString(&name),
Role: netbox.DeviceWithConfigContextRequestRole{Int32: Int32Ptr(roleID)},
Site: netbox.DeviceWithConfigContextRequestSite{Int32: Int32Ptr(siteID)},
DeviceType: netbox.DeviceBayTemplateRequestDeviceType{Int32: Int32Ptr(deviceTypeID)},
Serial: &serial,
Description: &description,
Status: (*netbox.DeviceStatusValue)(&status),
// CreateDeviceType creates a deicetype in NetBox
func CreateDeviceType(manufacturerID netbox.BriefDeviceTypeRequestManufacturer, model, slug string, uHeight float64) *netbox.WritableDeviceTypeRequest {
deviceType := &netbox.WritableDeviceTypeRequest{
Model: model,
Slug: slug,
UHeight: &uHeight,
Manufacturer: manufacturerID,
return deviceType
// CreateManufacturer creates a manufacturer in NetBox
func CreateManufacturer(name, slug, description string) *netbox.ManufacturerRequest {
manufacturer := &netbox.ManufacturerRequest{
Name: name,
Slug: slug,
Description: StringPtr(description),
return manufacturer
// CreateDeviceRole creates a device role in NetBox
func CreateDeviceRole(name, slug, description, color string) *netbox.DeviceRoleRequest {
deviceRole := &netbox.DeviceRoleRequest{
Name: name,
Slug: slug,
Description: StringPtr(description),
Color: &color,
return deviceRole
// CreateSite creates a site in NetBox
func CreateSite(name, slug, description, physicalAddress, shippingAddress, comments string) *netbox.WritableSiteRequest {
site := &netbox.WritableSiteRequest{
Name: name,
Slug: slug,
Description: StringPtr(description),
PhysicalAddress: StringPtr(physicalAddress),
ShippingAddress: StringPtr(shippingAddress),
Comments: StringPtr(comments),
return site
// CreateInterface creates an interface in NetBox
func CreateInterface(name string, deviceID netbox.BriefInterfaceRequestDevice, interfaceType netbox.InterfaceTypeValue, description string, enabled bool) *netbox.WritableInterfaceRequest {
interrface := &netbox.WritableInterfaceRequest{
Name: name,
Device: deviceID,
Type: interfaceType,
Description: StringPtr(description),
Enabled: &enabled,
return interrface
// CreateIPAddress creates an IP address in NetBox
func CreateIPAddress(address, description, status, assignedType string, interfaceID int64) *netbox.WritableIPAddressRequest {
ip := &netbox.WritableIPAddressRequest{
Address: address,
Status: (*netbox.PatchedWritableIPAddressRequestStatus)(&status),
AssignedObjectType: *netbox.NewNullableString(&assignedType),
AssignedObjectId: *netbox.NewNullableInt64(&interfaceID),
Description: StringPtr(description),
return ip