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:
Vincent Francoise
2016-05-03 10:04:34 +02:00
parent 544db1951f
commit bc572e70dc
5 changed files with 244 additions and 55 deletions

View File

@@ -18,7 +18,6 @@
import copy import copy
from six.moves.urllib import parse as urlparse from six.moves.urllib import parse as urlparse
import testtools
from testtools import matchers from testtools import matchers
from watcherclient.tests import utils from watcherclient.tests import utils
@@ -32,7 +31,9 @@ AUDIT_TMPL1 = {
'host_aggregate': 5, 'host_aggregate': 5,
'extra': {'automatic': False}, 'extra': {'automatic': False},
'goal_uuid': '7568667b-51fe-4087-9eb1-29b26891036f', 'goal_uuid': '7568667b-51fe-4087-9eb1-29b26891036f',
'goal_name': 'SERVER_CONSOLIDATION',
'strategy_uuid': 'bbe6b966-f98e-439b-a01a-17b9b3b8478b', 'strategy_uuid': 'bbe6b966-f98e-439b-a01a-17b9b3b8478b',
'strategy_name': 'server_consolidation',
} }
AUDIT_TMPL2 = { AUDIT_TMPL2 = {
@@ -43,7 +44,9 @@ AUDIT_TMPL2 = {
'host_aggregate': 8, 'host_aggregate': 8,
'extra': {'automatic': True}, 'extra': {'automatic': True},
'goal_uuid': 'e75ee410-b32b-465f-88b5-4397705f9473', 'goal_uuid': 'e75ee410-b32b-465f-88b5-4397705f9473',
'goal_name': 'DUMMY',
'strategy_uuid': 'ae99a4a4-acbc-4c67-abe1-e37128fac45d', 'strategy_uuid': 'ae99a4a4-acbc-4c67-abe1-e37128fac45d',
'strategy_name': 'dummy',
} }
AUDIT_TMPL3 = { AUDIT_TMPL3 = {
@@ -54,11 +57,16 @@ AUDIT_TMPL3 = {
'host_aggregate': 7, 'host_aggregate': 7,
'extra': {'automatic': True}, 'extra': {'automatic': True},
'goal_uuid': '7568667b-51fe-4087-9eb1-29b26891036f', 'goal_uuid': '7568667b-51fe-4087-9eb1-29b26891036f',
'goal_name': 'SERVER_CONSOLIDATION',
} }
CREATE_AUDIT_TEMPLATE = copy.deepcopy(AUDIT_TMPL1) CREATE_AUDIT_TEMPLATE = copy.deepcopy(AUDIT_TMPL1)
del CREATE_AUDIT_TEMPLATE['id'] del CREATE_AUDIT_TEMPLATE['id']
del CREATE_AUDIT_TEMPLATE['uuid'] 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) UPDATED_AUDIT_TMPL1 = copy.deepcopy(AUDIT_TMPL1)
NEW_NAME = 'Audit Template_1 new name' NEW_NAME = 'Audit Template_1 new name'
@@ -127,14 +135,14 @@ fake_responses = {
{"audit_templates": [AUDIT_TMPL1]}, {"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': ( 'GET': (
{}, {},
{"audit_templates": [AUDIT_TMPL1, AUDIT_TMPL3]}, {"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': ( 'GET': (
{}, {},
@@ -179,7 +187,17 @@ fake_responses_sorting = {
} }
fake_responses_filter_by_goal_uuid = { 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': ( 'GET': (
{}, {},
@@ -189,7 +207,27 @@ fake_responses_filter_by_goal_uuid = {
} }
fake_responses_filter_by_strategy_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': ( 'GET': (
{}, {},
@@ -199,7 +237,7 @@ fake_responses_filter_by_strategy_uuid = {
} }
class AuditTemplateManagerTest(testtools.TestCase): class AuditTemplateManagerTest(utils.BaseTestCase):
def setUp(self): def setUp(self):
super(AuditTemplateManagerTest, self).setUp() super(AuditTemplateManagerTest, self).setUp()
@@ -229,10 +267,23 @@ class AuditTemplateManagerTest(testtools.TestCase):
self.mgr = watcherclient.v1.audit_template.AuditTemplateManager( self.mgr = watcherclient.v1.audit_template.AuditTemplateManager(
self.api) self.api)
audit_templates = self.mgr.list( audit_templates = self.mgr.list(
goal_uuid="e75ee410-b32b-465f-88b5-4397705f9473") goal="e75ee410-b32b-465f-88b5-4397705f9473")
expect = [ expect = [
('GET', ('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), {}, None),
] ]
self.assertEqual(expect, self.api.calls) self.assertEqual(expect, self.api.calls)
@@ -243,16 +294,45 @@ class AuditTemplateManagerTest(testtools.TestCase):
self.mgr = watcherclient.v1.audit_template.AuditTemplateManager( self.mgr = watcherclient.v1.audit_template.AuditTemplateManager(
self.api) self.api)
audit_templates = self.mgr.list( audit_templates = self.mgr.list(
strategy_uuid="ae99a4a4-acbc-4c67-abe1-e37128fac45d") strategy="ae99a4a4-acbc-4c67-abe1-e37128fac45d")
expect = [ expect = [
('GET', ('GET',
'/v1/audit_templates/?strategy_uuid=%s' % ( '/v1/audit_templates/?strategy=%s' % (
AUDIT_TMPL2['strategy_uuid']), AUDIT_TMPL2['strategy_uuid']),
{}, None), {}, None),
] ]
self.assertEqual(expect, self.api.calls) self.assertEqual(expect, self.api.calls)
self.assertEqual(1, len(audit_templates)) 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): def test_audit_templates_list_detail(self):
audit_templates = self.mgr.list(detail=True) audit_templates = self.mgr.list(detail=True)
expect = [ expect = [

View File

@@ -24,14 +24,35 @@ from watcherclient.tests.v1 import base
from watcherclient import v1 as resource from watcherclient import v1 as resource
from watcherclient.v1 import resource_fields 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 = { AUDIT_TEMPLATE_1 = {
'uuid': 'f8e47706-efcf-49a4-a5c4-af604eb492f2', 'uuid': 'f8e47706-efcf-49a4-a5c4-af604eb492f2',
'name': 'at1', 'name': 'at1',
'description': 'Audit Template 1 description', 'description': 'Audit Template 1 description',
'host_aggregate': 5, 'host_aggregate': 5,
'extra': {'automatic': False}, 'extra': {'automatic': False},
'goal_uuid': '7568667b-51fe-4087-9eb1-29b26891036f', 'goal_uuid': 'fc087747-61be-4aad-8126-b701731ae836',
'strategy_uuid': 'bbe6b966-f98e-439b-a01a-17b9b3b8478b', 'goal_name': 'SERVER_CONSOLIDATION',
'strategy_uuid': '2cf86250-d309-4b81-818e-1537f3dba6e5',
'strategy_name': 'basic',
'created_at': datetime.datetime.now().isoformat(), 'created_at': datetime.datetime.now().isoformat(),
'updated_at': None, 'updated_at': None,
'deleted_at': None, 'deleted_at': None,
@@ -43,8 +64,10 @@ AUDIT_TEMPLATE_2 = {
'description': 'Audit Template 2', 'description': 'Audit Template 2',
'host_aggregate': 3, 'host_aggregate': 3,
'extra': {'automatic': False}, '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_uuid': None,
'strategy_name': None,
'created_at': datetime.datetime.now().isoformat(), 'created_at': datetime.datetime.now().isoformat(),
'updated_at': None, 'updated_at': None,
'deleted_at': None, 'deleted_at': None,
@@ -62,6 +85,23 @@ class AuditTemplateShellTest(base.CommandTestCase):
def setUp(self): def setUp(self):
super(self.__class__, self).setUp() 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( p_audit_template_manager = mock.patch.object(
resource, 'AuditTemplateManager') resource, 'AuditTemplateManager')
self.m_audit_template_mgr_cls = p_audit_template_manager.start() 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 = mock.Mock()
self.m_audit_template_mgr_cls.return_value = self.m_audit_template_mgr self.m_audit_template_mgr_cls.return_value = self.m_audit_template_mgr
# stdout mock
self.stdout = six.StringIO() self.stdout = six.StringIO()
self.cmd = shell.WatcherShell(stdout=self.stdout) self.cmd = shell.WatcherShell(stdout=self.stdout)
@@ -116,8 +157,8 @@ class AuditTemplateShellTest(base.CommandTestCase):
audit_template1, audit_template2] audit_template1, audit_template2]
exit_code, results = self.run_cmd( exit_code, results = self.run_cmd(
'audittemplate list --goal-uuid ' 'audittemplate list --goal '
'7568667b-51fe-4087-9eb1-29b26891036f') 'fc087747-61be-4aad-8126-b701731ae836')
self.assertEqual(0, exit_code) self.assertEqual(0, exit_code)
self.assertEqual( self.assertEqual(
@@ -129,16 +170,46 @@ class AuditTemplateShellTest(base.CommandTestCase):
self.m_audit_template_mgr.list.assert_called_once_with( self.m_audit_template_mgr.list.assert_called_once_with(
detail=False, 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): 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) 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] self.m_audit_template_mgr.list.return_value = [audit_template1]
exit_code, results = self.run_cmd( exit_code, results = self.run_cmd(
'audittemplate list --strategy-uuid ' 'audittemplate list --strategy '
'bbe6b966-f98e-439b-a01a-17b9b3b8478b') '2cf86250-d309-4b81-818e-1537f3dba6e5')
self.assertEqual(0, exit_code) self.assertEqual(0, exit_code)
self.assertEqual( self.assertEqual(
@@ -148,7 +219,26 @@ class AuditTemplateShellTest(base.CommandTestCase):
self.m_audit_template_mgr.list.assert_called_once_with( self.m_audit_template_mgr.list.assert_called_once_with(
detail=False, 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): 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 self.m_audit_template_mgr.create.return_value = audit_template
exit_code, result = self.run_cmd( 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(0, exit_code)
self.assertEqual(self.resource_as_dict(audit_template, self.FIELDS, self.assertEqual(self.resource_as_dict(audit_template, self.FIELDS,
self.FIELD_LABELS), self.FIELD_LABELS),
result) result)
self.m_audit_template_mgr.create.assert_called_once_with( 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') name='at1')
def test_do_audit_template_create_with_description(self): 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 self.m_audit_template_mgr.create.return_value = audit_template
exit_code, result = self.run_cmd( 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"') '-d "Audit Template 1 description"')
self.assertEqual(0, exit_code) self.assertEqual(0, exit_code)
@@ -247,7 +337,7 @@ class AuditTemplateShellTest(base.CommandTestCase):
self.FIELD_LABELS), self.FIELD_LABELS),
result) result)
self.m_audit_template_mgr.create.assert_called_once_with( 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', name='at1',
description='Audit Template 1 description') description='Audit Template 1 description')
@@ -256,7 +346,7 @@ class AuditTemplateShellTest(base.CommandTestCase):
self.m_audit_template_mgr.create.return_value = audit_template self.m_audit_template_mgr.create.return_value = audit_template
exit_code, result = self.run_cmd( exit_code, result = self.run_cmd(
'audittemplate create at1 7568667b-51fe-4087-9eb1-29b26891036f ' 'audittemplate create at1 fc087747-61be-4aad-8126-b701731ae836 '
'-a 5') '-a 5')
self.assertEqual(0, exit_code) self.assertEqual(0, exit_code)
@@ -264,7 +354,7 @@ class AuditTemplateShellTest(base.CommandTestCase):
self.FIELD_LABELS), self.FIELD_LABELS),
result) result)
self.m_audit_template_mgr.create.assert_called_once_with( 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', name='at1',
host_aggregate='5') host_aggregate='5')
@@ -273,7 +363,7 @@ class AuditTemplateShellTest(base.CommandTestCase):
self.m_audit_template_mgr.create.return_value = audit_template self.m_audit_template_mgr.create.return_value = audit_template
exit_code, result = self.run_cmd( 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') '-e automatic=true')
self.assertEqual(0, exit_code) self.assertEqual(0, exit_code)
@@ -281,6 +371,6 @@ class AuditTemplateShellTest(base.CommandTestCase):
self.FIELD_LABELS), self.FIELD_LABELS),
result) result)
self.m_audit_template_mgr.create.assert_called_once_with( 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', name='at1',
extra={'automatic': True}) extra={'automatic': True})

View File

@@ -19,7 +19,7 @@ from watcherclient.common import utils
from watcherclient import exceptions as exc from watcherclient import exceptions as exc
CREATION_ATTRIBUTES = ['host_aggregate', 'description', 'name', CREATION_ATTRIBUTES = ['host_aggregate', 'description', 'name',
'extra', 'goal_uuid', 'strategy_uuid'] 'extra', 'goal', 'strategy']
class AuditTemplate(base.Resource): class AuditTemplate(base.Resource):
@@ -34,7 +34,7 @@ class AuditTemplateManager(base.Manager):
def _path(id_=None): def _path(id_=None):
return '/v1/audit_templates/%s' % id_ if id_ else '/v1/audit_templates' 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): sort_key=None, sort_dir=None, detail=False):
"""Retrieve a list of audit template. """Retrieve a list of audit template.
@@ -65,10 +65,10 @@ class AuditTemplateManager(base.Manager):
filters = utils.common_filters(limit, sort_key, sort_dir) filters = utils.common_filters(limit, sort_key, sort_dir)
if name is not None: if name is not None:
filters.append('name=%s' % name) filters.append('name=%s' % name)
if goal_uuid is not None: if goal is not None:
filters.append("goal_uuid=%s" % goal_uuid) filters.append("goal=%s" % goal)
if strategy_uuid is not None: if strategy is not None:
filters.append("strategy_uuid=%s" % strategy_uuid) filters.append("strategy=%s" % strategy)
path = '' path = ''
if detail: if detail:

View File

@@ -15,6 +15,7 @@
# limitations under the License. # limitations under the License.
from openstackclient.common import utils from openstackclient.common import utils
from oslo_utils import uuidutils
from watcherclient._i18n import _ from watcherclient._i18n import _
from watcherclient.common import command from watcherclient.common import command
@@ -64,13 +65,15 @@ class ListAuditTemplate(command.Lister):
default=False, default=False,
help=_("Show detailed information about audit templates.")) help=_("Show detailed information about audit templates."))
parser.add_argument( parser.add_argument(
'--goal-uuid', '--goal',
metavar='<goal-uuid>', dest='goal',
help=_('UUID the goal used for filtering.')) metavar='<goal>',
help=_('UUID or name of the goal used for filtering.'))
parser.add_argument( parser.add_argument(
'--strategy-uuid', '--strategy',
metavar='<strategy-uuid>', dest='strategy',
help=_('UUID the strategy used for filtering.')) metavar='<strategy>',
help=_('UUID or name of the strategy used for filtering.'))
parser.add_argument( parser.add_argument(
'--limit', '--limit',
metavar='<limit>', metavar='<limit>',
@@ -95,10 +98,14 @@ class ListAuditTemplate(command.Lister):
params = {} params = {}
if parsed_args.goal_uuid is not None: # Optional
params['goal_uuid'] = parsed_args.goal_uuid if parsed_args.goal:
if parsed_args.strategy_uuid is not None: params['goal'] = parsed_args.goal
params['strategy_uuid'] = parsed_args.strategy_uuid
# Optional
if parsed_args.strategy:
params['strategy'] = parsed_args.strategy
if parsed_args.detail: if parsed_args.detail:
fields = res_fields.AUDIT_TEMPLATE_FIELDS fields = res_fields.AUDIT_TEMPLATE_FIELDS
field_labels = res_fields.AUDIT_TEMPLATE_FIELD_LABELS field_labels = res_fields.AUDIT_TEMPLATE_FIELD_LABELS
@@ -125,14 +132,14 @@ class CreateAuditTemplate(command.ShowOne):
metavar='<name>', metavar='<name>',
help=_('Name for this audit template.')) help=_('Name for this audit template.'))
parser.add_argument( parser.add_argument(
'goal_uuid', 'goal',
metavar='<goal-uuid>', metavar='<goal>',
help=_('Goal ID associated to this audit template.')) help=_('Goal UUID or name associated to this audit template.'))
parser.add_argument( parser.add_argument(
'-s', '--strategy-uuid', '-s', '--strategy',
dest='strategy_uuid', dest='strategy',
metavar='<strategy-uuid>', metavar='<strategy>',
help=_('Strategy ID associated to this audit template.')) help=_('Strategy UUID or name associated to this audit template.'))
parser.add_argument( parser.add_argument(
'-d', '--description', '-d', '--description',
metavar='<description>', metavar='<description>',
@@ -156,9 +163,20 @@ class CreateAuditTemplate(command.ShowOne):
client = getattr(self.app.client_manager, "infra-optim") client = getattr(self.app.client_manager, "infra-optim")
field_list = ['host_aggregate', 'description', 'name', 'extra', 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() fields = dict((k, v) for (k, v) in vars(parsed_args).items()
if k in field_list and v is not None) 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') fields = common_utils.args_array_to_dict(fields, 'extra')
audit_template = client.audit_template.create(**fields) audit_template = client.audit_template.create(**fields)

View File

@@ -20,16 +20,17 @@
AUDIT_TEMPLATE_FIELDS = [ AUDIT_TEMPLATE_FIELDS = [
'uuid', 'created_at', 'updated_at', 'deleted_at', 'uuid', 'created_at', 'updated_at', 'deleted_at',
'description', 'host_aggregate', 'name', 'description', 'host_aggregate', 'name',
'extra', 'goal_uuid', 'strategy_uuid'] 'extra', 'goal_name', 'strategy_name']
AUDIT_TEMPLATE_FIELD_LABELS = [ AUDIT_TEMPLATE_FIELD_LABELS = [
'UUID', 'Created At', 'Updated At', 'Deleted At', 'UUID', 'Created At', 'Updated At', 'Deleted At',
'Description', 'Host Aggregate ID or Name', 'Name', '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
AUDIT_FIELDS = ['uuid', 'created_at', 'updated_at', 'deleted_at', AUDIT_FIELDS = ['uuid', 'created_at', 'updated_at', 'deleted_at',