Revision b3d28af2 snf-cyclades-app/synnefo/logic/backend.py
b/snf-cyclades-app/synnefo/logic/backend.py | ||
---|---|---|
606 | 606 |
for i in instances: |
607 | 607 |
mem += i['oper_ram'] |
608 | 608 |
return mem |
609 |
|
|
610 |
## |
|
611 |
## Synchronized operations for reconciliation |
|
612 |
## |
|
613 |
|
|
614 |
|
|
615 |
def create_network_synced(network, backend): |
|
616 |
result = _create_network_synced(network, backend) |
|
617 |
if result[0] != 'success': |
|
618 |
return result |
|
619 |
result = connect_network_synced(network, backend) |
|
620 |
return result |
|
621 |
|
|
622 |
|
|
623 |
def _create_network_synced(network, backend): |
|
624 |
client = backend.client |
|
625 |
job = client.CreateNetwork(network.backend_id, network.subnet) |
|
626 |
return wait_for_job(client, job) |
|
627 |
|
|
628 |
|
|
629 |
def connect_network_synced(network, backend): |
|
630 |
mode = network.public and 'routed' or 'bridged' |
|
631 |
client = backend.client |
|
632 |
|
|
633 |
for group in client.GetGroups(): |
|
634 |
job = client.ConnectNetwork(network.backend_id, group, mode, |
|
635 |
network.link) |
|
636 |
result = wait_for_job(client, job) |
|
637 |
if result[0] != 'success': |
|
638 |
return result |
|
639 |
|
|
640 |
return result |
|
641 |
|
|
642 |
|
|
643 |
def wait_for_job(client, jobid): |
|
644 |
result = client.WaitForJobChange(jobid, ['status', 'opresult'], None, None) |
|
645 |
status = result['job_info'][0] |
|
646 |
while status not in ['success', 'error', 'cancel']: |
|
647 |
result = client.WaitForJobChange(jobid, ['status', 'opresult'], |
|
648 |
[result], None) |
|
649 |
status = result['job_info'][0] |
|
650 |
|
|
651 |
if status == 'success': |
|
652 |
return (status, None) |
|
653 |
else: |
|
654 |
error = result['job_info'][1] |
|
655 |
return (status, error) |
Also available in: Unified diff