Revision 43ee6ae1 kamaki/cli/commands/cyclades_cli.py

b/kamaki/cli/commands/cyclades_cli.py
34 34
from kamaki.cli import command
35 35
from kamaki.cli.command_tree import CommandTree
36 36
from kamaki.cli.utils import print_dict, print_list, bold
37
from kamaki.cli.errors import CLIError, raiseCLIError, CLISyntaxError
37
from kamaki.cli.errors import raiseCLIError, CLISyntaxError
38 38
from kamaki.clients.cyclades import CycladesClient, ClientError
39 39
from kamaki.cli.argument import FlagArgument, ValueArgument, KeyValueArgument
40 40
from kamaki.cli.argument import ProgressBarArgument
......
101 101
        try:
102 102
            servers = self.client.list_servers(self.get_argument('detail'))
103 103
            self._print(servers)
104
        except ClientError as err:
104
        except Exception as err:
105 105
            raiseCLIError(err)
106 106

  
107 107

  
......
130 130
        super(self.__class__, self).main()
131 131
        try:
132 132
            server = self.client.get_server_details(int(server_id))
133
        except ClientError as err:
134
            raiseCLIError(err)
135 133
        except ValueError as err:
136
            raise CLIError(message='Server id must be positive integer',
137
                importance=1)
134
            raiseCLIError(err, 'Server id must be positive integer', 1)
135
        except Exception as err:
136
            raiseCLIError(err)
138 137
        self._print(server)
139 138

  
140 139

  
......
151 150
        for i, terms in enumerate(newvalue):
152 151
            termlist = terms.split(',')
153 152
            if len(termlist) > 5:
154
                raise CLISyntaxError(details='Wrong number of terms'\
155
                + ' ("PATH,[SERVER_PATH,[OWNER,[GROUP,[MODE]]]]"')
153
                raiseCLIError(CLISyntaxError(details='Wrong number of terms'\
154
                + ' ("PATH,[SERVER_PATH,[OWNER,[GROUP,[MODE]]]]"'))
156 155
            path = termlist[0]
157 156
            if not exists(path):
158
                raise CLIError(message="File %s does not exist" % path,
159
                importance=1)
157
                raiseCLIError(None, "File %s does not exist" % path, 1)
160 158
            self._value.append(dict(path=path))
161 159
            with open(path) as f:
162 160
                self._value[i]['contents'] = b64encode(f.read())
......
191 189
        except ClientError as err:
192 190
            raiseCLIError(err)
193 191
        except ValueError as err:
194
            raise CLIError('Invalid flavor id %s ' % flavor_id,
192
            raiseCLIError(err, 'Invalid flavor id %s ' % flavor_id,
195 193
                details='Flavor id must be a positive integer',
196 194
                importance=1)
197 195
        except Exception as err:
198
            raise CLIError('Syntax error: %s\n' % err, importance=1)
196
            raiseCLIError(err, 'Syntax error: %s\n' % err, importance=1)
199 197
        print_dict(reply)
200 198

  
201 199

  
......
209 207
            self.client.update_server_name(int(server_id), new_name)
210 208
        except ClientError as err:
211 209
            raiseCLIError(err)
212
        except ValueError:
213
            raise CLIError('Invalid server id %s ' % server_id,
210
        except ValueError as err:
211
            raiseCLIError(err, 'Invalid server id %s ' % server_id,
214 212
                details='Server id must be positive integer\n',
215 213
                importance=1)
216 214

  
......
223 221
        super(self.__class__, self).main()
224 222
        try:
225 223
            self.client.delete_server(int(server_id))
226
        except ClientError as err:
224
        except ValueError as err:
225
            raiseCLIError(err, 'Server id must be positive integer', 1)
226
        except Exception as err:
227 227
            raiseCLIError(err)
228
        except ValueError:
229
            raise CLIError(message='Server id must be positive integer',
230
                importance=1)
231 228

  
232 229

  
233 230
@command(server_cmds)
......
243 240
        try:
244 241
            self.client.reboot_server(int(server_id),
245 242
                self.get_argument('hard'))
246
        except ClientError as err:
243
        except ValueError as err:
244
            raiseCLIError(err, 'Server id must be positive integer', 1)
245
        except Exception as err:
247 246
            raiseCLIError(err)
248
        except ValueError:
249
            raise CLIError(message='Server id must be positive integer',
250
                importance=1)
251 247

  
252 248

  
253 249
@command(server_cmds)
......
258 254
        super(self.__class__, self).main()
259 255
        try:
260 256
            self.client.start_server(int(server_id))
261
        except ClientError as err:
257
        except ValueError as err:
258
            raiseCLIError(err, 'Server id must be positive integer', 1)
259
        except Exception as err:
262 260
            raiseCLIError(err)
263
        except ValueError:
264
            raise CLIError(message='Server id must be positive integer',
265
                importance=1)
266 261

  
267 262

  
268 263
@command(server_cmds)
......
273 268
        super(self.__class__, self).main()
274 269
        try:
275 270
            self.client.shutdown_server(int(server_id))
276
        except ClientError as err:
271
        except ValueError as err:
272
            raiseCLIError(err, 'Server id must be positive integer', 1)
273
        except Exception as err:
277 274
            raiseCLIError(err)
278
        except ValueError:
279
            raise CLIError(message='Server id must be positive integer',
280
                importance=1)
281 275

  
282 276

  
283 277
@command(server_cmds)
......
288 282
        super(self.__class__, self).main()
289 283
        try:
290 284
            reply = self.client.get_server_console(int(server_id))
291
        except ClientError as err:
285
        except ValueError as err:
286
            raiseCLIError(err, 'Server id must be positive integer', 1)
287
        except Exception as err:
292 288
            raiseCLIError(err)
293
        except ValueError:
294
            raise CLIError(message='Server id must be positive integer',
295
                importance=1)
296 289
        print_dict(reply)
297 290

  
298 291

  
......
304 297
        super(self.__class__, self).main()
305 298
        try:
306 299
            self.client.set_firewall_profile(int(server_id), profile)
307
        except ClientError as err:
300
        except ValueError as err:
301
            raiseCLIError(err, 'Server id must be positive integer', 1)
302
        except Exception as err:
308 303
            raiseCLIError(err)
309
        except ValueError:
310
            raise CLIError(message='Server id must be positive integer',
311
                importance=1)
312 304

  
313 305

  
314 306
@command(server_cmds)
......
319 311
        super(self.__class__, self).main()
320 312
        try:
321 313
            reply = self.client.list_server_nics(int(server_id))
322
        except ClientError as err:
314
        except ValueError as err:
315
            raiseCLIError(err, 'Server id must be positive integer', 1)
316
        except Exception as err:
323 317
            raiseCLIError(err)
324
        except ValueError:
325
            raise CLIError(message='Server id must be positive integer',
326
                importance=1)
327 318
        print_list(reply)
328 319

  
329 320

  
......
335 326
        super(self.__class__, self).main()
336 327
        try:
337 328
            reply = self.client.get_server_metadata(int(server_id), key)
338
        except ValueError:
339
            raise CLIError(message='Server id must be positive integer',
340
                importance=1)
341
        except ClientError as err:
329
        except ValueError as err:
330
            raiseCLIError(err, 'Server id must be positive integer', 1)
331
        except Exception as err:
342 332
            raiseCLIError(err)
343 333
        print_dict(reply)
344 334

  
......
352 342
        try:
353 343
            reply = self.client.create_server_metadata(\
354 344
                int(server_id), key, val)
355
        except ClientError as err:
345
        except ValueError as err:
346
            raiseCLIError(err, 'Server id must be positive integer', 1)
347
        except Exception as err:
356 348
            raiseCLIError(err)
357
        except ValueError:
358
            raise CLIError(message='Server id must be positive integer',
359
                importance=1)
360 349
        print_dict(reply)
361 350

  
362 351

  
......
370 359
        try:
371 360
            reply = self.client.update_server_metadata(int(server_id),
372 361
                **metadata)
373
        except ClientError as err:
362
        except ValueError as err:
363
            raiseCLIError(err, 'Server id must be positive integer', 1)
364
        except Exception as err:
374 365
            raiseCLIError(err)
375
        except ValueError:
376
            raise CLIError(message='Server id must be positive integer',
377
                importance=1)
378 366
        print_dict(reply)
379 367

  
380 368

  
......
386 374
        super(self.__class__, self).main()
387 375
        try:
388 376
            self.client.delete_server_metadata(int(server_id), key)
389
        except ClientError as err:
377
        except ValueError as err:
378
            raiseCLIError(err, 'Server id must be positive integer', 1)
379
        except Exception as err:
390 380
            raiseCLIError(err)
391
        except ValueError:
392
            raise CLIError(message='Server id must be positive integer',
393
                importance=1)
394 381

  
395 382

  
396 383
@command(server_cmds)
......
401 388
        super(self.__class__, self).main()
402 389
        try:
403 390
            reply = self.client.get_server_stats(int(server_id))
404
        except ClientError as err:
391
        except ValueError as err:
392
            raiseCLIError(err, 'Server id must be positive integer', 1)
393
        except Exception as err:
405 394
            raiseCLIError(err)
406
        except ValueError:
407
            raise CLIError(message='Server id must be positive integer',
408
                importance=1)
409 395
        print_dict(reply, exclude=('serverRef',))
410 396

  
411 397

  
......
441 427
        if new_mode:
442 428
            print('Server %s is now in %s mode' % (server_id, new_mode))
443 429
        else:
444
            print('Time out')
430
            raiseCLIError(None, 'Time out')
445 431

  
446 432

  
447 433
@command(flavor_cmds)
......
463 449
        super(self.__class__, self).main()
464 450
        try:
465 451
            flavors = self.client.list_flavors(self.get_argument('detail'))
466
        except ClientError as err:
452
        except Exception as err:
467 453
            raiseCLIError(err)
468
        #print_list(flavors)
469 454
        self._print(flavors)
470 455

  
471 456

  
......
477 462
        super(self.__class__, self).main()
478 463
        try:
479 464
            flavor = self.client.get_flavor_details(int(flavor_id))
480
        except ClientError as err:
465
        except ValueError as err:
466
            raiseCLIError(err, 'Server id must be positive integer', 1)
467
        except Exception as err:
481 468
            raiseCLIError(err)
482
        except ValueError:
483
            raise CLIError(message='Server id must be positive integer',
484
                importance=1)
485 469
        print_dict(flavor)
486 470

  
487 471

  
......
505 489
        super(self.__class__, self).main()
506 490
        try:
507 491
            networks = self.client.list_networks(self.get_argument('detail'))
508
        except ClientError as err:
492
        except Exception as err:
509 493
            raiseCLIError(err)
510 494
        self.print_networks(networks)
511 495

  
......
533 517
                gateway=self.get_argument('gateway'),
534 518
                dhcp=self.get_argument('dhcp'),
535 519
                type=self.get_argument('type'))
536
        except ClientError as err:
520
        except Exception as err:
537 521
            raiseCLIError(err)
538 522
        print_dict(reply)
539 523

  
......
553 537
        super(self.__class__, self).main()
554 538
        try:
555 539
            network = self.client.get_network_details(network_id)
556
        except ClientError as err:
540
        except Exception as err:
557 541
            raiseCLIError(err)
558 542
        network_info.print_network(network)
559 543

  
......
566 550
        super(self.__class__, self).main()
567 551
        try:
568 552
            self.client.update_network_name(network_id, new_name)
569
        except ClientError as err:
553
        except Exception as err:
570 554
            raiseCLIError(err)
571 555

  
572 556

  
......
578 562
        super(self.__class__, self).main()
579 563
        try:
580 564
            self.client.delete_network(network_id)
581
        except ClientError as err:
565
        except Exception as err:
582 566
            raiseCLIError(err)
583 567

  
584 568

  
......
590 574
        super(self.__class__, self).main()
591 575
        try:
592 576
            self.client.connect_server(server_id, network_id)
593
        except ClientError as err:
577
        except Exception as err:
594 578
            raiseCLIError(err)
595 579

  
596 580

  
......
603 587
        try:
604 588
            server_id = nic_id.split('-')[1]
605 589
            self.client.disconnect_server(server_id, nic_id)
606
        except IndexError:
607
            raise CLIError(message='Incorrect nic format', importance=1,
590
        except IndexError as err:
591
            raiseCLIError(err, 'Incorrect nic format', importance=1,
608 592
                details='nid_id format: nic-<server_id>-<nic_index>')
609
        except ClientError as err:
593
        except Exception as err:
610 594
            raiseCLIError(err)

Also available in: Unified diff