Revision 0b827aa4 snf-cyclades-app/synnefo/db/models.py
b/snf-cyclades-app/synnefo/db/models.py | ||
---|---|---|
487 | 487 |
def __unicode__(self): |
488 | 488 |
return self.name |
489 | 489 |
|
490 |
def update_oper_state(self):
|
|
491 |
"""Update operstate of the Network.
|
|
490 |
def update_state(self): |
|
491 |
"""Update state of the Network. |
|
492 | 492 |
|
493 |
Update the operstate of the Network depending on the related
|
|
493 |
Update the state of the Network depending on the related |
|
494 | 494 |
backend_networks. When backend networks do not have the same operstate, |
495 |
the Network's operstate is PENDING. Otherwise it is the same with
|
|
495 |
the Network's state is PENDING. Otherwise it is the same with |
|
496 | 496 |
the BackendNetworks operstate. |
497 | 497 |
|
498 | 498 |
""" |
499 | 499 |
backend_states = [s.operstate for s in self.backend_networks.all()] |
500 | 500 |
if not backend_states: |
501 |
self.operstate = 'PENDING'
|
|
501 |
self.state = 'PENDING' |
|
502 | 502 |
self.save() |
503 | 503 |
return |
504 | 504 |
|
505 | 505 |
all_equal = len(set(backend_states)) <= 1 |
506 |
self.operstate = all_equal and backend_states[0] or 'PENDING'
|
|
506 |
self.state = all_equal and backend_states[0] or 'PENDING' |
|
507 | 507 |
|
508 |
if self.operstate == 'DELETED':
|
|
508 |
if self.state == 'DELETED': |
|
509 | 509 |
self.deleted = True |
510 | 510 |
|
511 | 511 |
if self.mac_prefix: |
... | ... | |
577 | 577 |
|
578 | 578 |
def save(self, *args, **kwargs): |
579 | 579 |
super(BackendNetwork, self).save(*args, **kwargs) |
580 |
self.network.update_oper_state()
|
|
580 |
self.network.update_state() |
|
581 | 581 |
|
582 | 582 |
def delete(self, *args, **kwargs): |
583 | 583 |
super(BackendNetwork, self).delete(*args, **kwargs) |
584 |
self.network.update_oper_state()
|
|
584 |
self.network.update_state() |
|
585 | 585 |
|
586 | 586 |
|
587 | 587 |
class NetworkInterface(models.Model): |
Also available in: Unified diff