Commit 8c06ef30 by Dudás Ádám

initial import

parents
*.py[cod]
# C extensions
*.so
# Packages
*.egg
*.egg-info
dist
build
eggs
parts
bin
var
sdist
develop-eggs
.installed.cfg
lib
lib64
# Installer logs
pip-log.txt
# Unit test / coverage reports
.coverage
.tox
nosetests.xml
# Translations
*.mo
# Mr Developer
.mr.developer.cfg
.project
.pydevproject
# Other
*.swp
# Django settings for cloud project.
DEBUG = True
TEMPLATE_DEBUG = DEBUG
ADMINS = (
('Ory, Mate', 'maat@iit.bme.hu'),
)
MANAGERS = ADMINS
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql', # Add 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'.
'NAME': 'webadmin', # Or path to database file if using sqlite3.
'USER': 'webadmin', # Not used with sqlite3.
'PASSWORD': 'asjklddfjklqjf', # Not used with sqlite3.
'HOST': '', # Set to empty string for localhost. Not used with sqlite3.
'PORT': '', # Set to empty string for default. Not used with sqlite3.
}
}
# Local time zone for this installation. Choices can be found here:
# http://en.wikipedia.org/wiki/List_of_tz_zones_by_name
# although not all choices may be available on all operating systems.
# In a Windows environment this must be set to your system time zone.
TIME_ZONE = 'Europe/Budapest'
# Language code for this installation. All choices can be found here:
# http://www.i18nguy.com/unicode/language-identifiers.html
LANGUAGE_CODE = 'hu-hu'
SITE_ID = 1
# If you set this to False, Django will make some optimizations so as not
# to load the internationalization machinery.
USE_I18N = True
# If you set this to False, Django will not format dates, numbers and
# calendars according to the current locale.
USE_L10N = True
# If you set this to False, Django will not use timezone-aware datetimes.
USE_TZ = True
# Absolute filesystem path to the directory that will hold user-uploaded files.
# Example: "/home/media/media.lawrence.com/media/"
MEDIA_ROOT = ''
# URL that handles the media served from MEDIA_ROOT. Make sure to use a
# trailing slash.
# Examples: "http://media.lawrence.com/media/", "http://example.com/media/"
MEDIA_URL = ''
# Absolute path to the directory static files should be collected to.
# Don't put anything in this directory yourself; store your static files
# in apps' "static/" subdirectories and in STATICFILES_DIRS.
# Example: "/home/media/media.lawrence.com/static/"
STATIC_ROOT = '/opt/webadmin/static/'
# URL prefix for static files.
# Example: "http://media.lawrence.com/static/"
STATIC_URL = '/static/'
# Additional locations of static files
STATICFILES_DIRS = (
# Put strings here, like "/home/html/static" or "C:/www/django/static".
# Always use forward slashes, even on Windows.
# Don't forget to use absolute paths, not relative paths.
'/opt/webadmin/cloud/one/static',
)
# List of finder classes that know how to find static files in
# various locations.
STATICFILES_FINDERS = (
'django.contrib.staticfiles.finders.FileSystemFinder',
'django.contrib.staticfiles.finders.AppDirectoriesFinder',
# 'django.contrib.staticfiles.finders.DefaultStorageFinder',
)
# Make this unique, and don't share it with anybody.
SECRET_KEY = 'sx%4b1oa2)mn%##6+e1+25g@r8ht(cqk(nko^fr66w&26f22ba'
# List of callables that know how to import templates from various sources.
TEMPLATE_LOADERS = (
'django.template.loaders.filesystem.Loader',
'django.template.loaders.app_directories.Loader',
# 'django.template.loaders.eggs.Loader',
)
MIDDLEWARE_CLASSES = (
'django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.middleware.transaction.TransactionMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
)
ROOT_URLCONF = 'cloud.urls'
# Python dotted path to the WSGI application used by Django's runserver.
WSGI_APPLICATION = 'cloud.wsgi.application'
TEMPLATE_DIRS = (
# Put strings here, like "/home/html/django_templates" or "C:/www/django/templates".
# Always use forward slashes, even on Windows.
# Don't forget to use absolute paths, not relative paths.
)
INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles',
# Uncomment the next line to enable the admin:
'django.contrib.admin',
# Uncomment the next line to enable admin documentation:
'django.contrib.admindocs',
'one',
'school',
'cloud',
'south',
)
# A sample logging configuration. The only tangible logging
# performed by this configuration is to send an email to
# the site admins on every HTTP 500 error when DEBUG=False.
# See http://docs.djangoproject.com/en/dev/topics/logging for
# more details on how to customize your logging configuration.
from logging.handlers import SysLogHandler
LOGGING = {
'version': 1,
'disable_existing_loggers': False,
'filters': {
'require_debug_false': {
'()': 'django.utils.log.RequireDebugFalse'
}
},
'handlers': {
'mail_admins': {
'level': 'ERROR',
'filters': ['require_debug_false'],
'class': 'django.utils.log.AdminEmailHandler'
},
'syslog':{
'level':'WARNING',
'class': 'logging.handlers.SysLogHandler',
'address': '/dev/log',
},
},
'loggers': {
'': {
'handlers': ['syslog'],
'level': 'WARNING',
},
'django.request': {
'handlers': ['mail_admins'],
'level': 'ERROR',
'propagate': True,
},
}
}
LOGIN_URL="/login"
AUTH_PROFILE_MODULE = 'school.Person'
# vim: et sw=4 ai fenc=utf8 smarttab :
from django.conf.urls import patterns, include, url
from django.contrib import admin
admin.autodiscover()
import one.views
urlpatterns = patterns('',
url(r'^admin/doc/', include('django.contrib.admindocs.urls')),
url(r'^admin/', include(admin.site.urls)),
url(r'^$', 'one.views.home', name='home'),
url(r'^login/$', 'school.views.login', name='login'),
url(r'^logout/$', 'school.views.logout', name='logout'),
url(r'^vm/new/(?P<template>\d+)/$', 'one.views.vm_new', name='vm_new'),
url(r'^vm/show/(?P<iid>\d+)/$', 'one.views.vm_show', name='vm_show'),
url(r'^vm/delete/(?P<iid>\d+)/$', 'one.views.vm_delete', name='vm_delete'),
)
"""
WSGI config for cloud project.
This module contains the WSGI application used by Django's development server
and any production WSGI deployments. It should expose a module-level variable
named ``application``. Django's ``runserver`` and ``runfcgi`` commands discover
this application via the ``WSGI_APPLICATION`` setting.
Usually you will have the standard Django WSGI application here, but it also
might make sense to replace the whole Django WSGI application with a custom one
that later delegates to the Django one. For example, you could introduce WSGI
middleware here, or combine a Django application with an application of another
framework.
"""
import os
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "cloud.settings")
# This application object is used by any WSGI server configured to use this
# file. This includes Django's development server, if the WSGI_APPLICATION
# setting points here.
from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()
# Apply WSGI middleware here.
# from helloworld.wsgi import HelloWorldApplication
# application = HelloWorldApplication(application)
#!/usr/bin/env python
import os
import sys
if __name__ == "__main__":
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "cloud.settings")
from django.core.management import execute_from_command_line
execute_from_command_line(sys.argv)
from django.contrib import messages
from django.core.exceptions import ValidationError
from django import contrib
from django.utils.translation import ugettext_lazy as _
from one import models
import string
class PersonInline(contrib.admin.StackedInline):
model = models.Person
max_num = 1
can_delete = False
class SshKeyInline(contrib.admin.TabularInline):
model = models.SshKey
extra = 2
class DetailsInline(contrib.admin.StackedInline):
model = models.UserCloudDetails
max_num = 1
can_delete = False
class MyUserAdmin(contrib.auth.admin.UserAdmin):
list_display = ('username', 'email', 'is_staff', 'date_joined', 'get_profile')
try:
inlines = inlines + (PersonInline, SshKeyInline, DetailsInline)
except NameError:
inlines = (PersonInline, SshKeyInline, DetailsInline)
contrib.admin.site.unregister(contrib.auth.models.User)
contrib.admin.site.register(contrib.auth.models.User, MyUserAdmin)
def update_state(modeladmin, request, queryset):
for i in queryset.all():
i.update_state()
update_state.short_description = _('Update status')
def submit_vm(modeladmin, request, queryset):
for i in queryset.all():
i.submit(request.user)
submit_vm.short_description = _('Submit VM')
class TemplateAdmin(contrib.admin.ModelAdmin):
model=models.Template
class InstanceAdmin(contrib.admin.ModelAdmin):
model=models.Instance
actions = [update_state,submit_vm]
list_display = ['id', 'name', 'owner', 'state']
readonly_fields = ['ip', 'active_since', 'pw', 'template']
list_filter = ['owner', 'template', 'state']
contrib.admin.site.register(models.Template, TemplateAdmin)
contrib.admin.site.register(models.Instance, InstanceAdmin)
from django.core.management.base import BaseCommand, CommandError
from one.models import *
class Command(BaseCommand):
args = None
help = 'Update status of One resources'
def handle(self, *args, **options):
Disk.update()
Network.update()
This diff is collapsed. Click to expand it.
.contentblock {
background-color: #ccc;
border-radius: 10px;
margin: 5px;
}
.contentblock p, dl {
padding: 5px;
margin: 0;
}
.contentblock h2 {
background-color: #000;
background-image: url(hexabar.png);
background-position: right center;
background-repeat: no-repeat;
border-radius: 10px;
color: #fff;
font-weight: bold;
padding: 10px;
border-style: none!important;
margin-bottom: 5px;
font-size: 1.3em;
}
/* TABLES */
table {
/*border-left: 1px solid #ccc;
border-right: 1px solid #ccc;*/
background-color: #ccc;
border-radius: 10px;
margin: 5px;
}
td, th {
border-bottom: 1px solid #bbb;
padding: 5px;
vertical-align: top;
}
table input,
table select,
table textarea {
min-width: 300px;
border: 1px solid #aaa;
display: block;
}
input[type=submit], .button, .smallbutton {
background-color: #072c61;
padding: 5px;
text-decoration: none;
color: #fff!important;
border: 2px solid #fff;
border-radius: 10px;
min-width: 5em;
margin: 0;
font-size: .9em;
line-height: .9em;
font-weight: bold;
}
.smallbutton {
padding: 1px 5px;
}
p.rightbuttons {
float: right;
margin: 7px 0;
}
table p.help {
font-size: .85em;
color: #666;
}
th.fieldset {
background-color: #000;
background-image: url(hexabar.png);
background-position: right center;
background-repeat: no-repeat;
border-radius: 10px;
color: #fff;
font-weight: bold;
padding: 10px;
border-style: none!important;
margin-bottom: 5px;
font-size: 1.3em;
}
html {
/* background: #b3b3b3;*/
min-height: 100%;
margin: 0;
padding: 0;
}
body {
min-height: 100%;
margin: 0;
padding: 0;
font-family: sans-serif;
font-size: .9em;
background: #dadada url("site_bgr.png") repeat-x;
background-position: 80px 0;
}
div#header {
margin: 0;
padding: 0;
height: 80px;
background-color: #379acc; /* per www.ik.bme.hu */
background-color: #072c61; /* per www.ik.bme.hu */
padding-left: 200px;
background-image: url(bme_feher2.png);
background-repeat: no-repeat;
background-position: 20px 18px;
border-bottom: 2px solid #fff;
}
div#header a:link,
div#header a:visited {
color: #fff;
}
div#header #loginblock {
position: absolute;
right: 0;
top: 0;
margin: 0;
padding: 7px;
background-color: #000;
background-image: url(hexabar.png);
background-position: center center;
border-radius: 0 0 0 10px;
color: #fff;
font-weight: bold;
}
div#header #loginblock p {
margin: 0;
}
div#header h1 {
margin: 0;
padding: 0 1em;
font-size: 2em;
line-height: 80px;
float: left;
color: #fff;
}
div#header h1 a {
color: #fff;
text-decoration: none;
}
div#content {
width: 850px;
margin: 0 auto;
text-align: left;
}
div.boxes{
width: 420px;
float: left;
}
div.box {
background-color: #000;
background-image: url(hexa.png);
background-position: center 30%;
background-repeat: no-repeat;
color: #fff;
font-weight: bold;
line-height: 1.5em;
width: 400px;
margin: 10px;
padding: 2px;
border-radius: 10px;
border-top-width: 30px;
margin-right: 420px;
}
div.box h3 {
color: #fff;
margin: 0;
padding: 3px;
text-align: center;
}
div.box .content {
padding: 5px;
margin: 0;
min-height: 100px;
}
div.box a:link, div.box a:visited {
color: #fff;
}
a:link, a:visited {
color: #892034;
}
#project_running ul a:link, #project_running ul a:visited,
#project_closed ul a:link, #project_closed ul a:visited {
color: #fff;
text-decoration: none;
}
/* MESSAGES & ERRORS */
ul.messagelist {
padding: 0 0 5px 0;
margin: 0;
text-align: left;
}
ul.messagelist li {
font-size: 12px;
display: block;
padding: 4px 5px 4px 25px;
margin: 0 0 3px 0;
border-bottom: 1px solid #ddd;
color: #666;
background: #ffc url(admin/img/icon_success.gif) 5px .3em no-repeat;
}
ul.messagelist li.warning{
background-image: url(admin/img/icon_alert.gif);
}
ul.messagelist li.error{
background-image: url(admin/img/icon_error.gif);
}
.errornote {
font-size: 12px !important;
display: block;
padding: 4px 5px 4px 25px;
margin: 0 0 3px 0;
border: 1px solid red;
color: red;
background: #ffc url(admin/img/icon_error.gif) 5px .3em no-repeat;
}
ul.errorlist {
margin: 0 !important;
padding: 0 !important;
}
.errorlist li {
font-size: 12px !important;
display: block;
padding: 4px 5px 4px 25px;
margin: 0 0 3px 0;
border: 1px solid red;
color: white;
background: red url(admin/img/icon_alert.gif) 5px .3em no-repeat;
}
.errorlist li a {
color: white;
text-decoration: underline;
}
td ul.errorlist {
margin: 0 !important;
padding: 0 !important;
}
td ul.errorlist li {
margin: 0 !important;
}
.errors {
background: #ffc;
}
.errors input, .errors select, .errors textarea {
border: 1px solid red;
}
div.system-message {
background: #ffc;
margin: 10px;
padding: 6px 8px;
font-size: .8em;
}
div.system-message p.system-message-title {
padding: 4px 5px 4px 25px;
margin: 0;
color: red;
background: #ffc url(admin/img/icon_error.gif) 5px .3em no-repeat;
}
.description {
font-size: 12px;
padding: 5px 0 0 12px;
}
#state .content p {
text-align: center;
}
#state .content a img {
border: solid #072C61 2px;
border-radius:10px;
background-color: #fff;
padding: 3px;
}
input.widebutton {
font-size:25px;
line-height:1em;
text-align:left;
width:400px;
display:block;
cursor:pointer;
}
.icon-delete {
background-image: url(/static/icons/Edit-delete-2.png);
}
.button, .smallbutton {
background-color: #892034;
padding: 5px;
text-decoration: none;
color: #fff!important;
border: 2px solid #fff;
border-radius: 10px;
min-width: 5em;
margin: 0;
font-size: .9em;
line-height: .9em;
font-weight: bold;
}
.smallbutton {
padding: 1px 5px;
}
<!DOCTYPE html>
{% load i18n %}
{% get_current_language as lang %}
<html lang="{{lang}}">
<head>
<title>{% block title %}IK Cloud{% endblock %}</title>
<link rel="stylesheet" href="/static/style.css" />
<link rel="icon" type="image/png" href="/static/favicon.png" />
{{ form.media }}
{% block js %}{% endblock %}
</head>
<body>
<div id="header">
{% block login %}
<div id="loginblock"><p>
{% if user.is_authenticated %}
Bejelentkezve: {{ user.username }}.
<a href="/logout/">Kijelentkezés</a>.
{% if user.is_staff %}
<a href="/admin/">Admin</a>.
{% endif %}
{% else %}
<a href="/login/">Bejelentkezés</a>.
{% endif %}
<!--{% if lang == 'hu' %}
<a href="/language/en-US/">In English</a>.
{% else %}
<a href="/language/hu/">Magyarul</a>.
{% if autolang %}
<p style="position: absolute; top: 40px; right: 1em;" class="triangle-border top">Böngészője kifejezetten angol tartalmat kért.<br/>A <a href="/language/hu/">magyar változat</a> részletesebb és frissebb!</p>
{% endif %}
{% endif %}-->
</p>
</div>
{% endblock %}
{% block header %}
{% block header_title %}
<h1><a href="/">IK Cloud</a></h1>
{% endblock %}
{% endblock %}
</div>
{% block messages %}
{% if messages %}
<ul class="messagelist">{% for message in messages %}
<li{% if message.tags %} class="{{ message.tags }}"{% endif %}>{{ message }}</li>
{% endfor %}</ul>
{% endif %}
{% endblock messages %}
<div id="content">
{% block content %}{% endblock %}
</div>
</body>
</html>
<div class="contentblock" id="state">
<h2>Saját gépek</h2>
<div class="content">
{% if instances %}
<table style="width:388px">
<tr><th>#</th><th>Megnevezés</th><th>Állapot</th><th style="width: 96px">Műveletek</th></tr>
{% for i in instances %}
<tr style="line-height: 22px;">
<td>{{i.id}}</td>
<td><a href="/vm/show/{{i.id}}/" title="{{i.name}}">{{i.name|truncatechars:20}}</td>
<td>{{i.state}}</td>
<td>
{% if i.state == 'ACTIVE' %}
<a href="{{i.get_connect_uri}}" title="Csatlakozás"><img src="/static/icons/Video-display.png" alt="⌨" /></a><a href="/vm/suspend/{{i.id}}/" onclick="alert('Hamarosan a mozikban.'); return false" title="Felfüggesztés"><img src="/static/icons/Media-playback-pause.png" alt="||" /></a><a href="/vm/delete/{{i.id}}/" onclick="return confirm('Biztosan törli a gépet?')" title="Törlés"><img src="/static/icons/Edit-delete-2.png" alt="⌫" /></a><a href="/vm/reset/{{i.id}}/" onclick="alert('Hamarosan a mozikban.'); return false" title="Újraindítás"><img src="/static/icons/View-refresh.png" alt="↺" /></a>
{% endif %}
{% if i.state == 'PENDING' %}
<img src="/static/load-2.gif" /> indítás...
{% endif %}
{% if i.state == 'SUSPENDED' %}
<a href="/vm/continue/{{i.id}}/" title="Folytatás"><img src="/static/icons/Media-playback-start.png" alt=">" /></a>
<a href="/vm/delete/{{i.id}}/" onclick="return confirm('Biztosan törli a gépet?')" title="Törlés"><img src="/static/icons/Edit-delete-2.png" alt="⌫" /></a>
{% endif %}
{% if i.state == 'FAILED' %}
<a href="/vm/delete/{{i.id}}/" title="Törlés"><img src="/static/icons/Edit-delete-2.png" alt="⌫" /></a>
{% endif %}
</td>
</tr>
{% endfor %}
</table>
{% else %}
<p>Nem fut egy gép sem.</p>
{% endif %}
</div>
</div>
{% extends "base.html" %}
{% load i18n %}
{% block content %}
<div class="boxes">
<div class="contentblock" id="state">
<h2>Új virtuális gép indítása</h2>
<div class="content">
{% for m in templates %}
<form method="POST" action="/vm/new/{{m.pk}}/">{% csrf_token %}
<p><input type="submit" value="{{m.name}}" class="button widebutton"/></p>
</form>
{% endfor %}
</div>
</div>
{% include "box-vmlist.html" %}
{% for box in boxes %}
{% if forloop.counter0|divisibleby:2 %}
<div class="contentblock">
<h2>{{ box.title }}</h2>
<div class="content">
{{ box.text|safe }}
</div>
</div>
{% endif %}
{% endfor %}
</div>
<div class="boxes">
{% for box in boxes %}
{% if forloop.counter|divisibleby:2 %}
<div class="contentblock">
<h2>{{ box.title }}</h2>
<div class="content">
{{ box.text|safe }}
</div>
</div>
{% endif %}
{% endfor %}
<div class="contentblock" id="state">
<h2>A cluster állapota</h2>
<div class="content">
<p>
<a href="http://cloud.ik.bme.hu/">
<img src="/stat/cpu.png" alt="aktuális terhelés" />
<img src="/stat/ram.png" alt="aktuális memóriafoglaltság" />
</a>
</p>
</div>
</div>
</div>
{% endblock %}
{% extends "base.html" %}
{% load i18n %}
{% block content %}
<div class="boxes">
<div class="contentblock" id="project_closed">
<h2>Bejelentkezés</h2>
<div class="content">
<p>A tesztüzem alatt a felhasználók belépése és azonosítása "önbevallásos" alapon működik (a jövőben <a href="http://login.bme.hu/">EduID-s</a> bejelentkezésre lesz lehetőség):</p>
<form action="/login/" method="POST">{% csrf_token %}
<p><label>NEPTUN-kód: <input maxlength="8" size="8" type="text" name="neptun" required pattern="[A-Z][A-Z0-9]{5}" onkeyup="javascript:this.value=this.value.toUpperCase();"/></label></p>
<p><label>Jelszó: <input maxlength="8" size="8" type="password" name="pw" required /></label></p>
<p><input type="hidden" name="next" value="{{nex}}"/><input type="submit" value="Bejelentkezés"/></label></p>
</div>
</div>
</div>
{% endblock %}
<!DOCTYPE html>
{% load i18n %}
{% get_current_language as lang %}
<html lang="{{lang}}">
<head>
<title>{% block title %}Superman{% endblock %}</title>
<link rel="icon" type="image/png" href="/static/favicon.png" />
<link rel="stylesheet" href="/static/style.css" />
{{ form.media }}
{% block js %}{% endblock %}
</head>
<body>
<div id="header">
{% block login %}
<div id="loginblock"><p>
{% if user.is_authenticated %}
{% blocktrans with user.get_profile.name|default:user.username as name %}
Logged in: <a href="/me/">{{ name }}</a>.
{% endblocktrans %}
<a href="/logout/">{% trans "Log out" %}</a>.
<a href="{% url project_own %}">{% trans "My projects" %}</a>.
{% if user.is_staff %}
<a href="/admin/">Admin</a>.
{% endif %}
{% else %}
<a href="/secure/login/">{% trans "EduID login" %}</a>.
{% endif %}
{% if lang == 'hu' %}
<a href="/language/en-US/">In English</a>.
{% else %}
<a href="/language/hu/">Magyarul</a>.
{% if autolang %}
<p style="position: absolute; top: 40px; right: 1em;" class="triangle-border top">Böngészője kifejezetten angol tartalmat kért.<br/>A <a href="/language/hu/">magyar változat</a> részletesebb és frissebb!</p>
{% endif %}
{% endif %}
</p>
</div>
{% endblock %}
{% block header %}
{% block header_title %}
<h1><a href="/">{% trans "BME HPC Cluster" %}</a></h1>
{% endblock %}
{% endblock %}
</div>
{% block messages %}
{% if messages %}
<ul class="messagelist">{% for message in messages %}
<li{% if message.tags %} class="{{ message.tags }}"{% endif %}>{{ message }}</li>
{% endfor %}</ul>
{% endif %}
{% endblock messages %}
<div id="content">
{% block content %}{% endblock %}
</div>
</body>
</html>
{% extends "base.html" %}
{% load i18n %}
{% block content %}
<div class="boxes">
<div class="contentblock" id="state">
<h2>Csatlakozás</h2>
<div class="content">
<p style="font-size:25px; line-height:2em;text-align:center;"><a href="{{uri}}" class="button">Csatlakozás</a></p>
</div>
</div>
{% for box in boxes %}
{% if forloop.counter0|divisibleby:2 %}
<div class="contentblock" id="project_closed">
<h2>{{ box.title }}</h2>
<div class="content">
{{ box.text|safe }}
</div>
</div>
{% endif %}
{% endfor %}
</div>
<div class="boxes">
{% for box in boxes %}
{% if forloop.counter|divisibleby:2 %}
<div class="contentblock" id="project_closed">
<h2>{{ box.title }}</h2>
<div class="content">
{{ box.text|safe }}
</div>
</div>
{% endif %}
{% endfor %}
<div class="contentblock" id="state">
<h2>A cluster állapota</h2>
<div class="content">
<p style="text-align:center"><a href="http://cloud.ik.bme.hu/"><img src="http://cloud.ik.bme.hu/cpu.png" alt="aktuális terhelés" style="border: solid #892034 2px; border-radius:10px;" /><img src="http://cloud.ik.bme.hu/ram.png" alt="aktuális memóriafoglaltság" style="border: solid #892034 2px; border-radius:10px;" /></a></p>
</div>
</div>
{% if user.is_staff %}
<p class="rightbuttons"><a class="button" href="{{ page_edit }}">Szerkesztés</a></p>
{% endif %}
</div>
{% endblock %}
{% extends "base.html" %}
{% load i18n %}
{% block js %}
<script type="text/javascript">
{% if state == "PENDING" %}
setTimeout("location.reload(true);", 1500)
{% endif %}
{% if state == "ACTIVE" %}
{% if age < 15 %}
setTimeout("document.getElementById('wait').style.display='none';document.getElementById('connect').style.display='block';", 15000-{{age}}000);
{% endif %}
var meloading = false;
function connectbutton() {
if (meloading) {
return false;
}
meloading = true;
setTimeout("document.getElementById('connecting').style.display='none';meloading=false;", 15000);
document.getElementById('connecting').style.display='inline';
return true;
}
{% endif %}
</script>
{% endblock %}
{% block content %}
<div class="boxes">
<div class="contentblock" id="state">
<h2>{{name}}</h2>
<div class="content">
{% if state == "PENDING" %}
<p style="font-size:25px; line-height:2em;text-align:center;"><img src="/static/load-2.gif" /> Gép indítása..</p>
<p style="font-size:25px; line-height:2em;text-align:center;">
<form action="{% url vm_delete id %}" method="post" onsubmit="return confirm('Biztosan törli a gépet?')">{% csrf_token %}<input type="submit" class="icon-delete" value="Törlés" /></form>
<a href="/"><img src="/static/icons/Go-home.png" alt="&lt;-" /></a>
</p>
{% endif %}
{% if state == "ACTIVE" %}
{% if age < 15 %}
<p id="wait" style="font-size:25px; line-height:2em;text-align:center;"><img src="/static/load-2.gif" /> Gép indítása...</p>
<p id="connect" style="display:none; font-size:25px; line-height:2em;text-align:center;">
<a href="{{uri}}" class="button" onclick="return connectbutton();">
<img src="/static/load-1.gif" id="connecting" style="display:none;" /> Csatlakozás
</a>
</p>
<p style="font-size:25px; line-height:2em;text-align:center;">
<form action="{% url vm_delete id %}" method="post" onsubmit="return confirm('Biztosan törli a gépet?')">{% csrf_token %}<input type="submit" class="icon-delete" value="Törlés" /></form>
<a href="/"><img src="/static/icons/Go-home.png" alt="&lt;-" /></a>
</p>
{% else %}
<p id="connect" style="font-size:25px; line-height:2em;text-align:center;">
<a href="{{uri}}" class="button" onclick="return connectbutton();">
<img src="/static/load-1.gif" id="connecting" style="display:none;" /> Csatlakozás
</a>
</p>
<p style="font-size:25px; line-height:2em;text-align:center;">
<form action="{% url vm_delete id %}" method="post" onsubmit="return confirm('Biztosan törli a gépet?')">{% csrf_token %}<input type="submit" class="icon-delete" value="Törlés" /></form>
<a href="/"><img src="/static/icons/Go-home.png" alt="&lt;-" /></a>
</p>
{% endif %}
{% endif %}
{% if state == "DONE" %}
<p style="font-size:25px; line-height:2em;text-align:center;">A gép törölve van!</p>
<p style="font-size:25px; line-height:2em;text-align:center;">
<a href="/"><img src="/static/icons/Go-home.png" alt="⌫" /></a>
</p>
{% endif %}
{% if state == "FAILED" %}
<p style="font-size:25px; line-height:2em;text-align:center;">Váratlan hiba lépett fel.</p>
<p style="font-size:25px; line-height:2em;text-align:center;">
<form action="{% url vm_delete id %}" method="post" onsubmit="return confirm('Biztosan törli a gépet?')">{% csrf_token %}<input type="submit" class="icon-delete" value="Törlés" /></form>
<a href="/"><img src="/static/icons/Go-home.png" alt="⌫" /></a>
</p>
{% endif %}
{% if state == "SUSPENDED" %}
<p style="font-size:25px; line-height:2em;text-align:center;">
<a href="/vm/suspend/{{i.id}}/"><img src="/static/icons/Media-playback-start.png" alt="&gt;" /></a>
<a href="/"><img src="/static/icons/Go-home.png" alt="⌫" /></a>
</p>
{% endif %}
</div>
</div>
<div class="contentblock" id="state">
<h2>Bejelentkezési adatok</h2>
<div class="content">
<table><tr><th>Protokoll:</th><td>{{i.template.access_type|upper}}</td></tr>
<tr><th>Gépnév:</th><td>cloud.ik.bme.hu</td></tr>
<tr><th>Port:</th><td>{{ i.get_port}}
</td></tr>
<tr><th>Felhasználónév:</th><td>cloud</td></tr>
<tr><th>Jelszó:</th><td>ezmiez</td></tr>
</table>
</div>
</div>
</div>
<div class="boxes">
{% include "box-vmlist.html" %}
</div>
{% endblock %}
"""
This file demonstrates writing tests using the unittest module. These will pass
when you run "manage.py test".
Replace this with more appropriate tests for your application.
"""
from django.test import TestCase
class SimpleTest(TestCase):
def test_basic_addition(self):
"""
Tests that 1 + 1 always equals 2.
"""
self.assertEqual(1 + 1, 2)
def keygen(len=1024):
import os
from Crypto.PublicKey import RSA
key = RSA.generate(len, os.urandom)
try:
pub = key.exportKey('OpenSSH')
if not pub.startswith("ssh-"):
raise ValueError(pub)
except ValueError:
ssh_rsa = '00000007' + base64.b16encode('ssh-rsa')
exponent = '%x' % (key.e, )
if len(exponent) % 2:
exponent = '0' + exponent
ssh_rsa += '%08x' % (len(exponent) / 2, )
ssh_rsa += exponent
modulus = '%x' % (key.n, )
if len(modulus) % 2:
modulus = '0' + modulus
if modulus[0] in '89abcdef':
modulus = '00' + modulus
ssh_rsa += '%08x' % (len(modulus) / 2, )
ssh_rsa += modulus
pub = 'ssh-rsa %s' % (
base64.b64encode(base64.b16decode(ssh_rsa.upper())), )
return key.exportKey(), pub
from datetime import datetime
from django.conf import settings
from django.contrib.auth.decorators import login_required
from django.contrib.auth.models import User
from django.contrib import messages
from django.core.exceptions import PermissionDenied
from django.core import signing
from django.core.mail import mail_managers, send_mail
from django.db import transaction
from django.forms import ModelForm, Textarea
from django.http import Http404
#from django_shibboleth.forms import BaseRegisterForm
from django.shortcuts import render, render_to_response, get_object_or_404, redirect
from django.template import RequestContext
from django.template.loader import render_to_string
from django.utils.decorators import method_decorator
from django.utils.translation import get_language as lang
from django.utils.translation import ugettext_lazy as _
from django.views.decorators.http import *
from django.views.generic import *
from one.models import *
import django.contrib.auth as auth
class LoginView(View):
def get(self, request, *args, **kwargs):
nex = '/'
try:
nex = request.GET['next']
except:
pass
return render_to_response("login.html", RequestContext(request,{'next': nex}))
def post(self, request, *args, **kwargs):
if request.POST['pw'] != 'ezmiez':
return redirect('/')
p, created = User.objects.get_or_create(username=request.POST['neptun'])
if created:
p.set_unusable_password()
if not p.email:
p.email = "%s@nc.hszk.bme.hu" % p.username
p.save()
if not p.person_set.exists():
person = Person(neptun = p.username)
p.person_set.add(person)
p.save()
p.backend = 'django.contrib.auth.backends.ModelBackend'
auth.login(request, p)
path = '/'
try:
path = request.POST['next']
if not path.startswith("/"):
path = '/'
except:
pass
return redirect(path)
def logout(request):
auth.logout(request)
return redirect('/')
def _list_instances(request):
instances = Instance.objects.exclude(state='DONE').filter(owner=request.user)
for i in instances:
i.update_state()
return instances
@require_GET
@login_required
def home(request):
return render_to_response("home.html", RequestContext(request,{
"templates": Template.objects.all(),
'instances': _list_instances(request),
}))
@require_POST
@login_required
def vm_new(request, template):
m = get_object_or_404(Template, pk=template)
try:
i = Instance.submit(m, request.user)
return redirect(i)
except:
raise
messages.error(request, _('Failed to create virtual machine.'))
return redirect('/')
class VmListView(ListView):
context_object_name = 'instances'
template_name = 'list.html'
def get_queryset(self):
self.profile = request.user
return Instance.objects.filter(owner=self.profile)
vm_list = login_required(VmListView.as_view())
@require_safe
@login_required
def vm_show(request, iid):
inst = get_object_or_404(Instance, id=iid, owner=request.user)
inst.update_state()
return render_to_response("show.html", RequestContext(request,{
'uri': inst.get_connect_uri(),
'state': inst.state,
'name': inst.name,
'id': iid,
'age': inst.get_age(),
'instances': _list_instances(request),
'i': inst
}))
class VmDeleteView(View):
def post(self, request, iid, *args, **kwargs):
try:
get_object_or_404(Instance, id=id, owner=request.user).one_delete()
messages.success(request, _('Virtual machine is successfully deleted.'))
except:
messages.error(request, _('Failed to delete virtual machine.'))
return redirect('/')
def get(self, request, iid, *args, **kwargs):
i = get_object_or_404(Instance, id=iid, owner=request.user)
return render_to_response("confirm_delete.html", RequestContext(request,{
'i': i}))
vm_delete = login_required(VmDeleteView.as_view())
def vm_active(request, token):
id = signing.loads(token, salt='activate', max_age=300)
vm = get_object_or_404(Instance, id=id)
vm.active_since = datetime.now()
vm.save()
return HttpResponse("Ok.", content_type="text/plain")
# vim: et sw=4 ai fenc=utf8 smarttab :
from django.db import models
from django.utils.translation import ugettext_lazy as _
from django.contrib.auth.models import User
from django.db.models.signals import post_save
def create_user_profile(sender, instance, created, **kwargs):
if created:
Person.objects.create(user=instance)
post_save.connect(create_user_profile, sender=User)
LANGS = [('hu', _('Hungarian')), ('en_US', _('US English'))]
class Person(models.Model):
user = models.ForeignKey(User, null=False, blank=False, unique=True)
language = models.CharField(max_length=6, choices=LANGS,
verbose_name=_('Preferred language'))
def __unicode__(self):
return self.user.__unicode__()
class Entity(models.Model):
parent = models.ForeignKey('school.Group')
name = models.CharField(max_length=100)
class Group(Entity):
recursive_unique = models.BooleanField()
class Course(Entity):
pass
class Semester(Entity):
start = models.DateField()
end = models.DateField()
EVENT_CHOICES = [('free', _('free text')), ('num', _('number')), ('int', _('integer'))]
class Event(models.Model):
title = models.CharField(max_length=100)
group = models.ForeignKey('school.Group')
type = models.CharField(max_length=5, choices=EVENT_CHOICES)
class Mark(models.Model):
value = models.CharField(max_length=100)
student = models.ForeignKey('Person')
event = models.ForeignKey('school.Event')
created_by = models.ForeignKey('Person', related_name='created_marks')
created_at = models.DateTimeField(auto_now_add=True)
modified_by = models.ForeignKey('Person', related_name='modified_marks')
modified_at = models.DateTimeField(auto_now=True)
class Attendance(models.Model):
present = models.NullBooleanField()
student = models.ForeignKey('Person')
lesson = models.ForeignKey('school.Lesson')
modified_by = models.ForeignKey('Person',
related_name='modified_attendances')
modified_at = models.DateTimeField(auto_now=True)
class LessonClass(models.Model):
group = models.ForeignKey('school.Group')
class Lesson(models.Model):
lesson_class = models.ForeignKey('school.LessonClass')
group = models.ForeignKey('school.Group')
"""
This file demonstrates writing tests using the unittest module. These will pass
when you run "manage.py test".
Replace this with more appropriate tests for your application.
"""
from django.test import TestCase
class SimpleTest(TestCase):
def test_basic_addition(self):
"""
Tests that 1 + 1 always equals 2.
"""
self.assertEqual(1 + 1, 2)
from django.conf.urls import patterns, include, url
urlpatterns = patterns('',
)
from datetime import datetime
from django.conf import settings
from django.contrib.auth.decorators import login_required
from django.contrib.auth.models import User
from django.contrib import messages
from django.core.exceptions import PermissionDenied
from django.core import signing
from django.core.mail import mail_managers, send_mail
from django.db import transaction
from django.forms import ModelForm, Textarea
from django.http import Http404
#from django_shibboleth.forms import BaseRegisterForm
from django.shortcuts import render, render_to_response, get_object_or_404, redirect
from django.template import RequestContext
from django.template.loader import render_to_string
from django.utils.decorators import method_decorator
from django.utils.translation import get_language as lang
from django.utils.translation import ugettext_lazy as _
from django.views.decorators.http import *
from django.views.generic import *
from one.models import *
import django.contrib.auth as auth
SHIB_ATTRIBUTE_MAP = {
"HTTP_SHIB_IDENTITY_PROVIDER": (True, "idp"),
"email": (True, "email"),
"sn": (True, "sn"),
"givenName": (True, "givenName"),
"niifPersonOrgID": (True, "niifPersonOrgID"),
}
def parse_attributes(META):
shib_attrs = {}
error = False
for header, attr in SHIB_ATTRIBUTE_MAP.items():
required, name = attr
values = META.get(header, None)
value = None
if values:
# If multiple attributes releases just care about the 1st one
try:
value = values.split(';')[0]
except:
value = values
shib_attrs[name] = value
if not value or value == '':
if required:
error = True
return shib_attrs, error
def logout(request):
auth.logout(request)
return redirect('/Shibboleth.sso/Logout?return=https%3a%2f%2fcloud.ik.bme.hu%2f')
def login(request):
attr, error = parse_attributes(request.META)
try:
user = User.objects.get(username=attr['niifPersonOrgID'])
except User.DoesNotExist:
user = User(username=attr['niifPersonOrgID'])
user.set_unusable_password()
user.first_name = attr['givenName']
user.last_name = attr['sn']
user.email = attr['email']
user.save()
user.backend = 'django.contrib.auth.backends.ModelBackend'
auth.login(request, user)
return redirect('/')
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