-from invirt.database import Machine, NIC, Type, Disk, CDROM, Autoinstall
+from invirt.database import Machine, NIC, Type, Disk, CDROM, Autoinstall, Owner
class Validate:
def __init__(self, username, state, machine_id=None, name=None, description=None, owner=None,
class Validate:
def __init__(self, username, state, machine_id=None, name=None, description=None, owner=None,
machines = getMachinesByOwner(owner, machine)
active_machines = [m for m in machines if m.name in g.xmlist_raw]
mem_usage = sum([x.memory for x in active_machines if x != machine])
machines = getMachinesByOwner(owner, machine)
active_machines = [m for m in machines if m.name in g.xmlist_raw]
mem_usage = sum([x.memory for x in active_machines if x != machine])
def maxDisk(owner, machine=None):
"""Return the maximum disk that a machine can reach.
def maxDisk(owner, machine=None):
"""Return the maximum disk that a machine can reach.
If machine is None, the maximum disk for a new machine. Otherwise,
return the maximum that a given machine can be changed to.
"""
If machine is None, the maximum disk for a new machine. Otherwise,
return the maximum that a given machine can be changed to.
"""
disk_usage = Disk.query().filter(Disk.c.machine_id != machine_id).\
join('machine').\
filter_by(owner=owner).sum(Disk.c.size) or 0
disk_usage = Disk.query().filter(Disk.c.machine_id != machine_id).\
join('machine').\
filter_by(owner=owner).sum(Disk.c.size) or 0
def cantAddVm(owner, g):
machines = getMachinesByOwner(owner)
active_machines = [m for m in machines if m.name in g.xmlist_raw]
def cantAddVm(owner, g):
machines = getMachinesByOwner(owner)
active_machines = [m for m in machines if m.name in g.xmlist_raw]
return ('You already have the maximum number of VMs turned on. '
'To create more, turn one off.')
return False
return ('You already have the maximum number of VMs turned on. '
'To create more, turn one off.')
return False
if machine is not None and owner in (machine.owner, None):
return machine.owner
if owner is None:
raise InvalidInput('owner', owner, "Owner must be specified")
if machine is not None and owner in (machine.owner, None):
return machine.owner
if owner is None:
raise InvalidInput('owner', owner, "Owner must be specified")
try:
if user not in cache_acls.expandLocker(owner):
raise InvalidInput('owner', owner, 'You do not have access to the '
try:
if user not in cache_acls.expandLocker(owner):
raise InvalidInput('owner', owner, 'You do not have access to the '
except dns.resolver.NoAnswer, e:
# If we can get the TXT record, then we can verify it's
# reserved. If this lookup fails, let it bubble up and be
# dealt with
except dns.resolver.NoAnswer, e:
# If we can get the TXT record, then we can verify it's
# reserved. If this lookup fails, let it bubble up and be
# dealt with
txt = answer[0].strings[0]
if txt.startswith('reserved'):
raise InvalidInput('name', name, 'The name you have requested has been %s. For more information, contact us at %s' % (txt, config.dns.contact))
txt = answer[0].strings[0]
if txt.startswith('reserved'):
raise InvalidInput('name', name, 'The name you have requested has been %s. For more information, contact us at %s' % (txt, config.dns.contact))