config/sysinv/cgts-client/cgts-client/cgtsclient/v1/iinfra_shell.py
Al Bailey d7330d0f44 Convert cgtsclient from setuptools to pbr. Add tox.
Primary reason for this change was to update the spec and setup files
from basic setuptools to use pbr
This allows the autogenerated  /usr/bin/system file to directly call the
main method without using pkg-resources.
This will provide a performance improvement of .5 seconds per CLI call,
once the other pkg_resources issues are resolved

Second reason for this change was to wire in the tox unit tests.  This
also includes pep8, pylint and coverage.
Currently pep8 does not perform the 80 char limit check
Currently pylint still reports some issues

This should not affect the RPM names being generated or otherwise affect
patching or upgrades.

Change-Id: I9f14c9216fdcc63930a4b2849102b58442706144
2018-06-28 22:07:37 -04:00

115 lines
3.3 KiB
Python

#!/usr/bin/env python
#
# Copyright (c) 2013-2015 Wind River Systems, Inc.
#
# SPDX-License-Identifier: Apache-2.0
#
# vim: tabstop=4 shiftwidth=4 softtabstop=4
# All Rights Reserved.
#
from cgtsclient.common import utils
from cgtsclient import exc
def _print_iinfra_show(iinfra):
fields = ['uuid', 'infra_subnet', 'infra_start', 'infra_end',
'infra_mtu', 'infra_vlan_id',
'isystem_uuid', 'created_at', 'updated_at']
data = [(f, getattr(iinfra, f, '')) for f in fields]
utils.print_tuple_list(data)
def do_infra_show(cc, args):
"""Show infrastructure network attributes."""
iinfras = cc.iinfra.list()
if not iinfras:
print "Infrastructure network not configured"
return
iinfra = iinfras[0]
_print_iinfra_show(iinfra)
@utils.arg('subnet',
metavar='<network subnet>',
help="Network subnet")
@utils.arg('--start',
metavar='<ip-address>',
help="The start IP address in subnet")
@utils.arg('--end',
metavar='<ip-address>',
help="The end IP address in subnet")
@utils.arg('--mtu',
metavar='<mtu>',
help='The MTU of the infrastructure interface')
@utils.arg('--vlan_id',
metavar='<vlan_id>',
help='The VLAN id of the infrastructure interface')
def do_infra_add(cc, args):
"""Add an Infrastructure network."""
field_list = ['subnet', 'start', 'end', 'mtu', 'vlan_id']
# Prune input fields down to required/expected values
data = dict(('infra_' + k, v) for (k, v) in vars(args).items()
if k in field_list and not (v is None))
infra = cc.iinfra.create(**data)
_print_iinfra_show(infra)
@utils.arg('attributes',
metavar='<path=value>',
nargs='+',
action='append',
default=[],
help="Infrastructure Network attributes to modify ")
def do_infra_modify(cc, args):
"""Modify infrastructure network IP attributes."""
iinfras = cc.iinfra.list()
if not iinfras:
print "Infrastructure network not configured"
return
iinfra = iinfras[0]
# caused by the split on parameters without a '='
for entry in args.attributes[0]:
if(entry.count("=") != 1):
raise exc.CommandError('infra-modify parameters must be '
'of the form property=value')
patch = utils.args_array_to_patch("replace", args.attributes[0])
try:
iinfra = cc.iinfra.update(iinfra.uuid, patch)
except exc.HTTPNotFound:
raise exc.CommandError('Infrastructure network not found: %s' %
iinfra.uuid)
_print_iinfra_show(iinfra)
def do_infra_apply(cc, args):
infras = cc.iinfra.list()
if not infras:
print "Infrastructure network not configured"
return
infra = infras[0]
patch = utils.args_array_to_patch("replace", ['action=apply'])
try:
cc.iinfra.update(infra.uuid, patch)
print("\nApplying infrastructure network configuration to active "
"controller.\n"
"Please wait for configuration to be applied before unlocking "
"additional hosts.\n")
except exc.HTTPNotFound:
raise exc.CommandError('Infrastructure network not found: %s' %
infra.uuid)