Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add OpenStack & oVirt Support #132

Closed
wants to merge 12 commits into from
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -39,6 +39,7 @@ This ensures stale objects are removed from NetBox keeping an accurate current s
* aiodns==2.0.0
* setuptools>=62.00.0
* pyyaml==6.0
* openstack

### Environment
* NetBox >= 2.9
5 changes: 3 additions & 2 deletions module/sources/__init__.py
Original file line number Diff line number Diff line change
@@ -9,6 +9,8 @@

# define all available sources here
from module.sources.vmware.connection import VMWareHandler
from module.sources.openstack.connection import OpenStackHandler
from module.sources.ovirt.connection import OVirtHandler
from module.sources.check_redfish.import_inventory import CheckRedfish

from module.common.logging import get_logger
@@ -18,8 +20,7 @@
from module.config import source_config_section_name

# list of valid sources
valid_sources = [VMWareHandler, CheckRedfish]

valid_sources = [VMWareHandler, OpenStackHandler, OVirtHandler, CheckRedfish]

def validate_source(source_class_object=None, state="pre"):
"""
377 changes: 377 additions & 0 deletions module/sources/openstack/config.py

Large diffs are not rendered by default.

1,171 changes: 1,171 additions & 0 deletions module/sources/openstack/connection.py

Large diffs are not rendered by default.

359 changes: 359 additions & 0 deletions module/sources/ovirt/config.py

Large diffs are not rendered by default.

1,285 changes: 1,285 additions & 0 deletions module/sources/ovirt/connection.py

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -6,3 +6,4 @@ pyvmomi==7.0.3
aiodns==3.0.0
setuptools>=62.00.0
pyyaml==6.0
openstack
266 changes: 266 additions & 0 deletions settings-example.ini
Original file line number Diff line number Diff line change
@@ -403,4 +403,270 @@ inventory_file_path = /full/path/to/inventory/files
; If the device has a tenant then this one will be used. If not, the prefix tenant will be used if defined
;ip_tenant_inheritance_order = device, prefix


[source/my-openstack-example]

# Defines if this source is enabled or not
#enabled = true

# type of source. This defines which source handler to use.
type = openstack

# URL to the Openstack API
auth_url = https://api.openstack-instance.local:5000/v3

# Openstack project to connect to
project = MyProject

# Openstack region
region = RegionOne

# Openstack user_domain
user_domain = Default

# Openstack project_domain
project_domain = Default

# Enforces TLS certificate validation. If Openstack API uses a valid TLS certificate then
# this option should be set to 'true' to ensure a secure connection.
#validate_tls_certs = false

# username and password to use to log into OpenStack
username = openstackuser
password = supersecret

# IP networks eligible to be synced to NetBox.
# If an IP address is not part of this networks then it WON'T be synced to NetBox
permitted_subnets = 172.16.0.0/12, 10.0.0.0/8, 192.168.0.0/16, fd00::/8

# filters can be used to include/exclude certain objects from importing into NetBox
# Include filters are checked first and exclude filters after. An object name has to
# pass both filters to be synced to NetBox. If a filter is unset it will be ignored.
# Filters are all treated as regex expressions!

# If a cluster is excluded from sync then ALL VMs and HOSTS inside the cluster will
# be ignored!
#cluster_exclude_filter =
#cluster_include_filter =

# This will only include/exclude the host, not the VM if Host is part of a multi host
# cluster.
#host_exclude_filter =
#host_include_filter =

# simply include/exclude VMs
#vm_exclude_filter =
#vm_include_filter =

# This option defines which Openstack Availability Zones is part of a NetBox site. This is done
# with a comma separated key = value list.
# key: defines the cluster name as regex
# value: defines the NetBox site name (use quotes if name contains commas)
# This is a quite important config setting as IP addresses, prefixes, VLANs and
# VRFs are site dependent. In order to assign the correct prefix to an IP
# address it is important to pick the correct site.
# A VM always depends on the cluster site relation
#cluster_site_relation = Cluster_NYC = New York , Cluster_FFM.* = Frankfurt

# Same as cluster site but on host level. If unset it will fall back
# to cluster_site_relation.
#host_site_relation = nyc02.* = New York, ffm01.* = Frankfurt

# This option defines which cluster/host/VM belongs to which tenant. This is done
# with a comma separated key = value list.
# key: defines a hosts/VM name as regex
# value: defines the NetBox tenant name (use quotes if name contains commas)
#cluster_tenant_relation = Cluster_NYC.* = Customer A
#host_tenant_relation = esxi300.* = Infrastructure
#vm_tenant_relation = grafana.* = Infrastructure

# This option defines custom platforms if the used Flavors are not suitable.
# Pretty much a mapping of Openstack flavor name to your own platform name.
# This is done with a comma separated key = value list.
# key: defines a Openstack returned flavor name
# value: defines the desired NetBox platform name
#vm_platform_relation = centos-7.* = centos7, microsoft-windows-server-2016.* = Windows2016

# Define the NetBox device role used for hosts and VMs. The default is set to "Server". This is done
# with a comma separated key = value list.
# key: defines a hosts/VM name as regex
# value: defines the NetBox role name (use quotes if name contains commas)
#host_role_relation = .* = Server
#vm_role_relation = .* = Server

# Define NetBox tags which are assigned to a cluster, host or VM. This is done
# with a comma separated key = value list.
# key: defines a hosts/VM name as regex
# value: defines the NetBox tag (use quotes if name contains commas)
#cluster_tag_relation = Cluster_NYC.* = Infrastructure
#host_tag_relation = esxi300.* = Infrastructure
#vm_tag_relation = grafana.* = Infrastructure

# Perform a reverse lookup for all collected IP addresses. If a dns name
# was found it will be added to the IP address object in NetBox
#dns_name_lookup = True

# use custom DNS server to do the reverse lookups
#custom_dns_servers = 192.168.1.11, 192.168.1.12

# define how the primary IPs should be set
# possible values
#
# always: will remove primary IP from the object where this address is
# currently set as primary and moves it to new object
#
# when-undefined: (default)
# only sets primary IP if undefined, will cause ERRORs if same IP is
# assigned more then once to different hosts and IP is set as the
# objects primary IP
#
# never: don't set any primary IPs, will cause the same ERRORs
# as "when-undefined"

#set_primary_ip = when-undefined

# Do not sync flavors from a VM in Openstack to the comments field on a VM in netbox
#skip_vm_platform = False

# Do not sync ID from a VM in Openstack to the comments field on a VM in netbox
#skip_vm_comments = False

# strip domain part from host name before syncing device to NetBox
#strip_host_domain_name = False

# strip domain part from VM name before syncing VM to NetBox
#strip_vm_domain_name = False

# Set name in Netbox to the UUID instead of the name in Openstack
# This is useful as the names are not always unique
#set_vm_name_to_uuid = False

[source/my-ovirt-example]

# Defines if this source is enabled or not
#enabled = true

# type of source. This defines which source handler to use.
type = ovirt

# URL to the oVirt API
url = https://engine40.example.com/ovirt-engine/api

# CA file path to validate oVirt certificate.
ca_file = "ca.pem"

# Enforces TLS certificate validation. If Openstack API uses a valid TLS certificate then
# this option should be set to 'true' to ensure a secure connection.
#validate_tls_certs = false

# username and password to use to log into OpenStack
username = ovirtuser
password = supersecret

# IP networks eligible to be synced to NetBox.
# If an IP address is not part of this networks then it WON'T be synced to NetBox
permitted_subnets = 172.16.0.0/12, 10.0.0.0/8, 192.168.0.0/16, fd00::/8

# filters can be used to include/exclude certain objects from importing into NetBox
# Include filters are checked first and exclude filters after. An object name has to
# pass both filters to be synced to NetBox. If a filter is unset it will be ignored.
# Filters are all treated as regex expressions!

# If a cluster is excluded from sync then ALL VMs and HOSTS inside the cluster will
# be ignored!
#cluster_exclude_filter =
#cluster_include_filter =

# This will only include/exclude the host, not the VM if Host is part of a multi host
# cluster.
#host_exclude_filter =
#host_include_filter =

# simply include/exclude VMs
#vm_exclude_filter =
#vm_include_filter =

# This option defines which Openstack Availability Zones is part of a NetBox site. This is done
# with a comma separated key = value list.
# key: defines the cluster name as regex
# value: defines the NetBox site name (use quotes if name contains commas)
# This is a quite important config setting as IP addresses, prefixes, VLANs and
# VRFs are site dependent. In order to assign the correct prefix to an IP
# address it is important to pick the correct site.
# A VM always depends on the cluster site relation
#cluster_site_relation = Cluster_NYC = New York , Cluster_FFM.* = Frankfurt

# Same as cluster site but on host level. If unset it will fall back
# to cluster_site_relation.
#host_site_relation = nyc02.* = New York, ffm01.* = Frankfurt

# This option defines which cluster/host/VM belongs to which tenant. This is done
# with a comma separated key = value list.
# key: defines a hosts/VM name as regex
# value: defines the NetBox tenant name (use quotes if name contains commas)
#cluster_tenant_relation = Cluster_NYC.* = Customer A
#host_tenant_relation = esxi300.* = Infrastructure
#vm_tenant_relation = grafana.* = Infrastructure

# This option defines custom platforms if the used Flavors are not suitable.
# Pretty much a mapping of Openstack flavor name to your own platform name.
# This is done with a comma separated key = value list.
# key: defines a Openstack returned flavor name
# value: defines the desired NetBox platform name
#vm_platform_relation = centos-7.* = centos7, microsoft-windows-server-2016.* = Windows2016

# Define the NetBox device role used for hosts and VMs. The default is set to "Server". This is done
# with a comma separated key = value list.
# key: defines a hosts/VM name as regex
# value: defines the NetBox role name (use quotes if name contains commas)
#host_role_relation = .* = Server
#vm_role_relation = .* = Server

# Define NetBox tags which are assigned to a cluster, host or VM. This is done
# with a comma separated key = value list.
# key: defines a hosts/VM name as regex
# value: defines the NetBox tag (use quotes if name contains commas)
#cluster_tag_relation = Cluster_NYC.* = Infrastructure
#host_tag_relation = esxi300.* = Infrastructure
#vm_tag_relation = grafana.* = Infrastructure

# Perform a reverse lookup for all collected IP addresses. If a dns name
# was found it will be added to the IP address object in NetBox
#dns_name_lookup = True

# use custom DNS server to do the reverse lookups
#custom_dns_servers = 192.168.1.11, 192.168.1.12

# define how the primary IPs should be set
# possible values
#
# always: will remove primary IP from the object where this address is
# currently set as primary and moves it to new object
#
# when-undefined: (default)
# only sets primary IP if undefined, will cause ERRORs if same IP is
# assigned more then once to different hosts and IP is set as the
# objects primary IP
#
# never: don't set any primary IPs, will cause the same ERRORs
# as "when-undefined"

#set_primary_ip = when-undefined

# Do not sync flavors from a VM in Openstack to the comments field on a VM in netbox
#skip_vm_platform = False

# Do not sync ID from a VM in Openstack to the comments field on a VM in netbox
#skip_vm_comments = False

# strip domain part from host name before syncing device to NetBox
#strip_host_domain_name = False

# strip domain part from VM name before syncing VM to NetBox
#strip_vm_domain_name = False

# Set name in Netbox to the UUID instead of the name in Openstack
# This is useful as the names are not always unique
#set_vm_name_to_uuid = False

;EOF