Revision 602888f4 kamaki/cli/commands/errors.py

b/kamaki/cli/commands/errors.py
39 39
from kamaki.cli import _debug, kloger
40 40
from kamaki.cli.utils import format_size
41 41

  
42
CLOUDNAME = [
43
    'Note: If you use a named cloud, use its name instead of "default"']
42
CLOUDNAME = ['Note: Set a cloud and use its name instead of "default"']
44 43

  
45 44

  
46 45
class generic(object):
......
69 68
                if ce.status == 401:
70 69
                    raiseCLIError(ce, 'Authorization failed', details=[
71 70
                        'Make sure a valid token is provided:',
72
                        '  to check if token is valid: /user authenticate',
73
                        '  to set token:',
74
                        '    /config set cloud.default.token <token>',
75
                        '  to get current token:',
76
                        '    /config get cloud.default.token'] + CLOUDNAME)
71
                        '  # to check if token is valid',
72
                        '  $ kamaki user authenticate',
73
                        '  # to set token:',
74
                        '  $ kamaki config set cloud.default.token <token>',
75
                        '  # to get current token:',
76
                        '  $ kamaki config get cloud.default.token',
77
                    ] + CLOUDNAME)
77 78
                elif ce.status in range(-12, 200) + [302, 401, 500]:
78 79
                    raiseCLIError(ce, importance=3, details=[
79 80
                        'Check if service is up'])
......
85 86
                    msg = 'Invalid service URL %s' % url
86 87
                    raiseCLIError(ce, msg, details=[
87 88
                        'Check if authentication URL is correct',
88
                        '  check current URL:',
89
                        '    /config get cloud.default.url',
90
                        '  set new authentication URL:',
91
                        '    /config set cloud.default.url'] + CLOUDNAME)
89
                        '  # check current URL',
90
                        '  $ kamaki config get cloud.default.url',
91
                        '  # set new authentication URL',
92
                        '  $ kamaki config set cloud.default.url'] + CLOUDNAME)
92 93
                raise
93 94
        return _raise
94 95

  
......
98 99
    _token_details = [
99 100
        'To check default token: /config get cloud.default.token',
100 101
        'If set/update a token:',
101
        '*  (permanent):  /config set cloud.default.token <token>',
102
        '*  (temporary):  re-run with <token> parameter'] + CLOUDNAME
102
        '  #  (permanent)',
103
        '  $ kamaki config set cloud.default.token <token>'] + CLOUDNAME
103 104

  
104 105
    @classmethod
105 106
    def astakosclient(this, func):
......
127 128
                msg = 'Missing synnefo authentication URL'
128 129
                raise CLIError(msg, importance=3, details=[
129 130
                    'Check if authentication URL is correct',
130
                        '  check current URL:',
131
                        '    /config get cloud.default.url',
132
                        '  set new auth. URL:',
133
                        '    /config set cloud.default.url'] + CLOUDNAME)
131
                    '  # check current URL:',
132
                    '  $ kamaki config get cloud.default.url',
133
                    '  # set new auth. URL:',
134
                    '  $ kamaki config set cloud.default.url'] + CLOUDNAME)
134 135
            return r
135 136
        return _raise
136 137

  
......
175 176
class cyclades(object):
176 177
    about_flavor_id = [
177 178
        'How to pick a valid flavor id:',
178
        '* get a list of flavor ids: /flavor list',
179
        '* details of flavor: /flavor info <flavor id>']
179
        '  # get a list of flavor ids',
180
        '  $ kamaki flavor list',
181
        '  # details of flavor',
182
        '  $ kamaki flavor info <flavor id>',
183
        '',
184
    ]
180 185

  
181 186
    about_network_id = [
182 187
        'How to pick a valid network id:',
183
        '* get a list of network ids: /network list',
184
        '* details of network: /network info <network id>']
188
        '  # get a list of network ids',
189
        '  $ kamaki network list',
190
        '  # details of network',
191
        '  $ kamaki network info <network id>',
192
        '',
193
    ]
185 194

  
186 195
    net_types = ('CUSTOM', 'MAC_FILTERED', 'IP_LESS_ROUTED', 'PHYSICAL_VLAN')
187 196

  
......
252 261
        return _raise
253 262

  
254 263
    @classmethod
255
    def network_max(this, func):
256
        def _raise(self, *args, **kwargs):
257
            try:
258
                return func(self, *args, **kwargs)
259
            except ClientError as ce:
260
                if ce.status == 413:
261
                    msg = 'Cannot create another network',
262
                    details = [
263
                        'Maximum number of networks reached',
264
                        '* to get a list of networks: /network list',
265
                        '* to delete a network: /network delete <net id>']
266
                    raiseCLIError(ce, msg, details=details)
267
                raise
268
        return _raise
269

  
270
    @classmethod
271
    def network_in_use(this, func):
272
        def _raise(self, *args, **kwargs):
273
            network_id = kwargs.get('network_id', None)
274
            try:
275
                return func(self, *args, **kwargs)
276
            except ClientError as ce:
277
                if network_id and ce.status in (400, ):
278
                    msg = 'Network with id %s does not exist' % network_id,
279
                    raiseCLIError(ce, msg, details=this.about_network_id)
280
                elif network_id or ce.status in (421, ):
281
                    msg = 'Network with id %s is in use' % network_id,
282
                    raiseCLIError(ce, msg, details=[
283
                        'Disconnect all nics/servers of this network first',
284
                        '* to get nics: /network info %s' % network_id,
285
                        '.  (under "attachments" section)',
286
                        '* to disconnect: /network disconnect <nic id>'])
287
                raise
288
        return _raise
289

  
290
    @classmethod
291 264
    def flavor_id(this, func):
292 265
        def _raise(self, *args, **kwargs):
293 266
            flavor_id = kwargs.get('flavor_id', None)
......
327 300
                ):
328 301
                    msg = 'virtual server with id %s not found' % server_id,
329 302
                    raiseCLIError(ce, msg, details=[
330
                        '* to get ids of all servers: /server list',
331
                        '* to get server details: /server info <server id>'])
303
                        '# to get ids of all servers',
304
                        '$ kamaki server list',
305
                        '# to get server details',
306
                        '$ kamaki server info <server id>'])
332 307
                raise
333 308
        return _raise
334 309

  
......
375 350
        return _raise
376 351

  
377 352
    @classmethod
378
    def nic_format(this, func):
379
        def _raise(self, *args, **kwargs):
380
            try:
381
                return func(self, *args, **kwargs)
382
            except IndexError as ie:
383
                nic_id = kwargs.get('nic_id', None)
384
                msg = 'Invalid format for network interface (nic) %s' % nic_id
385
                raiseCLIError(ie, msg, importance=1, details=[
386
                    'nid_id format: nic-<server id>-<nic id>',
387
                    '* get nics of a network: /network info <net id>',
388
                    '    (listed the "attachments" section)'])
389
        return _raise
390

  
391
    @classmethod
392 353
    def metadata(this, func):
393 354
        def _raise(self, *args, **kwargs):
394 355
            key = kwargs.get('key', None)
......
408 369

  
409 370
    about_image_id = [
410 371
        'How to pick a suitable image:',
411
        '* get a list of image ids: /image list',
412
        '* details of image: /image meta <image id>']
372
        '  # get a list of image ids',
373
        '  $ kamaki image list',
374
        '  # details of an image',
375
        '  $ kamaki image meta <image id>',
376
        '',
377
    ]
413 378

  
414 379
    @classmethod
415 380
    def connection(this, func):
......
452 417

  
453 418
class pithos(object):
454 419
    container_howto = [
455
        'To specify a container:',
456
        '  1. --container=<container> (temporary, overrides all)',
457
        '  2. Use the container:path format (temporary, overrides 3)',
458
        '  3. Set pithos_container variable (permanent)',
459
        '     /config set pithos_container <container>',
460
        'For a list of containers: /file list']
420
        'Use a / to refer to a container (default: /pithos) e.g.,',
421
        '  # list the contents of container "images"',
422
        '  $ kamaki file list /images',
423
        '  # get information on file "my.img" in container "images"',
424
        '  $ kamaki file info /images/my.img',
425
        '',
426
        'To get a list of containers:',
427
        '  $ kamaki container list',
428
        '',
429
    ]
461 430

  
462 431
    @classmethod
463 432
    def connection(this, func):
......
505 474
                        cont = ('%s or %s' % (
506 475
                            self.container,
507 476
                            dst_cont)) if dst_cont else self.container
508
                        msg = 'Is container %s in current account?' % (cont),
477
                        msg = 'Container "%s" does not exist' % cont,
509 478
                        raiseCLIError(ce, msg, details=this.container_howto)
510 479
                raise
511 480
        return _raise

Also available in: Unified diff