项目作者: benclaussen

项目描述 :
Powershell module for Netbox
高级语言: PowerShell
项目地址: git://github.com/benclaussen/NetboxPS.git
创建时间: 2018-05-18T16:20:07Z
项目社区:https://github.com/benclaussen/NetboxPS

开源协议:MIT License

下载


NetboxPS

Powershell Netbox API module

Disclaimer

This module is beta. Use it at your own risk. I have only added functions as I have needed them, so not everything is available.

All functions are exported at the moment, including internal/private functions.

Description

This module is a wrapper for the Netbox API.

Usage

  1. Install module from the netboxPS folder
  2. Import module
  3. Connect to an API endpoint by using Connect-NetboxAPI -Hostname netbox.example.com

Basic Commands

  1. #Just adding a new IP
  2. New-NetboxIPAMAddress -Address 10.0.0.1/24 -Dns_name this.is.thedns.fqdn -Custom_Fields @{CustomFieldID="CustomFieldContent"} -Tenant 1 -Description "Description"
  3. #Creating a new VM, add an interface and assign Interface IP
  4. function New-NBVirtualMachine
  5. {
  6. [CmdletBinding()]
  7. [Alias()]
  8. [OutputType([int])]
  9. Param
  10. (
  11. [string]$Name,
  12. [string]$Cluster,
  13. [string]$IP,
  14. [string]$tenant,
  15. [string]$VMNICName
  16. )
  17. Begin
  18. {
  19. $NBCluster = Get-NetboxVirtualizationCluster -name $Cluster
  20. $NBTenant = Get-NetboxTenant -Name $tenant
  21. }
  22. Process
  23. {
  24. $vm = New-NetboxVirtualMachine -Name $Name -Cluster $NBCluster.id -Tenant $NBtenant.id
  25. $interface = Add-NetboxVirtualMachineInterface -Name $VMNICName -Virtual_Machine $vm.id
  26. $NBip = New-NetboxIPAMAddress -Address $IP -Tenant $NBtenant.id
  27. Set-NetboxIPAMAddress -Assigned_Object_Type virtualization.vminterface -Assigned_Object_Id $interface.id -id $NBip.id
  28. Set-NetboxVirtualMachine -Primary_IP4 $NBip.id -Id $vm.id
  29. }
  30. }

Notes

I started this project years ago with Powershell Studio using the built in deployment methods, learning Git, and learning PS best practices. So please forgive any “obvious” mistakes 😅
Over time I have had to adjust my methods for deployment… change the design of functions, and refactor code as I learn new and better things.

This was built out of a need at my job to interact with Netbox for automation. Only recently has it become a “public” project with other collaborators (which I truly appreciate!).
I have done my best to ensure each function does exactly one thing according to the API.

I will do my best to keep up, but please understand it is given attention as I can at work. As time permits, I will open issues for TODOs for things I have wanted to do for a while, just haven’t had time or enough “need” to do them.

Contributing

I am always open to suggestions for improvement with reasons and data to back up the suggestion.