Files
python-tackerclient/neutronclient/neutron/v2_0/credential.py
Isaku Yamahata e8debf8d55 setup logger name of NeutronCommand automatically
It is a common pattern to add
class XXXCommand(NeutronCommand):
    log = logging.getLogger(__name__ + '.<command name>').
So introduce a metaclass to do that automatically in order to simplify
the code a bit.

Change-Id: I7febdcd806eb2da51781a5866cc5fac5422b1721
2014-07-04 19:10:31 +09:00

74 lines
2.4 KiB
Python

# 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.
#
from neutronclient.neutron import v2_0 as neutronV20
from neutronclient.openstack.common.gettextutils import _
class ListCredential(neutronV20.ListCommand):
"""List credentials that belong to a given tenant."""
resource = 'credential'
_formatters = {}
list_columns = ['credential_id', 'credential_name', 'user_name',
'password', 'type']
class ShowCredential(neutronV20.ShowCommand):
"""Show information of a given credential."""
resource = 'credential'
allow_names = False
class CreateCredential(neutronV20.CreateCommand):
"""Creates a credential."""
resource = 'credential'
def add_known_arguments(self, parser):
parser.add_argument(
'credential_name',
help=_('Name/Ip address for Credential'))
parser.add_argument(
'credential_type',
help=_('Type of the Credential'))
parser.add_argument(
'--username',
help=_('Username for the credential'))
parser.add_argument(
'--password',
help=_('Password for the credential'))
def args2body(self, parsed_args):
body = {'credential': {
'credential_name': parsed_args.credential_name}}
if parsed_args.credential_type:
body['credential'].update({'type':
parsed_args.credential_type})
if parsed_args.username:
body['credential'].update({'user_name':
parsed_args.username})
if parsed_args.password:
body['credential'].update({'password':
parsed_args.password})
return body
class DeleteCredential(neutronV20.DeleteCommand):
"""Delete a given credential."""
resource = 'credential'
allow_names = False