Revision d30f29aa

b/snf-cyclades-app/synnefo/db/models.py
371 371
        """Returns the backend id for this VM by prepending backend-prefix."""
372 372
        if not self.id:
373 373
            raise VirtualMachine.InvalidBackendIdError("self.id is None")
374
        return '%s%s' % (settings.BACKEND_PREFIX_ID, self.id)
374
        return "%s%s" % (settings.BACKEND_PREFIX_ID, str(self.id))
375 375

  
376 376
    class Meta:
377 377
        verbose_name = u'Virtual machine instance'
......
475 475
        """Return the backend id by prepending backend-prefix."""
476 476
        if not self.id:
477 477
            raise Network.InvalidBackendIdError("self.id is None")
478
        return '%s%s' % (settings.BACKEND_PREFIX_ID, self.id)
478
        return "%snet-%s" % (settings.BACKEND_PREFIX_ID, str(self.id))
479 479

  
480 480
    @property
481 481
    def backend_tag(self):
b/snf-cyclades-app/synnefo/logic/management/commands/network_reconcile.py
42 42
from django.core.management.base import BaseCommand, CommandError
43 43

  
44 44
from synnefo.db.models import Backend, Network, BackendNetwork
45
from synnefo.logic import reconciliation, backend
45
from synnefo.logic import reconciliation, backend, utils
46 46

  
47 47

  
48 48
class Command(BaseCommand):
......
163 163
                #XXX:Move this to backend
164 164
                for id in orphans:
165 165
                    out.write('Disconnecting and deleting network %d\n' % id)
166
                    network = '%s%s' % (settings.BACKEND_PREFIX_ID, str(id))
166
                    network = utils.id_to_network_name(id)
167 167
                    for group in client.GetGroups():
168 168
                        client.DisconnectNetwork(network, group)
169 169
                        client.DeleteNetwork(network)
b/snf-cyclades-app/synnefo/logic/management/commands/reconcile.py
44 44
from django.core.management.base import BaseCommand, CommandError
45 45

  
46 46
from synnefo.db.models import VirtualMachine
47
from synnefo.logic import reconciliation, backend
47
from synnefo.logic import reconciliation, backend, utils
48 48

  
49 49

  
50 50
class Command(BaseCommand):
......
202 202
                len(orphans)
203 203
            for id in orphans:
204 204
                vm = VirtualMachine.objects.get(pk=id)
205
                vm.client.DeleteInstance('%s%s' %
206
                                    (settings.BACKEND_PREFIX_ID, str(id)))
205
                vm.client.DeleteInstance(utils.id_to_instance_name(id))
207 206
            print >> sys.stderr, "    ...done"
208 207

  
209 208
        if options['fix_unsynced'] and len(unsynced) > 0:
b/snf-cyclades-app/synnefo/logic/reconciliation.py
75 75
from synnefo.util.dictconfig import dictConfig
76 76
from synnefo.util.rapi import GanetiApiError
77 77
from synnefo.logic.backend import get_ganeti_instances
78
from synnefo.logic import utils
78 79

  
79 80

  
80 81
log = logging.getLogger()
......
96 97
                        # Server is still building in Ganeti
97 98
                        continue
98 99
                    else:
99
                        new_vm = vm.client.GetInstance('%s%d' %
100
                                (settings.BACKEND_PREFIX_ID, i))
100
                        new_vm = vm.client.GetInstance(utils.id_to_instance_name(i))
101 101
                        # Server has just been created in Ganeti
102 102
                        continue
103 103
                except GanetiApiError:
......
172 172
    for i in ganeti_instances:
173 173
        if i['name'].startswith(prefix):
174 174
            try:
175
                id = int(i['name'].split(prefix)[1])
175
                id = utils.id_from_instance_name(i['name'])
176 176
            except Exception:
177 177
                log.error("Ignoring instance with malformed name %s",
178 178
                              i['name'])
......
201 201
    for i in instances:
202 202
        if i['name'].startswith(prefix):
203 203
            try:
204
                id = int(i['name'].split(prefix)[1])
204
                id = utils.id_from_instance_name(i['name'])
205 205
            except Exception:
206 206
                log.error("Ignoring instance with malformed name %s",
207 207
                              i['name'])
......
282 282
    networks = {}
283 283
    for net in backend.client.GetNetworks(bulk=True):
284 284
        if net['name'].startswith(prefix):
285
            # TODO: Get it from fun. Catch errors
286
            id = int(net['name'].split(prefix)[1])
285
            id = utils.id_from_network_name(net['name'])
287 286
            networks[id] = net
288 287

  
289 288
    return networks
b/snf-cyclades-app/synnefo/logic/utils.py
48 48

  
49 49
    return int(ns)
50 50

  
51

  
52
def id_to_instance_name(id):
53
    return "%s%s" (settings.BACKEND_PREFIX_ID, str(id))
54

  
55

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

  
......
63 68
    return int(ns)
64 69

  
65 70

  
71
def id_to_network_name(id):
72
    return "%snet-%s" (settings.BACKEND_PREFIX_ID, str(id))
73

  
74

  
66 75
def get_rsapi_state(vm):
67 76
    """Returns the API state for a virtual machine
68 77

  

Also available in: Unified diff