Skip to content
Snippets Groups Projects
netboxUtility.go 3.46 KiB
Newer Older
  • Learn to ignore specific revisions
  • package netboxManager
    
    
    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),
    
    	}
    	return device
    }
    
    
    // CreateDeviceType creates a deicetype in NetBox
    func CreateDeviceType(manufacturerID netbox.BriefDeviceTypeRequestManufacturer, model, slug string, uHeight float64) *netbox.WritableDeviceTypeRequest {
    
    	// /dcim/device-types/ 		Gerätetyp
    
    	deviceType := &netbox.WritableDeviceTypeRequest{
    		Model:        model,
    		Slug:         slug,
    		UHeight:      &uHeight,
    		Manufacturer: manufacturerID,
    
    // CreateManufacturer creates a manufacturer in NetBox
    func CreateManufacturer(name, slug, description string) *netbox.ManufacturerRequest {
    
    	// /dcim/manufacturers/		Hersteller
    
    	manufacturer := &netbox.ManufacturerRequest{
    		Name:        name,
    		Slug:        slug,
    		Description: StringPtr(description),
    
    // CreateDeviceRole creates a device role in NetBox
    func CreateDeviceRole(name, slug, description, color string) *netbox.DeviceRoleRequest {
    
    	// /dcim/device-roles/		Geräterolle
    
    	deviceRole := &netbox.DeviceRoleRequest{
    		Name:        name,
    		Slug:        slug,
    		Description: StringPtr(description),
    		Color:       &color,
    
    // CreateSite creates a site in NetBox
    func CreateSite(name, slug, description, physicalAddress, shippingAddress, comments string) *netbox.WritableSiteRequest {
    
    	// /dcim/sites/		Standorts
    
    	site := &netbox.WritableSiteRequest{
    		Name:            name,
    		Slug:            slug,
    		Description:     StringPtr(description),
    		PhysicalAddress: StringPtr(physicalAddress),
    		ShippingAddress: StringPtr(shippingAddress),
    		Comments:        StringPtr(comments),
    
    // 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,
    
    // CreateIPAddress creates an IP address in NetBox
    
    func CreateIPAddress(address, description, status, assignedType string, interfaceID int64) *netbox.WritableIPAddressRequest {
    
    	// /api/ipam/ip-addresses/
    
    
    	ip := &netbox.WritableIPAddressRequest{
    		Address:            address,
    
    		Status:             (*netbox.PatchedWritableIPAddressRequestStatus)(&status),
    
    		AssignedObjectType: *netbox.NewNullableString(&assignedType),
    		AssignedObjectId:   *netbox.NewNullableInt64(&interfaceID),
    
    		Description:        StringPtr(description),