Commit 04d2fa9b by Belákovics Ádám

Merge branch 'logging' into 'DEV'

Logging

See merge request !10
parents ee5bcf00 ccb52b46
Pipeline #782 failed with stages
in 1 minute 38 seconds
export DJANGO_SECRET = "very very secret key"
export OS_AUTH_URL=http://example/identity/v3
export OS_PROJECT_ID=123456789
export OS_PROJECT_NAME="example"
......
# Generated by Django 2.2.3 on 2019-07-15 09:29
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('instance', '0008_auto_20190704_1310'),
]
operations = [
migrations.AlterField(
model_name='instance',
name='flavor',
field=models.ForeignKey(help_text='Reasources given to the vm', on_delete='CASCADE', related_name='instances', to='instance.Flavor', verbose_name='flavor'),
),
migrations.AlterField(
model_name='instance',
name='lease',
field=models.ForeignKey(on_delete='CASCADE', related_name='instances', to='instance.Lease'),
),
]
......@@ -7,7 +7,9 @@ from image.models import Disk
from interface_openstack.implementation.vm.instance import (
OSVirtualMachineManager
)
import logging
logger = logging.getLogger(__name__)
ACCESS_METHODS = tuple(
[(key, val[0]) for key, val in settings.VM_ACCESS_PROTOCOLS.items()]
......@@ -43,13 +45,17 @@ class Flavor(models.Model):
def create(cls, name, description, ram=0, vcpu=0,
initial_disk=0, priority=0):
interface = OSVirtualMachineManager(settings.CONNECTION)
try:
remote_flavor = interface.create_flavor(name, ram, vcpu, initial_disk)
flavor = cls(name=name, description=description,
remote_id=remote_flavor.id, ram=ram, vcpu=vcpu,
initial_disk=initial_disk, priority=priority)
flavor.save()
return flavor
except Exception as e:
logger.error(str(e))
raise ValueError("Couldn't create Flavor in remote cloud.")
class Instance(models.Model):
......@@ -110,6 +116,7 @@ class Instance(models.Model):
inst.full_clean()
inst.save()
logger.info("New instance created")
return inst
@classmethod
......@@ -117,6 +124,7 @@ class Instance(models.Model):
disks, networks, flavor):
# TODO: attach disks when the remote instance created
interface = OSVirtualMachineManager(settings.CONNECTION)
try:
remote_inst = interface.create_vm_from_template(params["name"],
template.remote_ID,
flavor.remote_id,
......@@ -124,8 +132,11 @@ class Instance(models.Model):
)
remote_id = remote_inst.id
new_inst = cls.create(lease, owner, flavor, remote_id, params)
return new_inst
except Exception as e:
logger.error(str(e))
raise ValueError("Couldn't create Flavor in remote cloud."
"Search the logs for more detail.")
def clean(self, *args, **kwargs):
self.time_of_suspend, self.time_of_delete = self.get_renew_times()
......
......@@ -3,7 +3,7 @@ import os
import sys
if __name__ == "__main__":
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "recircle.settings")
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "recircle.settings.local")
try:
from django.core.management import execute_from_command_line
except ImportError as exc:
......
......@@ -30,8 +30,6 @@ ALLOWED_HOSTS = ["vm.niif.cloud.bme.hu", "localhost"]
# Application definition
INSTALLED_APPS = [
"instance.apps.InstanceConfig",
"image.apps.ImageConfig",
"django.contrib.admin",
"django.contrib.auth",
"django.contrib.contenttypes",
......@@ -42,9 +40,17 @@ INSTALLED_APPS = [
"djoser",
"rest_framework_swagger",
"corsheaders",
"template"
]
LOCAL_APPS = [
"image",
"instance",
"storage",
"template",
]
INSTALLED_APPS += LOCAL_APPS
MIDDLEWARE = [
"django.middleware.security.SecurityMiddleware",
"django.contrib.sessions.middleware.SessionMiddleware",
......@@ -172,3 +178,48 @@ CONNECTION = {
"interface": os.getenv("OS_INTERFACE"),
"identity_api_version": os.getenv("OS_IDENTITY_API_VERSION"),
}
# LOGGING = {
# 'version': 1,
# 'disable_existing_loggers': False,
# 'handlers': {
# 'file': {
# 'level': 'DEBUG',
# 'class': 'logging.FileHandler',
# 'filename': '/recircle/logs/django/debug.log',
# },
# },
# 'loggers': {
# 'django': {
# 'handlers': ['file'],
# 'level': 'DEBUG',
# 'propagate': True,
# },
# },
# }
LOGGING = {
'version': 1,
'disable_existing_loggers': False,
'formatters': {
'simple': {
'format': '%(asctime)s [%(levelname)s]: %(name)s %(message)s',
'datefmt': '%Y-%m-%d %H:%M:%S',
},
},
'handlers': {
'console': {
'class': 'logging.StreamHandler',
'formatter': 'simple',
},
},
'loggers': {
'django': {
'handlers': ['console'],
'level': os.getenv('DJANGO_LOG_LEVEL', 'INFO'),
},
},
}
for i in LOCAL_APPS:
LOGGING['loggers'][i] = {'handlers': ['console'], 'level': 'DEBUG'}
from .base import *
DEBUG = True
# CORS config for development version only
CORS_ORIGIN_WHITELIST = ("http://localhost:3000",)
for i in LOCAL_APPS:
LOGGING['loggers'][i] = {'handlers': ['console'], 'level': 'DEBUG'}
ADMIN_ENABLED = True
ALLOWED_HOSTS = ['*']
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment