Replaced UUID of goal and strategy with name
In this changeset, I updated the CLI to now display the names of the goal and strategy associated to an audit template (instead of their UUIDs). Change-Id: I57e83f23ed2240048d8ef07a629aec6ef13970e8 Closes-Bug: #1573582
This commit is contained in:
parent
544db1951f
commit
bc572e70dc
@ -18,7 +18,6 @@
|
||||
import copy
|
||||
|
||||
from six.moves.urllib import parse as urlparse
|
||||
import testtools
|
||||
from testtools import matchers
|
||||
|
||||
from watcherclient.tests import utils
|
||||
@ -32,7 +31,9 @@ AUDIT_TMPL1 = {
|
||||
'host_aggregate': 5,
|
||||
'extra': {'automatic': False},
|
||||
'goal_uuid': '7568667b-51fe-4087-9eb1-29b26891036f',
|
||||
'goal_name': 'SERVER_CONSOLIDATION',
|
||||
'strategy_uuid': 'bbe6b966-f98e-439b-a01a-17b9b3b8478b',
|
||||
'strategy_name': 'server_consolidation',
|
||||
}
|
||||
|
||||
AUDIT_TMPL2 = {
|
||||
@ -43,7 +44,9 @@ AUDIT_TMPL2 = {
|
||||
'host_aggregate': 8,
|
||||
'extra': {'automatic': True},
|
||||
'goal_uuid': 'e75ee410-b32b-465f-88b5-4397705f9473',
|
||||
'goal_name': 'DUMMY',
|
||||
'strategy_uuid': 'ae99a4a4-acbc-4c67-abe1-e37128fac45d',
|
||||
'strategy_name': 'dummy',
|
||||
}
|
||||
|
||||
AUDIT_TMPL3 = {
|
||||
@ -54,11 +57,16 @@ AUDIT_TMPL3 = {
|
||||
'host_aggregate': 7,
|
||||
'extra': {'automatic': True},
|
||||
'goal_uuid': '7568667b-51fe-4087-9eb1-29b26891036f',
|
||||
'goal_name': 'SERVER_CONSOLIDATION',
|
||||
}
|
||||
|
||||
CREATE_AUDIT_TEMPLATE = copy.deepcopy(AUDIT_TMPL1)
|
||||
del CREATE_AUDIT_TEMPLATE['id']
|
||||
del CREATE_AUDIT_TEMPLATE['uuid']
|
||||
del CREATE_AUDIT_TEMPLATE['goal_name']
|
||||
del CREATE_AUDIT_TEMPLATE['strategy_name']
|
||||
CREATE_AUDIT_TEMPLATE['goal'] = CREATE_AUDIT_TEMPLATE.pop('goal_uuid')
|
||||
CREATE_AUDIT_TEMPLATE['strategy'] = CREATE_AUDIT_TEMPLATE.pop('strategy_uuid')
|
||||
|
||||
UPDATED_AUDIT_TMPL1 = copy.deepcopy(AUDIT_TMPL1)
|
||||
NEW_NAME = 'Audit Template_1 new name'
|
||||
@ -127,14 +135,14 @@ fake_responses = {
|
||||
{"audit_templates": [AUDIT_TMPL1]},
|
||||
),
|
||||
},
|
||||
'/v1/audit_templates/detail?goal_uuid=%s' % AUDIT_TMPL1['goal_uuid']:
|
||||
'/v1/audit_templates/detail?goal=%s' % AUDIT_TMPL1['goal_uuid']:
|
||||
{
|
||||
'GET': (
|
||||
{},
|
||||
{"audit_templates": [AUDIT_TMPL1, AUDIT_TMPL3]},
|
||||
),
|
||||
},
|
||||
'/v1/audit_templates/?goal_uuid=%s' % AUDIT_TMPL1['goal_uuid']:
|
||||
'/v1/audit_templates/?goal=%s' % AUDIT_TMPL1['goal_uuid']:
|
||||
{
|
||||
'GET': (
|
||||
{},
|
||||
@ -179,7 +187,17 @@ fake_responses_sorting = {
|
||||
}
|
||||
|
||||
fake_responses_filter_by_goal_uuid = {
|
||||
'/v1/audit_templates/?goal_uuid=e75ee410-b32b-465f-88b5-4397705f9473':
|
||||
'/v1/audit_templates/?goal=e75ee410-b32b-465f-88b5-4397705f9473':
|
||||
{
|
||||
'GET': (
|
||||
{},
|
||||
{"audit_templates": [AUDIT_TMPL2]}
|
||||
),
|
||||
},
|
||||
}
|
||||
|
||||
fake_responses_filter_by_goal_name = {
|
||||
'/v1/audit_templates/?goal=DUMMY':
|
||||
{
|
||||
'GET': (
|
||||
{},
|
||||
@ -189,7 +207,27 @@ fake_responses_filter_by_goal_uuid = {
|
||||
}
|
||||
|
||||
fake_responses_filter_by_strategy_uuid = {
|
||||
'/v1/audit_templates/?strategy_uuid=ae99a4a4-acbc-4c67-abe1-e37128fac45d':
|
||||
'/v1/audit_templates/?strategy=ae99a4a4-acbc-4c67-abe1-e37128fac45d':
|
||||
{
|
||||
'GET': (
|
||||
{},
|
||||
{"audit_templates": [AUDIT_TMPL2]}
|
||||
),
|
||||
},
|
||||
}
|
||||
|
||||
fake_responses_filter_by_strategy_name = {
|
||||
'/v1/audit_templates/?strategy=dummy':
|
||||
{
|
||||
'GET': (
|
||||
{},
|
||||
{"audit_templates": [AUDIT_TMPL2]}
|
||||
),
|
||||
},
|
||||
}
|
||||
|
||||
fake_responses_filter_by_strategy_and_goal_name = {
|
||||
'/v1/audit_templates/?goal=DUMMY&strategy=dummy':
|
||||
{
|
||||
'GET': (
|
||||
{},
|
||||
@ -199,7 +237,7 @@ fake_responses_filter_by_strategy_uuid = {
|
||||
}
|
||||
|
||||
|
||||
class AuditTemplateManagerTest(testtools.TestCase):
|
||||
class AuditTemplateManagerTest(utils.BaseTestCase):
|
||||
|
||||
def setUp(self):
|
||||
super(AuditTemplateManagerTest, self).setUp()
|
||||
@ -229,10 +267,23 @@ class AuditTemplateManagerTest(testtools.TestCase):
|
||||
self.mgr = watcherclient.v1.audit_template.AuditTemplateManager(
|
||||
self.api)
|
||||
audit_templates = self.mgr.list(
|
||||
goal_uuid="e75ee410-b32b-465f-88b5-4397705f9473")
|
||||
goal="e75ee410-b32b-465f-88b5-4397705f9473")
|
||||
expect = [
|
||||
('GET',
|
||||
'/v1/audit_templates/?goal_uuid=%s' % AUDIT_TMPL2['goal_uuid'],
|
||||
'/v1/audit_templates/?goal=%s' % AUDIT_TMPL2['goal_uuid'],
|
||||
{}, None),
|
||||
]
|
||||
self.assertEqual(expect, self.api.calls)
|
||||
self.assertEqual(1, len(audit_templates))
|
||||
|
||||
def test_audit_templates_list_filter_by_goal_name(self):
|
||||
self.api = utils.FakeAPI(fake_responses_filter_by_goal_name)
|
||||
self.mgr = watcherclient.v1.audit_template.AuditTemplateManager(
|
||||
self.api)
|
||||
audit_templates = self.mgr.list(goal="DUMMY")
|
||||
expect = [
|
||||
('GET',
|
||||
'/v1/audit_templates/?goal=%s' % AUDIT_TMPL2['goal_name'],
|
||||
{}, None),
|
||||
]
|
||||
self.assertEqual(expect, self.api.calls)
|
||||
@ -243,16 +294,45 @@ class AuditTemplateManagerTest(testtools.TestCase):
|
||||
self.mgr = watcherclient.v1.audit_template.AuditTemplateManager(
|
||||
self.api)
|
||||
audit_templates = self.mgr.list(
|
||||
strategy_uuid="ae99a4a4-acbc-4c67-abe1-e37128fac45d")
|
||||
strategy="ae99a4a4-acbc-4c67-abe1-e37128fac45d")
|
||||
expect = [
|
||||
('GET',
|
||||
'/v1/audit_templates/?strategy_uuid=%s' % (
|
||||
'/v1/audit_templates/?strategy=%s' % (
|
||||
AUDIT_TMPL2['strategy_uuid']),
|
||||
{}, None),
|
||||
]
|
||||
self.assertEqual(expect, self.api.calls)
|
||||
self.assertEqual(1, len(audit_templates))
|
||||
|
||||
def test_audit_templates_list_filter_by_strategy_name(self):
|
||||
self.api = utils.FakeAPI(fake_responses_filter_by_strategy_name)
|
||||
self.mgr = watcherclient.v1.audit_template.AuditTemplateManager(
|
||||
self.api)
|
||||
audit_templates = self.mgr.list(strategy="dummy")
|
||||
expect = [
|
||||
('GET',
|
||||
'/v1/audit_templates/?strategy=%s' % (
|
||||
AUDIT_TMPL2['strategy_name']),
|
||||
{}, None),
|
||||
]
|
||||
self.assertEqual(expect, self.api.calls)
|
||||
self.assertEqual(1, len(audit_templates))
|
||||
|
||||
def test_audit_templates_list_filter_by_goal_and_strategy_name(self):
|
||||
self.api = utils.FakeAPI(
|
||||
fake_responses_filter_by_strategy_and_goal_name)
|
||||
self.mgr = watcherclient.v1.audit_template.AuditTemplateManager(
|
||||
self.api)
|
||||
audit_templates = self.mgr.list(goal="DUMMY", strategy="dummy")
|
||||
expect = [
|
||||
('GET',
|
||||
'/v1/audit_templates/?goal=%s&strategy=%s' % (
|
||||
AUDIT_TMPL2['goal_name'], AUDIT_TMPL2['strategy_name']),
|
||||
{}, None),
|
||||
]
|
||||
self.assertEqual(expect, self.api.calls)
|
||||
self.assertEqual(1, len(audit_templates))
|
||||
|
||||
def test_audit_templates_list_detail(self):
|
||||
audit_templates = self.mgr.list(detail=True)
|
||||
expect = [
|
||||
|
@ -24,14 +24,35 @@ from watcherclient.tests.v1 import base
|
||||
from watcherclient import v1 as resource
|
||||
from watcherclient.v1 import resource_fields
|
||||
|
||||
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,
|
||||
}
|
||||
|
||||
AUDIT_TEMPLATE_1 = {
|
||||
'uuid': 'f8e47706-efcf-49a4-a5c4-af604eb492f2',
|
||||
'name': 'at1',
|
||||
'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',
|
||||
'goal_name': 'SERVER_CONSOLIDATION',
|
||||
'strategy_uuid': '2cf86250-d309-4b81-818e-1537f3dba6e5',
|
||||
'strategy_name': 'basic',
|
||||
'created_at': datetime.datetime.now().isoformat(),
|
||||
'updated_at': None,
|
||||
'deleted_at': None,
|
||||
@ -43,8 +64,10 @@ AUDIT_TEMPLATE_2 = {
|
||||
'description': 'Audit Template 2',
|
||||
'host_aggregate': 3,
|
||||
'extra': {'automatic': False},
|
||||
'goal_uuid': '7568667b-51fe-4087-9eb1-29b26891036f',
|
||||
'goal_uuid': 'fc087747-61be-4aad-8126-b701731ae836',
|
||||
'goal_name': 'SERVER_CONSOLIDATION',
|
||||
'strategy_uuid': None,
|
||||
'strategy_name': None,
|
||||
'created_at': datetime.datetime.now().isoformat(),
|
||||
'updated_at': None,
|
||||
'deleted_at': None,
|
||||
@ -62,6 +85,23 @@ class AuditTemplateShellTest(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
|
||||
|
||||
# audit template mock
|
||||
p_audit_template_manager = mock.patch.object(
|
||||
resource, 'AuditTemplateManager')
|
||||
self.m_audit_template_mgr_cls = p_audit_template_manager.start()
|
||||
@ -70,6 +110,7 @@ class AuditTemplateShellTest(base.CommandTestCase):
|
||||
self.m_audit_template_mgr = mock.Mock()
|
||||
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)
|
||||
|
||||
@ -116,8 +157,8 @@ class AuditTemplateShellTest(base.CommandTestCase):
|
||||
audit_template1, audit_template2]
|
||||
|
||||
exit_code, results = self.run_cmd(
|
||||
'audittemplate list --goal-uuid '
|
||||
'7568667b-51fe-4087-9eb1-29b26891036f')
|
||||
'audittemplate list --goal '
|
||||
'fc087747-61be-4aad-8126-b701731ae836')
|
||||
|
||||
self.assertEqual(0, exit_code)
|
||||
self.assertEqual(
|
||||
@ -129,16 +170,46 @@ class AuditTemplateShellTest(base.CommandTestCase):
|
||||
|
||||
self.m_audit_template_mgr.list.assert_called_once_with(
|
||||
detail=False,
|
||||
goal_uuid='7568667b-51fe-4087-9eb1-29b26891036f',
|
||||
goal='fc087747-61be-4aad-8126-b701731ae836',
|
||||
)
|
||||
|
||||
def test_do_audit_template_list_filter_by_goal_name(self):
|
||||
goal1 = resource.Goal(mock.Mock(), GOAL_1)
|
||||
strategy1 = resource.Strategy(mock.Mock(), STRATEGY_1)
|
||||
audit_template1 = resource.AuditTemplate(mock.Mock(), AUDIT_TEMPLATE_1)
|
||||
audit_template2 = resource.AuditTemplate(mock.Mock(), AUDIT_TEMPLATE_2)
|
||||
self.m_goal_mgr.get.return_value = goal1
|
||||
self.m_strategy_mgr.get.return_value = strategy1
|
||||
self.m_audit_template_mgr.list.return_value = [
|
||||
audit_template1, audit_template2]
|
||||
|
||||
exit_code, results = self.run_cmd(
|
||||
'audittemplate list --goal SERVER_CONSOLIDATION')
|
||||
|
||||
self.assertEqual(0, exit_code)
|
||||
self.assertEqual(
|
||||
[self.resource_as_dict(audit_template1, self.SHORT_LIST_FIELDS,
|
||||
self.SHORT_LIST_FIELD_LABELS),
|
||||
self.resource_as_dict(audit_template2, self.SHORT_LIST_FIELDS,
|
||||
self.SHORT_LIST_FIELD_LABELS)],
|
||||
results)
|
||||
|
||||
self.m_audit_template_mgr.list.assert_called_once_with(
|
||||
detail=False,
|
||||
goal='SERVER_CONSOLIDATION',
|
||||
)
|
||||
|
||||
def test_do_audit_template_list_filter_by_strategy_uuid(self):
|
||||
goal1 = resource.Goal(mock.Mock(), GOAL_1)
|
||||
strategy1 = resource.Strategy(mock.Mock(), STRATEGY_1)
|
||||
audit_template1 = resource.AuditTemplate(mock.Mock(), AUDIT_TEMPLATE_1)
|
||||
self.m_goal_mgr.get.return_value = goal1
|
||||
self.m_strategy_mgr.get.return_value = strategy1
|
||||
self.m_audit_template_mgr.list.return_value = [audit_template1]
|
||||
|
||||
exit_code, results = self.run_cmd(
|
||||
'audittemplate list --strategy-uuid '
|
||||
'bbe6b966-f98e-439b-a01a-17b9b3b8478b')
|
||||
'audittemplate list --strategy '
|
||||
'2cf86250-d309-4b81-818e-1537f3dba6e5')
|
||||
|
||||
self.assertEqual(0, exit_code)
|
||||
self.assertEqual(
|
||||
@ -148,7 +219,26 @@ class AuditTemplateShellTest(base.CommandTestCase):
|
||||
|
||||
self.m_audit_template_mgr.list.assert_called_once_with(
|
||||
detail=False,
|
||||
strategy_uuid='bbe6b966-f98e-439b-a01a-17b9b3b8478b',
|
||||
strategy='2cf86250-d309-4b81-818e-1537f3dba6e5',
|
||||
)
|
||||
|
||||
def test_do_audit_template_list_filter_by_strategy_name(self):
|
||||
audit_template1 = resource.AuditTemplate(mock.Mock(), AUDIT_TEMPLATE_1)
|
||||
self.m_audit_template_mgr.list.return_value = [audit_template1]
|
||||
|
||||
exit_code, results = self.run_cmd(
|
||||
'audittemplate list --strategy '
|
||||
'basic')
|
||||
|
||||
self.assertEqual(0, exit_code)
|
||||
self.assertEqual(
|
||||
[self.resource_as_dict(audit_template1, self.SHORT_LIST_FIELDS,
|
||||
self.SHORT_LIST_FIELD_LABELS)],
|
||||
results)
|
||||
|
||||
self.m_audit_template_mgr.list.assert_called_once_with(
|
||||
detail=False,
|
||||
strategy='basic',
|
||||
)
|
||||
|
||||
def test_do_audit_template_show_by_name(self):
|
||||
@ -224,14 +314,14 @@ class AuditTemplateShellTest(base.CommandTestCase):
|
||||
self.m_audit_template_mgr.create.return_value = audit_template
|
||||
|
||||
exit_code, result = self.run_cmd(
|
||||
'audittemplate create at1 7568667b-51fe-4087-9eb1-29b26891036f')
|
||||
'audittemplate create at1 fc087747-61be-4aad-8126-b701731ae836')
|
||||
|
||||
self.assertEqual(0, exit_code)
|
||||
self.assertEqual(self.resource_as_dict(audit_template, self.FIELDS,
|
||||
self.FIELD_LABELS),
|
||||
result)
|
||||
self.m_audit_template_mgr.create.assert_called_once_with(
|
||||
goal_uuid='7568667b-51fe-4087-9eb1-29b26891036f',
|
||||
goal='fc087747-61be-4aad-8126-b701731ae836',
|
||||
name='at1')
|
||||
|
||||
def test_do_audit_template_create_with_description(self):
|
||||
@ -239,7 +329,7 @@ class AuditTemplateShellTest(base.CommandTestCase):
|
||||
self.m_audit_template_mgr.create.return_value = audit_template
|
||||
|
||||
exit_code, result = self.run_cmd(
|
||||
'audittemplate create at1 7568667b-51fe-4087-9eb1-29b26891036f '
|
||||
'audittemplate create at1 fc087747-61be-4aad-8126-b701731ae836 '
|
||||
'-d "Audit Template 1 description"')
|
||||
|
||||
self.assertEqual(0, exit_code)
|
||||
@ -247,7 +337,7 @@ class AuditTemplateShellTest(base.CommandTestCase):
|
||||
self.FIELD_LABELS),
|
||||
result)
|
||||
self.m_audit_template_mgr.create.assert_called_once_with(
|
||||
goal_uuid='7568667b-51fe-4087-9eb1-29b26891036f',
|
||||
goal='fc087747-61be-4aad-8126-b701731ae836',
|
||||
name='at1',
|
||||
description='Audit Template 1 description')
|
||||
|
||||
@ -256,7 +346,7 @@ class AuditTemplateShellTest(base.CommandTestCase):
|
||||
self.m_audit_template_mgr.create.return_value = audit_template
|
||||
|
||||
exit_code, result = self.run_cmd(
|
||||
'audittemplate create at1 7568667b-51fe-4087-9eb1-29b26891036f '
|
||||
'audittemplate create at1 fc087747-61be-4aad-8126-b701731ae836 '
|
||||
'-a 5')
|
||||
|
||||
self.assertEqual(0, exit_code)
|
||||
@ -264,7 +354,7 @@ class AuditTemplateShellTest(base.CommandTestCase):
|
||||
self.FIELD_LABELS),
|
||||
result)
|
||||
self.m_audit_template_mgr.create.assert_called_once_with(
|
||||
goal_uuid='7568667b-51fe-4087-9eb1-29b26891036f',
|
||||
goal='fc087747-61be-4aad-8126-b701731ae836',
|
||||
name='at1',
|
||||
host_aggregate='5')
|
||||
|
||||
@ -273,7 +363,7 @@ class AuditTemplateShellTest(base.CommandTestCase):
|
||||
self.m_audit_template_mgr.create.return_value = audit_template
|
||||
|
||||
exit_code, result = self.run_cmd(
|
||||
'audittemplate create at1 7568667b-51fe-4087-9eb1-29b26891036f '
|
||||
'audittemplate create at1 fc087747-61be-4aad-8126-b701731ae836 '
|
||||
'-e automatic=true')
|
||||
|
||||
self.assertEqual(0, exit_code)
|
||||
@ -281,6 +371,6 @@ class AuditTemplateShellTest(base.CommandTestCase):
|
||||
self.FIELD_LABELS),
|
||||
result)
|
||||
self.m_audit_template_mgr.create.assert_called_once_with(
|
||||
goal_uuid='7568667b-51fe-4087-9eb1-29b26891036f',
|
||||
goal='fc087747-61be-4aad-8126-b701731ae836',
|
||||
name='at1',
|
||||
extra={'automatic': True})
|
||||
|
@ -19,7 +19,7 @@ from watcherclient.common import utils
|
||||
from watcherclient import exceptions as exc
|
||||
|
||||
CREATION_ATTRIBUTES = ['host_aggregate', 'description', 'name',
|
||||
'extra', 'goal_uuid', 'strategy_uuid']
|
||||
'extra', 'goal', 'strategy']
|
||||
|
||||
|
||||
class AuditTemplate(base.Resource):
|
||||
@ -34,7 +34,7 @@ class AuditTemplateManager(base.Manager):
|
||||
def _path(id_=None):
|
||||
return '/v1/audit_templates/%s' % id_ if id_ else '/v1/audit_templates'
|
||||
|
||||
def list(self, name=None, goal_uuid=None, strategy_uuid=None, limit=None,
|
||||
def list(self, name=None, goal=None, strategy=None, limit=None,
|
||||
sort_key=None, sort_dir=None, detail=False):
|
||||
"""Retrieve a list of audit template.
|
||||
|
||||
@ -65,10 +65,10 @@ class AuditTemplateManager(base.Manager):
|
||||
filters = utils.common_filters(limit, sort_key, sort_dir)
|
||||
if name is not None:
|
||||
filters.append('name=%s' % name)
|
||||
if goal_uuid is not None:
|
||||
filters.append("goal_uuid=%s" % goal_uuid)
|
||||
if strategy_uuid is not None:
|
||||
filters.append("strategy_uuid=%s" % strategy_uuid)
|
||||
if goal is not None:
|
||||
filters.append("goal=%s" % goal)
|
||||
if strategy is not None:
|
||||
filters.append("strategy=%s" % strategy)
|
||||
|
||||
path = ''
|
||||
if detail:
|
||||
|
@ -15,6 +15,7 @@
|
||||
# limitations under the License.
|
||||
|
||||
from openstackclient.common import utils
|
||||
from oslo_utils import uuidutils
|
||||
|
||||
from watcherclient._i18n import _
|
||||
from watcherclient.common import command
|
||||
@ -64,13 +65,15 @@ class ListAuditTemplate(command.Lister):
|
||||
default=False,
|
||||
help=_("Show detailed information about audit templates."))
|
||||
parser.add_argument(
|
||||
'--goal-uuid',
|
||||
metavar='<goal-uuid>',
|
||||
help=_('UUID the goal used for filtering.'))
|
||||
'--goal',
|
||||
dest='goal',
|
||||
metavar='<goal>',
|
||||
help=_('UUID or name of the goal used for filtering.'))
|
||||
parser.add_argument(
|
||||
'--strategy-uuid',
|
||||
metavar='<strategy-uuid>',
|
||||
help=_('UUID the strategy used for filtering.'))
|
||||
'--strategy',
|
||||
dest='strategy',
|
||||
metavar='<strategy>',
|
||||
help=_('UUID or name of the strategy used for filtering.'))
|
||||
parser.add_argument(
|
||||
'--limit',
|
||||
metavar='<limit>',
|
||||
@ -95,10 +98,14 @@ class ListAuditTemplate(command.Lister):
|
||||
|
||||
params = {}
|
||||
|
||||
if parsed_args.goal_uuid is not None:
|
||||
params['goal_uuid'] = parsed_args.goal_uuid
|
||||
if parsed_args.strategy_uuid is not None:
|
||||
params['strategy_uuid'] = parsed_args.strategy_uuid
|
||||
# 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_TEMPLATE_FIELDS
|
||||
field_labels = res_fields.AUDIT_TEMPLATE_FIELD_LABELS
|
||||
@ -125,14 +132,14 @@ class CreateAuditTemplate(command.ShowOne):
|
||||
metavar='<name>',
|
||||
help=_('Name for this audit template.'))
|
||||
parser.add_argument(
|
||||
'goal_uuid',
|
||||
metavar='<goal-uuid>',
|
||||
help=_('Goal ID associated to this audit template.'))
|
||||
'goal',
|
||||
metavar='<goal>',
|
||||
help=_('Goal UUID or name associated to this audit template.'))
|
||||
parser.add_argument(
|
||||
'-s', '--strategy-uuid',
|
||||
dest='strategy_uuid',
|
||||
metavar='<strategy-uuid>',
|
||||
help=_('Strategy ID associated to this audit template.'))
|
||||
'-s', '--strategy',
|
||||
dest='strategy',
|
||||
metavar='<strategy>',
|
||||
help=_('Strategy UUID or name associated to this audit template.'))
|
||||
parser.add_argument(
|
||||
'-d', '--description',
|
||||
metavar='<description>',
|
||||
@ -156,9 +163,20 @@ class CreateAuditTemplate(command.ShowOne):
|
||||
client = getattr(self.app.client_manager, "infra-optim")
|
||||
|
||||
field_list = ['host_aggregate', 'description', 'name', 'extra',
|
||||
'goal_uuid', 'strategy_uuid']
|
||||
'goal', 'strategy']
|
||||
fields = dict((k, v) for (k, v) in vars(parsed_args).items()
|
||||
if k in field_list and v is not None)
|
||||
|
||||
# mandatory
|
||||
if not uuidutils.is_uuid_like(fields['goal']):
|
||||
fields['goal'] = client.goal.get(fields['goal']).uuid
|
||||
|
||||
# optional
|
||||
if fields.get('strategy'):
|
||||
if not uuidutils.is_uuid_like(fields['strategy']):
|
||||
fields['strategy'] = client.strategy.get(
|
||||
fields['strategy']).uuid
|
||||
|
||||
fields = common_utils.args_array_to_dict(fields, 'extra')
|
||||
audit_template = client.audit_template.create(**fields)
|
||||
|
||||
|
@ -20,16 +20,17 @@
|
||||
AUDIT_TEMPLATE_FIELDS = [
|
||||
'uuid', 'created_at', 'updated_at', 'deleted_at',
|
||||
'description', 'host_aggregate', 'name',
|
||||
'extra', 'goal_uuid', 'strategy_uuid']
|
||||
'extra', 'goal_name', 'strategy_name']
|
||||
|
||||
AUDIT_TEMPLATE_FIELD_LABELS = [
|
||||
'UUID', 'Created At', 'Updated At', 'Deleted At',
|
||||
'Description', 'Host Aggregate ID or Name', 'Name',
|
||||
'Extra', 'Goal UUID', 'Strategy UUID']
|
||||
'Extra', 'Goal', 'Strategy']
|
||||
|
||||
AUDIT_TEMPLATE_SHORT_LIST_FIELDS = ['uuid', 'name']
|
||||
AUDIT_TEMPLATE_SHORT_LIST_FIELDS = [
|
||||
'uuid', 'name', 'goal_name', 'strategy_name']
|
||||
|
||||
AUDIT_TEMPLATE_SHORT_LIST_FIELD_LABELS = ['UUID', 'Name']
|
||||
AUDIT_TEMPLATE_SHORT_LIST_FIELD_LABELS = ['UUID', 'Name', 'Goal', 'Strategy']
|
||||
|
||||
# Audit
|
||||
AUDIT_FIELDS = ['uuid', 'created_at', 'updated_at', 'deleted_at',
|
||||
|
Loading…
Reference in New Issue
Block a user