Revision 9621c777 snf-cyclades-app/synnefo/api/management/commands/server-import.py
b/snf-cyclades-app/synnefo/api/management/commands/server-import.py | ||
---|---|---|
65 | 65 |
output_transaction = True |
66 | 66 |
|
67 | 67 |
option_list = BaseCommand.option_list + ( |
68 |
make_option("--backend-id", dest="backend_id", |
|
69 |
help="Unique identifier of the Ganeti backend that" |
|
70 |
" hosts the VM. Use snf-manage backend-list to" |
|
71 |
" find out available backends."), |
|
72 |
make_option("--user-id", dest="user_id", |
|
73 |
help="Unique identifier of the owner of the server"), |
|
74 |
make_option("--image-id", dest="image_id", |
|
75 |
default=None, |
|
76 |
help="Unique identifier of the image." |
|
77 |
" Use snf-manage image-list to find out" |
|
78 |
" available images."), |
|
79 |
make_option("--flavor-id", dest="flavor_id", |
|
80 |
help="Unique identifier of the flavor" |
|
81 |
" Use snf-manage flavor-list to find out" |
|
82 |
" available flavors."), |
|
83 |
make_option("--new-nics", dest='new_nics', |
|
84 |
default=False, |
|
85 |
action="store_true", |
|
86 |
help="Remove old NICs of instance, and create" |
|
87 |
" a new NIC connected to a public network of" |
|
88 |
" Synnefo.") |
|
89 |
) |
|
68 |
make_option( |
|
69 |
"--backend-id", |
|
70 |
dest="backend_id", |
|
71 |
help="Unique identifier of the Ganeti backend that" |
|
72 |
" hosts the VM. Use snf-manage backend-list to" |
|
73 |
" find out available backends."), |
|
74 |
make_option( |
|
75 |
"--user-id", |
|
76 |
dest="user_id", |
|
77 |
help="Unique identifier of the owner of the server"), |
|
78 |
make_option( |
|
79 |
"--image-id", |
|
80 |
dest="image_id", |
|
81 |
default=None, |
|
82 |
help="Unique identifier of the image." |
|
83 |
" Use snf-manage image-list to find out" |
|
84 |
" available images."), |
|
85 |
make_option( |
|
86 |
"--flavor-id", |
|
87 |
dest="flavor_id", |
|
88 |
help="Unique identifier of the flavor" |
|
89 |
" Use snf-manage flavor-list to find out" |
|
90 |
" available flavors."), |
|
91 |
make_option( |
|
92 |
"--new-nics", |
|
93 |
dest='new_nics', |
|
94 |
default=False, |
|
95 |
action="store_true", |
|
96 |
help="Remove old NICs of instance, and create" |
|
97 |
" a new NIC connected to a public network of" |
|
98 |
" Synnefo.") |
|
99 |
) |
|
90 | 100 |
|
91 | 101 |
REQUIRED = ("user-id", "backend-id", "image-id", "flavor-id") |
92 | 102 |
|
... | ... | |
127 | 137 |
instance = backend_client.GetInstance(instance_name) |
128 | 138 |
except GanetiApiError as e: |
129 | 139 |
if e.code == 404: |
130 |
raise CommandError("Instance %s does not exist in backend %s"\
|
|
131 |
% (instance_name, backend)) |
|
140 |
raise CommandError("Instance %s does not exist in backend %s" |
|
141 |
% (instance_name, backend))
|
|
132 | 142 |
else: |
133 | 143 |
raise CommandError("Unexpected error" + str(e)) |
134 | 144 |
|
... | ... | |
137 | 147 |
stream=stream) |
138 | 148 |
(network, address) = allocate_public_address(backend) |
139 | 149 |
if address is None: |
140 |
raise CommandError("Can not allocate a public address."\
|
|
150 |
raise CommandError("Can not allocate a public address." |
|
141 | 151 |
" No available public network.") |
142 | 152 |
nic = {'ip': address, 'network': network.backend_id} |
143 | 153 |
add_public_nic(instance_name, nic, backend_client, |
... | ... | |
187 | 197 |
networks = map(id_from_network_name, networks) |
188 | 198 |
except Network.InvalidBackendIdError: |
189 | 199 |
raise CommandError("Instance %s has NICs that do not belong to a" |
190 |
" network belonging to synnefo. Either manually" |
|
191 |
" modify the instance NICs or specify --new-nics" |
|
192 |
" to clear the old NICs and create a new NIC to" |
|
193 |
" a public network of synnefo." % instance_name) |
|
200 |
" network belonging to synnefo. Either manually"
|
|
201 |
" modify the instance NICs or specify --new-nics"
|
|
202 |
" to clear the old NICs and create a new NIC to"
|
|
203 |
" a public network of synnefo." % instance_name)
|
|
194 | 204 |
|
195 | 205 |
|
196 | 206 |
def remove_instance_nics(instance, backend_client, stream=sys.stdout): |
... | ... | |
218 | 228 |
instance_name = instance['name'] |
219 | 229 |
if instance['status'] != 'ADMIN_down': |
220 | 230 |
stream.write("Instance is not down. Shutting down" |
221 |
" instance\n")
|
|
231 |
" instance\n") |
|
222 | 232 |
jobid = backend_client.ShutdownInstance(instance_name) |
223 | 233 |
(status, error) = wait_for_job(backend_client, jobid) |
224 | 234 |
if status != 'success': |
... | ... | |
229 | 239 |
stream.write("Renaming instance to %s\n" % new_name) |
230 | 240 |
|
231 | 241 |
jobid = backend_client.RenameInstance(old_name, new_name, |
232 |
ip_check=False, name_check=False) |
|
242 |
ip_check=False, name_check=False)
|
|
233 | 243 |
(status, error) = wait_for_job(backend_client, jobid) |
234 | 244 |
if status != 'success': |
235 | 245 |
raise CommandError("Can not rename instance: %s" % error) |
Also available in: Unified diff