Commit a0c0e229 authored by Philippe Valfok's avatar Philippe Valfok

Adicioando logs do droplet ao cliente

parent d3ffe181
# Generated by Django 2.0.1 on 2018-01-27 10:38
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('core', '0011_remove_configuracao_chave_ssh'),
]
operations = [
migrations.AddField(
model_name='cliente',
name='droplet_logs',
field=models.TextField(blank=True, default=''),
),
migrations.AlterField(
model_name='cliente',
name='domain_name',
field=models.CharField(max_length=50, unique=True, verbose_name='Subdomínio'),
),
]
......@@ -21,6 +21,7 @@ class Cliente(models.Model):
droplet_id = models.CharField(_('ID do droplet'), max_length=50, blank=True, null=True)
droplet_ip = models.CharField(_('IP do droplet'), max_length=50, blank=True, null=True)
droplet_status = models.CharField(max_length=255, blank=True, null=True)
droplet_logs = models.TextField(blank=True, default='')
class Meta:
"""Meta definition for Cliente."""
......@@ -52,6 +53,26 @@ class Cliente(models.Model):
"""
Método para alterar status rapidamente enquanto
estiver executando tarefas em background
:param text: Status em que a operação se encontra
:type text: str
:returns:
"""
self.droplet_status = text
self.append_log(text)
self.save()
def append_log(self, log):
"""
Método para guardar log das operações realizadas
no droplet do cliente.
É incrementado em self.droplet_logs.
:param log: Status em que a operação se encontra
:type log: str
:returns:
"""
self.droplet_logs = "{}\n{}".format(
self.droplet_logs,
log
)
......@@ -56,6 +56,7 @@ def criar_droplet(cliente):
action.wait()
droplet.load()
cliente.droplet_ip = droplet.ip_address
cliente.droplet_id = droplet.id
cliente.save()
break
else:
......@@ -105,8 +106,10 @@ def criar_subdominio(cliente):
cliente.droplet_ip
], stdout=subprocess.PIPE
)
result = process.stdout.decode('utf-8').strip()
cliente.append_log(result)
cliente.set_status(
process.stdout.decode('utf-8').strip().split('\n').pop()
result.split('\n').pop()
)
......
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 to comment