Chris Spencer d865a4da95 Adding region-show capabilities to clients.
Added region-show to CLI client and region.get() to python client.

Change-Id: I8343f84a94c700d543de8b58c12cdcde4cefc817
Implements: blueprint craton-client-access-inventory (partial)
Closes-Bug: #1613344
2016-09-28 08:41:41 -07:00

43 lines
1.5 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.
"""Hosts resource and resource shell wrapper."""
from cratonclient.common import cliutils
from cratonclient.v1.regions import REGION_FIELDS as r_fields
@cliutils.arg('-n', '--name',
metavar='<name>',
required=True,
help='Name of the host.')
@cliutils.arg('--note',
help='Note about the host.')
def do_region_create(cc, args):
"""Register a new region with the Craton service."""
fields = {k: v for (k, v) in vars(args).items()
if k in r_fields and not (v is None)}
region = cc.regions.create(**fields)
data = {f: getattr(region, f, '') for f in r_fields}
cliutils.print_dict(data, wrap=72)
@cliutils.arg('id',
metavar='<region>',
type=int,
help='ID of the region.')
def do_region_show(cc, args):
"""Show detailed information about a region."""
region = cc.regions.get(args.id)
data = {f: getattr(region, f, '') for f in r_fields}
cliutils.print_dict(data, wrap=72)