Revision 22ee6892 snf-cyclades-app/synnefo/logic/utils.py

b/snf-cyclades-app/synnefo/logic/utils.py
29 29

  
30 30
# Utility functions
31 31

  
32
from synnefo.db.models import VirtualMachine
32
from synnefo.db.models import VirtualMachine, Network
33 33

  
34 34
from django.conf import settings
35 35

  
......
48 48

  
49 49
    return int(ns)
50 50

  
51
def id_from_network_name(name):
52
    """Returns Network's Django id, given a ganeti machine name.
53

  
54
    Strips the ganeti prefix atm. Needs a better name!
55

  
56
    """
57
    if not str(name).startswith(settings.BACKEND_PREFIX_ID):
58
        raise Network.InvalidBackendIdError(str(name))
59
    ns = str(name).replace(settings.BACKEND_PREFIX_ID, "", 1)
60
    if not ns.isdigit():
61
        raise Network.InvalidBackendIdError(str(name))
62

  
63
    return int(ns)
64

  
65

  
51 66
def get_rsapi_state(vm):
52 67
    """Returns the API state for a virtual machine
53 68

  

Also available in: Unified diff