Skip to content

Commit 03ae090

Browse files
committed
Get rid of example command line options
Everett mentioned cleaning up the example code and I'd like to start this by removing the command line options. There is a lot of complexity there I'd sooner not maintain. I'm pretty sure some of it is broken. It is also different than other CLIs. Use OCC. Change-Id: If759e02ede4baee5277c1a8a4bc9f2dca13f6c82
1 parent a70a873 commit 03ae090

File tree

1 file changed

+1
-209
lines changed

1 file changed

+1
-209
lines changed

examples/common.py

Lines changed: 1 addition & 209 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,10 @@
3535
import argparse
3636
import logging
3737
import os
38-
import subprocess
3938
import sys
4039
import traceback
4140
import uuid
4241

43-
from openstack import profile
4442
from openstack import utils
4543

4644
_logger = logging.getLogger('openstack.example')
@@ -82,72 +80,6 @@ def get_data_option(opts):
8280
return eval(data)
8381

8482

85-
def get_open_fds():
86-
'''Return the open file descriptors for current process
87-
88-
.. warning: will only work on UNIX-like os-es.
89-
'''
90-
pid = os.getpid()
91-
procs = subprocess.check_output(
92-
["lsof", '-w', '-Fftn0', "-p", str(pid)]
93-
)
94-
print('procs: %s' % procs)
95-
print('netstat: %s' % subprocess.check_output(['netstat', '-nlt']))
96-
procs_list = filter(
97-
lambda s: s and s[0] == 'f' and s[1].isdigit(),
98-
procs.split('\n')
99-
)
100-
return [d.replace('\000', '|') for d in procs_list]
101-
102-
103-
class ProfileAction(argparse.Action):
104-
"""A custom action to parse user proferences as key=value pairs
105-
106-
Stores results in users proferences object.
107-
"""
108-
prof = profile.Profile()
109-
110-
@classmethod
111-
def env(cls, *vars):
112-
for v in vars:
113-
values = os.environ.get(v, None)
114-
if values is None:
115-
continue
116-
cls.set_option(v, values)
117-
return cls.prof
118-
return cls.prof
119-
120-
@classmethod
121-
def set_option(cls, var, values):
122-
if var == '--os-extensions':
123-
cls.prof.load_extension(values)
124-
return
125-
if var == 'OS_REGION_NAME':
126-
var = 'region'
127-
var = var.replace('--os-api-', '')
128-
var = var.replace('OS_API_', '')
129-
var = var.lower()
130-
for kvp in values.split(','):
131-
if '=' in kvp:
132-
service, value = kvp.split('=')
133-
else:
134-
service = cls.prof.ALL
135-
value = kvp
136-
if var == 'name':
137-
cls.prof.set_name(service, value)
138-
elif var == 'region':
139-
cls.prof.set_region(service, value)
140-
elif var == 'version':
141-
cls.prof.set_version(service, value)
142-
elif var == 'interface':
143-
cls.prof.set_interface(service, value)
144-
145-
def __call__(self, parser, namespace, values, option_string=None):
146-
if getattr(namespace, self.dest, None) is None:
147-
setattr(namespace, self.dest, ProfileAction.prof)
148-
self.set_option(option_string, values)
149-
150-
15183
def env(*vars, **kwargs):
15284
"""Search for the first defined of possibly many env vars
15385
@@ -182,147 +114,6 @@ def option_parser():
182114
help=('Cloud configuration from ' +
183115
'https://pypi.python.org/pypi/os-client-config (Env: OS_CLOUD)')
184116
)
185-
parser.add_argument(
186-
'--os-auth-plugin',
187-
dest='auth_plugin',
188-
metavar='<auth-plugin>',
189-
default=env('OS_AUTH_PLUGIN', default=None),
190-
help='Authentication plugin (Env: OS_AUTH_PLUGIN)',
191-
)
192-
parser.add_argument(
193-
'--os-auth-url',
194-
dest='auth_url',
195-
metavar='<auth-url>',
196-
default=env('OS_AUTH_URL'),
197-
help='Authentication URL (Env: OS_AUTH_URL)',
198-
)
199-
parser.add_argument(
200-
'--os-project-name',
201-
dest='project_name',
202-
metavar='<auth-project-name>',
203-
default=env('OS_PROJECT_NAME', default=env('OS_TENANT_NAME')),
204-
help='Project name of the requested project-level'
205-
'authorization scope (Env: OS_PROJECT_NAME)',
206-
)
207-
parser.add_argument(
208-
'--os-domain-name',
209-
dest='domain_name',
210-
metavar='<auth-domain-name>',
211-
default=env('OS_DOMAIN_NAME'),
212-
help='Domain name for scope of '
213-
'authorization (Env: OS_DOMAIN_NAME)',
214-
)
215-
parser.add_argument(
216-
'--os-project-domain-name',
217-
dest='project_domain_name',
218-
metavar='<auth-project-domain-name>',
219-
default=env('OS_PROJECT_DOMAIN_NAME'),
220-
help='Project domain name for scope of '
221-
'authorization (Env: OS_PROJECT_DOMAIN_NAME)',
222-
)
223-
parser.add_argument(
224-
'--os-user-domain-name',
225-
dest='user_domain_name',
226-
metavar='<auth-user-domain-name>',
227-
default=env('OS_USER_DOMAIN_NAME'),
228-
help='User domain name for scope of '
229-
'authorization (Env: OS_USER_DOMAIN_NAME)',
230-
)
231-
parser.add_argument(
232-
'--os-username',
233-
dest='username',
234-
metavar='<auth-username>',
235-
default=env('OS_USERNAME'),
236-
help='Authentication username (Env: OS_USERNAME)',
237-
)
238-
parser.add_argument(
239-
'--os-password',
240-
dest='password',
241-
metavar='<auth-password>',
242-
default=env('OS_PASSWORD'),
243-
help='Authentication password (Env: OS_PASSWORD)',
244-
)
245-
parser.add_argument(
246-
'--os-access-info',
247-
dest='access_info',
248-
metavar='<access-info>',
249-
default=env('OS_ACCESS_INFO'),
250-
help='Access info (Env: OS_ACCESS_INFO)',
251-
)
252-
parser.add_argument(
253-
'--os-extensions',
254-
dest='user_preferences',
255-
metavar='<namespace>',
256-
action=ProfileAction,
257-
default=ProfileAction.env('OS_EXTENSIONS'),
258-
help='Entry point for namespace for service extensions'
259-
' env[OS_EXTENSIONS]',
260-
)
261-
parser.add_argument(
262-
'--os-api-name',
263-
dest='preferences',
264-
metavar='<service>=<name>',
265-
action=ProfileAction,
266-
default=ProfileAction.env('OS_API_NAME'),
267-
help='Desired API names defaults to env[OS_API_NAME]',
268-
)
269-
parser.add_argument(
270-
'--os-api-region',
271-
dest='preferences',
272-
metavar='<service>=<region>',
273-
action=ProfileAction,
274-
default=ProfileAction.env('OS_API_REGION', 'OS_REGION_NAME'),
275-
help='Desired API region defaults to env[OS_API_REGION]',
276-
)
277-
parser.add_argument(
278-
'--os-api-version',
279-
dest='preferences',
280-
metavar='<service>=<version>',
281-
action=ProfileAction,
282-
default=ProfileAction.env('OS_API_VERSION'),
283-
help='Desired API versions defaults to env[OS_API_VERSION]',
284-
)
285-
parser.add_argument(
286-
'--os-api-interface',
287-
dest='preferences',
288-
metavar='<service>=<interface>',
289-
action=ProfileAction,
290-
default=ProfileAction.env('OS_INTERFACE'),
291-
help='Desired API interface defaults to env[OS_INTERFACE]',
292-
)
293-
verify_group = parser.add_mutually_exclusive_group()
294-
verify_group.add_argument(
295-
'--os-cacert',
296-
dest='verify',
297-
metavar='<ca-bundle-file>',
298-
default=env('OS_CACERT', default=True),
299-
help='CA certificate bundle file (Env: OS_CACERT)',
300-
)
301-
verify_group.add_argument(
302-
'--verify',
303-
action='store_true',
304-
help='Verify server certificate (default)',
305-
)
306-
verify_group.add_argument(
307-
'--insecure',
308-
dest='verify',
309-
action='store_false',
310-
help='Disable server certificate verification',
311-
)
312-
parser.add_argument(
313-
'--os-token',
314-
dest='token',
315-
metavar='<token>',
316-
default=env('OS_TOKEN', default=None),
317-
help='Defaults to env[OS_TOKEN]',
318-
)
319-
parser.add_argument(
320-
'--os-trust-id',
321-
dest='trust_id',
322-
metavar='<trust_id>',
323-
default=env('OS_TRUST_ID', default=None),
324-
help='Defaults to env[OS_TRUST_ID]',
325-
)
326117
parser.add_argument(
327118
'--data',
328119
metavar='<data>',
@@ -337,6 +128,7 @@ def option_parser():
337128
help='Increase verbosity of output. Can be repeated.',
338129
)
339130
parser.add_argument(
131+
340132
'--debug',
341133
default=False,
342134
action='store_true',

0 commit comments

Comments
 (0)