Compare commits
24 Commits
0.24.0
...
newton-eol
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6082163049 | ||
|
|
d4dfe32d0d | ||
|
|
63a319c1d6 | ||
|
|
6347775f6d | ||
|
|
0a5edb5852 | ||
|
|
77a6c9a6d9 | ||
|
|
465d0d46a3 | ||
|
|
6e858233dc | ||
|
|
522bc4374a | ||
|
|
c2b5eea3fb | ||
|
|
824017fa1f | ||
|
|
545f153bba | ||
|
|
008b50ea67 | ||
|
|
b836d83bc2 | ||
|
|
6fbcfc794a | ||
|
|
aa90c536b3 | ||
|
|
9c32e6e6dc | ||
|
|
7b55f92e11 | ||
|
|
daa4a88447 | ||
|
|
776a251d98 | ||
|
|
613810e43c | ||
|
|
df8997129e | ||
|
|
e2586130e1 | ||
|
|
ea455477a0 |
@@ -2,3 +2,4 @@
|
||||
host=review.openstack.org
|
||||
port=29418
|
||||
project=openstack/python-watcherclient.git
|
||||
defaultbranch=stable/newton
|
||||
|
||||
@@ -4,10 +4,10 @@
|
||||
|
||||
Babel>=2.3.4 # BSD
|
||||
cliff!=1.16.0,!=1.17.0,>=1.15.0 # Apache-2.0
|
||||
osc-lib>=1.0.2 # Apache-2.0
|
||||
oslo.i18n>=2.1.0 # Apache-2.0
|
||||
oslo.utils>=3.14.0 # Apache-2.0
|
||||
oslo.utils>=3.16.0 # Apache-2.0
|
||||
pbr>=1.6 # Apache-2.0
|
||||
PrettyTable<0.8,>=0.7 # BSD
|
||||
python-keystoneclient!=1.8.0,!=2.1.0,>=1.7.0 # Apache-2.0
|
||||
python-openstackclient>=2.1.0 # Apache-2.0
|
||||
python-keystoneclient!=2.1.0,>=2.0.0 # Apache-2.0
|
||||
six>=1.9.0 # MIT
|
||||
|
||||
@@ -5,7 +5,7 @@ description-file =
|
||||
README.rst
|
||||
author = OpenStack
|
||||
author-email = openstack-dev@lists.openstack.org
|
||||
home-page = http://www.openstack.org/
|
||||
home-page = http://docs.openstack.org/developer/python-watcherclient
|
||||
classifier =
|
||||
Environment :: OpenStack
|
||||
Intended Audience :: Information Technology
|
||||
@@ -58,6 +58,9 @@ openstack.infra_optim.v1 =
|
||||
optimize_action_show = watcherclient.v1.action_shell:ShowAction
|
||||
optimize_action_list = watcherclient.v1.action_shell:ListAction
|
||||
|
||||
optimize_scoringengine_show = watcherclient.v1.scoring_engine_shell:ShowScoringEngine
|
||||
optimize_scoringengine_list = watcherclient.v1.scoring_engine_shell:ListScoringEngine
|
||||
|
||||
# The same as above but used by the 'watcher' command
|
||||
watcherclient.v1 =
|
||||
goal_show = watcherclient.v1.goal_shell:ShowGoal
|
||||
@@ -88,6 +91,9 @@ watcherclient.v1 =
|
||||
action_show = watcherclient.v1.action_shell:ShowAction
|
||||
action_list = watcherclient.v1.action_shell:ListAction
|
||||
|
||||
scoringengine_show = watcherclient.v1.scoring_engine_shell:ShowScoringEngine
|
||||
scoringengine_list = watcherclient.v1.scoring_engine_shell:ListScoringEngine
|
||||
|
||||
[pbr]
|
||||
autodoc_index_modules = True
|
||||
|
||||
|
||||
@@ -3,7 +3,6 @@
|
||||
# process, which may cause wedges in the gate later.
|
||||
|
||||
coverage>=3.6 # Apache-2.0
|
||||
discover # BSD
|
||||
hacking<0.11,>=0.10.2
|
||||
mock>=2.0 # BSD
|
||||
oslosphinx!=3.4.0,>=2.5.0 # Apache-2.0
|
||||
|
||||
9
tox.ini
9
tox.ini
@@ -1,15 +1,16 @@
|
||||
[tox]
|
||||
minversion = 1.6
|
||||
minversion = 1.8
|
||||
envlist = py34,py27,pep8
|
||||
skipsdist = True
|
||||
|
||||
[testenv]
|
||||
usedevelop = True
|
||||
install_command = pip install -U {opts} {packages}
|
||||
install_command =
|
||||
constraints: pip install -U --force-reinstall -c{env:UPPER_CONSTRAINTS_FILE:https://git.openstack.org/cgit/openstack/requirements/plain/upper-constraints.txt?h=stable/newton} {opts} {packages}
|
||||
pip install -U {opts} {packages}
|
||||
setenv =
|
||||
VIRTUAL_ENV={envdir}
|
||||
deps = -r{toxinidir}/requirements.txt
|
||||
-r{toxinidir}/test-requirements.txt
|
||||
deps = -r{toxinidir}/test-requirements.txt
|
||||
commands = python setup.py testr --slowest --testr-args='{posargs}'
|
||||
|
||||
[testenv:pep8]
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
|
||||
import logging
|
||||
|
||||
from openstackclient.common import utils
|
||||
from osc_lib import utils
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
||||
@@ -39,12 +39,19 @@ def make_client(instance):
|
||||
interface=instance._interface,
|
||||
)
|
||||
|
||||
auth_url = instance._auth_url \
|
||||
if hasattr(instance, '_auth_url') else instance.auth.auth_url
|
||||
username = instance._username \
|
||||
if hasattr(instance, '_username') else instance.auth._username
|
||||
password = instance._password \
|
||||
if hasattr(instance, '_password') else instance.auth._password
|
||||
|
||||
client = watcher_client(
|
||||
endpoint=endpoint,
|
||||
session=instance.session,
|
||||
auth_url=instance._auth_url,
|
||||
username=instance._username,
|
||||
password=instance._password,
|
||||
auth_url=auth_url,
|
||||
username=username,
|
||||
password=password,
|
||||
region_name=instance._region_name,
|
||||
)
|
||||
|
||||
|
||||
@@ -30,8 +30,8 @@ from keystoneclient.auth.identity import v3
|
||||
from keystoneclient import discover
|
||||
from keystoneclient import exceptions as ks_exc
|
||||
from keystoneclient import session
|
||||
from openstackclient.common import logs
|
||||
from openstackclient.common import utils
|
||||
from osc_lib import logs
|
||||
from osc_lib import utils
|
||||
import six.moves.urllib.parse as urlparse
|
||||
|
||||
from watcherclient._i18n import _
|
||||
|
||||
@@ -28,6 +28,7 @@ from watcherclient.v1 import resource_fields
|
||||
ACTION_PLAN_1 = {
|
||||
'uuid': 'd9d9978e-6db5-4a05-8eab-1531795d7004',
|
||||
'audit_uuid': '770ef053-ecb3-48b0-85b5-d55a2dbc6588',
|
||||
'strategy_name': 'dummy',
|
||||
'state': 'RECOMMENDED',
|
||||
'efficacy_indicators': [{'description': 'Indicator 1',
|
||||
'name': 'indicator1',
|
||||
@@ -46,6 +47,7 @@ ACTION_PLAN_1 = {
|
||||
ACTION_PLAN_2 = {
|
||||
'uuid': 'd6363285-5afa-4a26-96f2-89441e335765',
|
||||
'audit_uuid': '239f02a5-9649-4e14-9d33-ac2bf67cb755',
|
||||
'strategy_name': 'dummy',
|
||||
'state': 'RECOMMENDED',
|
||||
'created_at': datetime.datetime.now().isoformat(),
|
||||
'efficacy_indicators': [{'description': 'Indicator 2',
|
||||
|
||||
@@ -23,12 +23,14 @@ from testtools.matchers import HasLength
|
||||
from watcherclient.tests import utils
|
||||
import watcherclient.v1.audit
|
||||
|
||||
|
||||
AUDIT1 = {
|
||||
'id': 1,
|
||||
'uuid': 'f8e47706-efcf-49a4-a5c4-af604eb492f2',
|
||||
'uuid': '5869da81-4876-4687-a1ed-12cd64cf53d9',
|
||||
'deadline': None,
|
||||
'audit_type': 'ONE_SHOT',
|
||||
'audit_template_uuid': '770ef053-ecb3-48b0-85b5-d55a2dbc6588'
|
||||
'goal': 'fc087747-61be-4aad-8126-b701731ae836',
|
||||
'strategy': '2cf86250-d309-4b81-818e-1537f3dba6e5',
|
||||
}
|
||||
|
||||
AUDIT2 = {
|
||||
@@ -36,9 +38,11 @@ AUDIT2 = {
|
||||
'uuid': 'a5199d0e-0702-4613-9234-5ae2af8dafea',
|
||||
'deadline': None,
|
||||
'audit_type': 'ONE_SHOT',
|
||||
'audit_template_uuid': '770ef053-ecb3-48b0-85b5-d55a2dbc6588'
|
||||
'goal': 'fc087747-61be-4aad-8126-b701731ae836',
|
||||
'strategy': None,
|
||||
}
|
||||
|
||||
|
||||
CREATE_AUDIT = copy.deepcopy(AUDIT1)
|
||||
del CREATE_AUDIT['id']
|
||||
del CREATE_AUDIT['uuid']
|
||||
@@ -125,19 +129,8 @@ fake_responses_sorting = {
|
||||
},
|
||||
}
|
||||
|
||||
fake_responses_filters = {
|
||||
'/v1/audits/?audit_template=%s' % AUDIT2['audit_template_uuid']:
|
||||
{
|
||||
'GET': (
|
||||
{},
|
||||
{"audits": [AUDIT2]}
|
||||
),
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
class AuditManagerTest(testtools.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
super(AuditManagerTest, self).setUp()
|
||||
self.api = utils.FakeAPI(fake_responses)
|
||||
@@ -200,16 +193,6 @@ class AuditManagerTest(testtools.TestCase):
|
||||
self.assertEqual(expect, self.api.calls)
|
||||
self.assertEqual(2, len(audits))
|
||||
|
||||
def test_audits_list_filter_by_audit_template(self):
|
||||
self.api = utils.FakeAPI(fake_responses_filters)
|
||||
self.mgr = watcherclient.v1.audit.AuditManager(self.api)
|
||||
self.mgr.list(audit_template=AUDIT2['audit_template_uuid'])
|
||||
expect = [
|
||||
('GET', '/v1/audits/?audit_template=%s' %
|
||||
AUDIT2['audit_template_uuid'], {}, None),
|
||||
]
|
||||
self.assertEqual(expect, self.api.calls)
|
||||
|
||||
def test_audits_show(self):
|
||||
audit = self.mgr.get(AUDIT1['uuid'])
|
||||
expect = [
|
||||
|
||||
@@ -31,8 +31,27 @@ AUDIT_TEMPLATE_1 = {
|
||||
'description': 'Audit Template 1 description',
|
||||
'host_aggregate': 5,
|
||||
'extra': {'automatic': False},
|
||||
'goal_uuid': '7568667b-51fe-4087-9eb1-29b26891036f',
|
||||
'strategy_uuid': 'bbe6b966-f98e-439b-a01a-17b9b3b8478b',
|
||||
'goal_uuid': 'fc087747-61be-4aad-8126-b701731ae836',
|
||||
'strategy_uuid': '2cf86250-d309-4b81-818e-1537f3dba6e5',
|
||||
'created_at': datetime.datetime.now().isoformat(),
|
||||
'updated_at': None,
|
||||
'deleted_at': None,
|
||||
}
|
||||
|
||||
GOAL_1 = {
|
||||
'uuid': "fc087747-61be-4aad-8126-b701731ae836",
|
||||
'name': "SERVER_CONSOLIDATION",
|
||||
'display_name': 'Server Consolidation',
|
||||
'created_at': datetime.datetime.now().isoformat(),
|
||||
'updated_at': None,
|
||||
'deleted_at': None,
|
||||
}
|
||||
|
||||
STRATEGY_1 = {
|
||||
'uuid': '2cf86250-d309-4b81-818e-1537f3dba6e5',
|
||||
'name': 'basic',
|
||||
'display_name': 'Basic consolidation',
|
||||
'goal_uuid': 'fc087747-61be-4aad-8126-b701731ae836',
|
||||
'created_at': datetime.datetime.now().isoformat(),
|
||||
'updated_at': None,
|
||||
'deleted_at': None,
|
||||
@@ -45,6 +64,9 @@ AUDIT_1 = {
|
||||
'state': 'PENDING',
|
||||
'audit_template_uuid': 'f8e47706-efcf-49a4-a5c4-af604eb492f2',
|
||||
'audit_template_name': 'at1',
|
||||
'host_aggregate': 5,
|
||||
'goal_name': 'SERVER_CONSOLIDATION',
|
||||
'strategy_name': 'basic',
|
||||
'created_at': datetime.datetime.now().isoformat(),
|
||||
'updated_at': None,
|
||||
'deleted_at': None,
|
||||
@@ -56,9 +78,12 @@ AUDIT_2 = {
|
||||
'uuid': 'a5199d0e-0702-4613-9234-5ae2af8dafea',
|
||||
'deadline': None,
|
||||
'audit_type': 'ONESHOT',
|
||||
'audit_template_uuid': '770ef053-ecb3-48b0-85b5-d55a2dbc6588',
|
||||
'audit_template_name': 'at2',
|
||||
'state': 'PENDING',
|
||||
'audit_template_uuid': 'f8e47706-efcf-49a4-a5c4-af604eb492f2',
|
||||
'audit_template_name': 'at1',
|
||||
'host_aggregate': None,
|
||||
'goal_name': 'fc087747-61be-4aad-8126-b701731ae836',
|
||||
'strategy_name': None,
|
||||
'created_at': datetime.datetime.now().isoformat(),
|
||||
'updated_at': None,
|
||||
'deleted_at': None,
|
||||
@@ -69,10 +94,13 @@ AUDIT_2 = {
|
||||
AUDIT_3 = {
|
||||
'uuid': '43199d0e-0712-1213-9674-5ae2af8dhgte',
|
||||
'deadline': None,
|
||||
'audit_type': 'CONTINUOUS',
|
||||
'audit_type': 'ONESHOT',
|
||||
'state': 'PENDING',
|
||||
'audit_template_uuid': 'f8e47706-efcf-49a4-a5c4-af604eb492f2',
|
||||
'audit_template_name': 'at1',
|
||||
'state': 'PENDING',
|
||||
'host_aggregate': 3,
|
||||
'goal_name': None,
|
||||
'strategy_name': None,
|
||||
'created_at': datetime.datetime.now().isoformat(),
|
||||
'updated_at': None,
|
||||
'deleted_at': None,
|
||||
@@ -91,6 +119,22 @@ class AuditShellTest(base.CommandTestCase):
|
||||
def setUp(self):
|
||||
super(self.__class__, self).setUp()
|
||||
|
||||
# goal mock
|
||||
p_goal_manager = mock.patch.object(resource, 'GoalManager')
|
||||
self.m_goal_mgr_cls = p_goal_manager.start()
|
||||
self.addCleanup(p_goal_manager.stop)
|
||||
|
||||
self.m_goal_mgr = mock.Mock()
|
||||
self.m_goal_mgr_cls.return_value = self.m_goal_mgr
|
||||
|
||||
# strategy mock
|
||||
p_strategy_manager = mock.patch.object(resource, 'StrategyManager')
|
||||
self.m_strategy_mgr_cls = p_strategy_manager.start()
|
||||
self.addCleanup(p_strategy_manager.stop)
|
||||
|
||||
self.m_strategy_mgr = mock.Mock()
|
||||
self.m_strategy_mgr_cls.return_value = self.m_strategy_mgr
|
||||
|
||||
p_audit_manager = mock.patch.object(resource, 'AuditManager')
|
||||
p_audit_template_manager = mock.patch.object(
|
||||
resource, 'AuditTemplateManager')
|
||||
@@ -105,6 +149,7 @@ class AuditShellTest(base.CommandTestCase):
|
||||
self.m_audit_mgr_cls.return_value = self.m_audit_mgr
|
||||
self.m_audit_template_mgr_cls.return_value = self.m_audit_template_mgr
|
||||
|
||||
# stdout mock
|
||||
self.stdout = six.StringIO()
|
||||
self.cmd = shell.WatcherShell(stdout=self.stdout)
|
||||
|
||||
@@ -147,7 +192,6 @@ class AuditShellTest(base.CommandTestCase):
|
||||
def test_do_audit_show_by_uuid(self):
|
||||
audit = resource.Audit(mock.Mock(), AUDIT_1)
|
||||
self.m_audit_mgr.get.return_value = audit
|
||||
self.m_audit_template_mgr.get.return_value = audit
|
||||
|
||||
exit_code, result = self.run_cmd(
|
||||
'audit show 5869da81-4876-4687-a1ed-12cd64cf53d9')
|
||||
@@ -231,7 +275,9 @@ class AuditShellTest(base.CommandTestCase):
|
||||
self.assertEqual('', result)
|
||||
|
||||
def test_do_audit_create_with_audit_template_uuid(self):
|
||||
audit = resource.Audit(mock.Mock(), AUDIT_1)
|
||||
audit = resource.Audit(mock.Mock(), AUDIT_3)
|
||||
audit_template = resource.AuditTemplate(mock.Mock(), AUDIT_TEMPLATE_1)
|
||||
self.m_audit_template_mgr.get.return_value = audit_template
|
||||
self.m_audit_mgr.create.return_value = audit
|
||||
|
||||
exit_code, result = self.run_cmd(
|
||||
@@ -246,7 +292,7 @@ class AuditShellTest(base.CommandTestCase):
|
||||
audit_type='ONESHOT')
|
||||
|
||||
def test_do_audit_create_with_audit_template_name(self):
|
||||
audit = resource.Audit(mock.Mock(), AUDIT_1)
|
||||
audit = resource.Audit(mock.Mock(), AUDIT_3)
|
||||
audit_template = resource.AuditTemplate(mock.Mock(), AUDIT_TEMPLATE_1)
|
||||
self.m_audit_template_mgr.get.return_value = audit_template
|
||||
self.m_audit_mgr.create.return_value = audit
|
||||
@@ -261,73 +307,102 @@ class AuditShellTest(base.CommandTestCase):
|
||||
audit_template_uuid='f8e47706-efcf-49a4-a5c4-af604eb492f2',
|
||||
audit_type='ONESHOT')
|
||||
|
||||
def test_do_audit_create_with_deadline(self):
|
||||
def test_do_audit_create_with_goal(self):
|
||||
audit = resource.Audit(mock.Mock(), AUDIT_1)
|
||||
audit_template = resource.AuditTemplate(mock.Mock(), AUDIT_TEMPLATE_1)
|
||||
self.m_audit_template_mgr.get.return_value = audit_template
|
||||
self.m_audit_mgr.create.return_value = audit
|
||||
|
||||
exit_code, result = self.run_cmd(
|
||||
'audit create -a at1 -d 2016-04-28T10:48:32.064802')
|
||||
'audit create -g fc087747-61be-4aad-8126-b701731ae836')
|
||||
|
||||
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(
|
||||
audit_template_uuid='f8e47706-efcf-49a4-a5c4-af604eb492f2',
|
||||
goal='fc087747-61be-4aad-8126-b701731ae836',
|
||||
audit_type='ONESHOT'
|
||||
)
|
||||
|
||||
def test_do_audit_create_with_goal_and_strategy(self):
|
||||
audit = resource.Audit(mock.Mock(), AUDIT_1)
|
||||
self.m_audit_mgr.create.return_value = audit
|
||||
|
||||
exit_code, result = self.run_cmd(
|
||||
'audit create -g fc087747-61be-4aad-8126-b701731ae836 -s '
|
||||
'2cf86250-d309-4b81-818e-1537f3dba6e5')
|
||||
|
||||
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',
|
||||
strategy='2cf86250-d309-4b81-818e-1537f3dba6e5',
|
||||
audit_type='ONESHOT'
|
||||
)
|
||||
|
||||
def test_do_audit_create_with_deadline(self):
|
||||
audit = resource.Audit(mock.Mock(), AUDIT_1)
|
||||
self.m_audit_mgr.create.return_value = audit
|
||||
|
||||
exit_code, result = self.run_cmd(
|
||||
'audit create -g fc087747-61be-4aad-8126-b701731ae836 -d '
|
||||
'2016-04-28T10:48:32.064802')
|
||||
|
||||
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',
|
||||
audit_type='ONESHOT',
|
||||
deadline='2016-04-28T10:48:32.064802')
|
||||
|
||||
def test_do_audit_create_with_type(self):
|
||||
audit = resource.Audit(mock.Mock(), AUDIT_1)
|
||||
audit_template = resource.AuditTemplate(mock.Mock(), AUDIT_TEMPLATE_1)
|
||||
self.m_audit_template_mgr.get.return_value = audit_template
|
||||
self.m_audit_mgr.create.return_value = audit
|
||||
|
||||
exit_code, result = self.run_cmd(
|
||||
'audit create -a at1 -t ONESHOT')
|
||||
'audit create -g fc087747-61be-4aad-8126-b701731ae836 -t ONESHOT')
|
||||
|
||||
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(
|
||||
audit_template_uuid='f8e47706-efcf-49a4-a5c4-af604eb492f2',
|
||||
goal='fc087747-61be-4aad-8126-b701731ae836',
|
||||
audit_type='ONESHOT')
|
||||
|
||||
def test_do_audit_create_with_parameter(self):
|
||||
audit = resource.Audit(mock.Mock(), AUDIT_1)
|
||||
audit_template = resource.AuditTemplate(mock.Mock(), AUDIT_TEMPLATE_1)
|
||||
self.m_audit_template_mgr.get.return_value = audit_template
|
||||
self.m_audit_mgr.create.return_value = audit
|
||||
|
||||
exit_code, result = self.run_cmd(
|
||||
'audit create -a at1 -p para1=10 -p para2=20')
|
||||
'audit create -g fc087747-61be-4aad-8126-b701731ae836 -p para1=10 '
|
||||
'-p para2=20')
|
||||
|
||||
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(
|
||||
audit_template_uuid='f8e47706-efcf-49a4-a5c4-af604eb492f2',
|
||||
goal='fc087747-61be-4aad-8126-b701731ae836',
|
||||
audit_type='ONESHOT',
|
||||
parameters={'para1': 10, 'para2': 20})
|
||||
|
||||
def test_do_audit_create_with_type_continuous(self):
|
||||
audit = resource.Audit(mock.Mock(), AUDIT_3)
|
||||
audit_template = resource.AuditTemplate(mock.Mock(), AUDIT_TEMPLATE_1)
|
||||
self.m_audit_template_mgr.get.return_value = audit_template
|
||||
audit = resource.Audit(mock.Mock(), AUDIT_1)
|
||||
self.m_audit_mgr.create.return_value = audit
|
||||
|
||||
exit_code, result = self.run_cmd(
|
||||
'audit create -a at1 -t CONTINUOUS -i 3600')
|
||||
'audit create -g fc087747-61be-4aad-8126-b701731ae836 '
|
||||
'-t CONTINUOUS -i 3600')
|
||||
|
||||
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(
|
||||
audit_template_uuid='f8e47706-efcf-49a4-a5c4-af604eb492f2',
|
||||
goal='fc087747-61be-4aad-8126-b701731ae836',
|
||||
audit_type='CONTINUOUS',
|
||||
interval='3600')
|
||||
|
||||
186
watcherclient/tests/v1/test_scoring_engine.py
Normal file
186
watcherclient/tests/v1/test_scoring_engine.py
Normal file
@@ -0,0 +1,186 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
#
|
||||
# Copyright 2016 Intel
|
||||
#
|
||||
# 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 testtools.matchers import HasLength
|
||||
|
||||
from watcherclient.tests import utils
|
||||
import watcherclient.v1.scoring_engine
|
||||
|
||||
SE1 = {
|
||||
'uuid': '5b558998-57ed-11e6-9ca8-08002722cb22',
|
||||
'name': 'se-01',
|
||||
'description': 'Some Scoring Engine'
|
||||
}
|
||||
|
||||
SE2 = {
|
||||
'uuid': '1f856554-57ee-11e6-ac72-08002722cb22',
|
||||
'name': 'se-02',
|
||||
'description': 'Some Other Scoring Engine'
|
||||
}
|
||||
|
||||
fake_responses = {
|
||||
'/v1/scoring_engines':
|
||||
{
|
||||
'GET': (
|
||||
{},
|
||||
{"scoring_engines": [SE1]},
|
||||
),
|
||||
},
|
||||
'/v1/scoring_engines/detail':
|
||||
{
|
||||
'GET': (
|
||||
{},
|
||||
{"scoring_engines": [SE1]},
|
||||
)
|
||||
},
|
||||
'/v1/scoring_engines/%s' % SE1['uuid']:
|
||||
{
|
||||
'GET': (
|
||||
{},
|
||||
SE1,
|
||||
),
|
||||
},
|
||||
'/v1/scoring_engines/%s' % SE1['name']:
|
||||
{
|
||||
'GET': (
|
||||
{},
|
||||
SE1,
|
||||
),
|
||||
},
|
||||
}
|
||||
|
||||
fake_responses_pagination = {
|
||||
'/v1/scoring_engines':
|
||||
{
|
||||
'GET': (
|
||||
{},
|
||||
{"scoring_engines": [SE1],
|
||||
"next": "http://127.0.0.1:6385/v1/scoring_engines/?limit=1"}
|
||||
),
|
||||
},
|
||||
'/v1/scoring_engines/?limit=1':
|
||||
{
|
||||
'GET': (
|
||||
{},
|
||||
{"scoring_engines": [SE2]}
|
||||
),
|
||||
},
|
||||
}
|
||||
|
||||
fake_responses_sorting = {
|
||||
'/v1/scoring_engines/?sort_key=id':
|
||||
{
|
||||
'GET': (
|
||||
{},
|
||||
{"scoring_engines": [SE1, SE2]}
|
||||
),
|
||||
},
|
||||
'/v1/scoring_engines/?sort_dir=desc':
|
||||
{
|
||||
'GET': (
|
||||
{},
|
||||
{"scoring_engines": [SE2, SE1]}
|
||||
),
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
class ScoringEngineManagerTest(testtools.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
super(ScoringEngineManagerTest, self).setUp()
|
||||
self.api = utils.FakeAPI(fake_responses)
|
||||
self.mgr = \
|
||||
watcherclient.v1.scoring_engine.ScoringEngineManager(self.api)
|
||||
|
||||
def test_scoring_engines_list(self):
|
||||
scoring_engines = self.mgr.list()
|
||||
expect = [
|
||||
('GET', '/v1/scoring_engines', {}, None),
|
||||
]
|
||||
self.assertEqual(expect, self.api.calls)
|
||||
self.assertEqual(1, len(scoring_engines))
|
||||
|
||||
def test_scoring_engines_list_detail(self):
|
||||
scoring_engines = self.mgr.list(detail=True)
|
||||
expect = [
|
||||
('GET', '/v1/scoring_engines/detail', {}, None),
|
||||
]
|
||||
self.assertEqual(expect, self.api.calls)
|
||||
self.assertEqual(1, len(scoring_engines))
|
||||
|
||||
def test_scoring_engines_list_limit(self):
|
||||
self.api = utils.FakeAPI(fake_responses_pagination)
|
||||
self.mgr = \
|
||||
watcherclient.v1.scoring_engine.ScoringEngineManager(self.api)
|
||||
scoring_engines = self.mgr.list(limit=1)
|
||||
expect = [
|
||||
('GET', '/v1/scoring_engines/?limit=1', {}, None),
|
||||
]
|
||||
self.assertEqual(expect, self.api.calls)
|
||||
self.assertThat(scoring_engines, HasLength(1))
|
||||
|
||||
def test_scoring_engines_list_pagination_no_limit(self):
|
||||
self.api = utils.FakeAPI(fake_responses_pagination)
|
||||
self.mgr = \
|
||||
watcherclient.v1.scoring_engine.ScoringEngineManager(self.api)
|
||||
scoring_engines = self.mgr.list(limit=0)
|
||||
expect = [
|
||||
('GET', '/v1/scoring_engines', {}, None),
|
||||
('GET', '/v1/scoring_engines/?limit=1', {}, None)
|
||||
]
|
||||
self.assertEqual(expect, self.api.calls)
|
||||
self.assertThat(scoring_engines, HasLength(2))
|
||||
|
||||
def test_scoring_engines_list_sort_key(self):
|
||||
self.api = utils.FakeAPI(fake_responses_sorting)
|
||||
self.mgr = \
|
||||
watcherclient.v1.scoring_engine.ScoringEngineManager(self.api)
|
||||
scoring_engines = self.mgr.list(sort_key='id')
|
||||
expect = [
|
||||
('GET', '/v1/scoring_engines/?sort_key=id', {}, None)
|
||||
]
|
||||
self.assertEqual(expect, self.api.calls)
|
||||
self.assertEqual(2, len(scoring_engines))
|
||||
|
||||
def test_scoring_engines_list_sort_dir(self):
|
||||
self.api = utils.FakeAPI(fake_responses_sorting)
|
||||
self.mgr = \
|
||||
watcherclient.v1.scoring_engine.ScoringEngineManager(self.api)
|
||||
scoring_engines = self.mgr.list(sort_dir='desc')
|
||||
expect = [
|
||||
('GET', '/v1/scoring_engines/?sort_dir=desc', {}, None)
|
||||
]
|
||||
self.assertEqual(expect, self.api.calls)
|
||||
self.assertEqual(2, len(scoring_engines))
|
||||
|
||||
def test_scoring_engines_show(self):
|
||||
scoring_engine = self.mgr.get(SE1['uuid'])
|
||||
expect = [
|
||||
('GET', '/v1/scoring_engines/%s' % SE1['uuid'], {}, None),
|
||||
]
|
||||
self.assertEqual(expect, self.api.calls)
|
||||
self.assertEqual(SE1['uuid'], scoring_engine.uuid)
|
||||
|
||||
def test_scoring_engines_show_by_name(self):
|
||||
scoring_engine = self.mgr.get(SE1['name'])
|
||||
expect = [
|
||||
('GET', '/v1/scoring_engines/%s' % SE1['name'], {}, None),
|
||||
]
|
||||
self.assertEqual(expect, self.api.calls)
|
||||
self.assertEqual(SE1['name'], scoring_engine.name)
|
||||
130
watcherclient/tests/v1/test_scoring_engine_shell.py
Normal file
130
watcherclient/tests/v1/test_scoring_engine_shell.py
Normal file
@@ -0,0 +1,130 @@
|
||||
# -*- encoding: utf-8 -*-
|
||||
# Copyright (c) 2016 Intel
|
||||
#
|
||||
# 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 datetime
|
||||
|
||||
import mock
|
||||
import six
|
||||
|
||||
from watcherclient import shell
|
||||
from watcherclient.tests.v1 import base
|
||||
from watcherclient import v1 as resource
|
||||
from watcherclient.v1 import resource_fields
|
||||
|
||||
SCORING_ENGINE_1 = {
|
||||
'uuid': '5b558998-57ed-11e6-9ca8-08002722cb22',
|
||||
'name': 'se-01',
|
||||
'description': 'Scoring Engine 0.1',
|
||||
'metainfo': '{ "columns": ["cpu", "mem", "pci"] }',
|
||||
'created_at': datetime.datetime.now().isoformat(),
|
||||
'updated_at': None,
|
||||
'deleted_at': None,
|
||||
}
|
||||
|
||||
SCORING_ENGINE_2 = {
|
||||
'uuid': '1f856554-57ee-11e6-ac72-08002722cb22',
|
||||
'name': 'se-02',
|
||||
'description': 'Some other Scoring Engine',
|
||||
'metainfo': 'mode=simplified',
|
||||
'created_at': datetime.datetime.now().isoformat(),
|
||||
'updated_at': None,
|
||||
'deleted_at': None,
|
||||
}
|
||||
|
||||
|
||||
class ScoringEngineShellTest(base.CommandTestCase):
|
||||
|
||||
SHORT_LIST_FIELDS = resource_fields.SCORING_ENGINE_SHORT_LIST_FIELDS
|
||||
SHORT_LIST_FIELD_LABELS = (
|
||||
resource_fields.SCORING_ENGINE_SHORT_LIST_FIELD_LABELS)
|
||||
FIELDS = resource_fields.SCORING_ENGINE_FIELDS
|
||||
FIELD_LABELS = resource_fields.SCORING_ENGINE_FIELD_LABELS
|
||||
|
||||
def setUp(self):
|
||||
super(self.__class__, self).setUp()
|
||||
|
||||
p_se_manager = mock.patch.object(
|
||||
resource, 'ScoringEngineManager')
|
||||
self.m_se_mgr_cls = p_se_manager.start()
|
||||
self.addCleanup(p_se_manager.stop)
|
||||
|
||||
self.m_se_mgr = mock.Mock()
|
||||
self.m_se_mgr_cls.return_value = self.m_se_mgr
|
||||
|
||||
self.stdout = six.StringIO()
|
||||
self.cmd = shell.WatcherShell(stdout=self.stdout)
|
||||
|
||||
def test_do_scoringengine_list(self):
|
||||
se1 = resource.ScoringEngine(mock.Mock(), SCORING_ENGINE_1)
|
||||
se2 = resource.ScoringEngine(mock.Mock(), SCORING_ENGINE_2)
|
||||
self.m_se_mgr.list.return_value = [
|
||||
se1, se2]
|
||||
|
||||
exit_code, results = self.run_cmd('scoringengine list')
|
||||
|
||||
self.assertEqual(0, exit_code)
|
||||
self.assertEqual(
|
||||
[self.resource_as_dict(se1, self.SHORT_LIST_FIELDS,
|
||||
self.SHORT_LIST_FIELD_LABELS),
|
||||
self.resource_as_dict(se2, self.SHORT_LIST_FIELDS,
|
||||
self.SHORT_LIST_FIELD_LABELS)],
|
||||
results)
|
||||
|
||||
self.m_se_mgr.list.assert_called_once_with(detail=False)
|
||||
|
||||
def test_do_scoringengine_list_detail(self):
|
||||
se1 = resource.Goal(mock.Mock(), SCORING_ENGINE_1)
|
||||
se2 = resource.Goal(mock.Mock(), SCORING_ENGINE_2)
|
||||
self.m_se_mgr.list.return_value = [
|
||||
se1, se2]
|
||||
|
||||
exit_code, results = self.run_cmd('scoringengine list --detail')
|
||||
|
||||
self.assertEqual(0, exit_code)
|
||||
self.assertEqual(
|
||||
[self.resource_as_dict(se1, self.FIELDS, self.FIELD_LABELS),
|
||||
self.resource_as_dict(se2, self.FIELDS, self.FIELD_LABELS)],
|
||||
results)
|
||||
|
||||
self.m_se_mgr.list.assert_called_once_with(detail=True)
|
||||
|
||||
def test_do_scoringengine_show_by_name(self):
|
||||
scoringengine = resource.Goal(mock.Mock(), SCORING_ENGINE_1)
|
||||
self.m_se_mgr.get.return_value = scoringengine
|
||||
|
||||
exit_code, result = self.run_cmd('scoringengine show se-01')
|
||||
|
||||
self.assertEqual(0, exit_code)
|
||||
self.assertEqual(
|
||||
self.resource_as_dict(scoringengine, self.FIELDS,
|
||||
self.FIELD_LABELS),
|
||||
result)
|
||||
self.m_se_mgr.get.assert_called_once_with('se-01')
|
||||
|
||||
def test_do_scoringengine_show_by_uuid(self):
|
||||
scoringengine = resource.Goal(mock.Mock(), SCORING_ENGINE_1)
|
||||
self.m_se_mgr.get.return_value = scoringengine
|
||||
|
||||
exit_code, result = self.run_cmd(
|
||||
'scoringengine show 5b558998-57ed-11e6-9ca8-08002722cb22')
|
||||
|
||||
self.assertEqual(0, exit_code)
|
||||
self.assertEqual(
|
||||
self.resource_as_dict(scoringengine, self.FIELDS,
|
||||
self.FIELD_LABELS),
|
||||
result)
|
||||
self.m_se_mgr.get.assert_called_once_with(
|
||||
'5b558998-57ed-11e6-9ca8-08002722cb22')
|
||||
@@ -19,6 +19,7 @@ from watcherclient.v1 import action_plan
|
||||
from watcherclient.v1 import audit
|
||||
from watcherclient.v1 import audit_template
|
||||
from watcherclient.v1 import goal
|
||||
from watcherclient.v1 import scoring_engine
|
||||
from watcherclient.v1 import strategy
|
||||
|
||||
Action = action.Action
|
||||
@@ -31,10 +32,13 @@ AuditTemplate = audit_template.AuditTemplate
|
||||
AuditTemplateManager = audit_template.AuditTemplateManager
|
||||
Goal = goal.Goal
|
||||
GoalManager = goal.GoalManager
|
||||
ScoringEngine = scoring_engine.ScoringEngine
|
||||
ScoringEngineManager = scoring_engine.ScoringEngineManager
|
||||
Strategy = strategy.Strategy
|
||||
StrategyManager = strategy.StrategyManager
|
||||
|
||||
__all__ = (
|
||||
"Action", "ActionManager", "ActionPlan", "ActionPlanManager",
|
||||
"Audit", "AuditManager", "AuditTemplate", "AuditTemplateManager",
|
||||
"Goal", "GoalManager", "Strategy", "StrategyManager")
|
||||
"Goal", "GoalManager", "ScoringEngine", "ScoringEngineManager",
|
||||
"Strategy", "StrategyManager")
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
# limitations under the License.
|
||||
|
||||
from cliff.formatters import yaml_format
|
||||
from openstackclient.common import utils
|
||||
from osc_lib import utils
|
||||
from oslo_utils import uuidutils
|
||||
import six
|
||||
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
from openstackclient.common import utils
|
||||
from osc_lib import utils
|
||||
|
||||
from watcherclient._i18n import _
|
||||
from watcherclient.common import command
|
||||
|
||||
@@ -19,8 +19,9 @@ from watcherclient.common import utils
|
||||
from watcherclient import exceptions as exc
|
||||
|
||||
|
||||
CREATION_ATTRIBUTES = ['audit_template_uuid', 'deadline',
|
||||
'audit_type', 'parameters', 'interval']
|
||||
CREATION_ATTRIBUTES = ['audit_template_uuid', 'host_aggregate',
|
||||
'deadline', 'audit_type', 'interval',
|
||||
'parameters', 'goal', 'strategy']
|
||||
|
||||
|
||||
class Audit(base.Resource):
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
from openstackclient.common import utils
|
||||
from osc_lib import utils
|
||||
from oslo_utils import uuidutils
|
||||
|
||||
from watcherclient._i18n import _
|
||||
@@ -55,17 +55,22 @@ class ListAudit(command.Lister):
|
||||
|
||||
def get_parser(self, prog_name):
|
||||
parser = super(ListAudit, self).get_parser(prog_name)
|
||||
parser.add_argument(
|
||||
'--audit-template',
|
||||
metavar='<audit_template>',
|
||||
dest='audit_template',
|
||||
help=_('Name or UUID of an audit template used for filtering.'))
|
||||
parser.add_argument(
|
||||
'--detail',
|
||||
dest='detail',
|
||||
action='store_true',
|
||||
default=False,
|
||||
help=_("Show detailed information about audits."))
|
||||
parser.add_argument(
|
||||
'--goal',
|
||||
dest='goal',
|
||||
metavar='<goal>',
|
||||
help=_('UUID or name of the goal used for filtering.'))
|
||||
parser.add_argument(
|
||||
'--strategy',
|
||||
dest='strategy',
|
||||
metavar='<strategy>',
|
||||
help=_('UUID or name of the strategy used for filtering.'))
|
||||
parser.add_argument(
|
||||
'--limit',
|
||||
metavar='<limit>',
|
||||
@@ -89,8 +94,15 @@ class ListAudit(command.Lister):
|
||||
client = getattr(self.app.client_manager, "infra-optim")
|
||||
|
||||
params = {}
|
||||
if parsed_args.audit_template is not None:
|
||||
params['audit_template'] = parsed_args.audit_template
|
||||
|
||||
# Optional
|
||||
if parsed_args.goal:
|
||||
params['goal'] = parsed_args.goal
|
||||
|
||||
# Optional
|
||||
if parsed_args.strategy:
|
||||
params['strategy'] = parsed_args.strategy
|
||||
|
||||
if parsed_args.detail:
|
||||
fields = res_fields.AUDIT_FIELDS
|
||||
field_labels = res_fields.AUDIT_FIELD_LABELS
|
||||
@@ -115,12 +127,6 @@ class CreateAudit(command.ShowOne):
|
||||
|
||||
def get_parser(self, prog_name):
|
||||
parser = super(CreateAudit, self).get_parser(prog_name)
|
||||
parser.add_argument(
|
||||
'-a', '--audit-template',
|
||||
required=True,
|
||||
dest='audit_template_uuid',
|
||||
metavar='<audit_template>',
|
||||
help=_('Audit template used for this audit (name or uuid).'))
|
||||
parser.add_argument(
|
||||
'-d', '--deadline',
|
||||
dest='deadline',
|
||||
@@ -131,7 +137,9 @@ class CreateAudit(command.ShowOne):
|
||||
dest='audit_type',
|
||||
metavar='<audit_type>',
|
||||
default='ONESHOT',
|
||||
help=_("Audit type."))
|
||||
choices=['ONESHOT', 'CONTINUOUS'],
|
||||
help=_("Audit type. It must be ONESHOT or CONTINUOUS. "
|
||||
"Default is ONESHOT."))
|
||||
parser.add_argument(
|
||||
'-p', '--parameter',
|
||||
dest='parameters',
|
||||
@@ -144,22 +152,53 @@ class CreateAudit(command.ShowOne):
|
||||
dest='interval',
|
||||
metavar='<interval>',
|
||||
help=_("Audit interval."))
|
||||
|
||||
parser.add_argument(
|
||||
'-g', '--goal',
|
||||
dest='goal',
|
||||
metavar='<goal>',
|
||||
help=_('Goal UUID or name associated to this audit.'))
|
||||
parser.add_argument(
|
||||
'-s', '--strategy',
|
||||
dest='strategy',
|
||||
metavar='<strategy>',
|
||||
help=_('Strategy UUID or name associated to this audit.'))
|
||||
parser.add_argument(
|
||||
'-r', '--host-aggregate',
|
||||
dest='host_aggregate',
|
||||
metavar='<host-aggregate>',
|
||||
help=_('Name or UUID of the host aggregate targeted '
|
||||
'by this audit.'))
|
||||
parser.add_argument(
|
||||
'-a', '--audit-template',
|
||||
dest='audit_template_uuid',
|
||||
metavar='<audit_template>',
|
||||
help=_('Audit template used for this audit (name or uuid).'))
|
||||
return parser
|
||||
|
||||
def take_action(self, parsed_args):
|
||||
client = getattr(self.app.client_manager, "infra-optim")
|
||||
|
||||
field_list = ['audit_template_uuid', 'audit_type',
|
||||
'deadline', 'parameters', 'interval']
|
||||
field_list = ['audit_template_uuid', 'host_aggregate',
|
||||
'audit_type', 'deadline', 'parameters', 'interval',
|
||||
'goal', 'strategy']
|
||||
|
||||
fields = dict((k, v) for (k, v) in vars(parsed_args).items()
|
||||
if k in field_list and v is not None)
|
||||
fields = common_utils.args_array_to_dict(fields, 'parameters')
|
||||
|
||||
if fields.get('goal'):
|
||||
if not uuidutils.is_uuid_like(fields['goal']):
|
||||
fields['goal'] = client.goal.get(fields['goal']).uuid
|
||||
|
||||
if fields.get('audit_template_uuid'):
|
||||
if not uuidutils.is_uuid_like(fields['audit_template_uuid']):
|
||||
fields['audit_template_uuid'] = client.audit_template.get(
|
||||
fields['audit_template_uuid']).uuid
|
||||
# optional
|
||||
if fields.get('strategy'):
|
||||
if not uuidutils.is_uuid_like(fields['strategy']):
|
||||
fields['strategy'] = client.strategy.get(
|
||||
fields['strategy']).uuid
|
||||
|
||||
audit = client.audit.create(**fields)
|
||||
|
||||
@@ -182,7 +221,7 @@ class UpdateAudit(command.ShowOne):
|
||||
'op',
|
||||
metavar='<op>',
|
||||
choices=['add', 'replace', 'remove'],
|
||||
help=_("Operation: 'add'), 'replace', or 'remove'."))
|
||||
help=_("Operation: 'add', 'replace', or 'remove'."))
|
||||
parser.add_argument(
|
||||
'attributes',
|
||||
metavar='<path=value>',
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
from openstackclient.common import utils
|
||||
from osc_lib import utils
|
||||
from oslo_utils import uuidutils
|
||||
|
||||
from watcherclient._i18n import _
|
||||
|
||||
@@ -37,6 +37,7 @@ class Client(object):
|
||||
self.action = v1.ActionManager(self.http_client)
|
||||
self.action_plan = v1.ActionPlanManager(self.http_client)
|
||||
self.goal = v1.GoalManager(self.http_client)
|
||||
self.scoring_engine = v1.ScoringEngineManager(self.http_client)
|
||||
self.strategy = v1.StrategyManager(self.http_client)
|
||||
# self.metric_collector = v1.MetricCollectorManager(self.http_client)
|
||||
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from openstackclient.common import utils
|
||||
from osc_lib import utils
|
||||
import six
|
||||
|
||||
from watcherclient._i18n import _
|
||||
|
||||
@@ -34,27 +34,29 @@ AUDIT_TEMPLATE_SHORT_LIST_FIELD_LABELS = ['UUID', 'Name', 'Goal', 'Strategy']
|
||||
|
||||
# Audit
|
||||
AUDIT_FIELDS = ['uuid', 'created_at', 'updated_at', 'deleted_at',
|
||||
'deadline', 'state', 'audit_type', 'audit_template_uuid',
|
||||
'audit_template_name', 'parameters', 'interval']
|
||||
'deadline', 'state', 'audit_type',
|
||||
'parameters', 'interval',
|
||||
'host_aggregate', 'goal_name', 'strategy_name']
|
||||
|
||||
AUDIT_FIELD_LABELS = ['UUID', 'Created At', 'Updated At', 'Deleted At',
|
||||
'Deadline', 'State', 'Audit Type', 'Audit Template uuid',
|
||||
'Audit Template Name', 'Parameters', 'Interval']
|
||||
'Deadline', 'State', 'Audit Type',
|
||||
'Parameters', 'Interval', 'Host Aggregate ID or Name',
|
||||
'Goal', 'Strategy']
|
||||
|
||||
AUDIT_SHORT_LIST_FIELDS = [
|
||||
'uuid', 'audit_type', 'audit_template_name', 'state']
|
||||
AUDIT_SHORT_LIST_FIELDS = ['uuid', 'audit_type',
|
||||
'state', 'goal_name', 'strategy_name']
|
||||
|
||||
AUDIT_SHORT_LIST_FIELD_LABELS = [
|
||||
'UUID', 'Audit Type', 'Audit Template', 'State']
|
||||
AUDIT_SHORT_LIST_FIELD_LABELS = ['UUID', 'Audit Type', 'State', 'Goal',
|
||||
'Strategy']
|
||||
|
||||
# Action Plan
|
||||
ACTION_PLAN_FIELDS = ['uuid', 'created_at', 'updated_at', 'deleted_at',
|
||||
'audit_uuid', 'state', 'efficacy_indicators',
|
||||
'global_efficacy']
|
||||
'audit_uuid', 'strategy_name', 'state',
|
||||
'efficacy_indicators', 'global_efficacy']
|
||||
|
||||
ACTION_PLAN_FIELD_LABELS = ['UUID', 'Created At', 'Updated At', 'Deleted At',
|
||||
'Audit', 'State', 'Efficacy indicators',
|
||||
'Global efficacy']
|
||||
'Audit', 'Strategy', 'State',
|
||||
'Efficacy indicators', 'Global efficacy']
|
||||
|
||||
ACTION_PLAN_SHORT_LIST_FIELDS = ['uuid', 'audit_uuid', 'state',
|
||||
'updated_at', 'global_efficacy']
|
||||
@@ -110,3 +112,9 @@ METRIC_COLLECTOR_SHORT_LIST_FIELDS = ['uuid', 'endpoint', 'category']
|
||||
|
||||
METRIC_COLLECTOR_SHORT_LIST_FIELD_LABELS = ['UUID', 'Endpoint URL',
|
||||
'Metric Category']
|
||||
# Scoring Engines
|
||||
SCORING_ENGINE_FIELDS = ['uuid', 'name', 'description', 'metainfo']
|
||||
SCORING_ENGINE_FIELD_LABELS = ['UUID', 'Name', 'Description', 'Metainfo']
|
||||
|
||||
SCORING_ENGINE_SHORT_LIST_FIELDS = ['uuid', 'name', 'description']
|
||||
SCORING_ENGINE_SHORT_LIST_FIELD_LABELS = ['UUID', 'Name', 'Description']
|
||||
|
||||
78
watcherclient/v1/scoring_engine.py
Normal file
78
watcherclient/v1/scoring_engine.py
Normal file
@@ -0,0 +1,78 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
#
|
||||
# Copyright 2016 Intel
|
||||
#
|
||||
# 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 ScoringEngine(base.Resource):
|
||||
def __repr__(self):
|
||||
return "<ScoringEngine %s>" % self._info
|
||||
|
||||
|
||||
class ScoringEngineManager(base.Manager):
|
||||
resource_class = ScoringEngine
|
||||
|
||||
@staticmethod
|
||||
def _path(scoring_engine=None):
|
||||
return ('/v1/scoring_engines/%s' % scoring_engine
|
||||
if scoring_engine else '/v1/scoring_engines')
|
||||
|
||||
def list(self, limit=None, sort_key=None, sort_dir=None, detail=False):
|
||||
"""Retrieve a list of scoring engines.
|
||||
|
||||
:param limit: The maximum number of results to return per
|
||||
request, if:
|
||||
|
||||
1) limit > 0, the maximum number of scoring engines to return.
|
||||
2) limit == 0, return the entire list of scoring engines.
|
||||
3) limit param is NOT specified (None), the number of items
|
||||
returned respect the maximum imposed by the Watcher API
|
||||
(see Watcher's api.max_limit option).
|
||||
|
||||
:param sort_key: Optional, field used for sorting.
|
||||
|
||||
:param sort_dir: Optional, direction of sorting, either 'asc' (the
|
||||
default) or 'desc'.
|
||||
|
||||
:param detail: Optional, boolean whether to return detailed information
|
||||
about scoring engines.
|
||||
|
||||
:returns: A list of scoring engines.
|
||||
|
||||
"""
|
||||
if limit is not None:
|
||||
limit = int(limit)
|
||||
|
||||
filters = utils.common_filters(limit, sort_key, sort_dir)
|
||||
|
||||
path = ''
|
||||
if detail:
|
||||
path += 'detail'
|
||||
if filters:
|
||||
path += '?' + '&'.join(filters)
|
||||
|
||||
if limit is None:
|
||||
return self._list(self._path(path), "scoring_engines")
|
||||
else:
|
||||
return self._list_pagination(self._path(path), "scoring_engines",
|
||||
limit=limit)
|
||||
|
||||
def get(self, scoring_engine_name):
|
||||
try:
|
||||
return self._list(self._path(scoring_engine_name))[0]
|
||||
except IndexError:
|
||||
return None
|
||||
105
watcherclient/v1/scoring_engine_shell.py
Normal file
105
watcherclient/v1/scoring_engine_shell.py
Normal file
@@ -0,0 +1,105 @@
|
||||
# -*- encoding: utf-8 -*-
|
||||
# Copyright (c) 2016 Intel
|
||||
#
|
||||
# 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 osc_lib import utils
|
||||
|
||||
from watcherclient._i18n import _
|
||||
from watcherclient.common import command
|
||||
from watcherclient.common import utils as common_utils
|
||||
from watcherclient import exceptions
|
||||
from watcherclient.v1 import resource_fields as res_fields
|
||||
|
||||
|
||||
class ShowScoringEngine(command.ShowOne):
|
||||
"""Show detailed information about a given scoring engine."""
|
||||
|
||||
def get_parser(self, prog_name):
|
||||
parser = super(ShowScoringEngine, self).get_parser(prog_name)
|
||||
parser.add_argument(
|
||||
'scoring_engine',
|
||||
metavar='<scoring_engine>',
|
||||
help=_('Name of the scoring engine'),
|
||||
)
|
||||
return parser
|
||||
|
||||
def take_action(self, parsed_args):
|
||||
client = getattr(self.app.client_manager, "infra-optim")
|
||||
|
||||
try:
|
||||
scoring_engine = client.scoring_engine.get(
|
||||
parsed_args.scoring_engine)
|
||||
except exceptions.HTTPNotFound as exc:
|
||||
raise exceptions.CommandError(str(exc))
|
||||
|
||||
columns = res_fields.SCORING_ENGINE_FIELDS
|
||||
column_headers = res_fields.SCORING_ENGINE_FIELD_LABELS
|
||||
|
||||
return column_headers, utils.get_item_properties(scoring_engine,
|
||||
columns)
|
||||
|
||||
|
||||
class ListScoringEngine(command.Lister):
|
||||
"""List information on retrieved scoring engines."""
|
||||
|
||||
def get_parser(self, prog_name):
|
||||
parser = super(ListScoringEngine, self).get_parser(prog_name)
|
||||
parser.add_argument(
|
||||
'--detail',
|
||||
dest='detail',
|
||||
action='store_true',
|
||||
default=False,
|
||||
help=_("Show detailed information about scoring engines."))
|
||||
parser.add_argument(
|
||||
'--limit',
|
||||
metavar='<limit>',
|
||||
type=int,
|
||||
help=_('Maximum number of actions to return per request, '
|
||||
'0 for no limit. Default is the maximum number used '
|
||||
'by the Watcher API Service.'))
|
||||
parser.add_argument(
|
||||
'--sort-key',
|
||||
metavar='<field>',
|
||||
help=_('Action field that will be used for sorting.'))
|
||||
parser.add_argument(
|
||||
'--sort-dir',
|
||||
metavar='<direction>',
|
||||
choices=['asc', 'desc'],
|
||||
help=_('Sort direction: "asc" (the default) or "desc".'))
|
||||
|
||||
return parser
|
||||
|
||||
def take_action(self, parsed_args):
|
||||
client = getattr(self.app.client_manager, "infra-optim")
|
||||
|
||||
params = {}
|
||||
if parsed_args.detail:
|
||||
fields = res_fields.SCORING_ENGINE_FIELDS
|
||||
field_labels = res_fields.SCORING_ENGINE_FIELD_LABELS
|
||||
else:
|
||||
fields = res_fields.SCORING_ENGINE_SHORT_LIST_FIELDS
|
||||
field_labels = res_fields.SCORING_ENGINE_SHORT_LIST_FIELD_LABELS
|
||||
|
||||
params.update(
|
||||
common_utils.common_params_for_list(
|
||||
parsed_args, fields, field_labels))
|
||||
|
||||
try:
|
||||
data = client.scoring_engine.list(**params)
|
||||
except exceptions.HTTPNotFound as ex:
|
||||
raise exceptions.CommandError(str(ex))
|
||||
|
||||
return (field_labels,
|
||||
(utils.get_item_properties(item, fields) for item in data))
|
||||
@@ -15,7 +15,7 @@
|
||||
# limitations under the License.
|
||||
|
||||
import json
|
||||
from openstackclient.common import utils
|
||||
from osc_lib import utils
|
||||
|
||||
from watcherclient._i18n import _
|
||||
from watcherclient.common import command
|
||||
|
||||
Reference in New Issue
Block a user