40 |
40 |
from synnefo.settings import (CYCLADES_ASTAKOS_SERVICE_TOKEN as ASTAKOS_TOKEN,
|
41 |
41 |
ASTAKOS_URL)
|
42 |
42 |
from synnefo.logic.rapi import GanetiApiError, GanetiRapiClient
|
|
43 |
from synnefo.logic.utils import (id_from_instance_name,
|
|
44 |
id_from_network_name)
|
43 |
45 |
from synnefo.lib import astakos
|
44 |
46 |
|
45 |
47 |
import logging
|
... | ... | |
92 |
94 |
|
93 |
95 |
|
94 |
96 |
def get_vm(server_id):
|
|
97 |
"""Get a VirtualMachine object by its ID.
|
|
98 |
|
|
99 |
@type server_id: int or string
|
|
100 |
@param server_id: The server's DB id or the Ganeti name
|
|
101 |
|
|
102 |
"""
|
95 |
103 |
try:
|
96 |
104 |
server_id = int(server_id)
|
|
105 |
except (ValueError, TypeError):
|
|
106 |
try:
|
|
107 |
server_id = id_from_instance_name(server_id)
|
|
108 |
except VirtualMachine.InvalidBackendIdError:
|
|
109 |
raise CommandError("Invalid server ID: %s" % server_id)
|
|
110 |
|
|
111 |
try:
|
97 |
112 |
return VirtualMachine.objects.get(id=server_id)
|
98 |
|
except ValueError:
|
99 |
|
raise CommandError("Invalid server ID: %s", server_id)
|
100 |
113 |
except VirtualMachine.DoesNotExist:
|
101 |
114 |
raise CommandError("Server with ID %s not found in DB."
|
102 |
115 |
" Use snf-manage server-list to find out"
|
... | ... | |
104 |
117 |
|
105 |
118 |
|
106 |
119 |
def get_network(network_id):
|
|
120 |
"""Get a Network object by its ID.
|
|
121 |
|
|
122 |
@type network_id: int or string
|
|
123 |
@param network_id: The networks DB id or the Ganeti name
|
|
124 |
|
|
125 |
"""
|
|
126 |
|
107 |
127 |
try:
|
108 |
128 |
network_id = int(network_id)
|
|
129 |
except (ValueError, TypeError):
|
|
130 |
try:
|
|
131 |
network_id = id_from_network_name(network_id)
|
|
132 |
except Network.InvalidBackendIdError:
|
|
133 |
raise CommandError("Invalid network ID: %s" % network_id)
|
|
134 |
|
|
135 |
try:
|
109 |
136 |
return Network.objects.get(id=network_id)
|
110 |
|
except ValueError:
|
111 |
|
raise CommandError("Invalid network ID: %s", network_id)
|
112 |
137 |
except Network.DoesNotExist:
|
113 |
138 |
raise CommandError("Network with ID %s not found in DB."
|
114 |
139 |
" Use snf-manage network-list to find out"
|