Compare commits

..

16 Commits
2.3.0 ... 3.0.0

Author SHA1 Message Date
Andreas Jaeger
5946fbb5b1 Cleanup py27 support
Make a few cleanups:
- Remove python 2.7 stanza from setup.py
- Add requires on python >= 3.6 to setup.cfg so that pypi and pip
  know about the requirement
- Remove obsolete sections from setup.cfg: Wheel is not needed for python
  3 only repo
- Update requirements, no need for python_version anymore
- Use modern sphinx-build for docs building, update openstackdocstheme,
  fix api-doc building.

Change-Id: I40b67f330ac850bf45cca742a8b967fd12480ce3
2020-04-04 14:27:51 +02:00
Andreas Jaeger
2830afdc75 Update hacking for Python3
The repo is Python 3 now, so update hacking to version 3.0 which
supports Python 3.

Fix problems found.

Change-Id: I6bd9fdee0ee275e4d9d3fcaf96c1512933ce35a6
2020-03-31 13:29:10 +02:00
Zuul
1912b9aa82 Merge "Support audit type event" 2020-01-10 01:56:48 +00:00
licanwei
1f9194ced5 Support audit type event
Add a new EVENT type to audit type and change the microversion
to 1.4

Partially Implements: blueprint event-driven-optimization-based

Change-Id: Ia9608534d12f6877f9b93e88fa75fe9457c29347
2020-01-07 15:57:11 +08:00
Zuul
9387369cd7 Merge "Drop python 2.7 support and testing" 2019-12-16 02:42:17 +00:00
licanwei
431319ee4d Watcherclient supports list data model API
Change-Id: I5527414b5e87253d87a4a26398ad5dcce1193e43
Related-Bug: #1854121
2019-12-02 14:41:32 +08:00
Ghanshyam Mann
e3c903cfce Drop python 2.7 support and testing
OpenStack is dropping the py2.7 support in ussuri cycle.

python-watcherclient is ready with python 3 and ok to drop the
python 2.7 support.

Complete discussion & schedule can be found in
- http://lists.openstack.org/pipermail/openstack-discuss/2019-October/010142.html
- https://etherpad.openstack.org/p/drop-python2-support

Ussuri Communtiy-wide goal - https://review.opendev.org/#/c/691178/

Change-Id: Id66df6c12e7b533381a354937e23e33f992adbfa
2019-10-30 04:34:43 +00:00
Zuul
e3f0a3d2b5 Merge "Fix details doc format error" 2019-10-26 07:23:01 +00:00
chenke
88351df1c2 Fix details doc format error
This error was caused because of rst format.

pls see:
https://github.com/openstack/python-watcherclient/blob/master/doc/source/cli/details.rst

This patch solved this error.

Change-Id: I756d2f6327349c36e4523513a2ac84ad91f7785f
2019-10-26 09:55:34 +08:00
Zuul
df3ec7849e Merge "Switch to Ussuri jobs" 2019-10-25 03:43:15 +00:00
Eric Fried
0c7e306642 Fix python-openstackclient plugin doc build
A help string in a plugin command argument help string contained (a typo
and) some invalid sphinx-isms causing autoprogram-cliff building from
python-openstackclient to fail with:

.../python-openstackclient/doc/source/cli/plugin-commands/watcher.rst:30:Inline emphasis start-string without end-string.
and
<CreateAuditTemplate>:1:Unexpected indentation.

This commit fixes the (typo and) help string formatting.

Change-Id: Ifb668b9ada94b679672f3bab562410bf12f4ca64
2019-10-24 01:34:12 +00:00
kangyufei
db70063cee Switch to Ussuri jobs
Change-Id: I13ae604be95e8b8ddd81a957900199a1113fc3f2
2019-10-22 15:13:55 +08:00
licanwei
1d1f28a256 Build pdf docs
Add a new pdf-docs environment to enable PDF build.

Change-Id: I59bdc7cf339b022458b3b0d1fa3b694b7998c20f
2019-09-17 00:20:25 -07:00
Zuul
62fdb73dae Merge "Implement watcher datamodel list in watcherclient" 2019-09-09 02:30:52 +00:00
chenke
297ca1dfc5 Implement watcher datamodel list in watcherclient
1. Add data_model.py and data_model_shell.py for accept and
process request.

2. Add relative unittest.

Partically Implements: blueprint show-datamodel-api

Change-Id: I5e080453acaedf7e20734d67922b64511dd5f7fd
2019-08-28 09:45:03 +08:00
chenke
a8f919e1f7 Add datamodel doc in watcherclient
Change-Id: I319d47dc66cb10e5ba5b6e0e318ecff0438b2d05
2019-08-26 20:28:47 +08:00
24 changed files with 574 additions and 121 deletions

View File

@@ -2,8 +2,7 @@
templates:
- openstack-cover-jobs
- openstack-lower-constraints-jobs
- openstack-python-jobs
- openstack-python3-train-jobs
- openstack-python3-ussuri-jobs
- publish-openstack-docs-pti
- check-requirements
- openstackclient-plugin-jobs

View File

@@ -2,6 +2,7 @@
# of appearance. Changing the order has an impact on the overall integration
# process, which may cause wedges in the gate later.
openstackdocstheme>=1.18.1 # Apache-2.0
sphinx!=1.6.6,!=1.6.7,>=1.6.5,<2.0.0;python_version=='2.7' # BSD
sphinx!=1.6.6,!=1.6.7,>=1.6.5;python_version>='3.4' # BSD
openstackdocstheme>=1.32.1 # Apache-2.0
sphinx!=1.6.6,!=1.6.7,>=1.6.5 # BSD
sphinxcontrib-apidoc>=0.2.0 # BSD

View File

@@ -620,38 +620,43 @@ Create new audit template.
``--scope <path>``
Part of the cluster on which an audit will be done.
Can be provided either in yaml or json file.
YAML example:
---- host_aggregates:
- id: 1
- id: 2
- id: 3
YAML example:
::
---
- host_aggregates:
- id: 1
- id: 2
- id: 3
- availability_zones:
- name: AZ1
- name: AZ2
- name: AZ1
- name: AZ2
- exclude:
- instances:
- uuid: UUID1
- uuid: UUID2
- compute_nodes:
- name: compute1
JSON example:
[{'host_aggregates': [
{'id': 1},
{'id': 2},
{'id': 3}]},
{'availability_zones': [
{'name': 'AZ1'},
{'name': 'AZ2'}]},
{'exclude': [
{'instances': [
{'uuid': 'UUID1'},
{'uuid': 'UUID2'}
]},
{'compute_nodes': [
{'name': 'compute1'}
]}
]}]
- instances:
- uuid: UUID1
- uuid: UUID2
- compute_nodes:
- name: compute1
JSON example:
::
[
{'host_aggregates': [
{'id': 1},
{'id': 2},
{'id': 3}]},
{'availability_zones': [
{'name': 'AZ1'},
{'name': 'AZ2'}]},
{'exclude': [
{'instances': [
{'uuid': 'UUID1'},
{'uuid': 'UUID2'}]},
{'compute_nodes': [
{'name': 'compute1'}]}]}
]
.. _watcher_audittemplate_delete:
@@ -969,6 +974,40 @@ Show detailed information about a given service.
``-h, --help``
show this help message and exit
.. _watcher_datamodel_list:
watcher datamodel list
----------------------
.. code-block:: console
usage: watcher datamodel list [-h] [-f {csv,json,table,value,yaml}]
[-c COLUMN] [--max-width <integer>]
[--fit-width] [--print-empty] [--noindent]
[--quote {all,minimal,none,nonnumeric}]
[--sort-column SORT_COLUMN] [--type <type>]
[--audit <audit>] [--detail]
List information on retrieved data model.
**Optional arguments:**
``-h, --help``
show this help message and exit
``--type <type>``
Type of Datamodel user want to list. Supported values:
compute. Future support values: storage, baremetal.
Default type is compute.
``--audit <audit>``
UUID of the audit. used to filter data model
by the scope in audit.
``--detail``
Show detailed information about data model.
.. _watcher_strategy_list:
watcher strategy list

View File

@@ -20,12 +20,20 @@ from watcherclient import version as watcherclient_version
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom ones.
extensions = ['sphinx.ext.autodoc',
'sphinx.ext.viewcode',
'sphinxcontrib.apidoc',
'openstackdocstheme',
]
# autodoc generation is a bit aggressive and a nuisance when doing heavy
# text edit cycles.
# execute "export SPHINX_DEBUG=1" in your terminal to disable
# sphinxcontrib.apidoc options
apidoc_module_dir = '../../watcherclient'
apidoc_output_dir = 'reference/api'
apidoc_excluded_paths = [
'tests/*']
apidoc_separate_modules = True
# Add any paths that contain templates here, relative to this directory.
templates_path = ['_templates']
@@ -88,12 +96,21 @@ latex_documents = [
),
]
# Disable usage of xindy https://bugzilla.redhat.com/show_bug.cgi?id=1643664
latex_use_xindy = False
latex_domain_indices = False
latex_elements = {
'makeindex': '',
'printindex': '',
'preamble': r'\setcounter{tocdepth}{3}',
}
# openstackdocstheme options
repository_name = 'openstack/python-watcherclient'
bug_project = 'python-watcherclient'
bug_tag = ''
# Must set this variable to include year, month, day, hours, and minutes.
html_last_updated_fmt = '%Y-%m-%d %H:%M'
#html_theme_options = {"show_other_versions": "True"}

View File

@@ -1,8 +0,0 @@
======================
Python API Reference
======================
.. toctree::
:maxdepth: 2
autoindex

View File

@@ -10,5 +10,5 @@ done so, you can use the API like so.
.. toctree::
:maxdepth: 2
api/index
api/modules
api_v1

View File

@@ -40,7 +40,7 @@ msgpack-python==0.4.0
munch==2.2.0
netaddr==0.7.19
netifaces==0.10.6
openstackdocstheme==1.18.1
openstackdocstheme==1.32.1
openstacksdk==0.12.0
os-client-config==1.29.0
os-service-types==1.2.0

View File

@@ -0,0 +1,6 @@
---
upgrade:
- |
Python 2.7 support has been dropped. Last release of python-watcherclient
to support py2.7 is OpenStack Train. The minimum version of Python now
supported by python-watcherclient is Python 3.6.

View File

@@ -6,6 +6,7 @@ description-file =
author = OpenStack
author-email = openstack-discuss@lists.openstack.org
home-page = https://docs.openstack.org/python-watcherclient/latest/
python-requires = >=3.6
classifier =
Environment :: OpenStack
Intended Audience :: Information Technology
@@ -13,8 +14,6 @@ classifier =
License :: OSI Approved :: Apache Software License
Operating System :: POSIX :: Linux
Programming Language :: Python
Programming Language :: Python :: 2
Programming Language :: Python :: 2.7
Programming Language :: Python :: 3
Programming Language :: Python :: 3.6
Programming Language :: Python :: 3.7
@@ -67,6 +66,8 @@ openstack.infra_optim.v1 =
optimize_service_show = watcherclient.v1.service_shell:ShowService
optimize_service_list = watcherclient.v1.service_shell:ListService
optimize_datamodel_list = watcherclient.v1.data_model_shell:ListDataModel
# The same as above but used by the 'watcher' command
watcherclient.v1 =
goal_show = watcherclient.v1.goal_shell:ShowGoal
@@ -104,21 +105,14 @@ watcherclient.v1 =
service_show = watcherclient.v1.service_shell:ShowService
service_list = watcherclient.v1.service_shell:ListService
datamodel_list = watcherclient.v1.data_model_shell:ListDataModel
[pbr]
autodoc_index_modules = True
autodoc_exclude_modules =
watcherclient.tests.*
api_doc_dir = reference/api
[build_sphinx]
source-dir = doc/source
build-dir = doc/build
all_files = 1
warning-is-error = 1
[bdist_wheel]
universal = 1
[compile_catalog]
directory = watcherclient/locale
domain = watcherclient

View File

@@ -13,17 +13,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.
# THIS FILE IS MANAGED BY THE GLOBAL REQUIREMENTS REPO - DO NOT EDIT
import setuptools
# In python < 2.7.4, a lazy loading of package `pbr` will break
# setuptools if some other modules registered functions in `atexit`.
# solution from: http://bugs.python.org/issue15881#msg170215
try:
import multiprocessing # noqa
except ImportError:
pass
setuptools.setup(
setup_requires=['pbr>=2.0.0'],
pbr=True)

View File

@@ -4,7 +4,7 @@
coverage!=4.4,>=4.0 # Apache-2.0
fixtures>=3.0.0 # Apache-2.0/BSD
hacking>=1.1.0,<1.2.0 # Apache-2.0
hacking>=3.0,<3.1.0 # Apache-2.0
mock>=2.0.0 # BSD
oslotest>=3.2.0 # Apache-2.0
python-subunit>=1.0.0 # Apache-2.0/BSD

19
tox.ini
View File

@@ -1,6 +1,6 @@
[tox]
minversion = 2.0
envlist = py36,py37,py27,pep8
envlist = py36,py37,pep8
skipsdist = True
[testenv]
@@ -46,7 +46,20 @@ deps =
-c{env:UPPER_CONSTRAINTS_FILE:https://releases.openstack.org/constraints/upper/master}
-r{toxinidir}/requirements.txt
-r{toxinidir}/doc/requirements.txt
commands = python setup.py build_sphinx
commands = sphinx-build -W -b html doc/source doc/build/html
[testenv:pdf-docs]
basepython = python3
envdir = {toxworkdir}/docs
deps = {[testenv:docs]deps}
whitelist_externals =
rm
make
commands =
rm -rf doc/build/pdf
sphinx-build -W -b latex doc/source doc/build/pdf
make -C doc/build/pdf
[testenv:debug]
basepython = python3
@@ -56,7 +69,7 @@ commands = oslo_debug_helper -t watcherclient/tests/unit {posargs}
# E123, E125 skipped as they are invalid PEP-8.
show-source = True
enable-extensions = H203,H106
ignore = E123,E125
ignore = E123,E125,W504
builtins = _
exclude=.venv,.git,.tox,dist,doc,*lib/python*,*egg,build

View File

@@ -40,8 +40,8 @@ from watcherclient import exceptions
# Record the latest version that this client was tested with.
DEFAULT_VER = '1.latest'
# Minor version 2 for adding force option to audit
LAST_KNOWN_API_VERSION = 2
# Minor version 4 for adding webhook API
LAST_KNOWN_API_VERSION = 4
LATEST_VERSION = '1.{}'.format(LAST_KNOWN_API_VERSION)
LOG = logging.getLogger(__name__)

View File

@@ -71,6 +71,7 @@ class AmbiguousAuthSystem(exceptions.ClientException):
"""Could not obtain token and endpoint using provided credentials."""
pass
# Alias for backwards compatibility
AmbigiousAuthSystem = AmbiguousAuthSystem

View File

@@ -426,6 +426,23 @@ class AuditShellTest(base.CommandTestCase):
parameters={'para1': 10, 'para2': 20}
)
def test_do_audit_create_with_type_event(self):
audit = resource.Audit(mock.Mock(), self.AUDIT_1)
self.m_audit_mgr.create.return_value = audit
exit_code, result = self.run_cmd(
'audit create -g fc087747-61be-4aad-8126-b701731ae836 -t EVENT')
self.assertEqual(0, exit_code)
self.assertEqual(
self.resource_as_dict(audit, self.FIELDS, self.FIELD_LABELS),
result)
self.m_audit_mgr.create.assert_called_once_with(
goal='fc087747-61be-4aad-8126-b701731ae836',
auto_trigger=False,
audit_type='EVENT'
)
def test_do_audit_create_with_type_continuous(self):
audit = resource.Audit(mock.Mock(), self.AUDIT_1)
self.m_audit_mgr.create.return_value = audit
@@ -642,6 +659,24 @@ class AuditShellTestv12(AuditShellTest):
force=False
)
def test_do_audit_create_with_type_event(self):
audit = resource.Audit(mock.Mock(), self.AUDIT_1)
self.m_audit_mgr.create.return_value = audit
exit_code, result = self.run_cmd(
'audit create -g fc087747-61be-4aad-8126-b701731ae836 -t EVENT')
self.assertEqual(0, exit_code)
self.assertEqual(
self.resource_as_dict(audit, self.FIELDS, self.FIELD_LABELS),
result)
self.m_audit_mgr.create.assert_called_once_with(
goal='fc087747-61be-4aad-8126-b701731ae836',
auto_trigger=False,
audit_type='EVENT',
force=False
)
def test_do_audit_create_with_name(self):
audit = resource.Audit(mock.Mock(), self.AUDIT_1)
self.m_audit_mgr.create.return_value = audit

View File

@@ -0,0 +1,75 @@
# Copyright 2019 ZTE corporation.
# 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.
import testtools
from watcherclient.tests.unit import utils
import watcherclient.v1.data_model
DATA_MODEL = {
'context': [{
"server_uuid": "1bf91464-9b41-428d-a11e-af691e5563bb",
"server_name": "fake-name",
"server_state": "active",
"node_uuid": "253e5dd0-9384-41ab-af13-4f2c2ce26112",
"node_hostname": "localhost.localdomain",
}]
}
AUDIT = "81332bfc-36f8-444d-99e2-b7285d602528"
fake_responses = {
'/v1/data_model/?data_model_type=compute':
{
'GET': (
{},
DATA_MODEL,
),
},
'/v1/data_model/?audit_uuid=%s&data_model_type=compute' % AUDIT:
{
'GET': (
{},
DATA_MODEL,
),
},
}
class DataModelManagerTest(testtools.TestCase):
def setUp(self):
super(DataModelManagerTest, self).setUp()
self.api = utils.FakeAPI(fake_responses)
self.mgr = watcherclient.v1.data_model.DataModelManager(self.api)
def test_data_model_list(self):
data_model = self.mgr.list()
expect = [
('GET', '/v1/data_model/?data_model_type=compute', {}, None),
]
self.assertEqual(expect, self.api.calls)
self.assertEqual(1, len(data_model.context))
def test_data_model_list_audit(self):
data_model = self.mgr.list(
audit='%s' % AUDIT)
expect = [
('GET', '/v1/data_model/?'
'audit_uuid=81332bfc-36f8-444d-99e2-b7285d602528'
'&data_model_type=compute',
{}, None),
]
self.assertEqual(expect, self.api.calls)
self.assertEqual(1, len(data_model.context))

View File

@@ -0,0 +1,129 @@
# Copyright 2019 ZTE Corporation.
#
# 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.
import mock
import six
from watcherclient import shell
from watcherclient.tests.unit.v1 import base
from watcherclient import v1 as resource
from watcherclient.v1 import resource_fields
DATA_MODEL = {
'context': [{
"server_uuid": "1bf91464-9b41-428d-a11e-af691e5563bb",
"server_name": "fake-name",
"server_state": "active",
"server_vcpus": "1",
"server_memory": "512",
"server_disk": "1",
"node_uuid": "253e5dd0-9384-41ab-af13-4f2c2ce26112",
"node_hostname": "localhost.localdomain",
"node_vcpus": "4",
"node_vcpu_ratio": "16.0",
"node_memory": "16383",
"node_memory_ratio": "1.5",
"node_disk": "37",
"node_disk_ratio": "1.0",
"node_state": "up",
}]
}
LIST_RESULT = [{
"Server UUID": "1bf91464-9b41-428d-a11e-af691e5563bb",
"Server Name": "fake-name",
"Server Vcpus": "1",
"Server Memory": "512",
"Server Disk": "1",
"Server State": "active",
"Node UUID": "253e5dd0-9384-41ab-af13-4f2c2ce26112",
"Node Host Name": "localhost.localdomain",
"Node Vcpus": "4",
"Node Vcpu Ratio": "16.0",
"Node Memory": "16383",
"Node Memory Ratio": "1.5",
"Node Disk": "37",
"Node Disk Ratio": "1.0",
"Node State": "up",
}]
SHORT_LIST_RESULT = [{
"Server UUID": "1bf91464-9b41-428d-a11e-af691e5563bb",
"Server Name": "fake-name",
"Server State": "active",
"Node UUID": "253e5dd0-9384-41ab-af13-4f2c2ce26112",
"Node Host Name": "localhost.localdomain",
}]
class DataModelShellTest(base.CommandTestCase):
SHORT_LIST_FIELDS = resource_fields.COMPUTE_MODEL_SHORT_LIST_FIELDS
SHORT_LIST_FIELD_LABELS = (
resource_fields.COMPUTE_MODEL_SHORT_LIST_FIELD_LABELS)
FIELDS = resource_fields.COMPUTE_MODEL_LIST_FIELDS
FIELD_LABELS = resource_fields.COMPUTE_MODEL_LIST_FIELD_LABELS
def setUp(self):
super(self.__class__, self).setUp()
p_data_model_manager = mock.patch.object(
resource, 'DataModelManager')
self.m_data_model_mgr_cls = p_data_model_manager.start()
self.addCleanup(p_data_model_manager.stop)
self.m_data_model_mgr = mock.Mock()
self.m_data_model_mgr_cls.return_value = self.m_data_model_mgr
self.stdout = six.StringIO()
self.cmd = shell.WatcherShell(stdout=self.stdout)
def test_do_data_model_list(self):
data_model = resource.DataModel(mock.Mock(), DATA_MODEL)
self.m_data_model_mgr.list.return_value = data_model
exit_code, results = self.run_cmd('datamodel list')
self.assertEqual(0, exit_code)
expect_values = sorted(SHORT_LIST_RESULT[0].values())
result_values = sorted(results[0].values())
self.assertEqual(expect_values, result_values)
def test_do_data_model_list_detail(self):
data_model = resource.DataModel(mock.Mock(), DATA_MODEL)
self.m_data_model_mgr.list.return_value = data_model
exit_code, results = self.run_cmd('datamodel list --detail')
self.assertEqual(0, exit_code)
expect_values = sorted(LIST_RESULT[0].values())
result_values = sorted(results[0].values())
self.assertEqual(expect_values, result_values)
def test_do_data_model_list_filter_by_audit(self):
data_model = resource.DataModel(mock.Mock(), DATA_MODEL)
self.m_data_model_mgr.list.return_value = data_model
exit_code, results = self.run_cmd(
'datamodel list --audit '
'770ef053-ecb3-48b0-85b5-d55a2dbc6588')
self.assertEqual(0, exit_code)
expect_values = sorted(SHORT_LIST_RESULT[0].values())
result_values = sorted(results[0].values())
self.assertEqual(expect_values, result_values)

View File

@@ -17,6 +17,7 @@ from watcherclient.v1 import action
from watcherclient.v1 import action_plan
from watcherclient.v1 import audit
from watcherclient.v1 import audit_template
from watcherclient.v1 import data_model
from watcherclient.v1 import goal
from watcherclient.v1 import scoring_engine
from watcherclient.v1 import service
@@ -38,9 +39,12 @@ Service = service.Service
ServiceManager = service.ServiceManager
Strategy = strategy.Strategy
StrategyManager = strategy.StrategyManager
DataModel = data_model.DataModel
DataModelManager = data_model.DataModelManager
__all__ = (
"Action", "ActionManager", "ActionPlan", "ActionPlanManager",
"Audit", "AuditManager", "AuditTemplate", "AuditTemplateManager",
"Goal", "GoalManager", "ScoringEngine", "ScoringEngineManager",
"Service", "ServiceManager", "Strategy", "StrategyManager")
"Service", "ServiceManager", "Strategy", "StrategyManager",
"DataModel", "DataModelManager")

View File

@@ -167,8 +167,8 @@ class CreateAudit(command.ShowOne):
dest='audit_type',
metavar='<audit_type>',
default='ONESHOT',
choices=['ONESHOT', 'CONTINUOUS'],
help=_("Audit type. It must be ONESHOT or CONTINUOUS. "
choices=['ONESHOT', 'CONTINUOUS', 'EVENT'],
help=_("Audit type. It must be ONESHOT, CONTINUOUS or EVENT. "
"Default is ONESHOT."))
parser.add_argument(
'-p', '--parameter',
@@ -182,7 +182,7 @@ class CreateAudit(command.ShowOne):
dest='interval',
metavar='<interval>',
help=_('Audit interval (in seconds or cron format). '
'Cron inteval can be used like: "*/5 * * * *". '
'Cron interval can be used like: ``*/5 * * * *``. '
'Only used if the audit is CONTINUOUS.'))
parser.add_argument(
'-g', '--goal',

View File

@@ -167,8 +167,8 @@ class CreateAuditTemplate(command.ShowOne):
metavar='<path>',
help=_("Part of the cluster on which an audit will be done.\n"
"Can be provided either in yaml or json file.\n"
"YAML example:\n"
"---\n"
"YAML example::\n"
"\n"
" - compute:\n"
" - host_aggregates:\n"
" - id: 1\n"
@@ -201,48 +201,49 @@ class CreateAuditTemplate(command.ShowOne):
" - uuid: UUID1\n"
" - uuid: UUID2\n"
"\n"
"JSON example:\n"
"[\n"
" {\"compute\":\n"
" [{\"host_aggregates\": [\n"
" {\"id\": 1},\n"
" {\"id\": 2},\n"
" {\"id\": 3}]},\n"
" {\"availability_zones\": [\n"
" {\"name\": \"AZ1\"},\n"
" {\"name\": \"AZ2\"}]},\n"
" {\"exclude\": [\n"
" {\"instances\": [\n"
" {\"uuid\": \"UUID1\"},\n"
" {\"uuid\": \"UUID2\"}\n"
" ]},\n"
" {\"compute_nodes\": [\n"
" {\"name\": \"compute1\"}\n"
" ]}\n"
" ]}]\n"
" },\n"
" {\"storage\":\n"
" [{\"availability_zones\": [\n"
" {\"name\": \"AZ1\"},\n"
" {\"name\": \"AZ2\"}]},\n"
" {\"volume_types\": [\n"
" {\"name\": \"lvm1\"},\n"
" {\"name\": \"lvm2\"}]},\n"
" {\"exclude\": [\n"
" {\"storage_pools\": [\n"
" {\"name\": \"host0@backend0#pool0\"},\n"
" {\"name\": \"host1@backend1#pool1\"}\n"
" ]},\n"
" {\"volumes\": [\n"
" {\"uuid\": \"UUID1\"},\n"
" {\"uuid\": \"UUID2\"}\n"
" ]},\n"
" {\"projects\": [\n"
" {\"uuid\": \"UUID1\"},\n"
" {\"uuid\": \"UUID2\"}\n"
" ]},\n"
" ]}]\n"
" }\n"
"JSON example::\n"
"\n"
" [\n"
" {\"compute\":\n"
" [{\"host_aggregates\": [\n"
" {\"id\": 1},\n"
" {\"id\": 2},\n"
" {\"id\": 3}]},\n"
" {\"availability_zones\": [\n"
" {\"name\": \"AZ1\"},\n"
" {\"name\": \"AZ2\"}]},\n"
" {\"exclude\": [\n"
" {\"instances\": [\n"
" {\"uuid\": \"UUID1\"},\n"
" {\"uuid\": \"UUID2\"}\n"
" ]},\n"
" {\"compute_nodes\": [\n"
" {\"name\": \"compute1\"}\n"
" ]}\n"
" ]}]\n"
" },\n"
" {\"storage\":\n"
" [{\"availability_zones\": [\n"
" {\"name\": \"AZ1\"},\n"
" {\"name\": \"AZ2\"}]},\n"
" {\"volume_types\": [\n"
" {\"name\": \"lvm1\"},\n"
" {\"name\": \"lvm2\"}]},\n"
" {\"exclude\": [\n"
" {\"storage_pools\": [\n"
" {\"name\": \"host0@backend0#pool0\"},\n"
" {\"name\": \"host1@backend1#pool1\"}\n"
" ]},\n"
" {\"volumes\": [\n"
" {\"uuid\": \"UUID1\"},\n"
" {\"uuid\": \"UUID2\"}\n"
" ]},\n"
" {\"projects\": [\n"
" {\"uuid\": \"UUID1\"},\n"
" {\"uuid\": \"UUID2\"}\n"
" ]},\n"
" ]}]\n"
" }\n"
" ]\n"
)
)

View File

@@ -56,3 +56,4 @@ class Client(object):
self.scoring_engine = v1.ScoringEngineManager(self.http_client)
self.service = v1.ServiceManager(self.http_client)
self.strategy = v1.StrategyManager(self.http_client)
self.data_model = v1.DataModelManager(self.http_client)

View File

@@ -0,0 +1,56 @@
# Copyright 2019 ZTE Corporation.
#
# 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 watcherclient.common import base
from watcherclient.common import utils
class DataModel(base.Resource):
def __repr__(self):
return "<DataModel %s>" % self._info
class DataModelManager(base.Manager):
resource_class = DataModel
@staticmethod
def _path(filters=None):
if filters:
path = '/v1/data_model/%s' % filters
else:
path = '/v1/data_model'
return path
def list(self, data_model_type='compute', audit=None):
"""Retrieve a list of data model.
:param data_model_type: The type of data model user wants to list.
Supported values: compute.
Future support values: storage, baremetal.
The default value is compute.
:param audit: The UUID of the audit, used to filter data model
by the scope in audit.
:returns: A list of data model.
"""
path = ''
filters = utils.common_filters()
if audit:
filters.append('audit_uuid=%s' % audit)
filters.append('data_model_type=%s' % data_model_type)
path += '?' + '&'.join(filters)
return self._list(self._path(path))[0]

View File

@@ -0,0 +1,77 @@
# Copyright 2019 ZTE Corporation.
#
# 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 watcherclient._i18n import _
from watcherclient.common import command
from watcherclient import exceptions
from watcherclient.v1 import resource_fields as res_fields
class ListDataModel(command.Lister):
"""List information on retrieved data model."""
def get_parser(self, prog_name):
parser = super(ListDataModel, self).get_parser(prog_name)
parser.add_argument(
'--type',
metavar='<type>',
dest='type',
help=_('Type of Datamodel user want to list. '
'Supported values: compute. '
'Future support values: storage, baremetal. '
'Default type is compute.'))
parser.add_argument(
'--audit',
metavar='<audit>',
dest='audit',
help=_('UUID of the audit'))
parser.add_argument(
'--detail',
dest='detail',
action='store_true',
default=False,
help=_("Show detailed information about data model."))
return parser
def get_tuple(self, dic, fields):
ret_tup = []
for item in fields:
ret_tup.append(dic.get(item))
return tuple(ret_tup)
def take_action(self, parsed_args):
client = getattr(self.app.client_manager, "infra-optim")
allowed_type = ['compute', 'storage', 'baremetal']
params = {}
if parsed_args.audit:
params["audit"] = parsed_args.audit
if parsed_args.type:
if parsed_args.type not in allowed_type:
raise exceptions.CommandError(
'Type %s error, '
'Please check the valid type!' % parsed_args.type)
params["data_model_type"] = parsed_args.type
try:
data_model = client.data_model.list(**params)
except exceptions.HTTPNotFound as exc:
raise exceptions.CommandError(str(exc))
# TODO(chenker) Add Storage MODEL_FIELDS when using Storage Datamodel.
if parsed_args.detail:
fields = res_fields.COMPUTE_MODEL_LIST_FIELDS
field_labels = res_fields.COMPUTE_MODEL_LIST_FIELD_LABELS
else:
fields = res_fields.COMPUTE_MODEL_SHORT_LIST_FIELDS
field_labels = res_fields.COMPUTE_MODEL_SHORT_LIST_FIELD_LABELS
return (field_labels,
(self.get_tuple(item, fields) for item in data_model.context))

View File

@@ -98,6 +98,28 @@ STRATEGY_FIELDS = ['uuid', 'name', 'display_name', 'goal_name',
STRATEGY_FIELD_LABELS = ['UUID', 'Name', 'Display name', 'Goal',
'Parameters spec']
# Data Model
COMPUTE_MODEL_LIST_FIELDS = [
'server_uuid', 'server_name', 'server_vcpus',
'server_memory', 'server_disk', 'server_state', 'node_uuid',
'node_hostname', 'node_vcpus', 'node_vcpu_ratio', 'node_memory',
'node_memory_ratio', 'node_disk', 'node_disk_ratio', 'node_state']
COMPUTE_MODEL_LIST_FIELD_LABELS = [
'Server_UUID', 'Server Name', 'Server Vcpus',
'Server Memory', 'Server Disk', 'Server State', 'Node UUID',
'Node Host Name', 'Node Vcpus', 'Node Vcpu Ratio', 'Node Memory',
'Node Memory Ratio', 'Node Disk', 'Node Disk Ratio', 'Node State']
COMPUTE_MODEL_SHORT_LIST_FIELDS = [
'server_uuid', 'server_name',
'server_state', 'node_uuid', 'node_hostname']
COMPUTE_MODEL_SHORT_LIST_FIELD_LABELS = [
'Server UUID', 'Server Name',
'Server State', 'Node UUID', 'Node Host Name']
STRATEGY_SHORT_LIST_FIELDS = ['uuid', 'name', 'display_name', 'goal_name']
STRATEGY_SHORT_LIST_FIELD_LABELS = ['UUID', 'Name', 'Display name', 'Goal']