~ubuntu-branches/ubuntu/wily/python-heatclient/wily-proposed

« back to all changes in this revision

Viewing changes to heatclient/shell.py

  • Committer: Package Import Robot
  • Author(s): Chuck Short
  • Date: 2015-03-12 10:43:34 UTC
  • mfrom: (1.1.8)
  • Revision ID: package-import@ubuntu.com-20150312104334-8e2j6r81g24r0h3y
Tags: 0.3.0-0ubuntu1
* New upstream release
* debian/control: Adjust dependencies. 

Show diffs side-by-side

added added

removed removed

Lines of Context:
23
23
import six
24
24
import six.moves.urllib.parse as urlparse
25
25
 
 
26
from oslo.utils import encodeutils
 
27
from oslo.utils import importutils
 
28
 
26
29
from keystoneclient.auth.identity import v2 as v2_auth
27
30
from keystoneclient.auth.identity import v3 as v3_auth
28
31
from keystoneclient import discover
33
36
from heatclient import client as heat_client
34
37
from heatclient.common import utils
35
38
from heatclient import exc
36
 
from heatclient.openstack.common.gettextutils import _
37
 
from heatclient.openstack.common import importutils
38
 
from heatclient.openstack.common import strutils
 
39
from heatclient.openstack.common._i18n import _
39
40
 
40
41
logger = logging.getLogger(__name__)
41
42
osprofiler_profiler = importutils.try_import("osprofiler.profiler")
52
53
        parser.add_argument('-k', '--insecure',
53
54
                            default=False,
54
55
                            action='store_true',
55
 
                            help='Explicitly allow heatclient to perform '
 
56
                            help=_('Explicitly allow heatclient to perform '
56
57
                            '\"insecure SSL\" (https) requests. The server\'s '
57
58
                            'certificate will not be verified against any '
58
59
                            'certificate authorities. This option should '
59
 
                            'be used with caution.')
 
60
                            'be used with caution.'))
60
61
 
61
62
        parser.add_argument('--os-cert',
62
 
                            help='Path of certificate file to use in SSL '
 
63
                            help=_('Path of certificate file to use in SSL '
63
64
                            'connection. This file can optionally be '
64
 
                            'prepended with the private key.')
 
65
                            'prepended with the private key.'))
65
66
 
66
67
        # for backward compatibility only
67
68
        parser.add_argument('--cert-file',
68
69
                            dest='os_cert',
69
 
                            help='DEPRECATED! Use --os-cert.')
 
70
                            help=_('DEPRECATED! Use %(arg)s.') %
 
71
                                 {'arg': '--os-cert'})
70
72
 
71
73
        parser.add_argument('--os-key',
72
 
                            help='Path of client key to use in SSL '
 
74
                            help=_('Path of client key to use in SSL '
73
75
                            'connection. This option is not necessary '
74
 
                            'if your key is prepended to your cert file.')
 
76
                            'if your key is prepended to your cert file.'))
75
77
 
76
78
        parser.add_argument('--key-file',
77
79
                            dest='os_key',
78
 
                            help='DEPRECATED! Use --os-key.')
 
80
                            help=_('DEPRECATED! Use %(arg)s.') %
 
81
                                 {'arg': '--os-key'})
79
82
 
80
83
        parser.add_argument('--os-cacert',
81
84
                            metavar='<ca-certificate-file>',
82
85
                            dest='os_cacert',
83
86
                            default=utils.env('OS_CACERT'),
84
 
                            help='Path of CA TLS certificate(s) used to '
 
87
                            help=_('Path of CA TLS certificate(s) used to '
85
88
                            'verify the remote server\'s certificate. '
86
89
                            'Without this option glance looks for the '
87
 
                            'default system CA certificates.')
 
90
                            'default system CA certificates.'))
88
91
 
89
92
        parser.add_argument('--ca-file',
90
93
                            dest='os_cacert',
91
 
                            help='DEPRECATED! Use --os-cacert.')
 
94
                            help=_('DEPRECATED! Use %(arg)s.') %
 
95
                                 {'arg': '--os-cacert'})
92
96
 
93
97
        parser.add_argument('--os-username',
94
98
                            default=utils.env('OS_USERNAME'),
95
 
                            help='Defaults to env[OS_USERNAME].')
 
99
                            help=_('Defaults to %(value)s.') % {
 
100
                                'value': 'env[OS_USERNAME]'
 
101
                            })
96
102
 
97
103
        parser.add_argument('--os_username',
98
104
                            help=argparse.SUPPRESS)
99
105
 
100
106
        parser.add_argument('--os-user-id',
101
107
                            default=utils.env('OS_USER_ID'),
102
 
                            help='Defaults to env[OS_USER_ID].')
 
108
                            help=_('Defaults to %(value)s.') % {
 
109
                                'value': 'env[OS_USER_ID]'
 
110
                            })
103
111
 
104
112
        parser.add_argument('--os_user_id',
105
113
                            help=argparse.SUPPRESS)
106
114
 
107
115
        parser.add_argument('--os-user-domain-id',
108
116
                            default=utils.env('OS_USER_DOMAIN_ID'),
109
 
                            help='Defaults to env[OS_USER_DOMAIN_ID].')
 
117
                            help=_('Defaults to %(value)s.') % {
 
118
                                'value': 'env[OS_USER_DOMAIN_ID]'
 
119
                            })
110
120
 
111
121
        parser.add_argument('--os_user_domain_id',
112
122
                            help=argparse.SUPPRESS)
113
123
 
114
124
        parser.add_argument('--os-user-domain-name',
115
125
                            default=utils.env('OS_USER_DOMAIN_NAME'),
116
 
                            help='Defaults to env[OS_USER_DOMAIN_NAME].')
 
126
                            help=_('Defaults to %(value)s.') % {
 
127
                                'value': 'env[OS_USER_DOMAIN_NAME]'
 
128
                            })
117
129
 
118
130
        parser.add_argument('--os_user_domain_name',
119
131
                            help=argparse.SUPPRESS)
120
132
 
121
133
        parser.add_argument('--os-project-id',
122
134
                            default=utils.env('OS_PROJECT_ID'),
123
 
                            help='Another way to specify tenant ID. '
124
 
                                 'This option is mutually exclusive with '
125
 
                                 ' --os-tenant-id. '
126
 
                                 'Defaults to env[OS_PROJECT_ID].')
 
135
                            help=(_('Another way to specify tenant ID. '
 
136
                                    'This option is mutually exclusive with '
 
137
                                    '%(arg)s. Defaults to %(value)s.') %
 
138
                                  {
 
139
                                      'arg': '--os-tenant-id',
 
140
                                      'value': 'env[OS_PROJECT_ID]'
 
141
                                  }))
127
142
 
128
143
        parser.add_argument('--os_project_id',
129
144
                            help=argparse.SUPPRESS)
130
145
 
131
146
        parser.add_argument('--os-project-name',
132
147
                            default=utils.env('OS_PROJECT_NAME'),
133
 
                            help='Another way to specify tenant name. '
134
 
                                 'This option is mutually exclusive with '
135
 
                                 ' --os-tenant-name. '
136
 
                                 'Defaults to env[OS_PROJECT_NAME].')
 
148
                            help=(_('Another way to specify tenant name. '
 
149
                                    'This option is mutually exclusive with '
 
150
                                    '%(arg)s. Defaults to %(value)s.') %
 
151
                                  {
 
152
                                      'arg': '--os-tenant-name',
 
153
                                      'value': 'env[OS_PROJECT_NAME]'
 
154
                                  }))
137
155
 
138
156
        parser.add_argument('--os_project_name',
139
157
                            help=argparse.SUPPRESS)
140
158
 
141
159
        parser.add_argument('--os-project-domain-id',
142
160
                            default=utils.env('OS_PROJECT_DOMAIN_ID'),
143
 
                            help='Defaults to env[OS_PROJECT_DOMAIN_ID].')
 
161
                            help=_('Defaults to %(value)s.') % {
 
162
                                'value': 'env[OS_PROJECT_DOMAIN_ID]'
 
163
                            })
144
164
 
145
165
        parser.add_argument('--os_project_domain_id',
146
166
                            help=argparse.SUPPRESS)
147
167
 
148
168
        parser.add_argument('--os-project-domain-name',
149
169
                            default=utils.env('OS_PROJECT_DOMAIN_NAME'),
150
 
                            help='Defaults to env[OS_PROJECT_DOMAIN_NAME].')
 
170
                            help=_('Defaults to %(value)s.') % {
 
171
                                'value': 'env[OS_PROJECT_DOMAIN_NAME]'
 
172
                            })
151
173
 
152
174
        parser.add_argument('--os_project_domain_name',
153
175
                            help=argparse.SUPPRESS)
154
176
 
155
177
        parser.add_argument('--os-password',
156
178
                            default=utils.env('OS_PASSWORD'),
157
 
                            help='Defaults to env[OS_PASSWORD].')
 
179
                            help=_('Defaults to %(value)s.') % {
 
180
                                'value': 'env[OS_PASSWORD]'
 
181
                            })
158
182
 
159
183
        parser.add_argument('--os_password',
160
184
                            help=argparse.SUPPRESS)
161
185
 
162
186
        parser.add_argument('--os-tenant-id',
163
187
                            default=utils.env('OS_TENANT_ID'),
164
 
                            help='Defaults to env[OS_TENANT_ID].')
 
188
                            help=_('Defaults to %(value)s.') % {
 
189
                                'value': 'env[OS_TENANT_ID]'
 
190
                            })
165
191
 
166
192
        parser.add_argument('--os_tenant_id',
167
193
                            default=utils.env('OS_TENANT_ID'),
169
195
 
170
196
        parser.add_argument('--os-tenant-name',
171
197
                            default=utils.env('OS_TENANT_NAME'),
172
 
                            help='Defaults to env[OS_TENANT_NAME].')
 
198
                            help=_('Defaults to %(value)s.') % {
 
199
                                'value': 'env[OS_TENANT_NAME]'
 
200
                            })
173
201
 
174
202
        parser.add_argument('--os_tenant_name',
175
203
                            default=utils.env('OS_TENANT_NAME'),
177
205
 
178
206
        parser.add_argument('--os-auth-url',
179
207
                            default=utils.env('OS_AUTH_URL'),
180
 
                            help='Defaults to env[OS_AUTH_URL].')
 
208
                            help=_('Defaults to %(value)s.') % {
 
209
                                'value': 'env[OS_AUTH_URL]'
 
210
                            })
181
211
 
182
212
        parser.add_argument('--os_auth_url',
183
213
                            help=argparse.SUPPRESS)
184
214
 
185
215
        parser.add_argument('--os-region-name',
186
216
                            default=utils.env('OS_REGION_NAME'),
187
 
                            help='Defaults to env[OS_REGION_NAME].')
 
217
                            help=_('Defaults to %(value)s.') % {
 
218
                                'value': 'env[OS_REGION_NAME]'
 
219
                            })
188
220
 
189
221
        parser.add_argument('--os_region_name',
190
222
                            help=argparse.SUPPRESS)
191
223
 
192
224
        parser.add_argument('--os-auth-token',
193
225
                            default=utils.env('OS_AUTH_TOKEN'),
194
 
                            help='Defaults to env[OS_AUTH_TOKEN].')
 
226
                            help=_('Defaults to %(value)s.') % {
 
227
                                'value': 'env[OS_AUTH_TOKEN]'
 
228
                            })
195
229
 
196
230
        parser.add_argument('--os_auth_token',
197
231
                            help=argparse.SUPPRESS)
198
232
 
199
233
        parser.add_argument('--os-service-type',
200
234
                            default=utils.env('OS_SERVICE_TYPE'),
201
 
                            help='Defaults to env[OS_SERVICE_TYPE].')
 
235
                            help=_('Defaults to %(value)s.') % {
 
236
                                'value': 'env[OS_SERVICE_TYPE]'
 
237
                            })
202
238
 
203
239
        parser.add_argument('--os_service_type',
204
240
                            help=argparse.SUPPRESS)
205
241
 
206
242
        parser.add_argument('--os-endpoint-type',
207
243
                            default=utils.env('OS_ENDPOINT_TYPE'),
208
 
                            help='Defaults to env[OS_ENDPOINT_TYPE].')
 
244
                            help=_('Defaults to %(value)s.') % {
 
245
                                'value': 'env[OS_ENDPOINT_TYPE]'
 
246
                            })
209
247
 
210
248
        parser.add_argument('--os_endpoint_type',
211
249
                            help=argparse.SUPPRESS)
214
252
        parser = argparse.ArgumentParser(
215
253
            prog='heat',
216
254
            description=__doc__.strip(),
217
 
            epilog='See "heat help COMMAND" '
218
 
                   'for help on a specific command.',
 
255
            epilog=_('See "%(arg)s" for help on a specific command.') % {
 
256
                'arg': 'heat help COMMAND'
 
257
            },
219
258
            add_help=False,
220
259
            formatter_class=HelpFormatter,
221
260
        )
228
267
        parser.add_argument('--version',
229
268
                            action='version',
230
269
                            version=heatclient.__version__,
231
 
                            help="Shows the client version and exits.")
 
270
                            help=_("Shows the client version and exits."))
232
271
 
233
272
        parser.add_argument('-d', '--debug',
234
273
                            default=bool(utils.env('HEATCLIENT_DEBUG')),
235
274
                            action='store_true',
236
 
                            help='Defaults to env[HEATCLIENT_DEBUG].')
 
275
                            help=_('Defaults to %(value)s.') % {
 
276
                                'value': 'env[HEATCLIENT_DEBUG]'
 
277
                            })
237
278
 
238
279
        parser.add_argument('-v', '--verbose',
239
280
                            default=False, action="store_true",
240
 
                            help="Print more verbose output.")
 
281
                            help=_("Print more verbose output."))
241
282
 
242
283
        parser.add_argument('--api-timeout',
243
 
                            help='Number of seconds to wait for an '
244
 
                                 'API response, '
245
 
                                 'defaults to system socket timeout')
 
284
                            help=_('Number of seconds to wait for an '
 
285
                                   'API response, '
 
286
                                   'defaults to system socket timeout'))
246
287
 
247
288
        # os-no-client-auth tells heatclient to use token, instead of
248
289
        # env[OS_AUTH_URL]
249
290
        parser.add_argument('--os-no-client-auth',
250
291
                            default=utils.env('OS_NO_CLIENT_AUTH'),
251
292
                            action='store_true',
252
 
                            help="Do not contact keystone for a token. "
253
 
                                 "Defaults to env[OS_NO_CLIENT_AUTH].")
 
293
                            help=(_("Do not contact keystone for a token. "
 
294
                                   "Defaults to %(value)s.") %
 
295
                                  {'value': 'env[OS_NO_CLIENT_AUTH]'}))
254
296
 
255
297
        parser.add_argument('--heat-url',
256
298
                            default=utils.env('HEAT_URL'),
257
 
                            help='Defaults to env[HEAT_URL].')
 
299
                            help=_('Defaults to %(value)s.') % {
 
300
                                'value': 'env[HEAT_URL]'
 
301
                            })
258
302
 
259
303
        parser.add_argument('--heat_url',
260
304
                            help=argparse.SUPPRESS)
261
305
 
262
306
        parser.add_argument('--heat-api-version',
263
307
                            default=utils.env('HEAT_API_VERSION', default='1'),
264
 
                            help='Defaults to env[HEAT_API_VERSION] or 1.')
 
308
                            help=_('Defaults to %(value)s or 1.') % {
 
309
                                'value': 'env[HEAT_API_VERSION]'
 
310
                            })
265
311
 
266
312
        parser.add_argument('--heat_api_version',
267
313
                            help=argparse.SUPPRESS)
277
323
        parser.add_argument('--include-password',
278
324
                            default=bool(utils.env('HEAT_INCLUDE_PASSWORD')),
279
325
                            action='store_true',
280
 
                            help='Send os-username and os-password to heat.')
 
326
                            help=_('Send %(arg1)s and %(arg2)s to heat.') % {
 
327
                                'arg1': 'os-username',
 
328
                                'arg2': 'os-password'
 
329
                            })
281
330
 
282
331
        # FIXME(gyee): this method should come from python-keystoneclient.
283
332
        # Will refactor this code once it is available.
288
337
        if osprofiler_profiler:
289
338
            parser.add_argument('--profile',
290
339
                                metavar='HMAC_KEY',
291
 
                                help='HMAC key to use for encrypting context '
292
 
                                'data for performance profiling of operation. '
293
 
                                'This key should be the value of HMAC key '
294
 
                                'configured in osprofiler middleware in heat, '
295
 
                                'it is specified in the paste configuration '
296
 
                                '(/etc/heat/api-paste.ini). '
 
340
                                help=_('HMAC key to use for encrypting '
 
341
                                'context data for performance profiling of '
 
342
                                'operation. This key should be the value of '
 
343
                                'HMAC key configured in osprofiler middleware '
 
344
                                'in heat, it is specified in the paste '
 
345
                                'configuration (/etc/heat/api-paste.ini). '
297
346
                                'Without the key, profiling will not be '
298
347
                                'triggered even if osprofiler is enabled '
299
 
                                'on server side.')
 
348
                                'on server side.'))
300
349
        return parser
301
350
 
302
351
    def get_subcommand_parser(self, version):
462
511
            # support only v2
463
512
            auth = self._get_keystone_v2_auth(v2_auth_url, **kwargs)
464
513
        else:
465
 
            raise exc.CommandError('Unable to determine the Keystone version '
466
 
                                   'to authenticate with using the given '
467
 
                                   'auth_url.')
 
514
            raise exc.CommandError(_('Unable to determine the Keystone '
 
515
                                     'version to authenticate with using the '
 
516
                                     'given auth_url.'))
468
517
 
469
518
        return auth
470
519
 
498
547
            return 0
499
548
 
500
549
        if not args.os_username and not args.os_auth_token:
501
 
            raise exc.CommandError("You must provide a username via"
 
550
            raise exc.CommandError(_("You must provide a username via"
502
551
                                   " either --os-username or env[OS_USERNAME]"
503
552
                                   " or a token via --os-auth-token or"
504
 
                                   " env[OS_AUTH_TOKEN]")
 
553
                                   " env[OS_AUTH_TOKEN]"))
505
554
 
506
555
        if not args.os_password and not args.os_auth_token:
507
 
            raise exc.CommandError("You must provide a password via"
 
556
            raise exc.CommandError(_("You must provide a password via"
508
557
                                   " either --os-password or env[OS_PASSWORD]"
509
558
                                   " or a token via --os-auth-token or"
510
 
                                   " env[OS_AUTH_TOKEN]")
 
559
                                   " env[OS_AUTH_TOKEN]"))
511
560
 
512
561
        if args.os_no_client_auth:
513
562
            if not args.heat_url:
514
 
                raise exc.CommandError("If you specify --os-no-client-auth"
 
563
                raise exc.CommandError(_("If you specify --os-no-client-auth"
515
564
                                       " you must also specify a Heat API URL"
516
565
                                       " via either --heat-url or"
517
 
                                       " env[HEAT_URL]")
 
566
                                       " env[HEAT_URL]"))
518
567
        else:
519
568
            # Tenant/project name or ID is needed to make keystoneclient
520
569
            # retrieve a service catalog, it's not required if
522
571
 
523
572
            if not (args.os_tenant_id or args.os_tenant_name or
524
573
                    args.os_project_id or args.os_project_name):
525
 
                raise exc.CommandError("You must provide a tenant id via"
 
574
                raise exc.CommandError(_("You must provide a tenant id via"
526
575
                                       " either --os-tenant-id or"
527
576
                                       " env[OS_TENANT_ID] or a tenant name"
528
577
                                       " via either --os-tenant-name or"
530
579
                                       " via either --os-project-id or"
531
580
                                       " env[OS_PROJECT_ID] or a project"
532
581
                                       " name via either --os-project-name or"
533
 
                                       " env[OS_PROJECT_NAME]")
 
582
                                       " env[OS_PROJECT_NAME]"))
534
583
 
535
584
            if not args.os_auth_url:
536
 
                raise exc.CommandError("You must provide an auth url via"
 
585
                raise exc.CommandError(_("You must provide an auth url via"
537
586
                                       " either --os-auth-url or via"
538
 
                                       " env[OS_AUTH_URL]")
 
587
                                       " env[OS_AUTH_URL]"))
539
588
 
540
589
        kwargs = {
541
590
            'insecure': args.insecure,
553
602
            kwargs = {
554
603
                'username': args.os_username,
555
604
                'password': args.os_password,
 
605
                'auth_url': args.os_auth_url,
556
606
                'token': args.os_auth_token,
557
607
                'include_pass': args.include_password,
558
608
                'insecure': args.insecure,
607
657
 
608
658
        if profile:
609
659
            trace_id = osprofiler_profiler.get().get_base_id()
610
 
            print("Trace ID: %s" % trace_id)
611
 
            print("To display trace use next command:\n"
612
 
                  "osprofiler trace show --html %s " % trace_id)
 
660
            print(_("Trace ID: %s") % trace_id)
 
661
            print(_("To display trace use next command:\n"
 
662
                  "osprofiler trace show --html %s ") % trace_id)
613
663
 
614
664
    def do_bash_completion(self, args):
615
665
        """Prints all of the commands and options to stdout.
628
678
        print(' '.join(commands | options))
629
679
 
630
680
    @utils.arg('command', metavar='<subcommand>', nargs='?',
631
 
               help='Display help for <subcommand>.')
 
681
               help=_('Display help for <subcommand>.'))
632
682
    def do_help(self, args):
633
683
        """Display help about this program or one of its subcommands."""
634
684
        if getattr(args, 'command', None):
655
705
 
656
706
        HeatShell().main(args)
657
707
    except KeyboardInterrupt:
658
 
        print("... terminating heat client", file=sys.stderr)
 
708
        print(_("... terminating heat client"), file=sys.stderr)
659
709
        sys.exit(130)
660
710
    except Exception as e:
661
711
        if '--debug' in args or '-d' in args:
662
712
            raise
663
713
        else:
664
 
            print(strutils.safe_encode(six.text_type(e)), file=sys.stderr)
 
714
            print(encodeutils.safe_encode(six.text_type(e)), file=sys.stderr)
665
715
        sys.exit(1)
666
716
 
667
717
if __name__ == "__main__":