Revision a442c81d snf-cyclades-app/synnefo/logic/management/commands/server-import.py
b/snf-cyclades-app/synnefo/logic/management/commands/server-import.py | ||
---|---|---|
43 | 43 |
from synnefo.logic import servers |
44 | 44 |
from synnefo import quotas |
45 | 45 |
|
46 |
import sys |
|
47 |
|
|
48 | 46 |
|
49 | 47 |
HELP_MSG = """ |
50 | 48 |
|
... | ... | |
124 | 122 |
raise CommandError(field + " is mandatory") |
125 | 123 |
|
126 | 124 |
import_server(instance_name, backend_id, flavor_id, image_id, user_id, |
127 |
new_public_nic, self.stdout)
|
|
125 |
new_public_nic, self.stderr)
|
|
128 | 126 |
|
129 | 127 |
|
130 | 128 |
def import_server(instance_name, backend_id, flavor_id, image_id, user_id, |
131 |
new_public_nic, stream=sys.stdout):
|
|
129 |
new_public_nic, stream): |
|
132 | 130 |
flavor = common.get_resource("flavor", flavor_id) |
133 | 131 |
backend = common.get_resource("backend", backend_id) |
134 | 132 |
|
... | ... | |
144 | 142 |
raise CommandError("Unexpected error" + str(e)) |
145 | 143 |
|
146 | 144 |
if not new_public_nic: |
147 |
check_instance_nics(instance) |
|
145 |
check_instance_nics(instance, stream)
|
|
148 | 146 |
|
149 | 147 |
shutdown_instance(instance, backend_client, stream=stream) |
150 | 148 |
|
... | ... | |
180 | 178 |
return |
181 | 179 |
|
182 | 180 |
|
183 |
def flavor_from_instance(instance, flavor, stream=sys.stdout):
|
|
181 |
def flavor_from_instance(instance, flavor, stream): |
|
184 | 182 |
beparams = instance['beparams'] |
185 | 183 |
disk_sizes = instance['disk.sizes'] |
186 | 184 |
if len(disk_sizes) != 1: |
... | ... | |
195 | 193 |
cpu=cpu, ram=ram) |
196 | 194 |
|
197 | 195 |
|
198 |
def check_instance_nics(instance): |
|
196 |
def check_instance_nics(instance, stream):
|
|
199 | 197 |
instance_name = instance['name'] |
200 | 198 |
networks = instance['nic.networks.names'] |
201 |
print networks
|
|
199 |
stream.write(str(networks))
|
|
202 | 200 |
try: |
203 | 201 |
networks = map(id_from_network_name, networks) |
204 | 202 |
except Network.InvalidBackendIdError: |
... | ... | |
209 | 207 |
" a public network of synnefo." % instance_name) |
210 | 208 |
|
211 | 209 |
|
212 |
def remove_instance_nics(instance, backend_client, stream=sys.stdout):
|
|
210 |
def remove_instance_nics(instance, backend_client, stream): |
|
213 | 211 |
instance_name = instance['name'] |
214 | 212 |
ips = instance['nic.ips'] |
215 | 213 |
nic_indexes = xrange(0, len(ips)) |
... | ... | |
222 | 220 |
raise CommandError("Cannot remove instance NICs: %s" % error) |
223 | 221 |
|
224 | 222 |
|
225 |
def add_public_nic(instance_name, nic, backend_client, stream=sys.stdout):
|
|
223 |
def add_public_nic(instance_name, nic, backend_client, stream): |
|
226 | 224 |
stream.write("Adding public NIC %s\n" % nic) |
227 | 225 |
jobid = backend_client.ModifyInstance(instance_name, nics=[('add', nic)]) |
228 | 226 |
(status, error) = wait_for_job(backend_client, jobid) |
... | ... | |
230 | 228 |
raise CommandError("Cannot rename instance: %s" % error) |
231 | 229 |
|
232 | 230 |
|
233 |
def shutdown_instance(instance, backend_client, stream=sys.stdout):
|
|
231 |
def shutdown_instance(instance, backend_client, stream): |
|
234 | 232 |
instance_name = instance['name'] |
235 | 233 |
if instance['status'] != 'ADMIN_down': |
236 | 234 |
stream.write("Instance is not down. Shutting down instance...\n") |
... | ... | |
240 | 238 |
raise CommandError("Cannot shutdown instance: %s" % error) |
241 | 239 |
|
242 | 240 |
|
243 |
def rename_instance(old_name, new_name, backend_client, stream=sys.stdout):
|
|
241 |
def rename_instance(old_name, new_name, backend_client, stream): |
|
244 | 242 |
stream.write("Renaming instance to %s\n" % new_name) |
245 | 243 |
|
246 | 244 |
jobid = backend_client.RenameInstance(old_name, new_name, |
... | ... | |
250 | 248 |
raise CommandError("Cannot rename instance: %s" % error) |
251 | 249 |
|
252 | 250 |
|
253 |
def startup_instance(name, backend_client, stream=sys.stdout):
|
|
251 |
def startup_instance(name, backend_client, stream): |
|
254 | 252 |
stream.write("Starting instance %s\n" % name) |
255 | 253 |
jobid = backend_client.StartupInstance(name) |
256 | 254 |
(status, error) = wait_for_job(backend_client, jobid) |
Also available in: Unified diff