Revision 6fec4302

b/snf-cyclades-app/synnefo/api/util.py
1
# Copyright 2011-2012 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
4 4
# without modification, are permitted provided that the following
b/snf-cyclades-app/synnefo/logic/management/commands/server-import.py
142 142
            raise CommandError("Instance %s does not exist in backend %s"
143 143
                               % (instance_name, backend))
144 144
        else:
145
            raise CommandError("Unexpected error" + str(e))
145
            raise CommandError("Unexpected error: %s" % e)
146 146

  
147 147
    if not new_public_nic:
148 148
        check_instance_nics(instance)
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