|
Sample Code |
Top Previous Next |
|
Sample VB code showing you how to use the Device object of the CatTools API to add, edit or delete an entry in the database.
Add Dim DB As CatToolsAPI.Database Dim Device As CatToolsAPI.Device
Set DB = New CatToolsAPI.Database If DB.OpenConnection Then Set Device = DB.Devices.AddNew("Cisco.Router.General") If Not Device Is Nothing Then Device.Name = "My Device 01" Device.HostAddress = "192.168.1.1" Device.Group = "My Test Group" Device.RequireVTYLogin = True Device.VTYPass = "My Password" Device.ConnectionMethod = "Telnet" If DB.Devices.SaveDevice(Device) Then Debug.Print Device.Name & " saved to the database OK." Else Debug.Print "Adding " & Device.Name & " failed: " & DB.ErrDescription End If Else Debug.Print "Creation of a new device failed: " & DB.ErrDescription End If Else Debug.Print "DB connection failed: " & DB.ErrDescription End If
Set Device = Nothing Set DB = Nothing
Edit Dim DB As CatToolsAPI.Database Dim Devices As CatToolsAPI.Devices Dim Device As CatToolsAPI.Device
Set DB = New CatToolsAPI.Database If DB.OpenConnection Then Set Devices = DB.Devices Set Device = Devices.GetByName("My Device 01") If Not Device Is Nothing Then Debug.Print Device.Name & " Loaded OK" Device.AAAPassword = "My New Password " If Devices.SaveDevice(Device) Then Debug.Print Device.Name & " saved OK" Else Debug.Print Device.Name & " NOT saved: " & DB.ErrDescription End If Else Debug.Print "Device not found" End If Else Debug.Print "DB connection failed: " & DB.ErrDescription End If
Set Device = Nothing Set Devices = Nothing Set DB = Nothing
Delete Dim DB As CatToolsAPI.Database
Set DB = New CatToolsAPI.Database If DB.OpenConnection Then If DB.Devices.DeleteByName("My Device 01") Then Debug.Print "Deleted OK" Else Debug.Print "Delete failed: " & DB.ErrDescription End If Else Debug.Print "DB connection failed: " & DB.ErrDescription End If
Set DB = Nothing |