Revision 6fec4302 snf-cyclades-app/synnefo/logic/utils.py

b/snf-cyclades-app/synnefo/logic/utils.py
1
# Copyright 2011 GRNET S.A. All rights reserved.
1
# Copyright 2011-2014 GRNET S.A. All rights reserved.
2 2
#
3 3
# Redistribution and use in source and binary forms, with or without
4 4
# modification, are permitted provided that the following conditions
......
42 42
    Strips the ganeti prefix atm. Needs a better name!
43 43

  
44 44
    """
45
    sname = str(name)
45
    sname = smart_unicode(name)
46 46
    if not sname.startswith(settings.BACKEND_PREFIX_ID):
47 47
        raise VirtualMachine.InvalidBackendIdError(sname)
48 48
    ns = sname.replace(settings.BACKEND_PREFIX_ID, "", 1)
......
53 53

  
54 54

  
55 55
def id_to_instance_name(id):
56
    return "%s%s" % (settings.BACKEND_PREFIX_ID, str(id))
56
    return "%s%s" % (settings.BACKEND_PREFIX_ID, smart_unicode(id))
57 57

  
58 58

  
59 59
def id_from_network_name(name):
......
62 62
    Strips the ganeti prefix atm. Needs a better name!
63 63

  
64 64
    """
65
    if not str(name).startswith(settings.BACKEND_PREFIX_ID):
66
        raise Network.InvalidBackendIdError(str(name))
67
    ns = str(name).replace(settings.BACKEND_PREFIX_ID + 'net-', "", 1)
65
    if not smart_unicode(name).startswith(settings.BACKEND_PREFIX_ID):
66
        raise Network.InvalidBackendIdError(smart_unicode(name))
67
    ns = smart_unicode(name).replace(settings.BACKEND_PREFIX_ID + 'net-', "", 1)
68 68
    if not ns.isdigit():
69
        raise Network.InvalidBackendIdError(str(name))
69
        raise Network.InvalidBackendIdError(smart_unicode(name))
70 70

  
71 71
    return int(ns)
72 72

  
73 73

  
74 74
def id_to_network_name(id):
75
    return "%snet-%s" % (settings.BACKEND_PREFIX_ID, str(id))
75
    return "%snet-%s" % (settings.BACKEND_PREFIX_ID, smart_unicode(id))
76 76

  
77 77

  
78 78
def id_from_nic_name(name):
79 79
    """Returns NIC's Django id, given a Ganeti's NIC name.
80 80

  
81 81
    """
82
    if not str(name).startswith(settings.BACKEND_PREFIX_ID):
82
    if not smart_unicode(name).startswith(settings.BACKEND_PREFIX_ID):
83 83
        raise ValueError("Invalid NIC name: %s" % name)
84
    ns = str(name).replace(settings.BACKEND_PREFIX_ID + 'nic-', "", 1)
84
    ns = smart_unicode(name).replace(settings.BACKEND_PREFIX_ID + 'nic-', "", 1)
85 85
    if not ns.isdigit():
86 86
        raise ValueError("Invalid NIC name: %s" % name)
87 87

  

Also available in: Unified diff