
Treat the CloudConfig object as if it has the config attributes directly. And add some simple tests. This makes it easier to replace an argparse.Namespace() object with a CloudConfig object. It also might make initialization of some of the default attributes unnecessary. An example of this usage is in https://review.openstack.org/#/c/129795/1/openstackclient/shell.py Change-Id: I00ced540cf94742e8cb738f8f0767445ffeb4bfe
35 lines
1.1 KiB
Python
35 lines
1.1 KiB
Python
# Copyright (c) 2014 Hewlett-Packard Development Company, L.P.
|
|
#
|
|
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
|
# not use this file except in compliance with the License. You may obtain
|
|
# a copy of the License at
|
|
#
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
#
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
# License for the specific language governing permissions and limitations
|
|
# under the License.
|
|
|
|
|
|
class CloudConfig(object):
|
|
def __init__(self, name, region, config):
|
|
self.name = name
|
|
self.region = region
|
|
self.config = config
|
|
|
|
def __getattr__(self, key):
|
|
"""Return arbitrary attributes."""
|
|
|
|
if key.startswith('os_'):
|
|
key = key[3:]
|
|
|
|
if key in [attr.replace('-', '_') for attr in self.config]:
|
|
return self.config[key]
|
|
else:
|
|
return None
|
|
|
|
def __iter__(self):
|
|
return self.config.__iter__()
|