Skip to content

Commit

Permalink
Python3 & Django 2.2 Migration - Fix & Updates
Browse files Browse the repository at this point in the history
  • Loading branch information
catborise committed Mar 16, 2020
1 parent fc8612c commit 4d40de1
Show file tree
Hide file tree
Showing 98 changed files with 1,510 additions and 6,643 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
.vagrant
venv
venv2
.vscode
.idea
.DS_*
Expand Down
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
language: python
python:
- "2.7"
- "3.6"
env:
- DJANGO=1.11.26
- DJANGO=2.2.10
install:
- pip install -r dev/requirements.txt
script:
Expand Down
10 changes: 5 additions & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,21 @@ RUN echo 'APT::Get::Clean=always;' >> /etc/apt/apt.conf.d/99AutomaticClean
RUN apt-get update -qqy
RUN DEBIAN_FRONTEND=noninteractive apt-get -qyy install \
-o APT::Install-Suggests=false \
git python-virtualenv python-dev python-lxml libvirt-dev zlib1g-dev nginx libsasl2-modules
git python3-virtualenv python3-dev python3-lxml virtualenv libvirt-dev zlib1g-dev nginx libsasl2-modules

ADD . /srv/webvirtcloud
RUN chown -R www-data:www-data /srv/webvirtcloud

# Setup webvirtcloud
RUN cd /srv/webvirtcloud && \
virtualenv venv && \
virtualenv --python=python3 venv && \
. venv/bin/activate && \
pip install -U pip && \
pip install -r conf/requirements.txt && \
pip3 install -U pip && \
pip3 install -r conf/requirements.txt && \
chown -R www-data:www-data /srv/webvirtcloud

RUN cd /srv/webvirtcloud && . venv/bin/activate && \
python manage.py migrate && \
python3 manage.py migrate && \
chown -R www-data:www-data /srv/webvirtcloud

# Setup Nginx
Expand Down
52 changes: 32 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
## WebVirtCloud

###### Python3 & Django 2.11

## Features
* QEMU/KVM Hypervisor Management
Expand Down Expand Up @@ -38,10 +38,10 @@ haystack = string.ascii_letters + string.digits + string.punctuation
print(''.join([random.SystemRandom().choice(haystack) for _ in range(50)]))
```

### Install WebVirtCloud panel (Ubuntu)
### Install WebVirtCloud panel (Ubuntu 18.04+ LTS)

```bash
sudo apt-get -y install git virtualenv python-virtualenv python-dev python-lxml libvirt-dev zlib1g-dev libxslt1-dev nginx supervisor libsasl2-modules gcc pkg-config python-guestfs
sudo apt-get -y install git virtualenv python3-virtualenv python3-dev python3-lxml libvirt-dev zlib1g-dev libxslt1-dev nginx supervisor libsasl2-modules gcc pkg-config python3-guestfs
git clone https://github.com/retspen/webvirtcloud
cd webvirtcloud
cp webvirtcloud/settings.py.template webvirtcloud/settings.py
Expand All @@ -52,7 +52,7 @@ cd ..
sudo mv webvirtcloud /srv
sudo chown -R www-data:www-data /srv/webvirtcloud
cd /srv/webvirtcloud
virtualenv venv
virtualenv -p python3 venv
source venv/bin/activate
pip install -r conf/requirements.txt
python manage.py migrate
Expand All @@ -76,11 +76,11 @@ Done!!

Go to http://serverip and you should see the login screen.


### Install WebVirtCloud panel (CentOS)
### Install WebVirtCloud panel (CentOS8/OEL8)

```bash
sudo yum -y install python-virtualenv python-devel libvirt-devel glibc gcc nginx supervisor python-lxml git python-libguestfs iproute-tc
sudo yum -y install epel-release
sudo yum -y install python3-virtualenv python3-devel libvirt-devel glibc gcc nginx supervisor python3-lxml git python3-libguestfs iproute-tc cyrus-sasl-md5 python3-libguestfs
```

#### Creating directories and cloning repo
Expand All @@ -90,15 +90,17 @@ sudo mkdir /srv && cd /srv
sudo git clone https://github.com/retspen/webvirtcloud && cd webvirtcloud
cp webvirtcloud/settings.py.template webvirtcloud/settings.py
# now put secret key to webvirtcloud/settings.py
# create secret key manually or use that command
sudo sed -r "s/SECRET_KEY = ''/SECRET_KEY = '"`python3 /srv/webvirtcloud/conf/runit/secret_generator.py`"'/" -i /srv/webvirtcloud/webvirtcloud/settings.py
```

#### Start installation webvirtcloud
```
sudo virtualenv venv
sudo source venv/bin/activate
sudo venv/bin/pip install -r conf/requirements.txt
sudo cp conf/nginx/webvirtcloud.conf /etc/nginx/conf.d/
sudo venv/bin/python manage.py migrate
virtualenv-3 venv
source venv/bin/activate
pip3 install -r conf/requirements.txt
cp conf/nginx/webvirtcloud.conf /etc/nginx/conf.d/
python3 manage.py migrate
```

#### Configure the supervisor for CentOS
Expand All @@ -115,7 +117,7 @@ autorestart=true
redirect_stderr=true

[program:novncd]
command=/srv/webvirtcloud/venv/bin/python /srv/webvirtcloud/console/novncd
command=/srv/webvirtcloud/venv/bin/python3 /srv/webvirtcloud/console/novncd
directory=/srv/webvirtcloud
user=nginx
autostart=true
Expand Down Expand Up @@ -191,11 +193,20 @@ Change permission for selinux:

```bash
sudo semanage fcontext -a -t httpd_sys_content_t "/srv/webvirtcloud(/.*)"
sudo setsebool -P httpd_can_network_connect on -P
```

Add required user to the kvm group:
Add required user to the kvm group(if you not install with root):
```bash
sudo usermod -G kvm -a webvirtmgr
sudo usermod -G kvm -a <username>
```

Allow http ports on firewall:
```bash
sudo firewall-cmd --add-service=http
sudo firewall-cmd --add-service=http --permanent
sudo firewall-cmd --add-port=6080/tcp
sudo firewall-cmd --add-port=6080/tcp --permanent
```

Let's restart nginx and the supervisord services:
Expand Down Expand Up @@ -226,7 +237,7 @@ Done!!

Go to http://serverip and you should see the login screen.

### Alternative running novncd via runit
### Alternative running novncd via runit(Debian)
Alternative to running nonvcd via supervisor is runit.

On Debian systems install runit and configure novncd service
Expand Down Expand Up @@ -272,11 +283,12 @@ datasource:

### How To Update
```bash
cd <installation-directory>
sudo source venv/bin/activate
# Go to Installation Directory
cd /srv/webvirtcloud
source venv/bin/activate
git pull
pip install -U -r conf/requirements.txt
python manage.py migrate
pip3 install -U -r conf/requirements.txt
python3 manage.py migrate
sudo service supervisor restart
```
### Screenshots
Expand Down
17 changes: 9 additions & 8 deletions Vagrantfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ Vagrant.configure(2) do |config|
sudo sed -i 's/auth_tcp = \"sasl\"/auth_tcp = \"none\"/g' /etc/libvirt/libvirtd.conf
sudo service libvirt-bin restart
sudo adduser vagrant libvirtd
sudo apt-get -y install python-virtualenv python-dev python-lxml libvirt-dev zlib1g-dev
virtualenv /vagrant/venv
sudo apt-get -y install python3-virtualenv virtualenv python3-pip python3-dev python3-lxml libvirt-dev zlib1g-dev python3-guestfs
virtualenv -p python3 /vagrant/venv
source /vagrant/venv/bin/activate
pip install -r /vagrant/dev/requirements.txt
pip3 install -r /vagrant/dev/requirements.txt
SHELL
end
# To start this machine run "vagrant up prod"
Expand All @@ -24,6 +24,7 @@ Vagrant.configure(2) do |config|
prod.vm.box = "ubuntu/bionic64"
prod.vm.hostname = "webvirtcloud"
prod.vm.network "private_network", ip: "192.168.33.11"
prod.vm.network "forwarded_port", guest: 80, host: 8081
#prod.vm.synced_folder ".", "/srv/webvirtcloud"
prod.vm.provision "shell", inline: <<-SHELL
sudo mkdir /srv/webvirtcloud
Expand All @@ -33,15 +34,15 @@ Vagrant.configure(2) do |config|
sudo service libvirt-bin restart
sudo adduser vagrant libvirtd
sudo chown -R vagrant:vagrant /srv/webvirtcloud
sudo apt-get -y install python-virtualenv python-dev python-lxml python-pip libvirt-dev zlib1g-dev libxslt1-dev nginx supervisor libsasl2-modules gcc pkg-config python-guestfs
virtualenv /srv/webvirtcloud/venv
sudo apt-get -y install python3-virtualenv python3-dev python3-lxml python3-pip virtualenv libvirt-dev zlib1g-dev libxslt1-dev nginx supervisor libsasl2-modules gcc pkg-config python3-guestfs
virtualenv -p python3 /srv/webvirtcloud/venv
source /srv/webvirtcloud/venv/bin/activate
pip install -r /srv/webvirtcloud/dev/requirements.txt
pip3 install -r /srv/webvirtcloud/requirements.txt
sudo cp /srv/webvirtcloud/conf/supervisor/webvirtcloud.conf /etc/supervisor/conf.d
sudo cp /srv/webvirtcloud/conf/nginx/webvirtcloud.conf /etc/nginx/conf.d
sudo cp /srv/webvirtcloud/webvirtcloud/settings.py.template /srv/webvirtcloud/webvirtcloud/settings.py
sudo sed "s/SECRET_KEY = ''/SECRET_KEY = '"`python /srv/webvirtcloud/conf/runit/secret_generator.py`"'/" -i /srv/webvirtcloud/webvirtcloud/settings.py
python /srv/webvirtcloud/manage.py migrate
sudo sed "s/SECRET_KEY = ''/SECRET_KEY = '"`python3 /srv/webvirtcloud/conf/runit/secret_generator.py`"'/" -i /srv/webvirtcloud/webvirtcloud/settings.py
python3 /srv/webvirtcloud/manage.py migrate
sudo rm /etc/nginx/sites-enabled/default
sudo chown -R www-data:www-data /srv/webvirtcloud
sudo service nginx restart
Expand Down
3 changes: 2 additions & 1 deletion accounts/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ class UserAddForm(forms.Form):
name = forms.CharField(label="Name",
error_messages={'required': _('No User name has been entered')},
max_length=20)
password = forms.CharField(required=not settings.ALLOW_EMPTY_PASSWORD, error_messages={'required': _('No password has been entered')},)
password = forms.CharField(required=not settings.ALLOW_EMPTY_PASSWORD,
error_messages={'required': _('No password has been entered')},)

def clean_name(self):
name = self.cleaned_data['name']
Expand Down
42 changes: 32 additions & 10 deletions accounts/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -1,29 +1,51 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
# Generated by Django 2.2.10 on 2020-01-28 07:01

from django.db import models, migrations
from django.conf import settings
import django.core.validators
from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):

initial = True

dependencies = [
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
('instances', '0001_initial'),
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
]

operations = [
migrations.CreateModel(
name='UserSSHKey',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('keyname', models.CharField(max_length=25)),
('keypublic', models.CharField(max_length=500)),
('user', models.ForeignKey(on_delete=django.db.models.deletion.DO_NOTHING, to=settings.AUTH_USER_MODEL)),
],
),
migrations.CreateModel(
name='UserInstance',
fields=[
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('is_change', models.BooleanField(default=False)),
('is_delete', models.BooleanField(default=False)),
('instance', models.ForeignKey(to='instances.Instance')),
('user', models.ForeignKey(to=settings.AUTH_USER_MODEL)),
('is_vnc', models.BooleanField(default=False)),
('instance', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='instances.Instance')),
('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)),
],
),
migrations.CreateModel(
name='UserAttributes',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('can_clone_instances', models.BooleanField(default=True)),
('max_instances', models.IntegerField(default=1, help_text='-1 for unlimited. Any integer value', validators=[django.core.validators.MinValueValidator(-1)])),
('max_cpus', models.IntegerField(default=1, help_text='-1 for unlimited. Any integer value', validators=[django.core.validators.MinValueValidator(-1)])),
('max_memory', models.IntegerField(default=2048, help_text='-1 for unlimited. Any integer value', validators=[django.core.validators.MinValueValidator(-1)])),
('max_disk_size', models.IntegerField(default=20, help_text='-1 for unlimited. Any integer value', validators=[django.core.validators.MinValueValidator(-1)])),
('user', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)),
],
options={
},
bases=(models.Model,),
),
]
24 changes: 0 additions & 24 deletions accounts/migrations/0002_auto_20150325_0846.py

This file was deleted.

25 changes: 0 additions & 25 deletions accounts/migrations/0003_usersshkey.py

This file was deleted.

26 changes: 0 additions & 26 deletions accounts/migrations/0004_userattributes.py

This file was deleted.

19 changes: 0 additions & 19 deletions accounts/migrations/0004_userinstance_is_vnc.py

This file was deleted.

Loading

0 comments on commit 4d40de1

Please sign in to comment.