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
									
								
								instances/__init__.py
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										0
									
								
								instances/__init__.py
									
										
									
									
									
										Normal file
									
								
							
							
								
								
									
										3
									
								
								instances/admin.py
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										3
									
								
								instances/admin.py
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,3 @@
 | 
			
		|||
from django.contrib import admin
 | 
			
		||||
 | 
			
		||||
# Register your models here.
 | 
			
		||||
							
								
								
									
										26
									
								
								instances/migrations/0001_initial.py
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										26
									
								
								instances/migrations/0001_initial.py
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,26 @@
 | 
			
		|||
# -*- coding: utf-8 -*-
 | 
			
		||||
from __future__ import unicode_literals
 | 
			
		||||
 | 
			
		||||
from django.db import models, migrations
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class Migration(migrations.Migration):
 | 
			
		||||
 | 
			
		||||
    dependencies = [
 | 
			
		||||
        ('computes', '0001_initial'),
 | 
			
		||||
    ]
 | 
			
		||||
 | 
			
		||||
    operations = [
 | 
			
		||||
        migrations.CreateModel(
 | 
			
		||||
            name='Instance',
 | 
			
		||||
            fields=[
 | 
			
		||||
                ('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
 | 
			
		||||
                ('name', models.CharField(max_length=20)),
 | 
			
		||||
                ('uuid', models.CharField(max_length=36)),
 | 
			
		||||
                ('compute', models.ForeignKey(to='computes.Compute')),
 | 
			
		||||
            ],
 | 
			
		||||
            options={
 | 
			
		||||
            },
 | 
			
		||||
            bases=(models.Model,),
 | 
			
		||||
        ),
 | 
			
		||||
    ]
 | 
			
		||||
							
								
								
									
										0
									
								
								instances/migrations/__init__.py
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										0
									
								
								instances/migrations/__init__.py
									
										
									
									
									
										Normal file
									
								
							
							
								
								
									
										11
									
								
								instances/models.py
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										11
									
								
								instances/models.py
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,11 @@
 | 
			
		|||
from django.db import models
 | 
			
		||||
from computes.models import Compute
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class Instance(models.Model):
 | 
			
		||||
    compute = models.ForeignKey(Compute)
 | 
			
		||||
    name = models.CharField(max_length=20)
 | 
			
		||||
    uuid = models.CharField(max_length=36)
 | 
			
		||||
 | 
			
		||||
    def __unicode__(self):
 | 
			
		||||
        return self.name
 | 
			
		||||
							
								
								
									
										0
									
								
								instances/templatetags/__init__.py
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										0
									
								
								instances/templatetags/__init__.py
									
										
									
									
									
										Normal file
									
								
							
							
								
								
									
										11
									
								
								instances/templatetags/tags_active.py
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										11
									
								
								instances/templatetags/tags_active.py
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,11 @@
 | 
			
		|||
from django import template
 | 
			
		||||
import re
 | 
			
		||||
 | 
			
		||||
register = template.Library()
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@register.simple_tag
 | 
			
		||||
def active(request, pattern):
 | 
			
		||||
    if re.search(pattern, request.path):
 | 
			
		||||
        return 'class="active"'
 | 
			
		||||
    return ''
 | 
			
		||||
							
								
								
									
										3
									
								
								instances/tests.py
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										3
									
								
								instances/tests.py
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,3 @@
 | 
			
		|||
from django.test import TestCase
 | 
			
		||||
 | 
			
		||||
# Create your tests here.
 | 
			
		||||
							
								
								
									
										55
									
								
								instances/views.py
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										55
									
								
								instances/views.py
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,55 @@
 | 
			
		|||
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 index(request):
 | 
			
		||||
    """
 | 
			
		||||
    :param request:
 | 
			
		||||
    :return:
 | 
			
		||||
    """
 | 
			
		||||
 | 
			
		||||
    if not request.user.is_authenticated():
 | 
			
		||||
        return HttpResponseRedirect(reverse('login'))
 | 
			
		||||
    else:
 | 
			
		||||
        return HttpResponseRedirect(reverse('instances'))
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def instances(request):
 | 
			
		||||
    """
 | 
			
		||||
    :param request:
 | 
			
		||||
    :return:
 | 
			
		||||
    """
 | 
			
		||||
 | 
			
		||||
    if not request.user.is_authenticated():
 | 
			
		||||
        return HttpResponseRedirect(reverse('login'))
 | 
			
		||||
 | 
			
		||||
    computes = Compute.objects.filter()
 | 
			
		||||
    all_host_vms = {}
 | 
			
		||||
 | 
			
		||||
    for compute in computes:
 | 
			
		||||
        if connection_manager.host_is_up(compute.type, compute.hostname):
 | 
			
		||||
            try:
 | 
			
		||||
                conn = wvmHostDetails(compute, compute.login, compute.password, compute.type)
 | 
			
		||||
                all_host_vms[compute.id, compute.name] = conn.get_host_instances()
 | 
			
		||||
                conn.close()
 | 
			
		||||
            except libvirtError:
 | 
			
		||||
                pass
 | 
			
		||||
 | 
			
		||||
    return render(request, 'instances.html', locals())
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def instance(request, comptes_id, vname):
 | 
			
		||||
    """
 | 
			
		||||
    :param request:
 | 
			
		||||
    :return:
 | 
			
		||||
    """
 | 
			
		||||
 | 
			
		||||
    if not request.user.is_authenticated():
 | 
			
		||||
        return HttpResponseRedirect(reverse('login'))
 | 
			
		||||
 | 
			
		||||
    return render(request, 'instances.html', locals())
 | 
			
		||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue