Statistics
| Branch: | Tag: | Revision:

root / logic / utils.py @ e3a99a08

History | View | Annotate | Download (615 Bytes)

1
#
2
# Various utility functions
3
#
4
# Copyright 2010 Greek Research and Technology Network
5
#
6
from django.conf import settings
7

    
8
from db.models import VirtualMachine
9

    
10
def id_from_instance_name(name):
11
    """Returns VirtualMachine's Django id, given a ganeti machine name.
12

13
    Strips the ganeti prefix atm. Needs a better name!
14

15
    """
16
    if not str(name).startswith(settings.BACKEND_PREFIX_ID):
17
        raise VirtualMachine.InvalidBackendIdError(str(name))
18
    ns = str(name).lstrip(settings.BACKEND_PREFIX_ID)
19
    if not ns.isdigit():
20
        raise VirtualMachine.InvalidBackendIdError(str(name))
21

    
22
    return int(ns)