Revision 43ee6ae1

b/kamaki/cli/commands/astakos_cli.py
32 32
# or implied, of GRNET S.A.command
33 33

  
34 34
from kamaki.cli import command
35
from kamaki.clients.astakos import AstakosClient, ClientError
35
from kamaki.clients.astakos import AstakosClient
36 36
from kamaki.cli.utils import print_dict
37 37
from kamaki.cli.errors import raiseCLIError
38 38
from kamaki.cli.commands import _command_init
......
49 49
        base_url = self.config.get('astakos', 'url')\
50 50
            or self.config.get('global', 'url')
51 51
        if base_url is None:
52
            raise ClientError('no URL for astakos')
52
            raiseCLIError(None, 'Missing astakos server URL')
53 53
        self.client = AstakosClient(base_url=base_url, token=token)
54 54

  
55 55

  
......
61 61
        super(self.__class__, self).main()
62 62
        try:
63 63
            reply = self.client.authenticate(custom_token)
64
        except ClientError as err:
64
        except Exception as err:
65 65
            raiseCLIError(err)
66 66
        print_dict(reply)
b/kamaki/cli/commands/config_cli.py
20 20
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 21
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 22
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
23
# USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
23
# USE, DATA, OR PROFITS; OR BUSINESS INTERaUPTION) HOWEVER CAUSED
24 24
# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 25
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
26 26
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
......
64 64
        section, sep, key = option.rpartition('.')
65 65
        section = section or 'global'
66 66
        value = self.config.get(section, key)
67
        if value is not None:
67
        if value:
68 68
            print(value)
69 69

  
70 70

  
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)
b/kamaki/cli/commands/image_cli.py
57 57
                or self.config.get('compute', 'url')\
58 58
                or self.config.get('global', 'url')
59 59
            self.client = ImageClient(base_url=base_url, token=token)
60
        except ClientError as err:
60
        except Exception as err:
61 61
            raiseCLIError(err)
62 62

  
63 63

  
......
100 100
        detail = self.get_argument('detail')
101 101
        try:
102 102
            images = self.client.list_public(detail, filters, order)
103
        except ClientError as err:
103
        except Exception as err:
104 104
            raiseCLIError(err)
105 105
        print_items(images, title=('name',))
106 106

  
......
177 177
                self.client.reregister(location, name, params, properties)
178 178
            else:
179 179
                self.client.register(name, location, params, properties)
180
        except ClientError as err:
180
        except Exception as err:
181 181
            raiseCLIError(err)
182 182

  
183 183

  
......
189 189
        super(self.__class__, self).main()
190 190
        try:
191 191
            members = self.client.list_members(image_id)
192
        except ClientError as err:
192
        except Exception as err:
193 193
            raiseCLIError(err)
194 194
        for member in members:
195 195
            print(member['member_id'])
......
203 203
        super(self.__class__, self).main()
204 204
        try:
205 205
            images = self.client.list_shared(member)
206
        except ClientError as err:
206
        except Exception as err:
207 207
            raiseCLIError(err)
208 208
        for image in images:
209 209
            print(image['image_id'])
......
217 217
        super(self.__class__, self).main()
218 218
        try:
219 219
            self.client.add_member(image_id, member)
220
        except ClientError as err:
220
        except Exception as err:
221 221
            raiseCLIError(err)
222 222

  
223 223

  
......
229 229
        super(self.__class__, self).main()
230 230
        try:
231 231
            self.client.remove_member(image_id, member)
232
        except ClientError as err:
232
        except Exception as err:
233 233
            raiseCLIError(err)
234 234

  
235 235

  
......
241 241
        super(self.__class__, self).main()
242 242
        try:
243 243
            self.client.set_members(image_id, member)
244
        except ClientError as err:
244
        except Exception as err:
245 245
            raiseCLIError(err)
246 246

  
247 247

  
......
267 267
        super(self.__class__, self).main()
268 268
        try:
269 269
            images = self.client.list_images(self.get_argument('detail'))
270
        except ClientError as err:
270
        except Exception as err:
271 271
            raiseCLIError(err)
272 272
        self._print(images)
273 273

  
......
286 286
        super(self.__class__, self).main()
287 287
        try:
288 288
            image = self.client.get_image_details(image_id)
289
        except ClientError as err:
289
        except Exception as err:
290 290
            raiseCLIError(err)
291 291
        self._print(image)
292 292

  
......
299 299
        super(self.__class__, self).main()
300 300
        try:
301 301
            self.client.delete_image(image_id)
302
        except ClientError as err:
302
        except Exception as err:
303 303
            raiseCLIError(err)
304 304

  
305 305

  
......
311 311
        super(self.__class__, self).main()
312 312
        try:
313 313
            reply = self.client.get_image_metadata(image_id, key)
314
        except ClientError as err:
314
        except Exception as err:
315 315
            raiseCLIError(err)
316 316
        print_dict(reply)
317 317

  
......
324 324
        super(self.__class__, self).main()
325 325
        try:
326 326
            reply = self.client.create_image_metadata(image_id, key, val)
327
        except ClientError as err:
327
        except Exception as err:
328 328
            raiseCLIError(err)
329 329
        print_dict(reply)
330 330

  
......
338 338
        metadata = {key: val}
339 339
        try:
340 340
            reply = self.client.update_image_metadata(image_id, **metadata)
341
        except ClientError as err:
341
        except Exception as err:
342 342
            raiseCLIError(err)
343 343
        print_dict(reply)
344 344

  
......
351 351
        super(self.__class__, self).main()
352 352
        try:
353 353
            self.client.delete_image_metadata(image_id, key)
354
        except ClientError as err:
354
        except Exception as err:
355 355
            raiseCLIError(err)
b/kamaki/cli/commands/pithos_cli.py
98 98
            try:
99 99
                (key, val) = p.split('=')
100 100
            except ValueError as err:
101
                raiseCLIError(err,
102
                    message='Error in --sharing',
101
                raiseCLIError(err, 'Error in --sharing',
103 102
                    details='Incorrect format',
104 103
                    importance=1)
105 104
            if key.lower() not in ('read', 'write'):
106
                raiseCLIError(err, message='Error in --sharing',
105
                raiseCLIError(err, 'Error in --sharing',
107 106
                    details='Invalid permission key %s' % key,
108 107
                    importance=1)
109 108
            val_list = val.split(',')
......
678 677
        except IOError as err:
679 678
            progress_bar.finish()
680 679
            hash_bar.finish()
681
            raiseCLIError(err,
682
                message='Failed to read form file %s' % local_path,
683
                importance=2)
680
            raiseCLIError(err, 'Failed to read form file %s' % local_path, 2)
684 681
        print 'Upload completed'
685 682

  
686 683

  
......
759 756
                else:
760 757
                    out = open(local_path, 'wb+')
761 758
            except IOError as err:
762
                raiseCLIError(err,
763
                    message='Cannot write to file %s' % local_path,
764
                    importance=1)
759
                raiseCLIError(err, 'Cannot write to file %s' % local_path, 1)
765 760
        poolsize = self.get_argument('poolsize')
766 761
        if poolsize is not None:
767 762
            self.client.POOL_SIZE = int(poolsize)
......
937 932
                read = False
938 933
                write = False
939 934
        if not read and not write:
940
            raiseCLIError(None, importance=0,
941
                message='Usage:\tread=<groups,users> write=<groups,users>')
935
            raiseCLIError(None,
936
            'Usage:\tread=<groups,users> write=<groups,users>')
942 937
        return (read, write)
943 938

  
944 939
    def main(self, container___path, *permissions):

Also available in: Unified diff