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
This commit is contained in:
Al Bailey 2018-03-26 10:49:48 -05:00 committed by Jack Ding
parent 7da2cf5582
commit d7330d0f44
102 changed files with 910 additions and 702 deletions

View File

@ -32,10 +32,16 @@ Contains SDK files for %{name} package
%prep
%autosetup -n %{name}-%{version} -S git
# Remove bundled egg-info
rm -rf *.egg-info
%build
export PBR_VERSION=%{version}
%{__python} setup.py build
%install
export PBR_VERSION=%{version}
%{__python} setup.py install --root=$RPM_BUILD_ROOT \
--install-lib=%{pythonroot} \
--prefix=/usr \
@ -59,10 +65,8 @@ rm -rf $RPM_BUILD_ROOT
%doc LICENSE
%{local_bindir}/*
%{local_etc_bash_completiond}/*
%dir %{pythonroot}/cgtsclient
%{pythonroot}/cgtsclient/*
%dir %{pythonroot}/cgtsclient-%{version}.0-py2.7.egg-info
%{pythonroot}/cgtsclient-%{version}.0-py2.7.egg-info/*
%{pythonroot}/cgtsclient
%{pythonroot}/cgtsclient-%{version}*.egg-info
%files sdk
/usr/share/remote-clients/python-wrs-system-client-%{version}.tgz

View File

@ -0,0 +1,4 @@
.testrepository
coverage.xml
.coverage
cover

View File

@ -0,0 +1,10 @@
[DEFAULT]
test_command=OS_STDOUT_CAPTURE=${OS_STDOUT_CAPTURE:-1} \
OS_STDERR_CAPTURE=${OS_STDERR_CAPTURE:-1} \
OS_TEST_TIMEOUT=${OS_TEST_TIMEOUT:-160} \
${PYTHON:-python} -m subunit.run discover -t ./ ${OS_TEST_PATH:-./cgtsclient/tests} $LISTOPT $IDOPTION
test_id_option=--load-list $IDFILE
test_list_option=--list
# group tests when running concurrently
# This regex groups by classname
#group_regex=([^\.]+\.)+

View File

@ -13,8 +13,6 @@
# License for the specific language governing permissions and limitations
# under the License.
# import pbr.version
try:
import cgtsclient.client
Client = cgtsclient.client.Client
@ -22,5 +20,4 @@ except ImportError:
import warnings
warnings.warn("Could not import cgtsclient.client", ImportWarning)
__version__ = "1.0"
#__version__ = pbr.version.VersionInfo('python-cgtsclient').version_string()
__version__ = "1.0.0"

View File

@ -4,10 +4,9 @@
# SPDX-License-Identifier: Apache-2.0
#
from cgtsclient import exc
from cgtsclient.common import utils
from cgtsclient import exc
from cgtsclient.openstack.common.gettextutils import _
from keystoneclient.v3 import client as ksclient
def _get_ksclient(**kwargs):
@ -22,6 +21,7 @@ def _get_ksclient(**kwargs):
* insecure: allow insecure SSL (no cert verification)
* project_name: Project name for project scoping.
"""
from keystoneclient.v3 import client as ksclient
return ksclient.Client(username=kwargs.get('username'),
password=kwargs.get('password'),
user_domain_name=kwargs.get('user_domain_name'),
@ -89,9 +89,7 @@ def get_client(api_version, **kwargs):
'os_cacert': kwargs.get('ca_file')
}
_ksclient = _get_ksclient(**ks_kwargs)
token = kwargs.get('os_auth_token') \
if kwargs.get('os_auth_token') \
else _ksclient.auth_ref.auth_token
token = kwargs.get('os_auth_token') if kwargs.get('os_auth_token') else _ksclient.auth_ref.auth_token
ep_kwargs = {
'service_type': kwargs.get('os_service_type'),
@ -117,8 +115,6 @@ def get_client(api_version, **kwargs):
'cert_file': kwargs.get('cert_file'),
'key_file': kwargs.get('key_file'),
'auth_ref': auth_ref,
#'tenant_id': kwargs.get('os_tenant_id'),
#'tenant_name': kwargs.get('os_tenant_name'),
'auth_url': kwargs.get('os_auth_url'),
'smapi_endpoint': 'http:localhost:7777',
}

View File

@ -11,6 +11,7 @@ used by the wrapping_formatters module
_no_wrap = [False]
def is_nowrap_set(no_wrap=None):
"""
returns True if no wrapping desired.

View File

@ -65,7 +65,7 @@ PARTITION_USER_MANAGED_GUID_PREFIX = "ba5eba11-0000-1111-2222-"
USER_PARTITION_PHYSICAL_VOLUME = (PARTITION_USER_MANAGED_GUID_PREFIX +
"000000000001")
# Size conversion types
# Size conversion types
KiB = 1
MiB = 2
GiB = 3

View File

@ -15,13 +15,10 @@
# under the License.
#
import copy
import httplib
import logging
import os
import requests
import socket
import StringIO
import httplib2
@ -31,7 +28,7 @@ import six.moves.urllib.parse as urlparse
try:
import ssl
except ImportError:
#TODO(bcwaldon): Handle this failure more gracefully
# TODO(bcwaldon): Handle this failure more gracefully
pass
try:
@ -46,7 +43,6 @@ if not hasattr(urlparse, 'parse_qsl'):
from cgtsclient import exc as exceptions
from neutronclient.common import utils
from cgtsclient.openstack.common.gettextutils import _
_logger = logging.getLogger(__name__)
@ -157,13 +153,13 @@ class HTTPClient(httplib2.Http):
def http_log_resp(_logger, resp, body=None):
if not _logger.isEnabledFor(logging.DEBUG):
return
resp_status_code = resp.get('status_code') or ""
resp_headers = resp.get('headers') or ""
_logger.debug("RESP:%(code)s %(headers)s %(body)s\n",
{'code': resp_status_code,
'headers': resp_headers,
'body': body})
{'code': resp_status_code,
'headers': resp_headers,
'body': body})
def _cs_request(self, *args, **kwargs):
kargs = {}
@ -248,8 +244,8 @@ class HTTPClient(httplib2.Http):
connection_url = self._get_connection_url(url)
try:
resp, body_iter = self._cs_request(connection_url, method,
**kwargs)
resp, body_iter = self._cs_request(connection_url,
method, **kwargs)
except exceptions.HTTPUnauthorized:
self.authenticate()
resp, body_iter = self._cs_request(
@ -408,8 +404,7 @@ class HTTPClient(httplib2.Http):
body = json.loads(body)
for endpoint in body.get('endpoints', []):
if (endpoint['type'] == 'platform' and
endpoint.get('region') == self.region_name):
if (endpoint['type'] == 'platform' and endpoint.get('region') == self.region_name):
if self.endpoint_type not in endpoint:
raise exceptions.EndpointTypeNotFound(
self.endpoint_type)

View File

@ -17,22 +17,25 @@
try:
import tsconfig.tsconfig as tsc
is_remote = False
except:
except Exception:
is_remote = True
import argparse
import copy
import dateutil
import os
import prettytable
import re
import six
import sys
import textwrap
import uuid
import six
import prettytable
from prettytable import FRAME, ALL, NONE
from prettytable import ALL
from prettytable import FRAME
from prettytable import NONE
import re
from datetime import datetime
import dateutil
from dateutil import parser
from cgtsclient import exc
@ -217,9 +220,11 @@ def _sort_for_list(objs, fields, formatters={}, sortby=0, reversesort=False):
return rows_to_sort
def default_printer(s):
print s
def pt_builder(field_labels, fields, formatters, paging, printer=default_printer):
"""
returns an object that 'fronts' a prettyTable object
@ -269,7 +274,7 @@ def pt_builder(field_labels, fields, formatters, paging, printer=default_printer
else:
printer(self.get_string())
if self.terminal_lines_left > 0:
printer("\n" * (self.terminal_lines_left-1))
printer("\n" * (self.terminal_lines_left - 1))
s = raw_input("Press Enter to continue or 'q' to exit...")
if s == 'q':
@ -359,7 +364,7 @@ def print_list(objs, fields, field_labels, formatters={}, sortby=0,
# print_list() is the same as print_long_list() with paging turned off
return print_long_list(objs, fields, field_labels, formatters=formatters, sortby=sortby,
reversesort=reversesort, no_wrap_fields=no_wrap_fields,
no_paging=True, printer=printer)
no_paging=True, printer=printer)
def _build_row_from_object(fields, formatters, o):
@ -421,7 +426,7 @@ def row_height(texts):
def print_long_list(objs, fields, field_labels, formatters={}, sortby=0, reversesort=False, no_wrap_fields=[],
no_paging=False, printer=default_printer):
no_paging=False, printer=default_printer):
formatters = wrapping_formatters.as_wrapping_formatters(objs, fields, field_labels, formatters,
no_wrap_fields=no_wrap_fields)
@ -440,7 +445,7 @@ def print_dict(d, dict_property="Property", wrap=0):
pt = prettytable.PrettyTable([dict_property, 'Value'],
caching=False, print_empty=False)
pt.align = 'l'
for k, v in d.iteritems():
for k, v in sorted(d.iteritems()):
v = parse_date(v)
# convert dict to str to check length
if isinstance(v, dict):
@ -516,9 +521,8 @@ def args_array_to_dict(kwargs, key_to_convert):
kwargs[key_to_convert] = dict(v.split("=", 1)
for v in values_to_convert)
except ValueError:
raise exc.CommandError(
'%s must be a list of KEY=VALUE not "%s"' % (
key_to_convert, values_to_convert))
raise exc.CommandError('%s must be a list of KEY=VALUE not "%s"' %
(key_to_convert, values_to_convert))
return kwargs
@ -634,16 +638,17 @@ def is_uuid_like(val):
def get_terminal_size():
"""Returns a tuple (x, y) representing the width(x) and the height(x)
in characters of the terminal window."""
in characters of the terminal window.
"""
def ioctl_GWINSZ(fd):
try:
import fcntl
import termios
import struct
import termios
cr = struct.unpack('hh', fcntl.ioctl(fd, termios.TIOCGWINSZ,
'1234'))
except:
except Exception:
return None
if cr == (0, 0):
return None
@ -657,7 +662,7 @@ def get_terminal_size():
fd = os.open(os.ctermid(), os.O_RDONLY)
cr = ioctl_GWINSZ(fd)
os.close(fd)
except:
except Exception:
pass
if not cr:
cr = (os.environ.get('LINES', 25), os.environ.get('COLUMNS', 80))
@ -675,8 +680,7 @@ def normalize_field_data(obj, fields):
class WRPrettyTable(prettytable.PrettyTable):
""" A PrettyTable that allows word wrapping of its headers.
"""
"""A PrettyTable that allows word wrapping of its headers."""
def __init__(self, field_names=None, **kwargs):
super(WRPrettyTable, self).__init__(field_names, **kwargs)
@ -742,10 +746,12 @@ def extract_keypairs(args):
attributes[key] = value
return attributes
# Convert size from BYTE to KiB, MiB, GiB, TiB, PiB
# 1 - KiB, 2 - MiB, 3 - GiB, 4 - TiB, 5 - PiB
def convert_size_from_bytes(bytes, type):
return '%.2f' % (float(bytes) / (1024**type))
return '%.2f' % (float(bytes) / (1024 ** type))
def _get_system_info(cc):
"""Gets the system mode and type"""

View File

@ -21,30 +21,33 @@ The basic idea is:
the existing prettyTable code base for rendering.
"""
import six
import copy
import textwrap, re
import re
import six
import textwrap
from cgtsclient.common.cli_no_wrap import is_nowrap_set
from cgtsclient.common.cli_no_wrap import set_no_wrap
from prettytable import _get_size
from cgtsclient.common.cli_no_wrap import is_nowrap_set, set_no_wrap
UUID_MIN_LENGTH = 36
# monkey patch (customize) how the textwrap module breaks text into chunks
wordsep_re = re.compile(
r'(\s+|' # any whitespace
r',|'
r'=|'
r'\.|'
r':|'
r'[^\s\w]*\w+[^0-9\W]-(?=\w+[^0-9\W])|' # hyphenated words
r'(?<=[\w\!\"\'\&\.\,\?])-{2,}(?=\w))') # em-dash
wordsep_re = re.compile(r'(\s+|' # any whitespace
r',|'
r'=|'
r'\.|'
r':|'
r'[^\s\w]*\w+[^0-9\W]-(?=\w+[^0-9\W])|' # hyphenated words
r'(?<=[\w\!\"\'\&\.\,\?])-{2,}(?=\w))') # em-dash
textwrap.TextWrapper.wordsep_re = wordsep_re
def _get_width(value):
if value is None:
return 0
# TODO: take into account \n
# TODO(jkung): take into account \n
return _get_size(six.text_type(value))[0] # get width from [width,height]
@ -137,7 +140,7 @@ def field_value_function_factory(formatter, field):
class WrapperFormatter(object):
""" Base (abstract) class definition of wrapping formatters """
"""Base (abstract) class definition of wrapping formatters"""
def __init__(self, ctx, field):
self.ctx = ctx
@ -159,7 +162,7 @@ class WrapperFormatter(object):
def get_calculated_desired_width(self):
basic_desired_width = self.get_basic_desired_width()
if self.header_width > basic_desired_width:
if self.header_width > basic_desired_width:
return self.header_width
return basic_desired_width
@ -186,8 +189,7 @@ class WrapperFormatter(object):
self.actual_column_char_len = actual
def get_actual_column_char_len(self, desired_char_len, check_remaining_row_chars=True):
"""
Utility method to adjust desired width to a width
"""Utility method to adjust desired width to a width
that can actually be applied based on current table width
and current terminal width
@ -216,7 +218,7 @@ class WrapperFormatter(object):
if actual > self.min_width:
# shrink column
while actual > self.min_width:
actual -= 1 # TODO: fix in next sprint
actual -= 1 # TODO(jkung): fix in next sprint
# each column needs to share in
# table shrinking - but this is good
# enough for now - also - why the loop?
@ -269,7 +271,7 @@ class WrapperFormatter(object):
class WrapperLambdaFormatter(WrapperFormatter):
""" A wrapper formatter that adapts a function (callable)
"""A wrapper formatter that adapts a function (callable)
to look like a WrapperFormatter
"""
@ -282,8 +284,8 @@ class WrapperLambdaFormatter(WrapperFormatter):
class WrapperFixedWidthFormatter(WrapperLambdaFormatter):
""" A wrapper formatter that forces the text to wrap within
a specific width (in chars)
"""A wrapper formatter that forces the text to wrap within
a specific width (in chars)
"""
def __init__(self, ctx, field, width):
@ -298,8 +300,8 @@ class WrapperFixedWidthFormatter(WrapperLambdaFormatter):
class WrapperPercentWidthFormatter(WrapperFormatter):
""" A wrapper formatter that forces the text to wrap within
a specific percentage width of the current terminal width
"""A wrapper formatter that forces the text to wrap within
a specific percentage width of the current terminal width
"""
def __init__(self, ctx, field, width_as_decimal):
@ -318,11 +320,11 @@ class WrapperPercentWidthFormatter(WrapperFormatter):
class WrapperWithCustomFormatter(WrapperLambdaFormatter):
""" A wrapper formatter that allows the programmer to have a custom
formatter (in the form of a function) that is first applied
and then a wrapper function is applied to the result
"""A wrapper formatter that allows the programmer to have a custom
formatter (in the form of a function) that is first applied
and then a wrapper function is applied to the result
See wrapperFormatterFactory for a better explanation! :-)
See wrapperFormatterFactory for a better explanation! :-)
"""
# noinspection PyUnusedLocal
@ -360,6 +362,7 @@ class WrapperWithCustomFormatter(WrapperLambdaFormatter):
def get_basic_desired_width(self):
return self.wrapper_formatter.get_basic_desired_width()
def wrapper_formatter_factory(ctx, field, formatter):
"""
This function is a factory for building WrapperFormatter objects.
@ -462,28 +465,26 @@ def build_column_stats_for_best_guess_formatting(objs, fields, field_labels, cus
self.average_percent = float(self.average_width) / float(avg_total_width)
def __str__(self):
return str(
[self.field,
self.average_width,
self.min_width,
self.max_width,
self.total_width,
self.count,
self.average_percent,
self.max_percent,
self.isUUID])
return str([self.field,
self.average_width,
self.min_width,
self.max_width,
self.total_width,
self.count,
self.average_percent,
self.max_percent,
self.isUUID])
def __repr__(self):
return str(
[self.field,
self.average_width,
self.min_width,
self.max_width,
self.total_width,
self.count,
self.average_percent,
self.max_percent,
self.isUUID])
return str([self.field,
self.average_width,
self.min_width,
self.max_width,
self.total_width,
self.count,
self.average_percent,
self.max_percent,
self.isUUID])
if objs is None or len(objs) == 0:
return {"stats": {},
@ -520,7 +521,7 @@ def build_best_guess_formatters_using_average_widths(objs, fields, field_labels,
# Handle no wrap fields by building formatters that will not wrap
for f in [ff for ff in fields if ff in no_wrap_fields]:
format_spec[f] = {"hard_width" : column_info["stats"][f].max_width }
format_spec[f] = {"hard_width": column_info["stats"][f].max_width}
custom_formatter = custom_formatters.get(f, None)
if custom_formatter:
format_spec[f] = {"formatter": custom_formatter, "wrapperFormatter": format_spec[f]}
@ -538,7 +539,7 @@ def build_best_guess_formatters_using_max_widths(objs, fields, field_labels, cus
# Handle no wrap fields by building formatters that will not wrap
for f in [ff for ff in fields if ff in no_wrap_fields]:
format_spec[f] = {"hard_width" : column_info["stats"][f].max_width }
format_spec[f] = {"hard_width": column_info["stats"][f].max_width}
custom_formatter = custom_formatters.get(f, None)
if custom_formatter:
format_spec[f] = {"formatter": custom_formatter, "wrapperFormatter": format_spec[f]}
@ -566,17 +567,17 @@ def needs_wrapping_formatters(formatters, no_wrap=None):
def as_wrapping_formatters(objs, fields, field_labels, formatters, no_wrap=None, no_wrap_fields=[]):
""" This function is the entry point for building the "best guess"
word wrapping formatters. A best guess formatter guesses what the best
columns widths should be for the table celldata. It does this by collecting
various stats on the celldata (min, max average width of column celldata) and from
this celldata decides the desired widths and the minimum widths.
"""This function is the entry point for building the "best guess"
word wrapping formatters. A best guess formatter guesses what the best
columns widths should be for the table celldata. It does this by collecting
various stats on the celldata (min, max average width of column celldata) and from
this celldata decides the desired widths and the minimum widths.
Given a list of formatters and the list of objects (objs), this function
first determines if we need to augment the passed formatters with word wrapping
formatters. If the no_wrap parameter or global no_wrap flag is set,
then we do not build wrapping formatters. If any of the formatters within formatters
is a word wrapping formatter, then it is assumed no more wrapping is required.
Given a list of formatters and the list of objects (objs), this function
first determines if we need to augment the passed formatters with word wrapping
formatters. If the no_wrap parameter or global no_wrap flag is set,
then we do not build wrapping formatters. If any of the formatters within formatters
is a word wrapping formatter, then it is assumed no more wrapping is required.
:param objs:
:param fields:
@ -717,13 +718,13 @@ def set_no_wrap_on_formatters(no_wrap, formatters):
global_orig_no_wrap = is_nowrap_set()
set_no_wrap(no_wrap)
for k,f in formatters.iteritems():
for k, f in formatters.iteritems():
if WrapperFormatter.is_wrapper_formatter(f):
formatter_no_wrap_settings[k] = (f.wrapper_formatter.no_wrap, f.wrapper_formatter)
f.wrapper_formatter.no_wrap = no_wrap
return { "global_orig_no_wrap" : global_orig_no_wrap,
"formatter_no_wrap_settings" : formatter_no_wrap_settings }
return {"global_orig_no_wrap": global_orig_no_wrap,
"formatter_no_wrap_settings": formatter_no_wrap_settings}
def unset_no_wrap_on_formatters(orig_no_wrap_settings):
@ -740,7 +741,7 @@ def unset_no_wrap_on_formatters(orig_no_wrap_settings):
formatters = {}
for k,v in formatter_no_wrap_settings.iteritems():
for k, v in formatter_no_wrap_settings.iteritems():
formatters[k] = v[1]
formatters[k].no_wrap = v[0]
@ -758,49 +759,46 @@ def _simpleTestHarness(no_wrap):
def buildFormatter(field, width):
def f(dict):
if field=='number':
if field == 'number':
return dict[field]
return "{}".format(dict[field]).replace("_"," ")
return {"formatter":f,"wrapperFormatter":width}
return "{}".format(dict[field]).replace("_", " ")
return {"formatter": f, "wrapperFormatter": width}
set_no_wrap(no_wrap)
field_labels = ['Time Stamp', 'State', 'Event Log ID', 'Reason Text',
'Entity Instance ID', 'Severity','Number']
'Entity Instance ID', 'Severity', 'Number']
fields = ['timestamp', 'state', 'event_log_id', 'reason_text',
'entity_instance_id', 'severity','number']
'entity_instance_id', 'severity', 'number']
formatterSpecX = {
"timestamp" : 10,
"state" : 8,
"event_log_id" : 70,
"reason_text" : 30,
"entity_instance_id" : 30,
"severity" : 12,
"number" : 4
}
formatterSpecX = {"timestamp": 10,
"state": 8,
"event_log_id": 70,
"reason_text": 30,
"entity_instance_id": 30,
"severity": 12,
"number": 4}
formatterSpec = {}
for f in fields:
formatterSpec[f] = buildFormatter(f,formatterSpecX[f])
formatterSpec[f] = buildFormatter(f, formatterSpecX[f])
logs = []
for i in xrange(0,30):
for i in xrange(0, 30):
log = {}
for f in fields:
if f == 'number':
log[f] = i
else:
log[f] = "{}{}".format(f,i)
log[f] = "{}{}".format(f, i)
logs.append(utils.objectify(log))
formatterSpec = formatterSpecX
formatters = build_wrapping_formatters(logs, fields, field_labels, formatterSpec)
utils.print_list(logs, fields, field_labels, formatters=formatters, sortby=6,
reversesort=True,no_wrap_fields=['entity_instance_id'])
utils.print_list(logs, fields, field_labels, formatters=formatters, sortby=6,
reversesort=True, no_wrap_fields=['entity_instance_id'])
print "nowrap = {}".format(is_nowrap_set())

View File

@ -139,7 +139,7 @@ class HTTPServiceUnavailable(ServiceUnavailable):
pass
#NOTE(bcwaldon): Build a mapping of HTTP codes to corresponding exception
# NOTE(bcwaldon): Build a mapping of HTTP codes to corresponding exception
# classes
_code_map = {}
for obj_name in dir(sys.modules[__name__]):

View File

@ -41,10 +41,9 @@ def import_object(import_str, *args, **kwargs):
def import_object_ns(name_space, import_str, *args, **kwargs):
"""
Import a class and return an instance of it, first by trying
to find the class in a default namespace, then failing back to
a full path if not found in the default namespace.
"""Import a class and return an instance of it, first by trying
to find the class in a default namespace, then failing back to
a full path if not found in the default namespace.
"""
import_value = "%s.%s" % (name_space, import_str)
try:

View File

@ -28,7 +28,6 @@ from cgtsclient import client as cgclient
from cgtsclient.common import utils
from cgtsclient import exc
import keyring
import os
@ -151,8 +150,7 @@ class CgtsShell(object):
help=argparse.SUPPRESS)
parser.add_argument('--system-api-version',
default=utils.env(
'SYSTEM_API_VERSION', default='1'),
default=utils.env('SYSTEM_API_VERSION', default='1'),
help='Defaults to env[SYSTEM_API_VERSION] '
'or 1')
@ -233,9 +231,7 @@ class CgtsShell(object):
httplib2.debuglevel = 1
else:
logging.basicConfig(
format="%(levelname)s %(message)s",
level=logging.CRITICAL)
logging.basicConfig(format="%(levelname)s %(message)s", level=logging.CRITICAL)
def main(self, argv):
# Parse args once to find version
@ -274,6 +270,7 @@ class CgtsShell(object):
if not args.os_password:
# priviledge check (only allow Keyring retrieval if we are root)
if os.geteuid() == 0:
import keyring
args.os_password = keyring.get_password('CGCS', args.os_username)
else:
raise exc.CommandError("You must provide a password via "
@ -315,7 +312,6 @@ class CgtsShell(object):
commands.remove('bash_completion')
print(' '.join(commands | options))
@utils.arg('command', metavar='<subcommand>', nargs='?',
help='Display help for <subcommand>')
def do_help(self, args):

View File

@ -1,44 +0,0 @@
# Copyright 2012 OpenStack LLC.
# All Rights Reserved.
#
# 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 cgtsclient.tests import utils
from cgtsclient.common import http
fixtures = {}
class HttpClientTest(utils.BaseTestCase):
def test_url_generation_trailing_slash_in_base(self):
client = http.HTTPClient('http://localhost/')
url = client._make_connection_url('/v1/resources')
self.assertEqual(url, '/v1/resources')
def test_url_generation_without_trailing_slash_in_base(self):
client = http.HTTPClient('http://localhost')
url = client._make_connection_url('/v1/resources')
self.assertEqual(url, '/v1/resources')
def test_url_generation_prefix_slash_in_path(self):
client = http.HTTPClient('http://localhost/')
url = client._make_connection_url('/v1/resources')
self.assertEqual(url, '/v1/resources')
def test_url_generation_without_prefix_slash_in_path(self):
client = http.HTTPClient('http://localhost')
url = client._make_connection_url('v1/resources')
self.assertEqual(url, '/v1/resources')

View File

@ -78,8 +78,12 @@ class ShellTest(utils.BaseTestCase):
def test_help_on_subcommand(self):
required = [
'.*?^usage: system host-show',
".*?^Show a host",
'.*?^usage: system host-show <hostname or id>'
'',
".*?^Show host attributes.",
'',
".*?^Positional arguments:",
".*?^ <hostname or id> Name or ID of host",
]
argstrings = [
'help host-show',

View File

@ -69,7 +69,7 @@ class UtilsTest(test_utils.BaseTestCase):
self.assertEqual(patch, [{'op': 'add',
'value': 'bar',
'path': '/foo'},
{'op': 'add',
{'op': 'add',
'value': 'baz',
'path': '/extra/bar'}])

View File

@ -1,5 +1,4 @@
# -*- encoding: utf-8 -*-
#!/usr/bin/env python
# vim: tabstop=4 shiftwidth=4 softtabstop=4
#
# Copyright 2013 Hewlett-Packard Development Company, L.P.
@ -23,25 +22,22 @@
import copy
import testtools
#hello
from cgtsclient.tests import utils
import cgtsclient.v1.ihost
IHOST = {'id': 123,
'uuid': '66666666-7777-8888-9999-000000000000',
'hostname': 'cgtshost',
'personality': 'controller',
'mgmt_mac': '11:22:33:44:55:66',
'mgmt_ip': '192.168.24.11',
'serialid': 'sn123456',
'location': {'City': 'Ottawa'},
'boot_device': 'sda',
'rootfs_device': 'sda',
'install_output': "text",
'console': 'ttyS0,115200',
'tboot': '',
}
# 'administrative': 'unlocked'} if have this, fails create
'uuid': '66666666-7777-8888-9999-000000000000',
'hostname': 'cgtshost',
'personality': 'controller',
'mgmt_mac': '11:22:33:44:55:66',
'mgmt_ip': '192.168.24.11',
'serialid': 'sn123456',
'location': {'City': 'Ottawa'},
'boot_device': 'sda',
'rootfs_device': 'sda',
'install_output': "text",
'console': 'ttyS0,115200',
'tboot': ''}
PORT = {'id': 456,
'uuid': '11111111-2222-3333-4444-555555555555',
@ -57,9 +53,6 @@ UPDATED_IHOST = copy.deepcopy(IHOST)
NEW_LOC = 'newlocOttawa'
UPDATED_IHOST['location'] = NEW_LOC
#NEW_MTCADMINSTATE = 'locked'
#UPDATED_IHOST['administrative'] = NEW_MTCADMINSTATE
fixtures = {
'/v1/ihosts':
@ -142,23 +135,9 @@ class ihostManagerTest(testtools.TestCase):
'value': NEW_LOC,
'path': '/location'}
ihost = self.mgr.update(ihost_id=IHOST['uuid'],
patch=patch)
patch=patch)
expect = [
('PATCH', '/v1/ihosts/%s' % IHOST['uuid'], {}, patch),
]
self.assertEqual(self.api.calls, expect)
self.assertEqual(ihost.location, NEW_LOC)
#def test_ihost_port_list(self):
# ports = self.mgr.list_iport(IHOST['uuid'])
#def test_ihost_port_list(self):
# ports = self.mgr.list_iport(IHOST['uuid'])
# expect = [
# ('GET', '/v1/ihosts/%s/iport'
# % IHOST['uuid'], {}, None),
# ]
# self.assertEqual(self.api.calls, expect)
# self.assertEqual(len(ports), 1)
# self.assertEqual(ports[0].uuid, PORT['uuid'])
# self.assertEqual(ports[0].address, PORT['address'])

View File

@ -1,6 +1,3 @@
#!/usr/bin/env python
# vim: tabstop=4 shiftwidth=4 softtabstop=4
# Copyright 2013 Red Hat, Inc.
# All Rights Reserved.
#
@ -18,4 +15,3 @@
#
# Copyright (c) 2013-2014 Wind River Systems, Inc.
#

View File

@ -63,9 +63,8 @@ def do_addrpool_delete(cc, args):
def _get_range_tuples(data):
"""
Split the ranges field from a comma separated list of start-end to a
real list of (start, end) tuples.
"""Split the ranges field from a comma separated list of start-end to a
real list of (start, end) tuples.
"""
ranges = []
for r in data['ranges'].split(',') or []:
@ -94,7 +93,7 @@ def do_addrpool_add(cc, args):
field_list = ['name', 'network', 'prefix', 'order', 'ranges']
## Prune input fields down to required/expected values
# Prune input fields down to required/expected values
data = dict((k, v) for (k, v) in vars(args).items()
if k in field_list and not (v is None))
@ -135,7 +134,7 @@ def do_addrpool_modify(cc, args):
patch = []
for (k, v) in data.items():
patch.append({'op':'replace', 'path':'/'+k, 'value':v})
patch.append({'op': 'replace', 'path': '/' + k, 'value': v})
address_pool = cc.address_pool.update(args.address_pool_uuid, patch)
_print_address_pool_show(address_pool)

View File

@ -71,15 +71,15 @@ def do_host_addr_add(cc, args):
field_list = ['address', 'prefix']
## Lookup parent host and interface
# Lookup parent host and interface
ihost = ihost_utils._find_ihost(cc, args.hostnameorid)
iinterface = iinterface_utils._find_interface(cc, ihost, args.ifnameorid)
## Prune input fields down to required/expected values
# Prune input fields down to required/expected values
data = dict((k, v) for (k, v) in vars(args).items()
if k in field_list and not (v is None))
## Insert interface UUID
# Insert interface UUID
data['interface_uuid'] = iinterface.uuid
address = cc.address.create(**data)

View File

@ -8,9 +8,7 @@
#
from cgtsclient.common import base
from cgtsclient.common import utils
from cgtsclient import exc
from cgtsclient.v1 import ihost as ihost_utils
CREATION_ATTRIBUTES = ['ceph_mon_gib', 'ceph_mon_dev',
'ceph_mon_dev_ctrl0', 'ceph_mon_dev_ctrl1']

View File

@ -9,8 +9,8 @@
# All Rights Reserved.
#
from cgtsclient.common import utils
from cgtsclient.common import constants
from cgtsclient.common import utils
from cgtsclient.v1 import ihost as ihost_utils
@ -36,8 +36,7 @@ def _print_ceph_mon_list(cc):
constants.CONTROLLER_1_HOSTNAME],
help='Specify controller host name <%s | %s> ' % (
constants.CONTROLLER_0_HOSTNAME,
constants.CONTROLLER_1_HOSTNAME
))
constants.CONTROLLER_1_HOSTNAME))
@utils.arg('attributes',
metavar='<path=value>',
nargs='+',
@ -76,6 +75,7 @@ def do_ceph_mon_list(cc, args):
"""List ceph mons"""
_print_ceph_mon_list(cc)
@utils.arg('hostnameorid',
metavar='<hostname or id>',
help="name or ID of host [REQUIRED]")

View File

@ -9,9 +9,9 @@
# All Rights Reserved.
#
import os
from cgtsclient import exc
from cgtsclient.common import utils
from collections import OrderedDict
from cgtsclient import exc
def _print_certificate_show(certificate):
@ -77,7 +77,7 @@ def do_certificate_install(cc, args):
certificate_file = args.certificate_file
try:
sec_file = open(certificate_file, 'rb')
except:
except Exception:
raise exc.CommandError("Error: Could not open file %s." %
certificate_file)

View File

@ -20,59 +20,59 @@
from cgtsclient.common import http
from cgtsclient.v1 import address
from cgtsclient.v1 import address_pool
from cgtsclient.v1 import isystem
from cgtsclient.v1 import ihost
from cgtsclient.v1 import inode
from cgtsclient.v1 import icpu
from cgtsclient.v1 import imemory
from cgtsclient.v1 import iinterface
from cgtsclient.v1 import idisk
from cgtsclient.v1 import istor
from cgtsclient.v1 import ipv
from cgtsclient.v1 import ilvg
from cgtsclient.v1 import iuser
from cgtsclient.v1 import idns
from cgtsclient.v1 import intp
from cgtsclient.v1 import iextoam
from cgtsclient.v1 import controller_fs
from cgtsclient.v1 import storage_backend
from cgtsclient.v1 import storage_lvm
from cgtsclient.v1 import storage_file
from cgtsclient.v1 import storage_external
from cgtsclient.v1 import storage_ceph
from cgtsclient.v1 import ceph_mon
from cgtsclient.v1 import certificate
from cgtsclient.v1 import cluster
from cgtsclient.v1 import controller_fs
from cgtsclient.v1 import drbdconfig
from cgtsclient.v1 import iprofile
from cgtsclient.v1 import icommunity
from cgtsclient.v1 import itrapdest
from cgtsclient.v1 import ialarm
from cgtsclient.v1 import iinfra
from cgtsclient.v1 import port
from cgtsclient.v1 import ethernetport
from cgtsclient.v1 import route
from cgtsclient.v1 import event_log
from cgtsclient.v1 import event_suppression
from cgtsclient.v1 import firewallrules
from cgtsclient.v1 import health
from cgtsclient.v1 import ialarm
from cgtsclient.v1 import icommunity
from cgtsclient.v1 import icpu
from cgtsclient.v1 import idisk
from cgtsclient.v1 import idns
from cgtsclient.v1 import iextoam
from cgtsclient.v1 import ihost
from cgtsclient.v1 import iinfra
from cgtsclient.v1 import iinterface
from cgtsclient.v1 import ilvg
from cgtsclient.v1 import imemory
from cgtsclient.v1 import inode
from cgtsclient.v1 import intp
from cgtsclient.v1 import iprofile
from cgtsclient.v1 import ipv
from cgtsclient.v1 import isensor
from cgtsclient.v1 import isensorgroup
from cgtsclient.v1 import load
from cgtsclient.v1 import pci_device
from cgtsclient.v1 import upgrade
from cgtsclient.v1 import network
from cgtsclient.v1 import service_parameter
from cgtsclient.v1 import cluster
from cgtsclient.v1 import istor
from cgtsclient.v1 import isystem
from cgtsclient.v1 import itrapdest
from cgtsclient.v1 import iuser
from cgtsclient.v1 import license
from cgtsclient.v1 import lldp_agent
from cgtsclient.v1 import lldp_neighbour
from cgtsclient.v1 import license
from cgtsclient.v1 import sm_service_nodes
from cgtsclient.v1 import sm_service
from cgtsclient.v1 import sm_servicegroup
from cgtsclient.v1 import health
from cgtsclient.v1 import remotelogging
from cgtsclient.v1 import sdn_controller
from cgtsclient.v1 import firewallrules
from cgtsclient.v1 import load
from cgtsclient.v1 import network
from cgtsclient.v1 import partition
from cgtsclient.v1 import certificate
from cgtsclient.v1 import pci_device
from cgtsclient.v1 import port
from cgtsclient.v1 import remotelogging
from cgtsclient.v1 import route
from cgtsclient.v1 import sdn_controller
from cgtsclient.v1 import service_parameter
from cgtsclient.v1 import sm_service
from cgtsclient.v1 import sm_service_nodes
from cgtsclient.v1 import sm_servicegroup
from cgtsclient.v1 import storage_backend
from cgtsclient.v1 import storage_ceph
from cgtsclient.v1 import storage_external
from cgtsclient.v1 import storage_file
from cgtsclient.v1 import storage_lvm
from cgtsclient.v1 import storage_tier
from cgtsclient.v1 import upgrade
class Client(http.HTTPClient):
@ -106,8 +106,8 @@ class Client(http.HTTPClient):
self.iextoam = iextoam.iextoamManager(self)
self.controller_fs = controller_fs.ControllerFsManager(self)
self.storage_backend = storage_backend.StorageBackendManager(self)
self.storage_lvm = storage_lvm.StorageLvmManager(self)
self.storage_file = storage_file.StorageFileManager(self)
self.storage_lvm = storage_lvm.StorageLvmManager(self)
self.storage_file = storage_file.StorageFileManager(self)
self.storage_external = storage_external.StorageExternalManager(self)
self.storage_ceph = storage_ceph.StorageCephManager(self)
self.ceph_mon = ceph_mon.CephMonManager(self)

View File

@ -10,8 +10,8 @@
#
from cgtsclient.common import utils
from cgtsclient.v1 import cluster as cluster_utils
from cgtsclient import exc
from cgtsclient.v1 import cluster as cluster_utils
import os

View File

@ -33,6 +33,7 @@ def _print_controller_fs_show(controller_fs):
data = [(f, getattr(controller_fs, f)) for f in fields]
utils.print_tuple_list(data, labels)
@utils.arg('attributes',
metavar='<fs_name=size>',
nargs='+',
@ -43,7 +44,6 @@ def _print_controller_fs_show(controller_fs):
action='store_true',
default=False,
help="Force the resize operation ")
def do_controllerfs_modify(cc, args):
"""Modify controller filesystem sizes."""
@ -90,6 +90,7 @@ def _print_controllerfs_list(cc):
fields = ['uuid', 'name', 'size', 'logical_volume', 'replicated', 'state']
utils.print_list(controller_fs_list, fields, field_labels, sortby=1)
def do_controllerfs_list(cc, args):
"""Show list of controller filesystems"""
_print_controllerfs_list(cc)

View File

@ -18,6 +18,7 @@ from cgtsclient import exc
CONTROLLER = 'controller'
def _print_drbdsync_show(drbdconfig):
fields = ['uuid',
'isystem_uuid',
@ -25,8 +26,7 @@ def _print_drbdsync_show(drbdconfig):
'updated_at',
'link_util',
'num_parallel',
'rtt_ms',
]
'rtt_ms']
data = [(f, getattr(drbdconfig, f, '')) for f in fields]
utils.print_tuple_list(data)
@ -34,8 +34,7 @@ def _print_drbdsync_show(drbdconfig):
def _print_controller_config_show(ihosts):
fields = ['id', 'hostname', 'personality',
'administrative', 'operational', 'availability',
'config_status',
]
'config_status']
field_labels = list(fields)
utils.print_list(ihosts, fields, field_labels, sortby=0)
@ -89,8 +88,7 @@ def do_drbdsync_modify(cc, args):
is_config = False
ihosts = cc.ihost.list_personality(personality=CONTROLLER)
for ihost in ihosts:
if ihost.config_target and \
ihost.config_applied != ihost.config_target:
if ihost.config_target and ihost.config_applied != ihost.config_target:
is_config = True
print ("host %s is configuring ..." % (ihost.hostname))
if is_config:
@ -114,14 +112,13 @@ def do_drbdsync_modify(cc, args):
do_wait = False
hosts = []
for ihost in ihosts:
if ihost.config_target and \
ihost.config_applied != ihost.config_target:
if ihost.config_target and ihost.config_applied != ihost.config_target:
do_wait = True
hosts.append(ihost.hostname)
if do_wait:
if x == 0:
print ("waiting for hosts: %s to finish configuring"
% ', '.join(hosts)),
print ("waiting for hosts: %s to finish configuring" %
', '.join(hosts)),
sys.stdout.flush()
else:
print ".",

View File

@ -12,13 +12,13 @@
from cgtsclient.common import utils
from cgtsclient import exc
from collections import OrderedDict
from cgtsclient.v1 import ihost as ihost_utils
def _bootp_formatter(value):
return bool(value)
def _bootp_port_formatter(port):
return _bootp_formatter(port.bootp)
@ -40,7 +40,7 @@ def _print_ethernet_port_show(port):
'link_mode', 'capabilities',
'uuid', 'host_uuid', 'interface_uuid',
'created_at', 'updated_at']
data = [ (f, getattr(port, f, '')) for f in fields ]
data = [(f, getattr(port, f, '')) for f in fields]
utils.print_tuple_list(data, labels,
formatters={'bootp': _bootp_formatter})
@ -52,7 +52,7 @@ def _find_port(cc, ihost, portnameoruuid):
break
else:
raise exc.CommandError('Ethernet port not found: host %s port %s' % (ihost.id, portnameoruuid))
p.autoneg = 'Yes' # TODO Remove when autoneg supported in DB
p.autoneg = 'Yes' # TODO(jkung) Remove when autoneg supported in DB
return p
@ -76,10 +76,10 @@ def do_host_ethernet_port_list(cc, args):
ports = cc.ethernet_port.list(ihost.uuid)
for p in ports:
p.autoneg = 'Yes' # TODO Remove when autoneg supported in DB
p.autoneg = 'Yes' # TODO(jkung) Remove when autoneg supported in DB
field_labels = ['uuid', 'name', 'mac address', 'pci address', 'processor', 'auto neg', 'device type', 'boot i/f' ]
fields = ['uuid', 'name', 'mac', 'pciaddr', 'numa_node', 'autoneg', 'pdevice', 'bootp' ]
field_labels = ['uuid', 'name', 'mac address', 'pci address', 'processor', 'auto neg', 'device type', 'boot i/f']
fields = ['uuid', 'name', 'mac', 'pciaddr', 'numa_node', 'autoneg', 'pdevice', 'bootp']
utils.print_list(ports, fields, field_labels, sortby=1,
formatters={'bootp': _bootp_port_formatter})

View File

@ -4,9 +4,8 @@
# SPDX-License-Identifier: Apache-2.0
#
from cgtsclient.common import base
from ceilometerclient.v2 import options
from cgtsclient.common import base
class EventLog(base.Resource):
@ -29,10 +28,10 @@ class EventLogManager(base.Manager):
params.append('marker=%s' % str(marker))
if include_suppress:
params.append('include_suppress=True')
if alarms==True and logs==False:
params.append('alarms=True')
elif alarms==False and logs==True:
params.append('logs=True')
if alarms is True and logs is False:
params.append('alarms=True')
elif alarms is False and logs is True:
params.append('logs=True')
restAPIURL = options.build_url(self._path(), q, params)
@ -44,4 +43,3 @@ class EventLogManager(base.Manager):
return self._list(self._path(iid))[0]
except IndexError:
return None

View File

@ -9,10 +9,10 @@
# All Rights Reserved.
#
from cgtsclient import exc
from ceilometerclient.v2 import options
from cgtsclient.common import utils
from cgtsclient.common import wrapping_formatters
from cgtsclient import exc
def _display_event(log):
@ -43,29 +43,21 @@ def do_event_show(cc, args={}):
'but if supplied must be string, integer, float, or boolean. '
'Valid query fields (event_log_id, entity_type_id, '
'entity_instance_id, severity, start, end)'
' Example: system event-list -q \'start=20160131 10:23:45;end=20171225\''
)
' Example: system event-list -q \'start=20160131 10:23:45;end=20171225\'')
@utils.arg('-l', '--limit', metavar='<NUMBER>',
help='Maximum number of event logs to return.')
@utils.arg('--alarms',
action='store_true',
help='Show alarms only')
@utils.arg('--logs',action='store_true',
@utils.arg('--logs', action='store_true',
help='Show logs only')
@utils.arg('--uuid',action='store_true',
@utils.arg('--uuid', action='store_true',
help='Include UUID in output')
@utils.arg('--include_suppress',
action='store_true',
help='Include suppressed alarms in output')
@utils.arg('--nopaging',action='store_true',
@utils.arg('--nopaging', action='store_true',
help='Output is not paged')
def do_event_list(cc, args={}):
'''List event logs.'''
@ -74,7 +66,7 @@ def do_event_list(cc, args={}):
no_paging = args.nopaging
alarms = False
logs = False
logs = False
include_suppress = False
includeUUID = args.uuid
@ -90,13 +82,13 @@ def do_event_list(cc, args={}):
logs = cc.event_log.list(q=queryAsArray, limit=args.limit,
alarms=alarms, logs=logs, include_suppress=include_suppress)
for l in logs:
utils.normalize_field_data(l, ['entity_instance_id','reason_text'])
utils.normalize_field_data(l, ['entity_instance_id', 'reason_text'])
# omit action initially to keep output width sane
# (can switch over to vertical formatting when available from CLIFF)
def hightlightEventId(event):
suppressed = hasattr(event,"suppression_status") and event.suppression_status=="suppressed"
suppressed = hasattr(event, "suppression_status") and event.suppression_status == "suppressed"
if suppressed:
value = "S({})".format(event.event_log_id)
else:
@ -108,33 +100,28 @@ def do_event_list(cc, args={}):
'Entity Instance ID', 'Severity']
fields = ['uuid', 'timestamp', 'state', 'event_log_id', 'reason_text',
'entity_instance_id', 'severity']
formatterSpec = {
"uuid" : wrapping_formatters.UUID_MIN_LENGTH,
"timestamp" : .08,
"state" : .08,
"event_log_id" : {"formatter" : hightlightEventId, "wrapperFormatter": .07},
"reason_text" : .42,
"entity_instance_id" : .13,
"severity" : .12
}
formatterSpec = {"uuid": wrapping_formatters.UUID_MIN_LENGTH,
"timestamp": .08,
"state": .08,
"event_log_id": {"formatter": hightlightEventId, "wrapperFormatter": .07},
"reason_text": .42,
"entity_instance_id": .13,
"severity": .12}
else:
field_labels = ['Time Stamp', 'State', 'Event Log ID', 'Reason Text',
'Entity Instance ID', 'Severity']
fields = ['timestamp', 'state', 'event_log_id', 'reason_text',
'entity_instance_id', 'severity']
# for best results, ensure width ratios add up to 1 (=100%)
formatterSpec = {
"timestamp" : .08,
"state" : .08,
"event_log_id" : {"formatter" : hightlightEventId, "wrapperFormatter": .07},
"reason_text" : .52,
"entity_instance_id" : .13,
"severity" : .12
}
formatterSpec = {"timestamp": .08,
"state": .08,
"event_log_id": {"formatter": hightlightEventId, "wrapperFormatter": .07},
"reason_text": .52,
"entity_instance_id": .13,
"severity": .12}
formatters = wrapping_formatters.build_wrapping_formatters(logs, fields,
field_labels, formatterSpec)
utils.print_long_list(logs, fields, field_labels,
formatters=formatters, sortby=fields.index('timestamp'),
reversesort=True, no_paging=no_paging)

View File

@ -4,8 +4,8 @@
# SPDX-License-Identifier: Apache-2.0
#
from cgtsclient.common import base
from ceilometerclient.v2 import options
from cgtsclient.common import base
class EventSuppression(base.Resource):

View File

@ -8,9 +8,6 @@
# vim: tabstop=4 shiftwidth=4 softtabstop=4
# All Rights Reserved.
#
import prettytable
from cgtsclient import exc
from ceilometerclient.v2 import options
from cgtsclient.common import utils
from cgtsclient.common import wrapping_formatters
@ -21,52 +18,49 @@ def _get_display_config(includeUUID):
field_labels = ['UUID', 'Event ID', 'Status']
fields = ['uuid', 'alarm_id', 'suppression_status']
formatterSpec = {
"uuid" : 40,
"alarm_id" : 25,
"suppression_status" : 15
}
formatterSpec = {"uuid": 40,
"alarm_id": 25,
"suppression_status": 15}
else:
field_labels = ['Event ID', 'Status']
fields = ['alarm_id', 'suppression_status']
formatterSpec = {
"alarm_id" : 25,
"suppression_status" : 15
}
formatterSpec = {"alarm_id": 25,
"suppression_status": 15}
return {
'field_labels' : field_labels,
'fields' : fields,
'field_labels': field_labels,
'fields': fields,
'formatterSpec': formatterSpec
}
def _display_event_suppression(log):
fields = ['uuid', 'alarm_id', 'description', 'suppression_status']
data = dict([(f, getattr(log, f, '')) for f in fields])
utils.print_dict(data, wrap=72)
def _get_suppressed_alarms_tuples(data):
"""
Split the suppressed_alarms field from a comma separated list alarm id's to a
"""Split the suppressed_alarms field from a comma separated list alarm id's to a
real list of (start, end) tuples. ??????
"""
suppressed_alarms = []
for a in data['suppressed_alarms'].split(',') or []:
suppressed_alarms.append((a))
return suppressed_alarms
def _event_suppression_list(cc, include_unsuppressed=False):
query = 'suppression_status=string::suppressed'
queryAsArray =[]
queryAsArray = []
if include_unsuppressed:
query = None
if query != None:
if query is not None:
queryAsArray = options.cli_to_array(query)
event_suppression_list = cc.event_suppression.list(q=queryAsArray)
@ -87,7 +81,7 @@ def print_event_suppression_list(cc, no_paging, includeUUID):
field_labels, formatterSpec)
utils.print_long_list(event_suppression_list, fields, field_labels, formatters=formatters, sortby=1,
reversesort=False, no_paging=no_paging)
reversesort=False, no_paging=no_paging)
def event_suppression_update(cc, data, suppress=False):
@ -111,15 +105,12 @@ def event_suppression_update(cc, data, suppress=False):
cc.event_suppression.update(uuid, patch)
@utils.arg('--include-unsuppressed',action='store_true',
@utils.arg('--include-unsuppressed', action='store_true',
help='Include unsuppressed Event ID\'s')
@utils.arg('--uuid',action='store_true',
@utils.arg('--uuid', action='store_true',
help='Include UUID in output')
@utils.arg('--nopaging',action='store_true',
@utils.arg('--nopaging', action='store_true',
help='Output is not paged')
def do_event_suppress_list(cc, args={}):
'''List Suppressed Event ID's '''
@ -141,24 +132,22 @@ def do_event_suppress_list(cc, args={}):
field_labels, formatterSpec)
utils.print_long_list(event_suppression_list, fields, field_labels, formatters=formatters, sortby=1,
reversesort=False, no_paging=no_paging)
reversesort=False, no_paging=no_paging)
@utils.arg('--alarm_id',
metavar='<alarm_id>,...',
help="The alarm_id list (comma separated) of alarm ID's to suppress.")
@utils.arg('--nopaging',action='store_true',
@utils.arg('--nopaging', action='store_true',
help='Output is not paged')
@utils.arg('--uuid',action='store_true',
@utils.arg('--uuid', action='store_true',
help='Include UUID in output')
def do_event_suppress(cc, args={}):
'''Suppress specified Event ID's.'''
field_list = ['alarm_id']
## Prune input fields down to required/expected values
# Prune input fields down to required/expected values
data = dict((k, v) for (k, v) in vars(args).items()
if k in field_list and not (v is None))
@ -174,18 +163,15 @@ def do_event_suppress(cc, args={}):
@utils.arg('--alarm_id',
metavar='<alarm_id>,...',
help="The alarm_id list (comma separated) of alarm ID's to unsuppress.")
@utils.arg('--nopaging',action='store_true',
@utils.arg('--nopaging', action='store_true',
help='Output is not paged')
@utils.arg('--uuid',action='store_true',
@utils.arg('--uuid', action='store_true',
help='Include UUID in output')
def do_event_unsuppress(cc, args):
'''Unsuppress specified Event ID's.'''
field_list = ['alarm_id']
## Prune input fields down to required/expected values
# Prune input fields down to required/expected values
data = dict((k, v) for (k, v) in vars(args).items()
if k in field_list and not (v is None))
@ -198,17 +184,13 @@ def do_event_unsuppress(cc, args):
print_event_suppression_list(cc, no_paging, includeUUID)
@utils.arg('--nopaging',action='store_true',
@utils.arg('--nopaging', action='store_true',
help='Output is not paged')
@utils.arg('--uuid',action='store_true',
@utils.arg('--uuid', action='store_true',
help='Include UUID in output')
def do_event_unsuppress_all(cc, args):
'''Unsuppress all Event ID's.'''
patch = []
alarms_suppression_list = _event_suppression_list(cc, include_unsuppressed=True)
for alarm_type in alarms_suppression_list:
@ -223,4 +205,4 @@ def do_event_unsuppress_all(cc, args):
no_paging = args.nopaging
includeUUID = args.uuid
print_event_suppression_list(cc, no_paging, includeUUID)
print_event_suppression_list(cc, no_paging, includeUUID)

View File

@ -39,10 +39,9 @@ def do_firewall_rules_install(cc, args):
filename = args.firewall_rules_path
try:
fw_file = open(filename, 'rb')
except:
raise exc.CommandError(
"Error: Could not open file %s for read." % filename)
except Exception:
raise exc.CommandError("Error: Could not open file %s for read." %
filename)
try:
response = cc.firewallrules.import_firewall_rules(fw_file)
error = response.get('error')

View File

@ -10,24 +10,20 @@
# All Rights Reserved.
#
import datetime
import json
import os
import requests
import time
from collections import OrderedDict
from cgtsclient import exc
import datetime
import os
from cgtsclient.common import constants
from cgtsclient.common import utils
from cgtsclient import exc
from cgtsclient.openstack.common.gettextutils import _
from cgtsclient.v1 import icpu as icpu_utils
from cgtsclient.v1 import ihost as ihost_utils
from cgtsclient.v1 import iinterface as iinterface_utils
from cgtsclient.v1 import ilvg as ilvg_utils
from cgtsclient.v1 import iprofile as iprofile_utils
from cgtsclient.v1 import ipv as ipv_utils
from cgtsclient.v1 import istor as istor_utils
from sys import stdout
from cgtsclient.common import constants
def _print_ihost_show(ihost):
fields = ['id', 'uuid', 'personality', 'hostname', 'invprovision',
@ -184,7 +180,7 @@ def do_host_bulk_add(cc, args):
raise exc.CommandError("Error: %s is a directory." % hostsfile)
try:
req = open(hostsfile, 'rb')
except:
except Exception:
raise exc.CommandError("Error: Could not open file %s." % hostsfile)
response = cc.ihost.create_many(req)
@ -223,10 +219,10 @@ def donot_host_sysaddlab(cc, args):
raise exc.CommandError('host not found: %s' % suuid)
else:
_print_ihost_show(ihost)
#field_list.append('uuid')
#field_list.append('id')
#data = dict([(f, getattr(ihost, f, '')) for f in field_list])
#utils.print_dict(data, wrap=72)
# field_list.append('uuid')
# field_list.append('id')
# data = dict([(f, getattr(ihost, f, '')) for f in field_list])
# utils.print_dict(data, wrap=72)
@utils.arg('hostnameorid',
@ -457,6 +453,8 @@ NOTE (neid):
or a profile including all of cpu, stor, if
or a profile including all of cpu, stor, if
"""
@utils.arg('hostnameorid',
metavar='<hostname or id>',
help="Name or ID of host")
@ -624,7 +622,7 @@ def _prepare_profile_patch(iprofile_uuid):
patch = []
for (k, v) in dict.items():
patch.append({'op':'replace', 'path':'/'+k, 'value':str(v)})
patch.append({'op': 'replace', 'path': '/' + k, 'value': str(v)})
return patch
@ -637,9 +635,7 @@ def _timestamped(dname, fmt='%Y-%m-%d-%H-%M-%S_{dname}'):
metavar='<hostname or id>',
help="Name or ID of host")
def do_host_patch_reboot(cc, args):
"""Command has been deprecated.
"""
"""Command has been deprecated."""
try:
ihost = cc.ihost.get(args.hostnameorid)
except exc.HTTPNotFound:
@ -660,7 +656,7 @@ def do_host_patch_reboot(cc, args):
@utils.arg('--filename',
help="The full file path to store the host file. Default './hosts.xml'")
def do_host_bulk_export (cc, args):
def do_host_bulk_export(cc, args):
"""Export host bulk configurations."""
result = cc.ihost.bulk_export()
@ -673,7 +669,7 @@ def do_host_bulk_export (cc, args):
fw.write(xml_content)
print _('Export successfully to %s') % config_filename
except IOError:
print _('Cannot write to file: %s' % config_filename)
print _('Cannot write to file: %s') % config_filename
return

View File

@ -4,8 +4,9 @@
# SPDX-License-Identifier: Apache-2.0
#
from cgtsclient.common import base
from ceilometerclient.v2 import options
from cgtsclient.common import base
class ialarm(base.Resource):
def __repr__(self):
@ -49,4 +50,4 @@ class ialarmManager(base.Manager):
params = []
if include_suppress:
params.append('include_suppress=True')
return self._list(options.build_url(self._path('summary'), None ,params))
return self._list(options.build_url(self._path('summary'), None, params))

View File

@ -9,11 +9,11 @@
# All Rights Reserved.
#
from cgtsclient import exc
from ceilometerclient.v2 import options
from ceilometerclient.common import utils
from cgtsclient.common import wrapping_formatters
from ceilometerclient.v2 import options
from cgtsclient.common import utils as cgts_utils
from cgtsclient.common import wrapping_formatters
from cgtsclient import exc
def _display_fault(fault):
@ -49,18 +49,14 @@ def do_alarm_delete(cc, args={}):
@utils.arg('-q', '--query', metavar='<QUERY>',
help='key[op]data_type::value; list. data_type is optional, '
'but if supplied must be string, integer, float, or boolean.')
@utils.arg('--uuid', action='store_true',
help='Include UUID in output')
@utils.arg('--include_suppress',
action='store_true',
help='Include suppressed alarms in output')
@utils.arg('--mgmt_affecting',
action='store_true',
help='Include management affecting status in output')
def do_alarm_list(cc, args={}):
'''List all active alarms.'''
@ -83,7 +79,7 @@ def do_alarm_list(cc, args={}):
# (can switch over to vertical formatting when available from CLIFF)
def hightlightAlarmId(alarm):
suppressed = hasattr(alarm,"suppression_status") and alarm.suppression_status=="suppressed"
suppressed = hasattr(alarm, "suppression_status") and alarm.suppression_status == "suppressed"
if suppressed:
value = "S({})".format(alarm.alarm_id)
else:
@ -93,13 +89,12 @@ def do_alarm_list(cc, args={}):
field_labels = ['Alarm ID', 'Reason Text', 'Entity ID', 'Severity', 'Time Stamp']
fields = ['alarm_id', 'reason_text', 'entity_instance_id', 'severity', 'timestamp']
# for best results, ensure width ratios add up to 1 (=100%)
formatterSpec = {
"alarm_id" : {"formatter" : hightlightAlarmId, "wrapperFormatter": .08},
"reason_text" : .54,
"entity_instance_id" : .15,
"severity" : .10,
"timestamp" : .10,
}
formatterSpec = {"alarm_id": {"formatter": hightlightAlarmId, "wrapperFormatter": .08},
"reason_text": .54,
"entity_instance_id": .15,
"severity": .10,
"timestamp": .10,
}
if includeUUID:
field_labels.insert(0, 'UUID')
@ -122,6 +117,7 @@ def do_alarm_list(cc, args={}):
cgts_utils.print_list(faults, fields, field_labels, formatters=formatters,
sortby=fields.index('timestamp'), reversesort=True)
@utils.arg('--include_suppress',
action='store_true',
help='Include suppressed alarms in output')
@ -136,5 +132,3 @@ def do_alarm_summary(cc, args={}):
field_labels = ['Critical Alarms', 'Major Alarms', 'Minor Alarms', 'Warnings']
fields = ['critical', 'major', 'minor', 'warnings']
cgts_utils.print_list(faults, fields, field_labels)

View File

@ -58,7 +58,7 @@ def do_snmp_comm_add(cc, args):
fields = dict((k, v) for (k, v) in vars(args).items()
if k in field_list and not (v is None))
# fields = utils.args_array_to_dict(fields, 'activity')
#fields = utils.args_array_to_dict(fields, 'reason')
# fields = utils.args_array_to_dict(fields, 'reason')
icommunity = cc.icommunity.create(**fields)
field_list.append('uuid')
@ -78,7 +78,3 @@ def do_snmp_comm_delete(cc, args):
except exc.HTTPNotFound:
raise exc.CommandError('Community not found: %s' % c)
print 'Deleted community %s' % c

View File

@ -11,10 +11,10 @@ from cgtsclient import exc
from cgtsclient.openstack.common.gettextutils import _
CREATION_ATTRIBUTES = ['ihost_uuid', 'inode_uuid', 'cpu', 'core', 'thread',
CREATION_ATTRIBUTES = ['ihost_uuid', 'inode_uuid', 'cpu', 'core', 'thread',
'cpu_family', 'cpu_model', 'allocated_function',
'numa_node', 'capabilities', 'function',
'num_cores_on_processor0', 'num_cores_on_processor1',
'numa_node', 'capabilities', 'function',
'num_cores_on_processor0', 'num_cores_on_processor1',
'num_cores_on_processor2', 'num_cores_on_processor3']
PLATFORM_CPU_TYPE = "Platform"
@ -113,25 +113,27 @@ def check_core_functions(personality, icpus):
if platform_cores == 0:
error_string = ("There must be at least one core for %s." %
PLATFORM_CPU_TYPE_FORMAT)
elif personality == 'compute' and vswitch_cores == 0 :
elif personality == 'compute' and vswitch_cores == 0:
error_string = ("There must be at least one core for %s." %
VSWITCH_CPU_TYPE_FORMAT)
elif personality == 'compute' and vm_cores == 0 :
elif personality == 'compute' and vm_cores == 0:
error_string = ("There must be at least one core for %s." %
VMS_CPU_TYPE_FORMAT)
return error_string
def compress_range(c_list):
c_list.append( 999 )
c_list.append(999)
c_list.sort()
c_sep = ""
c_item = ""
c_str = ""
pn = 0 # pn is not used until second loop anyways
for n in c_list:
if not c_item:
c_item = "%s" % n
else:
if n > (pn+1):
if n > (pn + 1):
if int(pn) == int(c_item):
c_str = "%s%s%s" % (c_str, c_sep, c_item)
else:
@ -141,6 +143,7 @@ def compress_range(c_list):
pn = n
return c_str
def restructure_host_cpu_data(host):
host.core_assignment = []
if host.cpus:
@ -160,39 +163,37 @@ def restructure_host_cpu_data(host):
host.hyperthreading = "Yes"
if cpu.numa_node not in host.node_min_max_cores:
host.node_min_max_cores[cpu.numa_node] = { 'min': 99999, 'max': 0 }
host.node_min_max_cores[cpu.numa_node] = {'min': 99999, 'max': 0}
if cpu.cpu < host.node_min_max_cores[cpu.numa_node]['min']:
host.node_min_max_cores[cpu.numa_node]['min'] = cpu.cpu
if cpu.cpu > host.node_min_max_cores[cpu.numa_node]['max']:
host.node_min_max_cores[cpu.numa_node]['max'] = cpu.cpu
if cpu.allocated_function == None:
if cpu.allocated_function is None:
cpu.allocated_function = NONE_CPU_TYPE
if cpu.allocated_function not in core_assignment:
core_assignment[cpu.allocated_function] = {}
number_of_cores[cpu.allocated_function] = {}
if cpu.numa_node not in core_assignment[cpu.allocated_function]:
core_assignment[cpu.allocated_function][cpu.numa_node] = [ int(cpu.cpu) ]
core_assignment[cpu.allocated_function][cpu.numa_node] = [int(cpu.cpu)]
number_of_cores[cpu.allocated_function][cpu.numa_node] = 1
else:
core_assignment[cpu.allocated_function][cpu.numa_node].append( int(cpu.cpu) )
core_assignment[cpu.allocated_function][cpu.numa_node].append(int(cpu.cpu))
number_of_cores[cpu.allocated_function][cpu.numa_node] = number_of_cores[cpu.allocated_function][cpu.numa_node] + 1
for f in CPU_TYPE_LIST:
cpufunction = CpuFunction(f)
if f in core_assignment:
host.core_assignment.append( cpufunction )
for s,cores in core_assignment[f].items():
host.core_assignment.append(cpufunction)
for s, cores in core_assignment[f].items():
cpufunction.socket_cores[s] = compress_range(cores)
cpufunction.socket_cores_number[s] = number_of_cores[f][s]
else:
if (f == PLATFORM_CPU_TYPE or
(hasattr(host, 'subfunctions') and
'compute' in host.subfunctions)):
if (f == PLATFORM_CPU_TYPE or (hasattr(host, 'subfunctions')
and 'compute' in host.subfunctions)):
if f != NONE_CPU_TYPE:
host.core_assignment.append( cpufunction )
host.core_assignment.append(cpufunction)
for s in range(0, len(host.nodes)):
cpufunction.socket_cores[s] = ""
cpufunction.socket_cores_number[s] = 0

View File

@ -12,9 +12,8 @@
from cgtsclient.common import utils
from cgtsclient import exc
from collections import OrderedDict
from cgtsclient.v1 import ihost as ihost_utils
from cgtsclient.v1 import icpu as icpu_utils
from cgtsclient.v1 import ihost as ihost_utils
def _print_icpu_show(icpu):
@ -47,7 +46,7 @@ def _find_cpu(cc, ihost, cpunameoruuid):
break
else:
raise exc.CommandError('CPU logical core not found: host %s cpu %s' %
(ihost.hostname, cpunameoruuid))
(ihost.hostname, cpunameoruuid))
return c

View File

@ -68,7 +68,7 @@ def _find_disk(cc, ihost, idisk):
try:
disk = cc.idisk.get(idisk)
except exc.HTTPNotFound:
return None
return None
else:
return disk
else:

View File

@ -13,7 +13,6 @@
from cgtsclient.common import constants
from cgtsclient.common import utils
from cgtsclient import exc
from collections import OrderedDict
from cgtsclient.v1 import ihost as ihost_utils

View File

@ -11,7 +11,6 @@
from cgtsclient.common import utils
from cgtsclient import exc
from collections import OrderedDict
def _print_idns_show(idns):
@ -52,7 +51,7 @@ def donot_dns_add(cc, args):
fields = {}
user_specified_fields = dict((k, v) for (k, v) in vars(args).items()
if k in field_list and not (v is None))
if k in field_list and not (v is None))
fields.update(user_specified_fields)

View File

@ -9,8 +9,8 @@
# All Rights Reserved.
#
from cgtsclient.common import utils
from cgtsclient.common import constants
from cgtsclient.common import utils
from cgtsclient import exc
from collections import OrderedDict

View File

@ -9,9 +9,8 @@
from cgtsclient.common import base
from cgtsclient.common import utils
from cgtsclient.v1 import icpu
from cgtsclient import exc
from cgtsclient.v1 import icpu
CREATION_ATTRIBUTES = ['hostname', 'personality', 'subfunctions',
@ -78,21 +77,21 @@ class ihostManager(base.Manager):
new = {}
new['force'] = force
resp, body = self.api.json_request(
'POST', self._path(hostid)+"/upgrade", body=new)
'POST', self._path(hostid) + "/upgrade", body=new)
return self.resource_class(self, body)
def downgrade(self, hostid, force):
new = {}
new['force'] = force
resp, body = self.api.json_request(
'POST', self._path(hostid)+"/downgrade", body=new)
'POST', self._path(hostid) + "/downgrade", body=new)
return self.resource_class(self, body)
def create_many(self, body):
return self._upload(self._path()+"/bulk_add", body)
return self._upload(self._path() + "/bulk_add", body)
def host_cpus_modify(self, hostid, patch):
path = self._path(hostid)+"/state/host_cpus_modify"
path = self._path(hostid) + "/state/host_cpus_modify"
resp, body = self.api.json_request(
'PUT', path, body=patch)
@ -134,5 +133,3 @@ def _find_ihost(cc, ihost):
return h
else:
raise exc.CommandError('host not found: %s' % ihost)

View File

@ -82,7 +82,7 @@ def do_infra_modify(cc, args):
for entry in args.attributes[0]:
if(entry.count("=") != 1):
raise exc.CommandError('infra-modify parameters must be '
'of the form property=value')
'of the form property=value')
patch = utils.args_array_to_patch("replace", args.attributes[0])
try:

View File

@ -11,7 +11,6 @@
from cgtsclient.common import utils
from cgtsclient import exc
from collections import OrderedDict
from cgtsclient.v1 import ihost as ihost_utils
from cgtsclient.v1 import iinterface as iinterface_utils
@ -24,12 +23,12 @@ def _print_iinterface_show(iinterface):
'vlan_id', 'uses', 'used_by',
'created_at', 'updated_at', 'sriov_numvfs']
optional_fields = ['ipv4_mode', 'ipv6_mode', 'ipv4_pool', 'ipv6_pool']
rename_fields = [{'field':'dpdksupport', 'label':'accelerated'}]
data = [ (f, getattr(iinterface, f, '')) for f in fields ]
data += [ (f, getattr(iinterface, f, '')) for f in optional_fields
if hasattr(iinterface, f) ]
data += [ (f['label'], getattr(iinterface, f['field'], '')) for f in rename_fields
if hasattr(iinterface, f['field']) ]
rename_fields = [{'field': 'dpdksupport', 'label': 'accelerated'}]
data = [(f, getattr(iinterface, f, '')) for f in fields]
data += [(f, getattr(iinterface, f, '')) for f in optional_fields
if hasattr(iinterface, f)]
data += [(f['label'], getattr(iinterface, f['field'], '')) for f in rename_fields
if hasattr(iinterface, f['field'])]
utils.print_tuple_list(data)
@ -82,7 +81,7 @@ def do_host_if_list(cc, args):
attr_str = "%s,AE_XMIT_POLICY=%s" % (
attr_str, i.txhashpolicy)
if (i.networktype and
any(network in ['data'] for \
any(network in ['data'] for
network in i.networktype.split(","))):
if False in i.dpdksupport:
attr_str = "%s,accelerated=False" % attr_str
@ -175,7 +174,7 @@ def do_host_if_add(cc, args):
ihost = ihost_utils._find_ihost(cc, args.hostnameorid)
user_specified_fields = dict((k, v) for (k, v) in vars(args).items()
if k in field_list and not (v is None))
if k in field_list and not (v is None))
if 'iftype' in user_specified_fields.keys():
if args.iftype == 'ae' or args.iftype == 'vlan':
@ -186,7 +185,7 @@ def do_host_if_add(cc, args):
portnamesoruuids = ','.join(args.portsorifaces)
user_specified_fields = dict((k, v) for (k, v) in vars(args).items()
if k in field_list and not (v is None))
if k in field_list and not (v is None))
if 'providernetworks' in user_specified_fields.keys():
user_specified_fields['providernetworks'] = user_specified_fields['providernetworks'].replace(" ", "")
@ -264,7 +263,7 @@ def do_host_if_modify(cc, args):
ihost = ihost_utils._find_ihost(cc, args.hostnameorid)
user_specified_fields = dict((k, v) for (k, v) in vars(args).items()
if k in rwfields and not (v is None))
if k in rwfields and not (v is None))
if 'providernetworks' in user_specified_fields.keys():
user_specified_fields['providernetworks'] = user_specified_fields['providernetworks'].replace(" ", "")
@ -283,13 +282,13 @@ def do_host_if_modify(cc, args):
for p in interface.ports:
user_specified_fields['ifname'] = p
break
if any(network in ['data'] for \
if any(network in ['data'] for
network in interface.networktype.split(",")):
user_specified_fields['providernetworks'] = 'none'
patch = []
for (k, v) in user_specified_fields.items():
patch.append({'op':'replace', 'path':'/'+k, 'value':v})
patch.append({'op': 'replace', 'path': '/' + k, 'value': v})
iinterface = cc.iinterface.update(interface.uuid, patch)
iinterface_utils._get_ports(cc, ihost, iinterface)

View File

@ -9,8 +9,8 @@
# All Rights Reserved.
#
from cgtsclient.common import utils
from cgtsclient.common import constants
from cgtsclient.common import utils
from cgtsclient import exc
from cgtsclient.v1 import ihost as ihost_utils
from cgtsclient.v1 import ilvg as ilvg_utils

View File

@ -44,7 +44,7 @@ class imemoryManager(base.Manager):
return self._list(path)[0]
except IndexError:
return None
def update(self, imemory_id, patch):
return self._update(self._path(imemory_id), patch)

View File

@ -60,8 +60,7 @@ def _print_imemory_show(imemory):
if d[0] == 'vm_hugepages_nr_1G_pending':
if d[1] is None:
fields.remove(d[0])
labels.pop(len(labels)-labels[::-1].
index(' Total Pending')-1)
labels.pop(len(labels) - labels[::-1].index(' Total Pending') - 1)
data = [(f, getattr(imemory, f, '')) for f in fields]
utils.print_tuple_list(data, labels)
@ -86,7 +85,7 @@ def do_host_memory_show(cc, args):
return
else:
raise exc.CommandError('Processor not found: host %s processor %s' %
(ihost.hostname, args.numa_node))
(ihost.hostname, args.numa_node))
@utils.arg('hostnameorid',
@ -141,21 +140,19 @@ def do_host_memory_list(cc, args):
utils.print_list(imemorys, fields, field_labels, sortby=1)
@utils.arg('hostnameorid',
metavar='<hostname or id>',
help="Name or ID of host")
@utils.arg('numa_node',
metavar='<processor>',
help="processor")
@utils.arg('-m', '--platform_reserved_mib',
metavar='<Platform Reserved MiB>',
help='The amount of platform memory (MiB) for the numa node')
@utils.arg('-2M', '--vm_hugepages_nr_2M_pending',
metavar='<2M hugepages number>',
help='The number of 2M vm huge pages for the numa node')
@utils.arg('-1G', '--vm_hugepages_nr_1G_pending',
metavar='<1G hugepages number>',
help='The number of 1G vm huge pages for the numa node')
@ -169,7 +166,7 @@ def do_host_memory_modify(cc, args):
ihost = ihost_utils._find_ihost(cc, args.hostnameorid)
user_specified_fields = dict((k, v) for (k, v) in vars(args).items()
if k in rwfields and not (v is None))
if k in rwfields and not (v is None))
ihost = ihost_utils._find_ihost(cc, args.hostnameorid)
inodes = cc.inode.list(ihost.uuid)
@ -180,19 +177,18 @@ def do_host_memory_modify(cc, args):
if m.inode_uuid == n.uuid:
if int(n.numa_node) == int(args.numa_node):
mem = m
break
break
if mem:
break
if mem is None:
raise exc.CommandError('Processor not found: host %s processor %s' %
(ihost.hostname, args.numa_node))
(ihost.hostname, args.numa_node))
patch = []
for (k, v) in user_specified_fields.items():
patch.append({'op':'replace', 'path':'/'+k, 'value':v})
patch.append({'op': 'replace', 'path': '/' + k, 'value': v})
if patch:
imemory = cc.imemory.update(mem.uuid, patch)
_print_imemory_show(imemory)

View File

@ -11,9 +11,7 @@
from cgtsclient.common import utils
from cgtsclient import exc
from collections import OrderedDict
from cgtsclient.v1 import ihost as ihost_utils
from cgtsclient.v1 import inode as inode_utils
def _print_inode_show(inode):
@ -109,7 +107,7 @@ def do_host_node_modify(cc, args):
ihost = ihost_utils._find_ihost(cc, args.hostnameorid)
user_specified_fields = dict((k, v) for (k, v) in vars(args).items()
if k in rwfields and not (v is None))
if k in rwfields and not (v is None))
i = _find_node(cc, ihost, args.inodeuuid)
fields = i.__dict__

View File

@ -11,7 +11,6 @@
from cgtsclient.common import utils
from cgtsclient import exc
from collections import OrderedDict
def _print_intp_show(intp):
@ -51,7 +50,7 @@ def donot_ntp_add(cc, args):
fields = {}
user_specified_fields = dict((k, v) for (k, v) in vars(args).items()
if k in field_list and not (v is None))
if k in field_list and not (v is None))
fields.update(user_specified_fields)

View File

@ -7,9 +7,9 @@
# -*- encoding: utf-8 -*-
#
from cgtsclient import exc
from cgtsclient.common import base
from cgtsclient.common import utils
from cgtsclient import exc
CREATION_ATTRIBUTES = ['profiletype', 'profilename', 'ihost_uuid']
@ -41,7 +41,7 @@ class iprofileManager(base.Manager):
def list_cpu_profiles(self):
path = "cpuprofiles_list"
profiles = self._list(self._path(path))
profiles = self._list(self._path(path))
for profile in profiles:
profile.cpus = [utils.objectify(n) for n in profile.cpus]
profile.nodes = [utils.objectify(n) for n in profile.nodes]

View File

@ -10,9 +10,9 @@
# All Rights Reserved.
#
from cgtsclient import exc
from cgtsclient.common import constants
from cgtsclient.common import utils
from cgtsclient import exc
from cgtsclient.v1 import ethernetport as ethernetport_utils
from cgtsclient.v1 import icpu as icpu_utils
from cgtsclient.v1 import ihost as ihost_utils
@ -47,7 +47,7 @@ def get_portconfig(iprofile):
pstr = ''
for port in iprofile.ports:
pstr = pstr + "%s: %s" % (ethernetport_utils.get_port_display_name(port), port.pdevice)
port.autoneg = 'Yes' # TODO Remove when autoneg supported in DB
port.autoneg = 'Yes' # TODO(jkung) Remove when autoneg supported in DB
if port.autoneg != 'na':
pstr = pstr + " | Auto Neg = %s" % (port.autoneg)
if port.bootp:
@ -351,7 +351,7 @@ def get_ilvg_config(iprofile):
str += "; "
capabilities_str = ''
for k,v in ilvg.capabilities.iteritems():
for k, v in ilvg.capabilities.iteritems():
if capabilities_str != '':
capabilities_str += "; "
capabilities_str += "%s: %s " % (k, v)
@ -394,7 +394,7 @@ def get_storprofile_data(cc, iprofile, detailed=False):
def do_storprofile_list(cc, args):
"""List storage profiles."""
profiles = cc.iprofile.list_storage_profiles()
storprofiles=[]
storprofiles = []
localstorprofiles = []
profile_disk_invalid = False
@ -654,7 +654,7 @@ def do_profile_import(cc, args):
try:
file = open(filename, 'rb')
except:
except Exception:
raise exc.CommandError("Error: Could not open file %s for read." % filename)
results = cc.iprofile.import_profile(file)

View File

@ -12,9 +12,9 @@
from cgtsclient.common import utils
from cgtsclient import exc
from cgtsclient.v1 import idisk as idisk_utils
from cgtsclient.v1 import partition as partition_utils
from cgtsclient.v1 import ihost as ihost_utils
from cgtsclient.v1 import ilvg as ilvg_utils
from cgtsclient.v1 import partition as partition_utils
def _print_ipv_show(ipv):
@ -114,7 +114,7 @@ def do_host_pv_add(cc, args):
fields['pv_type'] = 'disk'
else:
partition = partition_utils._find_partition(cc, ihost,
args.device_name_path_uuid)
args.device_name_path_uuid)
if partition:
fields['disk_or_part_uuid'] = partition.uuid
fields['pv_type'] = 'partition'
@ -122,7 +122,7 @@ def do_host_pv_add(cc, args):
if not idisk and not partition:
raise exc.CommandError("No disk or partition found on host \'%s\' "
"by device path or uuid %s" %
(ihost.hostname,args.device_name_path_uuid))
(ihost.hostname, args.device_name_path_uuid))
try:
ipv = cc.ipv.create(**fields)

View File

@ -12,8 +12,8 @@
from cgtsclient.common import utils
from cgtsclient import exc
from collections import OrderedDict
from cgtsclient.v1 import ihost as ihost_utils
from collections import OrderedDict
def _print_isensor_show(isensor):

View File

@ -73,7 +73,7 @@ class isensorgroupManager(base.Manager):
def relearn(self, ihost_uuid):
new = {}
new['host_uuid'] = ihost_uuid
return self.api.json_request('POST', self._path()+"/relearn", body=new)
return self.api.json_request('POST', self._path() + "/relearn", body=new)
def get_sensorgroup_display_name(s):

View File

@ -12,9 +12,9 @@
from cgtsclient.common import utils
from cgtsclient import exc
from collections import OrderedDict
from cgtsclient.v1 import ihost as ihost_utils
from cgtsclient.v1 import isensorgroup as isensorgroup_utils
from collections import OrderedDict
def _print_isensorgroup_show(isensorgroup):

View File

@ -25,6 +25,7 @@ from cgtsclient import exc
CREATION_ATTRIBUTES = ['servicename', 'hostname', 'state', 'activity', 'reason']
# missing forihostid
class iService(base.Resource):
def __repr__(self):
return "<iService %s>" % self._info

View File

@ -101,8 +101,8 @@ def do_service_delete(cc, args):
metavar='<path=value>',
nargs='+',
action='append',
default=[],
help="Attributes to add/replace or remove ")
default=[],
help="Attributes to add/replace or remove ")
def donot_service_modify_lab(cc, args):
"""LAB ONLY Update a service. """
# JKUNG comment this out prior to delivery

View File

@ -45,8 +45,7 @@ def do_servicegroup_show(cc, args):
try:
iservicegroup = cc.iservicegroup.get(args.iservicegroup)
except exc.HTTPNotFound:
raise exc.CommandError(
'servicegroup not found: %s' % args.iservicegroup)
raise exc.CommandError('servicegroup not found: %s' % args.iservicegroup)
else:
_print_iservicegroup_show(iservicegroup)
@ -91,8 +90,8 @@ def do_servicegroup_delete(cc, args):
metavar='<path=value>',
nargs='+',
action='append',
default=[],
help="Attributes to add/replace or remove ")
default=[],
help="Attributes to add/replace or remove ")
def donot_servicegroup_modify_labonly(cc, args):
"""LAB ONLY Update a servicegroup. """
# JKUNG comment this out prior to delivery
@ -100,6 +99,5 @@ def donot_servicegroup_modify_labonly(cc, args):
try:
iservicegroup = cc.iservicegroup.update(args.iservicegroup, patch)
except exc.HTTPNotFound:
raise exc.CommandError(
'Service Group not found: %s' % args.iservicegroup)
raise exc.CommandError('Service Group not found: %s' % args.iservicegroup)
_print_iservicegroup_show(iservicegroup)

View File

@ -172,7 +172,7 @@ def do_host_stor_update(cc, args):
patch = []
for (k, v) in user_specified_fields.items():
patch.append({'op': 'replace', 'path': '/'+k, 'value': v})
patch.append({'op': 'replace', 'path': '/' + k, 'value': v})
try:
istor = cc.istor.update(args.osd, patch)

View File

@ -10,19 +10,15 @@
# All Rights Reserved.
#
import subprocess
from cgtsclient.common import constants
from cgtsclient.common import utils
from cgtsclient import exc
from collections import OrderedDict
from cgtsclient.v1 import isystem as isystem_utils
from cgtsclient.common import constants
def _print_isystem_show(isystem):
fields = ['name', 'system_type', 'system_mode', 'description', 'location',
'contact', 'timezone', 'software_version', 'uuid',
'created_at', 'updated_at', 'region_name', 'service_project_name']
'created_at', 'updated_at', 'region_name', 'service_project_name']
if isystem.capabilities.get('region_config'):
fields.append('shared_services')
setattr(isystem, 'shared_services',
@ -31,7 +27,7 @@ def _print_isystem_show(isystem):
fields.append('sdn_enabled')
setattr(isystem, 'sdn_enabled',
isystem.capabilities.get('sdn_enabled'))
if isystem.capabilities.get('https_enabled') is not None:
fields.append('https_enabled')
setattr(isystem, 'https_enabled',
@ -89,7 +85,6 @@ def do_show(cc, args):
help='The vswitch type for the system')
def do_modify(cc, args):
"""Modify system attributes."""
isystems = cc.isystem.list()
isystem = isystems[0]
@ -134,7 +129,7 @@ def do_modify(cc, args):
print 'Please follow the admin guide to complete the reconfiguration.'
field_list = ['name', 'system_mode', 'description', 'location', 'contact',
'timezone', 'sdn_enabled','https_enabled', 'vswitch_type']
'timezone', 'sdn_enabled', 'https_enabled', 'vswitch_type']
# use field list as filter
user_fields = dict((k, v) for (k, v) in vars(args).items()
@ -148,8 +143,8 @@ def do_modify(cc, args):
for (k, v) in user_fields.items():
patch.append({'op': 'replace', 'path': '/' + k, 'value': v})
if k == "https_enabled" and v == "true" :
print_https_warning = True
if k == "https_enabled" and v == "true":
print_https_warning = True
try:
isystem = cc.isystem.update(isystem.uuid, patch)
@ -157,6 +152,6 @@ def do_modify(cc, args):
raise exc.CommandError('system not found: %s' % isystem.uuid)
_print_isystem_show(isystem)
if print_https_warning :
print "HTTPS enabled with a self-signed certificate.\nThis should be " \
"changed to a CA-signed certificate with 'system certificate-install'. "
if print_https_warning:
print "HTTPS enabled with a self-signed certificate.\nThis should be " \
"changed to a CA-signed certificate with 'system certificate-install'. "

View File

@ -51,4 +51,3 @@ class iTrapdestManager(base.Manager):
def update(self, iid, patch):
return self._update(self._path(iid), patch)

View File

@ -82,8 +82,3 @@ def do_snmp_trapdest_delete(cc, args):
except exc.HTTPNotFound:
raise exc.CommandError('IP not found: %s' % c)
print 'Deleted ip %s' % c

View File

@ -17,7 +17,6 @@
from cgtsclient.common import utils
from cgtsclient import exc
from collections import OrderedDict
def _print_iuser_show(iuser):
@ -36,6 +35,7 @@ def donot_user_show(cc, args):
_print_iuser_show(iusers[0])
@utils.arg('attributes',
metavar='<path=value>',
nargs='+',

View File

@ -8,7 +8,6 @@
#
from cgtsclient.common import base
from cgtsclient import exc
class License(base.Resource):

View File

@ -29,6 +29,7 @@ def do_license_list(cc, args):
utils.print_list(licenses, fields, labels, sortby=0)
@utils.arg('license_file_path',
metavar='<license file path>',
default=None,
@ -38,7 +39,7 @@ def do_license_install(cc, args):
filename = args.license_file_path
try:
license_file = open(filename, 'rb')
except:
except Exception:
raise exc.CommandError(
"Error: Could not open file %s for read." % filename)

View File

@ -8,7 +8,7 @@
#
from cgtsclient.common import base
from cgtsclient import exc
class LldpAgent(base.Resource):
def __repr__(self):
@ -33,4 +33,3 @@ class LldpAgentManager(base.Manager):
def get_by_port(self, port_id):
path = '/v1/ports/%s/lldp_agents' % port_id
return self._list(path, "lldp_agents")

View File

@ -11,15 +11,15 @@
#
from cgtsclient.common import utils
from cgtsclient import exc
from collections import OrderedDict
from cgtsclient.v1 import ihost as ihost_utils
class LldpAgentObj:
def __init__(self, dictionary):
for k, v in dictionary.items():
setattr(self, k, v)
def _print_lldp_agent_show(agent):
fields = ['uuid', 'host_uuid',
'created_at', 'updated_at',
@ -37,9 +37,10 @@ def _print_lldp_agent_show(agent):
'dot1_vlan_names',
'dot3_mac_status', 'dot3_max_frame'
]
data = [ (f, getattr(agent, f, '')) for f in fields ]
data = [(f, getattr(agent, f, '')) for f in fields]
utils.print_tuple_list(data, labels)
def _lldp_carriage_formatter(value):
chars = ['\n', '\\n', '\r', '\\r']
for char in chars:
@ -47,28 +48,31 @@ def _lldp_carriage_formatter(value):
value = value.replace(char, '. ')
return value
def _lldp_system_name_formatter(lldp):
system_name = getattr(lldp, 'system_name')
if system_name:
return _lldp_carriage_formatter(system_name)
def _lldp_system_description_formatter(lldp):
system_description = getattr(lldp, 'system_description')
if system_description:
return _lldp_carriage_formatter(system_description)
def _lldp_port_description_formatter(lldp):
port_description = getattr(lldp, 'port_description')
if port_description:
return _lldp_carriage_formatter(port_description)
@utils.arg('hostnameorid',
metavar='<hostname or id>',
help="Name or ID of host")
def do_host_lldp_agent_list(cc, args):
"""List host lldp agents."""
ihost = ihost_utils._find_ihost(cc, args.hostnameorid)
agent_list = []
agents = cc.lldp_agent.list(ihost.uuid)
field_labels = ['uuid', 'local_port', 'status', 'chassis_id', 'port_id',
@ -82,6 +86,7 @@ def do_host_lldp_agent_list(cc, args):
utils.print_list(agents, fields, field_labels, sortby=1,
formatters=formatters)
@utils.arg('uuid',
metavar='<uuid>',
help="UUID of the LLDP agent")
@ -90,4 +95,3 @@ def do_lldp_agent_show(cc, args):
agent = cc.lldp_agent.get(args.uuid)
_print_lldp_agent_show(agent)
return

View File

@ -8,7 +8,7 @@
#
from cgtsclient.common import base
from cgtsclient import exc
class LldpNeighbour(base.Resource):
def __repr__(self):

View File

@ -11,16 +11,15 @@
#
from cgtsclient.common import utils
from cgtsclient import exc
from collections import OrderedDict
from cgtsclient.v1 import ihost as ihost_utils
from cgtsclient.v1 import port as port_utils
class LldpNeighbourObj:
def __init__(self, dictionary):
for k, v in dictionary.items():
setattr(self, k, v)
def _lldp_carriage_formatter(value):
chars = ['\n', '\\n', '\r', '\\r']
for char in chars:
@ -28,21 +27,25 @@ def _lldp_carriage_formatter(value):
value = value.replace(char, '. ')
return value
def _lldp_system_name_formatter(lldp):
system_name = getattr(lldp, 'system_name')
if system_name:
return _lldp_carriage_formatter(system_name)
def _lldp_system_description_formatter(lldp):
system_description = getattr(lldp, 'system_description')
if system_description:
return _lldp_carriage_formatter(system_description)
def _lldp_port_description_formatter(lldp):
port_description = getattr(lldp, 'port_description')
if port_description:
return _lldp_carriage_formatter(port_description)
def _print_lldp_neighbour_show(neighbour):
fields = ['uuid', 'host_uuid',
'created_at', 'updated_at',
@ -63,7 +66,7 @@ def _print_lldp_neighbour_show(neighbour):
'dot1_proto_vids', 'dot1_proto_ids', 'dot3_mac_status',
'dot3_max_frame'
]
data = [ (f, getattr(neighbour, f, '')) for f in fields ]
data = [(f, getattr(neighbour, f, '')) for f in fields]
utils.print_tuple_list(data, labels)
@ -97,4 +100,3 @@ def do_lldp_neighbor_show(cc, args):
neighbour = cc.lldp_neighbour.get(args.uuid)
_print_lldp_neighbour_show(neighbour)
return

View File

@ -65,10 +65,10 @@ def do_host_disk_partition_list(cc, args):
ihost = ihost_utils._find_ihost(cc, args.hostname_or_id)
if args.disk:
idisk = idisk_utils._find_disk(cc, args.hostname_or_id, args.disk)
if not idisk:
raise exc.CommandError('Disk not found: %s' % args.disk)
ipartitions = cc.partition.list(ihost.uuid, idisk.uuid)
else:
ipartitions = cc.partition.list(ihost.uuid, None)
@ -212,7 +212,7 @@ def do_host_disk_partition_modify(cc, args):
patch = []
for (k, v) in user_specified_fields.items():
patch.append({'op': 'replace', 'path': '/'+k, 'value': v})
patch.append({'op': 'replace', 'path': '/' + k, 'value': v})
# Update the partition attributes
try:

View File

@ -8,7 +8,6 @@
#
from cgtsclient.common import base
from cgtsclient import exc
class PciDevice(base.Resource):
@ -44,4 +43,3 @@ def get_pci_device_display_name(p):
return p.name
else:
return '(' + str(p.uuid)[-8:] + ')'

View File

@ -12,9 +12,9 @@
from cgtsclient.common import utils
from cgtsclient import exc
from collections import OrderedDict
from cgtsclient.v1 import ihost as ihost_utils
def _print_device_show(device):
fields = ['name', 'pciaddr', 'pclass_id', 'pvendor_id', 'pdevice_id',
'pclass', 'pvendor', 'pdevice', 'numa_node', 'enabled',
@ -30,6 +30,7 @@ def _print_device_show(device):
data = [(f, getattr(device, f, '')) for f in fields]
utils.print_tuple_list(data, labels)
def _find_device(cc, host, nameorpciaddr):
devices = cc.pci_device.list(host.uuid)
for d in devices:
@ -39,6 +40,7 @@ def _find_device(cc, host, nameorpciaddr):
raise exc.CommandError('PCI devices not found: host %s device %s' % (host.id, nameorpciaddr))
return d
@utils.arg('hostnameorid',
metavar='<hostname or id>',
help="Name or ID of host")
@ -78,6 +80,7 @@ def do_host_device_list(cc, args):
utils.print_list(devices, fields, labels, sortby=1)
@utils.arg('hostnameorid',
metavar='<hostname or id>',
help="Name or ID of host")
@ -99,7 +102,7 @@ def do_host_device_modify(cc, args):
host = ihost_utils._find_ihost(cc, args.hostnameorid)
user_specified_fields = dict((k, v) for (k, v) in vars(args).items()
if k in rwfields and not (v is None))
if k in rwfields and not (v is None))
device = _find_device(cc, host, args.nameorpciaddr)
@ -108,12 +111,11 @@ def do_host_device_modify(cc, args):
patch = []
for (k, v) in user_specified_fields.items():
patch.append({'op':'replace', 'path':'/'+k, 'value':v})
patch.append({'op': 'replace', 'path': '/' + k, 'value': v})
if patch:
try:
device = cc.pci_device.update(device.uuid, patch)
_print_device_show(device)
except exc.HTTPNotFound:
raise exc.CommandError('Device update failed: host %s device %s : update %s' % (args.hostnameorid, nameorpciaddr, patch))
raise exc.CommandError('Device update failed: host %s device %s : update %s' % (args.hostnameorid, args.nameorpciaddr, patch))

View File

@ -8,7 +8,6 @@
#
from cgtsclient.common import base
from cgtsclient import exc
class Port(base.Resource):
@ -38,4 +37,3 @@ def get_port_display_name(p):
return p.namedisplay
else:
return '(' + str(p.uuid)[-8:] + ')'

View File

@ -12,7 +12,6 @@
from cgtsclient.common import utils
from cgtsclient import exc
from collections import OrderedDict
from cgtsclient.v1 import ihost as ihost_utils
@ -35,7 +34,7 @@ def _print_port_show(port):
'uuid', 'host_uuid', 'interface_uuid',
'accelerated',
'created_at', 'updated_at']
data = [ (f, getattr(port, f, '')) for f in fields ]
data = [(f, getattr(port, f, '')) for f in fields]
utils.print_tuple_list(data, labels)

View File

@ -11,7 +11,6 @@
from cgtsclient.common import utils
from cgtsclient import exc
from collections import OrderedDict
def _print_remotelogging_show(remotelogging):
@ -20,7 +19,6 @@ def _print_remotelogging_show(remotelogging):
'enabled',
'transport',
'port',
#NC 'key_file',
'created_at',
'updated_at']
@ -64,10 +62,6 @@ def donot_config_remotelogging_list(cc, args):
metavar='<port>',
default=None,
help="Remote log server port.")
#@utils.arg('--key_file',
# metavar='<key_file>',
# default=None,
# help="Remote log server TLS key file.")
def do_remotelogging_modify(cc, args):
"""Modify Remote Logging attributes."""

View File

@ -79,15 +79,15 @@ def do_host_route_add(cc, args):
field_list = ['network', 'prefix', 'gateway', 'metric']
## Lookup parent host and interface
# Lookup parent host and interface
ihost = ihost_utils._find_ihost(cc, args.hostnameorid)
iinterface = iinterface_utils._find_interface(cc, ihost, args.ifnameorid)
## Prune input fields down to required/expected values
# Prune input fields down to required/expected values
data = dict((k, v) for (k, v) in vars(args).items()
if k in field_list and not (v is None))
## Insert interface UUID
# Insert interface UUID
data['interface_uuid'] = iinterface.uuid
route = cc.route.create(**data)

View File

@ -36,7 +36,7 @@ class SDNControllerManager(base.Manager):
return None
def create(self, **kwargs):
# path = /v1/sdn_controller'
# path = /v1/sdn_controller'
new = {}
for (key, value) in kwargs.items():
if key in CREATION_ATTRIBUTES:

View File

@ -11,32 +11,33 @@
from cgtsclient.common import utils
from cgtsclient import exc
from cgtsclient.common import constants
def _print_sdn_controller_show(obj):
fields = ['uuid', 'state', 'ip_address', 'port', 'transport']
labels = ['uuid', 'administrative state', 'ip address',
fields = ['uuid', 'state', 'ip_address', 'port', 'transport']
labels = ['uuid', 'administrative state', 'ip address',
'remote port', 'transport mode']
data = [(f, getattr(obj, f, '')) for f in fields]
utils.print_tuple_list(data, labels)
@utils.arg('uuid', metavar='<uuid>',
help="ID of the SDN controller to show")
help="ID of the SDN controller to show")
def do_sdn_controller_show(cc, args):
"""Show SDN Controller details and attributes."""
try:
controller = cc.sdn_controller.get(args.uuid)
except exc.HTTPNotFound:
raise exc.CommandError('Create SDN Controller UUID not found: %s',
args.uuid)
args.uuid)
_print_sdn_controller_show(controller)
def do_sdn_controller_list(cc, args):
"""List all SDN controllers."""
controllers = cc.sdn_controller.list()
field_labels = ['uuid', 'administrative state', 'ip address',
@ -67,18 +68,18 @@ def do_sdn_controller_list(cc, args):
"(default: %(default)s)")
def do_sdn_controller_add(cc, args):
"""Add an SDN controller."""
field_list = ['ip_address', 'port', 'transport', 'state']
# use field list as filter
user_specified_fields = dict((k, v) for (k, v) in vars(args).items()
if k in field_list and not (v is None))
if k in field_list and not (v is None))
try:
controller = cc.sdn_controller.create(**user_specified_fields)
try:
controller = cc.sdn_controller.create(**user_specified_fields)
except exc.HTTPNotFound:
raise exc.CommandError("Failed to create SDN controller entry: "
"fields %s" % user_specified_fields)
"fields %s" % user_specified_fields)
uuid = getattr(controller, 'uuid', '')
try:
controller = cc.sdn_controller.get(uuid)
@ -87,6 +88,7 @@ def do_sdn_controller_add(cc, args):
% uuid)
_print_sdn_controller_show(controller)
@utils.arg('uuid',
metavar='<uuid>',
help="The UUID of the SDN Controller")
@ -98,7 +100,8 @@ def do_sdn_controller_delete(cc, args):
except exc.HTTPNotFound:
raise exc.CommandError("Failed to delete SDN controller entry: "
"invalid uuid: %s" % args.uuid)
print 'Deleted SDN controller: uuid %s' % args.uuid
print 'Deleted SDN controller: uuid %s' % args.uuid
@utils.arg('uuid',
metavar='<uuid>',
@ -130,18 +133,17 @@ def do_sdn_controller_modify(cc, args):
controller = cc.sdn_controller.get(args.uuid)
except exc.HTTPNotFound:
raise exc.CommandError("SDN controller not found: uuid %s" % args.uuid)
field_list = ['ip_address', 'port', 'transport', 'state']
# use field list as filter
user_specified_fields = dict((k, v) for (k, v) in vars(args).items()
if k in field_list and not (v is None))
if k in field_list and not (v is None))
# NOTE (knasim): Validate at SysInv so that we don't
# have to do it twice for cgcs client and Horizon
patch = []
for (k, v) in user_specified_fields.items():
patch.append({'op':'replace', 'path':'/'+k, 'value':v})
patch.append({'op': 'replace', 'path': '/' + k, 'value': v})
updated_controller = cc.sdn_controller.update(controller.uuid, patch)
_print_sdn_controller_show(updated_controller)

View File

@ -7,9 +7,8 @@
# -*- encoding: utf-8 -*-
#
from cgtsclient.common import base
from cgtsclient import exc
from ceilometerclient.v2 import options
from cgtsclient.common import base
class ServiceParameter(base.Resource):
@ -51,5 +50,4 @@ class ServiceParameterManager(base.Manager):
def apply(self, service):
new = {}
new['service'] = service
return self.api.json_request('POST', self._path()+"/apply", body=new)
return self.api.json_request('POST', self._path() + "/apply", body=new)

View File

@ -8,10 +8,10 @@
# All Rights Reserved.
#
from ceilometerclient.v2 import options
from cgtsclient.common import utils
from cgtsclient import exc
from collections import OrderedDict
from ceilometerclient.v2 import options
def _print_service_parameter_show(obj):
fields = ['uuid', 'service', 'section', 'name', 'value',
@ -25,7 +25,6 @@ def _print_service_parameter_show(obj):
help="UUID of service parameter")
def do_service_parameter_show(cc, args):
"""Show Service parameter."""
service_parameter = cc.service_parameter.get(args.uuid)
_print_service_parameter_show(service_parameter)
@ -41,7 +40,6 @@ def do_service_parameter_show(cc, args):
help="Search by parameter name")
def do_service_parameter_list(cc, args):
"""List Service parameters."""
query = None
field_list = ['service', 'section', 'name']
for (k, v) in vars(args).items():
@ -69,9 +67,7 @@ def do_service_parameter_delete(cc, args):
def _find_service_parameter(cc, service, section, name):
service_parameters = cc.service_parameter.list()
for p in service_parameters:
if (p.service == service and
p.section == section and
p.name == name):
if p.service == service and p.section == section and p.name == name:
break
else:
p = None
@ -187,5 +183,3 @@ def do_service_parameter_add(cc, args):
raise exc.CommandError('Service parameter not found: %s' % uuid)
_print_service_parameter_show(parameter)

View File

@ -3,62 +3,62 @@
#
# SPDX-License-Identifier: Apache-2.0
#
#
from cgtsclient.common import utils
from cgtsclient.v1 import address_shell
from cgtsclient.v1 import address_pool_shell
from cgtsclient.v1 import isystem_shell
from cgtsclient.v1 import iHost_shell
from cgtsclient.v1 import address_shell
from cgtsclient.v1 import ceph_mon_shell
from cgtsclient.v1 import certificate_shell
from cgtsclient.v1 import cluster_shell
from cgtsclient.v1 import controller_fs_shell
from cgtsclient.v1 import drbdconfig_shell
from cgtsclient.v1 import ethernetport_shell
from cgtsclient.v1 import event_log_shell
from cgtsclient.v1 import event_suppression_shell
from cgtsclient.v1 import firewallrules_shell
from cgtsclient.v1 import health_shell
from cgtsclient.v1 import ialarm_shell
from cgtsclient.v1 import icommunity_shell
from cgtsclient.v1 import icpu_shell
from cgtsclient.v1 import imemory_shell
from cgtsclient.v1 import iinterface_shell
from cgtsclient.v1 import idisk_shell
from cgtsclient.v1 import istor_shell
from cgtsclient.v1 import idns_shell
from cgtsclient.v1 import iextoam_shell
from cgtsclient.v1 import iHost_shell
from cgtsclient.v1 import iinfra_shell
from cgtsclient.v1 import iinterface_shell
from cgtsclient.v1 import ilvg_shell
from cgtsclient.v1 import ipv_shell
from cgtsclient.v1 import imemory_shell
from cgtsclient.v1 import intp_shell
from cgtsclient.v1 import iprofile_shell
from cgtsclient.v1 import ipv_shell
from cgtsclient.v1 import isensor_shell
from cgtsclient.v1 import isensorgroup_shell
from cgtsclient.v1 import istor_shell
from cgtsclient.v1 import isystem_shell
from cgtsclient.v1 import itrapdest_shell
from cgtsclient.v1 import iuser_shell
from cgtsclient.v1 import license_shell
from cgtsclient.v1 import lldp_agent_shell
from cgtsclient.v1 import lldp_neighbour_shell
from cgtsclient.v1 import load_shell
from cgtsclient.v1 import network_shell
from cgtsclient.v1 import partition_shell
from cgtsclient.v1 import pci_device_shell
from cgtsclient.v1 import port_shell
from cgtsclient.v1 import remotelogging_shell
from cgtsclient.v1 import route_shell
from cgtsclient.v1 import sdn_controller_shell
from cgtsclient.v1 import service_parameter_shell
from cgtsclient.v1 import sm_service_nodes_shell
from cgtsclient.v1 import sm_service_shell
from cgtsclient.v1 import sm_servicegroup_shell
from cgtsclient.v1 import ialarm_shell
from cgtsclient.v1 import icommunity_shell
from cgtsclient.v1 import itrapdest_shell
from cgtsclient.v1 import iuser_shell
from cgtsclient.v1 import idns_shell
from cgtsclient.v1 import intp_shell
from cgtsclient.v1 import iextoam_shell
from cgtsclient.v1 import controller_fs_shell
from cgtsclient.v1 import storage_backend_shell
from cgtsclient.v1 import ceph_mon_shell
from cgtsclient.v1 import drbdconfig_shell
from cgtsclient.v1 import event_log_shell
from cgtsclient.v1 import event_suppression_shell
from cgtsclient.v1 import iinfra_shell
from cgtsclient.v1 import ethernetport_shell
from cgtsclient.v1 import port_shell
from cgtsclient.v1 import route_shell
from cgtsclient.v1 import isensor_shell
from cgtsclient.v1 import isensorgroup_shell
from cgtsclient.v1 import load_shell
from cgtsclient.v1 import pci_device_shell
from cgtsclient.v1 import upgrade_shell
from cgtsclient.v1 import network_shell
from cgtsclient.v1 import service_parameter_shell
#from cgtsclient.v1 import storagepool_shell
from cgtsclient.v1 import cluster_shell
from cgtsclient.v1 import lldp_agent_shell
from cgtsclient.v1 import lldp_neighbour_shell
from cgtsclient.v1 import license_shell
from cgtsclient.v1 import health_shell
from cgtsclient.v1 import remotelogging_shell
from cgtsclient.v1 import sdn_controller_shell
from cgtsclient.v1 import firewallrules_shell
from cgtsclient.v1 import partition_shell
from cgtsclient.v1 import certificate_shell
from cgtsclient.v1 import storage_tier_shell
from cgtsclient.v1 import upgrade_shell
COMMAND_MODULES = [
isystem_shell,
@ -100,7 +100,6 @@ COMMAND_MODULES = [
upgrade_shell,
network_shell,
service_parameter_shell,
#storagepool_shell,
cluster_shell,
lldp_agent_shell,
lldp_neighbour_shell,

View File

@ -69,4 +69,4 @@ class SmServiceManager(base.Manager):
new[key] = value
else:
raise exc.InvalidAttribute()
return self._create(self._path(), new)
return self._create(self._path(), new)

View File

@ -59,4 +59,4 @@ class SmNodesManager(base.Manager):
return self._delete(self._path(nodes_id))
def update(self, nodes_id, patch):
return self._update(self._path(nodes_id), patch)
return self._update(self._path(nodes_id), patch)

View File

@ -53,8 +53,7 @@ def do_servicenode_show(cc, args):
try:
node = cc.sm_service_nodes.get(args.node)
except exc.HTTPNotFound:
raise exc.CommandError(
'Service Node not found: %s' % args.node)
raise exc.CommandError('Service Node not found: %s' % args.node)
except exc.Forbidden:
raise exc.CommandError("Not authorized. The requested action "
"requires 'admin' level")

View File

@ -18,9 +18,8 @@
#
# Copyright (c) 2013-2017 Wind River Systems, Inc.
#
import socket
from cgtsclient.common import utils
from cgtsclient import exc

View File

@ -59,4 +59,4 @@ class SmServiceGroupManager(base.Manager):
return self._delete(self._path(sm_servicegroup_id))
def update(self, sm_servicegroup_id, patch):
return self._update(self._path(sm_servicegroup_id), patch)
return self._update(self._path(sm_servicegroup_id), patch)

View File

@ -18,11 +18,10 @@
#
# Copyright (c) 2013-2014 Wind River Systems, Inc.
#
from cgtsclient.common import utils
from cgtsclient import exc
def _print_iservicegroup_show(servicegroup):
fields = ['uuid', 'name', 'hostname', 'service_group_name', 'state']
data = dict([(f, getattr(servicegroup, f, '')) for f in fields])
@ -52,8 +51,7 @@ def do_servicegroup_show(cc, args):
try:
servicegroup = cc.sm_servicegroup.get(args.servicegroup)
except exc.HTTPNotFound:
raise exc.CommandError(
'Service Group not found: %s' % args.servicegroup)
raise exc.CommandError('Service Group not found: %s' % args.servicegroup)
except exc.Forbidden:
raise exc.CommandError("Not authorized. The requested action "
"requires 'admin' level")
@ -105,8 +103,8 @@ def donot_servicegroup_delete(cc, args):
metavar='<path=value>',
nargs='+',
action='append',
default=[],
help="Attributes to add/replace or remove ")
default=[],
help="Attributes to add/replace or remove ")
def donot_servicegroup_modify_labonly(cc, args):
"""LAB ONLY Update a servicegroup. """
# JKUNG comment this out prior to delivery
@ -114,6 +112,5 @@ def donot_servicegroup_modify_labonly(cc, args):
try:
iservicegroup = cc.smapiClient.iservicegroup.update(args.iservicegroup, patch)
except exc.HTTPNotFound:
raise exc.CommandError(
'Service Group not found: %s' % args.iservicegroup)
raise exc.CommandError('Service Group not found: %s' % args.iservicegroup)
_print_iservicegroup_show(iservicegroup)

View File

@ -8,14 +8,14 @@
#
from cgtsclient.common import base
from cgtsclient.common import utils
from cgtsclient.common import constants
from cgtsclient.common import utils
from cgtsclient import exc
from cgtsclient.v1 import ceph_mon as ceph_mon_utils
from cgtsclient.v1 import storage_ceph # noqa
from cgtsclient.v1 import storage_external # noqa
from cgtsclient.v1 import storage_file # noqa
from cgtsclient.v1 import storage_lvm # noqa
from cgtsclient.v1 import storage_external # noqa
from oslo_serialization import jsonutils
CREATION_ATTRIBUTES = ['forisystemid', 'backend']

View File

@ -14,10 +14,12 @@ CREATION_ATTRIBUTES = ['confirmed', 'name', 'services', 'capabilities']
DISPLAY_ATTRIBUTES = []
PATCH_ATTRIBUTES = []
class StorageExternal(base.Resource):
def __repr__(self):
return "<storage_external %s>" % self._info
class StorageExternalManager(base.Manager):
resource_class = StorageExternal

View File

@ -142,7 +142,7 @@ def do_storage_tier_modify(cc, args):
args.storage_tier_or_uuid)
patch = []
for (k, v) in user_specified_fields.items():
patch.append({'op': 'replace', 'path': '/'+k, 'value': v})
patch.append({'op': 'replace', 'path': '/' + k, 'value': v})
# Update the storage tier attributes
try:

View File

@ -8,8 +8,6 @@
#
from cgtsclient.common import base
from cgtsclient import exc
CREATION_ATTRIBUTES = ['state', 'from_load', 'to_load']

View File

@ -9,9 +9,9 @@
# All Rights Reserved.
#
from cgtsclient.common import constants
from cgtsclient.common import utils
from cgtsclient import exc
from cgtsclient.common import constants
def _print_upgrade_show(obj):
@ -54,7 +54,7 @@ def do_upgrade_activate(cc, args):
patch = []
for (k, v) in data.items():
patch.append({'op': 'replace', 'path': '/'+k, 'value': v})
patch.append({'op': 'replace', 'path': '/' + k, 'value': v})
try:
upgrade = cc.upgrade.update(patch)
except exc.HTTPNotFound:
@ -143,7 +143,7 @@ def do_upgrade_abort(cc, args):
patch = []
for (k, v) in data.items():
patch.append({'op': 'replace', 'path': '/'+k, 'value': v})
patch.append({'op': 'replace', 'path': '/' + k, 'value': v})
try:
upgrade = cc.upgrade.update(patch)
except exc.HTTPNotFound:

View File

@ -0,0 +1,218 @@
[MASTER]
# Specify a configuration file.
rcfile=pylint.rc
# Python code to execute, usually for sys.path manipulation such as pygtk.require().
#init-hook=
# Add files or directories to the blacklist. They should be base names, not paths.
ignore=tests
# Pickle collected data for later comparisons.
persistent=yes
# List of plugins (as comma separated values of python modules names) to load,
# usually to register additional checkers.
load-plugins=
[MESSAGES CONTROL]
# Enable the message, report, category or checker with the given id(s). You can
# either give multiple identifier separated by comma (,) or put this option
# multiple time.
#enable=
# Disable the message, report, category or checker with the given id(s). You
# can either give multiple identifier separated by comma (,) or put this option
# multiple time (only on the command line, not in the configuration file where
# it should appear only once).
# https://pylint.readthedocs.io/en/latest/user_guide/output.html#source-code-analysis-section
# We are disabling (C)onvention
# We are disabling (R)efactor
# We are probably disabling (W)arning
# We are not disabling (F)atal, (E)rror
#disable=C,R,W
disable=C,R,W
[REPORTS]
# Set the output format. Available formats are text, parseable, colorized, msvs
# (visual studio) and html
output-format=text
# Put messages in a separate file for each module / package specified on the
# command line instead of printing them on stdout. Reports (if any) will be
# written in a file name "pylint_global.[txt|html]".
files-output=no
# Tells whether to display a full report or only the messages
reports=no
# Python expression which should return a note less than 10 (10 is the highest
# note). You have access to the variables errors warning, statement which
# respectively contain the number of errors / warnings messages and the total
# number of statements analyzed. This is used by the global evaluation report
# (RP0004).
evaluation=10.0 - ((float(5 * error + warning + refactor + convention) / statement) * 10)
[SIMILARITIES]
# Minimum lines number of a similarity.
min-similarity-lines=4
# Ignore comments when computing similarities.
ignore-comments=yes
# Ignore docstrings when computing similarities.
ignore-docstrings=yes
[FORMAT]
# Maximum number of characters on a single line.
max-line-length=85
# Maximum number of lines in a module
max-module-lines=1000
# String used as indentation unit. This is usually " " (4 spaces) or "\t" (1 tab).
indent-string=' '
[TYPECHECK]
# Tells whether missing members accessed in mixin class should be ignored. A
# mixin class is detected if its name ends with "mixin" (case insensitive).
ignore-mixin-members=yes
# List of classes names for which member attributes should not be checked
# (useful for classes with attributes dynamically set).
ignored-classes=SQLObject
# List of members which are set dynamically and missed by pylint inference
# system, and so shouldn't trigger E0201 when accessed. Python regular
# expressions are accepted.
generated-members=REQUEST,acl_users,aq_parent
[BASIC]
# List of builtins function names that should not be used, separated by a comma
bad-functions=map,filter,apply,input
# Regular expression which should only match correct module names
module-rgx=(([a-z_][a-z0-9_]*)|([A-Z][a-zA-Z0-9]+))$
# Regular expression which should only match correct module level names
const-rgx=(([A-Z_][A-Z0-9_]*)|(__.*__))$
# Regular expression which should only match correct class names
class-rgx=[A-Z_][a-zA-Z0-9]+$
# Regular expression which should only match correct function names
function-rgx=[a-z_][a-z0-9_]{2,30}$
# Regular expression which should only match correct method names
method-rgx=[a-z_][a-z0-9_]{2,30}$
# Regular expression which should only match correct instance attribute names
attr-rgx=[a-z_][a-z0-9_]{2,30}$
# Regular expression which should only match correct argument names
argument-rgx=[a-z_][a-z0-9_]{2,30}$
# Regular expression which should only match correct variable names
variable-rgx=[a-z_][a-z0-9_]{2,30}$
# Regular expression which should only match correct list comprehension /
# generator expression variable names
inlinevar-rgx=[A-Za-z_][A-Za-z0-9_]*$
# Good variable names which should always be accepted, separated by a comma
good-names=i,j,k,ex,Run,_
# Bad variable names which should always be refused, separated by a comma
bad-names=foo,bar,baz,toto,tutu,tata
# Regular expression which should only match functions or classes name which do
# not require a docstring
no-docstring-rgx=__.*__
[MISCELLANEOUS]
# List of note tags to take in consideration, separated by a comma.
notes=FIXME,XXX,TODO
[VARIABLES]
# Tells whether we should check for unused import in __init__ files.
init-import=no
# A regular expression matching the beginning of the name of dummy variables
# (i.e. not used).
dummy-variables-rgx=_|dummy
# List of additional names supposed to be defined in builtins. Remember that
# you should avoid to define new builtins when possible.
additional-builtins=
[IMPORTS]
# Deprecated modules which should not be used, separated by a comma
deprecated-modules=regsub,string,TERMIOS,Bastion,rexec
# Create a graph of every (i.e. internal and external) dependencies in the
# given file (report RP0402 must not be disabled)
import-graph=
# Create a graph of external dependencies in the given file (report RP0402 must
# not be disabled)
ext-import-graph=
# Create a graph of internal dependencies in the given file (report RP0402 must
# not be disabled)
int-import-graph=
[DESIGN]
# Maximum number of arguments for function / method
max-args=5
# Argument names that match this expression will be ignored. Default to name
# with leading underscore
ignored-argument-names=_.*
# Maximum number of locals for function / method body
max-locals=15
# Maximum number of return / yield for function / method body
max-returns=6
# Maximum number of branch for function / method body
max-branchs=12
# Maximum number of statements in function / method body
max-statements=50
# Maximum number of parents for a class (see R0901).
max-parents=7
# Maximum number of attributes for a class (see R0902).
max-attributes=7
# Minimum number of public methods for a class (see R0903).
min-public-methods=2
# Maximum number of public methods for a class (see R0904).
max-public-methods=20
[CLASSES]
# List of method names used to declare (i.e. assign) instance attributes.
defining-attr-methods=__init__,__new__,setUp
# List of valid names for the first argument in a class method.
valid-classmethod-first-arg=cls
[EXCEPTIONS]
# Exceptions that will emit a warning when being caught. Defaults to
# "Exception"
overgeneral-exceptions=Exception

View File

@ -0,0 +1,2 @@
python-neutronclient
python-ceilometerclient

View File

@ -0,0 +1,36 @@
[metadata]
name = cgtsclient
version = 1.0.0
summary = Titanium Cloud System Client and CLI
description-file =
README.rst
author = WindRiver
classifier =
Environment :: OpenStack
Intended Audience :: Information Technology
Intended Audience :: System Administrators
License :: windriver
Operating System :: POSIX :: Linux
Programming Language :: Python
Programming Language :: Python :: 2
Programming Language :: Python :: 2.7
[global]
setup-hooks =
pbr.hooks.setup_hook
[files]
packages =
cgtsclient
[entry_points]
console_scripts =
system = cgtsclient.shell:main
[pbr]
autodoc_index_modules = False
[egg_info]
tag_build =
tag_date = 0
tag_svn_revision = 0

View File

@ -6,18 +6,25 @@
import setuptools
setuptools.setup(
name='cgtsclient',
description='CGCS System Client and CLI',
version='1.0.0',
license='Apache-2.0',
packages=['cgtsclient', 'cgtsclient.v1', 'cgtsclient.openstack',
'cgtsclient.openstack.common',
'cgtsclient.openstack.common.config',
'cgtsclient.openstack.common.rootwrap',
'cgtsclient.common'],
entry_points={
'console_scripts': [
'system = cgtsclient.shell:main'
]}
description='Titanium Cloud System Client and CLI',
classifiers=[
'Environment :: OpenStack',
'Intended Audience :: Information Technology',
'Intended Audience :: System Administrators',
'License :: windriver',
'Operating System :: POSIX :: Linux',
'Programming Language :: Python',
'Programming Language :: Python :: 2',
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 2.6',
],
include_package_data=True,
setup_requires=['pbr>=0.5'],
pbr=True,
packages=setuptools.find_packages()
)

Some files were not shown because too many files have changed in this diff Show More