Arranging Netbox in a Virtualenv

538 views
Skip to first unread message

Alasdair Muckart

unread,
Jun 9, 2018, 4:32:49 AM6/9/18
to netbox-...@googlegroups.com
Hi all,

I'm a bit new to Python, and I'm wondering what the best way to organize Netbox in a virtualenv is on Centos 7.

I'm thinking of putting the virtualenv in /opt/netbox-venv and symlinking /opt/netbox-venv/netbox-2.3.4/netbox to /opt/netbox and pointing my nginx config to there to pick up the static files.

Is this a sane approach? Are there better ways to do it?

Thanks.
--
Alasdair Muckart | William de Wyke | http://wherearetheelves.net
"There is hardly anything in the world that some man cannot make a little worse
and sell a little cheaper, and the people who consider price only are this man's
lawful prey." - John Ruskin, 1819-1900.

Matthew Yauch

unread,
Jun 11, 2018, 10:47:57 AM6/11/18
to NetBox
Couple of qualifications:
  Everyone has their own workflow and preferences.
  I've never used virtualenv.

I suggest taking a serious look at Docker containers.  It's like virtualenv in that you can have whatever version of Python, modules, dependencies, etc. you want, but then you can also have whatever version of any software installed on the system, and in fact use any OS that uses the Linux kernel.  Then you can have it packaged in such a way that you can rapidly deploy the same exact environment on any other Linux device with Docker installed.

Having never used virtualenv (or pipenv) I look at its features and I can't imagine ever needing it after using Docker.  I've seen mention that maybe you might need multiple environments even in one Docker container... but then just run another container!  It also keeps your base server much cleaner.  No need to ever install anything on the host OS itself.  No extraneous applications putting files in random places.  You remove your containers and the server's as clean as when you deployed it.

Alasdair Muckart

unread,
Jun 12, 2018, 3:49:45 AM6/12/18
to netbox-...@googlegroups.com
Docker would be my preferred way to deploy this but that's not an option for the environments I'm working in at the moment.

--
You received this message because you are subscribed to the Google Groups "NetBox" group.
To unsubscribe from this group and stop receiving emails from it, send an email to netbox-discus...@googlegroups.com.
To post to this group, send email to netbox-...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/netbox-discuss/93f6024d-9aab-4832-954f-fff35a0e5221%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Matthew Yauch

unread,
Jun 12, 2018, 8:59:31 AM6/12/18
to NetBox
Ah well kudos for already knowing that, sorry I cannot help you then.  :(  Maybe someone else here has done this.

Musee Ullah

unread,
Jun 12, 2018, 6:43:30 PM6/12/18
to NetBox
You'll still need to install a configuration file somewhere - and you may not want to drop it inside the venv itself. Nothing really wrong with it though.

This is what I do, roughly:

- netbox release is extracted to /srv/netbox/releases/netbox-$VER
- venv is created at /srv/netbox/releases/netbox-$VER/venv
- /srv/netbox/current is symlinked to /srv/netbox/releases/netbox-$VER
- config is stored at /srv/netbox/shared/configuration.py and then symlinked to /srv/netbox/current/netbox/netbox/configuration.py
- configuration.py points to /srv/netbox/shared/media and /srv/netbox/shared/reports so they're kept on upgrade (important):
MEDIA_ROOT = "/srv/netbox/shared/media"
REPORTS_ROOT
= "/srv/netbox/shared/reports"

uwsgi (or gunicorn if you prefer) then just serves out of /srv/netbox/current and static files can be picked up from there too.

I could stick with a single venv and just symlink that to /srv/netbox/current/venv, but the above lets me isolate dependencies by version in case I need to swap/change back. (plus it's automated at https://github.com/lae/ansible-role-netbox/blob/master/tasks/deploy_netbox.yml anyway)
Reply all
Reply to author
Forward
0 new messages