Skip to content

Commit

Permalink
Merge pull request #331 from netbox-community/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
tobiasge committed Sep 1, 2020
2 parents e9a9d9b + dd49060 commit 00022e7
Show file tree
Hide file tree
Showing 9 changed files with 35 additions and 17 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
.netbox
.initializers
docker-compose.override.yml
*.pem
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ Before opening an issue on Github, please join the [Network To Code][ntc-slack]

Then there is currently one extra tags for each of the above tags:

* `-ldap`: Contains additional dependencies and configurations for connecting Netbox to an LDAP directroy.
* `-ldap`: Contains additional dependencies and configurations for connecting Netbox to an LDAP directory.
[Learn more about that in our wiki][netbox-docker-ldap].

New images are built and published automatically every ~24h.
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.24.1
0.25.0
4 changes: 4 additions & 0 deletions configuration/configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,10 @@ def read_secret(secret_name):
# are permitted to access most data in NetBox (excluding secrets) but not make any changes.
LOGIN_REQUIRED = os.environ.get('LOGIN_REQUIRED', 'False').lower() == 'true'

# The length of time (in seconds) for which a user will remain logged into the web UI before being prompted to
# re-authenticate. (Default: 1209600 [14 days])
LOGIN_TIMEOUT = os.environ.get('LOGIN_TIMEOUT', None)

# Setting this to True will display a "maintenance mode" banner at the top of every page.
MAINTENANCE_MODE = os.environ.get('MAINTENANCE_MODE', 'False').lower() == 'true'

Expand Down
1 change: 0 additions & 1 deletion docker/nginx.conf
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ http {
proxy_pass http://netbox:8001;
proxy_set_header X-Forwarded-Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-Proto $scheme;
add_header P3P 'CP="ALL DSP COR PSAa PSDa OUR NOR ONL UNI COM NAV"';
}
}
Expand Down
2 changes: 1 addition & 1 deletion startup_scripts/000_users.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
if not User.objects.filter(username=username):
user = User.objects.create_user(
username = username,
password = user_details.get('password', 0) or User.objects.make_random_password)
password = user_details.get('password', 0) or User.objects.make_random_password())

print("👤 Created user",username)

Expand Down
5 changes: 2 additions & 3 deletions startup_scripts/240_virtualization_interfaces.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from dcim.models import Interface
from virtualization.models import VirtualMachine
from virtualization.models import VirtualMachine, VMInterface
from extras.models import CustomField, CustomFieldValue
from startup_script_utils import load_yaml
import sys
Expand All @@ -22,7 +21,7 @@

params[assoc] = model.objects.get(**query)

interface, created = Interface.objects.get_or_create(**params)
interface, created = VMInterface.objects.get_or_create(**params)

if created:
if custom_fields is not None:
Expand Down
27 changes: 18 additions & 9 deletions startup_scripts/260_ip_addresses.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
from ipam.models import IPAddress, VRF
import sys

from dcim.models import Device, Interface
from virtualization.models import VirtualMachine
from tenancy.models import Tenant
from django.contrib.contenttypes.models import ContentType
from django.db.models import Q
from extras.models import CustomField, CustomFieldValue

from ipam.models import VRF, IPAddress
from netaddr import IPNetwork
from startup_script_utils import load_yaml
import sys
from tenancy.models import Tenant
from virtualization.models import VirtualMachine, VMInterface

ip_addresses = load_yaml('/opt/netbox/initializers/ip_addresses.yml')

Expand All @@ -16,9 +18,12 @@
optional_assocs = {
'tenant': (Tenant, 'name'),
'vrf': (VRF, 'name'),
'interface': (Interface, 'name')
'interface': (None, None)
}

vm_interface_ct = ContentType.objects.filter(Q(app_label='virtualization', model='vminterface')).first()
interface_ct = ContentType.objects.filter(Q(app_label='dcim', model='interface')).first()

for params in ip_addresses:
vm = params.pop('virtual_machine', None)
device = params.pop('device', None)
Expand All @@ -35,13 +40,17 @@
if assoc == 'interface':
if vm:
vm_id = VirtualMachine.objects.get(name=vm).id
query = { field: params.pop(assoc), "virtual_machine_id": vm_id }
query = { 'name': params.pop(assoc), "virtual_machine_id": vm_id }
params['assigned_object_type'] = vm_interface_ct
params['assigned_object_id'] = VMInterface.objects.get(**query).id
elif device:
dev_id = Device.objects.get(name=device).id
query = { field: params.pop(assoc), "device_id": dev_id }
query = { 'name': params.pop(assoc), "device_id": dev_id }
params['assigned_object_type'] = interface_ct
params['assigned_object_id'] = Interface.objects.get(**query).id
else:
query = { field: params.pop(assoc) }
params[assoc] = model.objects.get(**query)
params[assoc] = model.objects.get(**query)

ip_address, created = IPAddress.objects.get_or_create(**params)

Expand Down
8 changes: 7 additions & 1 deletion startup_scripts/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,13 @@ def filename(f):

with scandir(dirname(abspath(__file__))) as it:
for f in sorted(it, key = filename):
if f.name.startswith('__') or not f.is_file():
if not f.is_file():
continue

if f.name.startswith('__'):
continue

if not f.name.endswith('.py'):
continue

print(f"▶️ Running the startup script {f.path}")
Expand Down

0 comments on commit 00022e7

Please sign in to comment.