svn path=/trunk/web/; revision=152
"""Exception for internal errors or bad faith input."""
pass
"""Exception for internal errors or bad faith input."""
pass
+class Global(object):
+ def __init__(self, user):
+ self.user = user
+ def __get_uptimes(self):
+ if not hasattr(self, '_uptimes'):
+ self._uptimes = getUptimes(self.machines)
+ return self._uptimes
+ uptimes = property(__get_uptimes)
+
+g = None
def helppopup(subj):
"""Return HTML code for a (?) link to a specified help topic"""
def helppopup(subj):
"""Return HTML code for a (?) link to a specified help topic"""
"""Return the machines owned by a given owner."""
return Machine.select_by(owner=owner)
"""Return the machines owned by a given owner."""
return Machine.select_by(owner=owner)
-def maxMemory(user, machine=None, on=None):
+def maxMemory(user, machine=None):
"""Return the maximum memory for a machine or a user.
If machine is None, return the memory available for a new
"""Return the maximum memory for a machine or a user.
If machine is None, return the memory available for a new
"""
machines = getMachinesByOwner(user.username)
"""
machines = getMachinesByOwner(user.username)
- if on is None:
- on = getUptimes(machines)
- active_machines = [x for x in machines if on[x]]
+ active_machines = [x for x in machines if g.uptimes[x]]
mem_usage = sum([x.memory for x in active_machines if x != machine])
return min(MAX_MEMORY_SINGLE, MAX_MEMORY_TOTAL-mem_usage)
mem_usage = sum([x.memory for x in active_machines if x != machine])
return min(MAX_MEMORY_SINGLE, MAX_MEMORY_TOTAL-mem_usage)
for x in machines if x != machine])
return min(MAX_DISK_SINGLE, MAX_DISK_TOTAL-disk_usage/1024.)
for x in machines if x != machine])
return min(MAX_DISK_SINGLE, MAX_DISK_TOTAL-disk_usage/1024.)
-def canAddVm(user, on=None):
machines = getMachinesByOwner(user.username)
machines = getMachinesByOwner(user.username)
- if on is None:
- on = getUptimes(machines)
- active_machines = [x for x in machines if on[x]]
+ active_machines = [x for x in machines if g.uptimes[x]]
return (len(machines) < MAX_VMS_TOTAL and
len(active_machines) < MAX_VMS_ACTIVE)
return (len(machines) < MAX_VMS_TOTAL and
len(active_machines) < MAX_VMS_ACTIVE)
(args, p.stderr.read()))
return p.stdout.read()
(args, p.stderr.read()))
return p.stdout.read()
-def makeDisks():
- """Update the lvm partitions to include all disks in the database."""
- remctl('web', 'lvcreate')
+def lvcreate(machine, disk):
+ """Create a single disk for a machine"""
+ remctl('web', 'lvcreate', machine.name,
+ disk.guest_device_name, str(disk.size))
+
+def makeDisks(machine):
+ """Update the lvm partitions to add a disk."""
+ for disk in machine.disks:
+ lvcreate(machine, disk)
def bootMachine(machine, cdtype):
"""Boot a machine with a given boot CD.
def bootMachine(machine, cdtype):
"""Boot a machine with a given boot CD.
transaction.rollback()
raise
registerMachine(machine)
transaction.rollback()
raise
registerMachine(machine)
# tell it to boot with cdrom
bootMachine(machine, cdrom)
# tell it to boot with cdrom
bootMachine(machine, cdrom)
machines = [m for m in Machine.select() if haveAccess(user, m)]
on = {}
has_vnc = {}
machines = [m for m in Machine.select() if haveAccess(user, m)]
on = {}
has_vnc = {}
- uptimes = getUptimes(machines)
- on = uptimes
for m in machines:
if not on[m]:
has_vnc[m] = 'Off'
for m in machines:
if not on[m]:
has_vnc[m] = 'Off'
# status = statusInfo(m)
# on[m.name] = status is not None
# has_vnc[m.name] = hasVnc(status)
# status = statusInfo(m)
# on[m.name] = status is not None
# has_vnc[m.name] = hasVnc(status)
- max_mem=maxMemory(user, on=on)
+ max_mem=maxMemory(user)
max_disk=maxDisk(user)
d = dict(user=user,
max_disk=maxDisk(user)
d = dict(user=user,
- can_add_vm=canAddVm(user, on=on),
+ can_add_vm=canAddVm(user),
max_mem=max_mem,
max_disk=max_disk,
default_mem=max_mem,
max_mem=max_mem,
max_disk=max_disk,
default_mem=max_mem,
token = cPickle.dumps(token)
token = base64.urlsafe_b64encode(token)
token = cPickle.dumps(token)
token = base64.urlsafe_b64encode(token)
+ status = statusInfo(machine)
+ has_vnc = hasVnc(status)
+
+ on=status,
+ has_vnc=has_vnc,
machine=machine,
hostname=os.environ.get('SERVER_NAME', 'localhost'),
authtoken=token)
machine=machine,
hostname=os.environ.get('SERVER_NAME', 'localhost'),
authtoken=token)
username = "moo"
email = 'moo@cow.com'
u = User()
username = "moo"
email = 'moo@cow.com'
u = User()
if 'SSL_CLIENT_S_DN_Email' in os.environ:
username = os.environ[ 'SSL_CLIENT_S_DN_Email'].split("@")[0]
u.username = username
if 'SSL_CLIENT_S_DN_Email' in os.environ:
username = os.environ[ 'SSL_CLIENT_S_DN_Email'].split("@")[0]
u.username = username
#def body
<h1>Console</h1>
#def body
<h1>Console</h1>
+#if not $on
+<p> Your machine appears to be off.</p>
+#else if not $has_vnc
+<p> Your machine appears to not be accepting VNC connections. Perhaps you have a ParaVM machine?</p>
+#end if
<p>Here is a console to ${machine.name}.</p>
<APPLET CODE="VncViewer.class" ARCHIVE="../VncViewer.jar"
WIDTH="800" HEIGHT="632">
<p>Here is a console to ${machine.name}.</p>
<APPLET CODE="VncViewer.class" ARCHIVE="../VncViewer.jar"
WIDTH="800" HEIGHT="632">