mirror of
https://github.com/retspen/webvirtcloud
synced 2025-07-31 12:41:08 +00:00
Initial commit
This commit is contained in:
commit
4d48e79341
87 changed files with 5637 additions and 0 deletions
0
computes/__init__.py
Normal file
0
computes/__init__.py
Normal file
3
computes/admin.py
Normal file
3
computes/admin.py
Normal file
|
@ -0,0 +1,3 @@
|
|||
from django.contrib import admin
|
||||
|
||||
# Register your models here.
|
27
computes/migrations/0001_initial.py
Normal file
27
computes/migrations/0001_initial.py
Normal file
|
@ -0,0 +1,27 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.db import models, migrations
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name='Compute',
|
||||
fields=[
|
||||
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
|
||||
('name', models.CharField(max_length=20)),
|
||||
('hostname', models.CharField(max_length=20)),
|
||||
('login', models.CharField(max_length=20)),
|
||||
('password', models.CharField(max_length=14, null=True, blank=True)),
|
||||
('type', models.IntegerField()),
|
||||
],
|
||||
options={
|
||||
},
|
||||
bases=(models.Model,),
|
||||
),
|
||||
]
|
0
computes/migrations/__init__.py
Normal file
0
computes/migrations/__init__.py
Normal file
12
computes/models.py
Normal file
12
computes/models.py
Normal file
|
@ -0,0 +1,12 @@
|
|||
from django.db import models
|
||||
|
||||
|
||||
class Compute(models.Model):
|
||||
name = models.CharField(max_length=20)
|
||||
hostname = models.CharField(max_length=20)
|
||||
login = models.CharField(max_length=20)
|
||||
password = models.CharField(max_length=14, blank=True, null=True)
|
||||
type = models.IntegerField()
|
||||
|
||||
def __unicode__(self):
|
||||
return self.hostname
|
3
computes/tests.py
Normal file
3
computes/tests.py
Normal file
|
@ -0,0 +1,3 @@
|
|||
from django.test import TestCase
|
||||
|
||||
# Create your tests here.
|
65
computes/views.py
Normal file
65
computes/views.py
Normal file
|
@ -0,0 +1,65 @@
|
|||
from django.http import HttpResponseRedirect
|
||||
from django.core.urlresolvers import reverse
|
||||
from django.shortcuts import render
|
||||
from computes.models import Compute
|
||||
from vrtManager.hostdetails import wvmHostDetails
|
||||
from vrtManager.connection import connection_manager
|
||||
from libvirt import libvirtError
|
||||
|
||||
|
||||
def computes(request):
|
||||
"""
|
||||
:param request:
|
||||
:return:
|
||||
"""
|
||||
|
||||
if not request.user.is_authenticated():
|
||||
return HttpResponseRedirect(reverse('login'))
|
||||
|
||||
def get_hosts_status(computes):
|
||||
"""
|
||||
Function return all hosts all vds on host
|
||||
"""
|
||||
compute_data = []
|
||||
for compute in computes:
|
||||
compute_data.append({'id': compute.id,
|
||||
'name': compute.name,
|
||||
'hostname': compute.hostname,
|
||||
'status': connection_manager.host_is_up(compute.type, compute.hostname),
|
||||
'type': compute.type,
|
||||
'login': compute.login,
|
||||
'password': compute.password
|
||||
})
|
||||
return compute_data
|
||||
|
||||
computes = Compute.objects.filter()
|
||||
computes_info = get_hosts_status(computes)
|
||||
|
||||
return render(request, 'computes.html', locals())
|
||||
|
||||
def compute(request, compute_id):
|
||||
"""
|
||||
:param request:
|
||||
:return:
|
||||
"""
|
||||
|
||||
if not request.user.is_authenticated():
|
||||
return HttpResponseRedirect(reverse('login'))
|
||||
|
||||
errors = []
|
||||
|
||||
compute = Compute.objects.get(id=compute_id)
|
||||
|
||||
try:
|
||||
conn = wvmHostDetails(compute.hostname,
|
||||
compute.login,
|
||||
compute.password,
|
||||
compute.type)
|
||||
hostname, host_arch, host_memory, logical_cpu, model_cpu, uri_conn = conn.get_node_info()
|
||||
hypervisor = conn.hypervisor_type()
|
||||
mem_usage = conn.get_memory_usage()
|
||||
conn.close()
|
||||
except libvirtError as err:
|
||||
errors.append(err)
|
||||
|
||||
return render(request, 'compute.html', locals())
|
Loading…
Add table
Add a link
Reference in a new issue