Chris Spencer 743898d75a Adding support for creating a region.
Adding ability to create region in both python and CLI clients.
Adding doctests and unit tests for region creation.

Change-Id: I59bcf4e727d3fd7ed6d55a58560fcf48eed8cb3d
Implements: blueprint craton-client-access-inventory (partial)
Closes-Bug: #1611418
2016-09-16 12:49:42 -07:00

32 lines
1.2 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)