Compare commits
18 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5b914e8877 | ||
|
|
918d2f0bbd | ||
|
|
91d1d8b0e1 | ||
|
|
3ffe4869f3 | ||
|
|
bde259e38c | ||
|
|
75dd8dc561 | ||
|
|
a6aed1772d | ||
|
|
63a1039fb2 | ||
|
|
9d3a6c51b1 | ||
|
|
8bcdf13d7f | ||
|
|
f9fb0875e0 | ||
|
|
d36d835d08 | ||
|
|
20931e2ce7 | ||
|
|
fb84ae9b25 | ||
|
|
e64e597aa6 | ||
|
|
f9aac4fc9f | ||
|
|
0f276e483b | ||
|
|
888a58fd2a |
176
LICENSE
Normal file
176
LICENSE
Normal file
@@ -0,0 +1,176 @@
|
||||
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
|
||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||
|
||||
1. Definitions.
|
||||
|
||||
"License" shall mean the terms and conditions for use, reproduction,
|
||||
and distribution as defined by Sections 1 through 9 of this document.
|
||||
|
||||
"Licensor" shall mean the copyright owner or entity authorized by
|
||||
the copyright owner that is granting the License.
|
||||
|
||||
"Legal Entity" shall mean the union of the acting entity and all
|
||||
other entities that control, are controlled by, or are under common
|
||||
control with that entity. For the purposes of this definition,
|
||||
"control" means (i) the power, direct or indirect, to cause the
|
||||
direction or management of such entity, whether by contract or
|
||||
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||
|
||||
"You" (or "Your") shall mean an individual or Legal Entity
|
||||
exercising permissions granted by this License.
|
||||
|
||||
"Source" form shall mean the preferred form for making modifications,
|
||||
including but not limited to software source code, documentation
|
||||
source, and configuration files.
|
||||
|
||||
"Object" form shall mean any form resulting from mechanical
|
||||
transformation or translation of a Source form, including but
|
||||
not limited to compiled object code, generated documentation,
|
||||
and conversions to other media types.
|
||||
|
||||
"Work" shall mean the work of authorship, whether in Source or
|
||||
Object form, made available under the License, as indicated by a
|
||||
copyright notice that is included in or attached to the work
|
||||
(an example is provided in the Appendix below).
|
||||
|
||||
"Derivative Works" shall mean any work, whether in Source or Object
|
||||
form, that is based on (or derived from) the Work and for which the
|
||||
editorial revisions, annotations, elaborations, or other modifications
|
||||
represent, as a whole, an original work of authorship. For the purposes
|
||||
of this License, Derivative Works shall not include works that remain
|
||||
separable from, or merely link (or bind by name) to the interfaces of,
|
||||
the Work and Derivative Works thereof.
|
||||
|
||||
"Contribution" shall mean any work of authorship, including
|
||||
the original version of the Work and any modifications or additions
|
||||
to that Work or Derivative Works thereof, that is intentionally
|
||||
submitted to Licensor for inclusion in the Work by the copyright owner
|
||||
or by an individual or Legal Entity authorized to submit on behalf of
|
||||
the copyright owner. For the purposes of this definition, "submitted"
|
||||
means any form of electronic, verbal, or written communication sent
|
||||
to the Licensor or its representatives, including but not limited to
|
||||
communication on electronic mailing lists, source code control systems,
|
||||
and issue tracking systems that are managed by, or on behalf of, the
|
||||
Licensor for the purpose of discussing and improving the Work, but
|
||||
excluding communication that is conspicuously marked or otherwise
|
||||
designated in writing by the copyright owner as "Not a Contribution."
|
||||
|
||||
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||
on behalf of whom a Contribution has been received by Licensor and
|
||||
subsequently incorporated within the Work.
|
||||
|
||||
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
copyright license to reproduce, prepare Derivative Works of,
|
||||
publicly display, publicly perform, sublicense, and distribute the
|
||||
Work and such Derivative Works in Source or Object form.
|
||||
|
||||
3. Grant of Patent License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
(except as stated in this section) patent license to make, have made,
|
||||
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||
where such license applies only to those patent claims licensable
|
||||
by such Contributor that are necessarily infringed by their
|
||||
Contribution(s) alone or by combination of their Contribution(s)
|
||||
with the Work to which such Contribution(s) was submitted. If You
|
||||
institute patent litigation against any entity (including a
|
||||
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||
or a Contribution incorporated within the Work constitutes direct
|
||||
or contributory patent infringement, then any patent licenses
|
||||
granted to You under this License for that Work shall terminate
|
||||
as of the date such litigation is filed.
|
||||
|
||||
4. Redistribution. You may reproduce and distribute copies of the
|
||||
Work or Derivative Works thereof in any medium, with or without
|
||||
modifications, and in Source or Object form, provided that You
|
||||
meet the following conditions:
|
||||
|
||||
(a) You must give any other recipients of the Work or
|
||||
Derivative Works a copy of this License; and
|
||||
|
||||
(b) You must cause any modified files to carry prominent notices
|
||||
stating that You changed the files; and
|
||||
|
||||
(c) You must retain, in the Source form of any Derivative Works
|
||||
that You distribute, all copyright, patent, trademark, and
|
||||
attribution notices from the Source form of the Work,
|
||||
excluding those notices that do not pertain to any part of
|
||||
the Derivative Works; and
|
||||
|
||||
(d) If the Work includes a "NOTICE" text file as part of its
|
||||
distribution, then any Derivative Works that You distribute must
|
||||
include a readable copy of the attribution notices contained
|
||||
within such NOTICE file, excluding those notices that do not
|
||||
pertain to any part of the Derivative Works, in at least one
|
||||
of the following places: within a NOTICE text file distributed
|
||||
as part of the Derivative Works; within the Source form or
|
||||
documentation, if provided along with the Derivative Works; or,
|
||||
within a display generated by the Derivative Works, if and
|
||||
wherever such third-party notices normally appear. The contents
|
||||
of the NOTICE file are for informational purposes only and
|
||||
do not modify the License. You may add Your own attribution
|
||||
notices within Derivative Works that You distribute, alongside
|
||||
or as an addendum to the NOTICE text from the Work, provided
|
||||
that such additional attribution notices cannot be construed
|
||||
as modifying the License.
|
||||
|
||||
You may add Your own copyright statement to Your modifications and
|
||||
may provide additional or different license terms and conditions
|
||||
for use, reproduction, or distribution of Your modifications, or
|
||||
for any such Derivative Works as a whole, provided Your use,
|
||||
reproduction, and distribution of the Work otherwise complies with
|
||||
the conditions stated in this License.
|
||||
|
||||
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||
any Contribution intentionally submitted for inclusion in the Work
|
||||
by You to the Licensor shall be under the terms and conditions of
|
||||
this License, without any additional terms or conditions.
|
||||
Notwithstanding the above, nothing herein shall supersede or modify
|
||||
the terms of any separate license agreement you may have executed
|
||||
with Licensor regarding such Contributions.
|
||||
|
||||
6. Trademarks. This License does not grant permission to use the trade
|
||||
names, trademarks, service marks, or product names of the Licensor,
|
||||
except as required for reasonable and customary use in describing the
|
||||
origin of the Work and reproducing the content of the NOTICE file.
|
||||
|
||||
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||
agreed to in writing, Licensor provides the Work (and each
|
||||
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
implied, including, without limitation, any warranties or conditions
|
||||
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||
appropriateness of using or redistributing the Work and assume any
|
||||
risks associated with Your exercise of permissions under this License.
|
||||
|
||||
8. Limitation of Liability. In no event and under no legal theory,
|
||||
whether in tort (including negligence), contract, or otherwise,
|
||||
unless required by applicable law (such as deliberate and grossly
|
||||
negligent acts) or agreed to in writing, shall any Contributor be
|
||||
liable to You for damages, including any direct, indirect, special,
|
||||
incidental, or consequential damages of any character arising as a
|
||||
result of this License or out of the use or inability to use the
|
||||
Work (including but not limited to damages for loss of goodwill,
|
||||
work stoppage, computer failure or malfunction, or any and all
|
||||
other commercial damages or losses), even if such Contributor
|
||||
has been advised of the possibility of such damages.
|
||||
|
||||
9. Accepting Warranty or Additional Liability. While redistributing
|
||||
the Work or Derivative Works thereof, You may choose to offer,
|
||||
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||
or other liability obligations and/or rights consistent with this
|
||||
License. However, in accepting such obligations, You may act only
|
||||
on Your own behalf and on Your sole responsibility, not on behalf
|
||||
of any other Contributor, and only if You agree to indemnify,
|
||||
defend, and hold each Contributor harmless for any liability
|
||||
incurred by, or claims asserted against, such Contributor by reason
|
||||
of your accepting any such warranty or additional liability.
|
||||
|
||||
@@ -40,12 +40,4 @@ The preferred way to run the unit tests is using ``tox``.
|
||||
See `Consistent Testing Interface`_ for more details.
|
||||
|
||||
.. _Consistent Testing Interface: http://git.openstack.org/cgit/openstack/governance/tree/reference/project-testing-interface.rst
|
||||
|
||||
Indices and tables
|
||||
==================
|
||||
|
||||
* :ref:`genindex`
|
||||
* :ref:`modindex`
|
||||
* :ref:`search`
|
||||
|
||||
.. _Watcher: https://wiki.openstack.org/wiki/Watcher
|
||||
|
||||
@@ -2,12 +2,12 @@
|
||||
# of appearance. Changing the order has an impact on the overall integration
|
||||
# process, which may cause wedges in the gate later.
|
||||
|
||||
Babel!=2.3.0,!=2.3.1,!=2.3.2,!=2.3.3,>=1.3 # BSD
|
||||
Babel>=2.3.4 # BSD
|
||||
cliff!=1.16.0,!=1.17.0,>=1.15.0 # Apache-2.0
|
||||
oslo.i18n>=2.1.0 # Apache-2.0
|
||||
oslo.utils>=3.5.0 # Apache-2.0
|
||||
oslo.utils>=3.14.0 # Apache-2.0
|
||||
pbr>=1.6 # Apache-2.0
|
||||
PrettyTable>=0.7,<0.8 # BSD
|
||||
python-keystoneclient!=1.8.0,!=2.1.0,>=1.6.0 # 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
|
||||
six>=1.9.0 # MIT
|
||||
|
||||
@@ -5,12 +5,11 @@
|
||||
coverage>=3.6 # Apache-2.0
|
||||
discover # BSD
|
||||
hacking<0.11,>=0.10.2
|
||||
mock>=1.2 # BSD
|
||||
mock>=2.0 # BSD
|
||||
oslosphinx!=3.4.0,>=2.5.0 # Apache-2.0
|
||||
oslotest>=1.10.0 # Apache-2.0
|
||||
python-subunit>=0.0.18 # Apache-2.0/BSD
|
||||
sphinx!=1.2.0,!=1.3b1,<1.3,>=1.1.2 # BSD
|
||||
tempest-lib>=0.14.0 # Apache-2.0
|
||||
sphinx!=1.3b1,<1.3,>=1.2.1 # BSD
|
||||
testrepository>=0.0.18 # Apache-2.0/BSD
|
||||
testscenarios>=0.4 # Apache-2.0/BSD
|
||||
testtools>=1.4.0 # MIT
|
||||
|
||||
@@ -169,15 +169,18 @@ def print_list(objs, fields, formatters=None, sortby_index=0,
|
||||
for o in objs:
|
||||
row = []
|
||||
for field in fields:
|
||||
data = '-'
|
||||
if field in formatters:
|
||||
row.append(formatters[field](o))
|
||||
data = formatters[field](o)
|
||||
else:
|
||||
if field in mixed_case_fields:
|
||||
field_name = field.replace(' ', '_')
|
||||
else:
|
||||
field_name = field.lower().replace(' ', '_')
|
||||
data = getattr(o, field_name, '')
|
||||
row.append(data)
|
||||
if data is None:
|
||||
data = '-'
|
||||
row.append(data)
|
||||
pt.add_row(row)
|
||||
|
||||
if six.PY3:
|
||||
@@ -210,6 +213,8 @@ def print_dict(dct, dict_property="Property", wrap=0):
|
||||
pt.add_row([col1, line])
|
||||
col1 = ''
|
||||
else:
|
||||
if v is None:
|
||||
v = '-'
|
||||
pt.add_row([k, v])
|
||||
|
||||
if six.PY3:
|
||||
@@ -267,5 +272,5 @@ def pretty_choice_list(l):
|
||||
|
||||
def exit(msg=''):
|
||||
if msg:
|
||||
print (msg, file=sys.stderr)
|
||||
print(msg, file=sys.stderr)
|
||||
sys.exit(1)
|
||||
|
||||
@@ -165,7 +165,7 @@ class HTTPClient(object):
|
||||
url=url, e=e)
|
||||
except (socket.error, socket.timeout) as e:
|
||||
endpoint = self.endpoint
|
||||
raise exc.ConnectionRefused(
|
||||
raise exc.CommunicationError(
|
||||
_("Error communicating with %(endpoint)s %(e)s"),
|
||||
endpoint=endpoint, e=e)
|
||||
body_iter = ResponseBodyIterator(resp)
|
||||
|
||||
@@ -29,8 +29,17 @@ ACTION_PLAN_1 = {
|
||||
'uuid': 'd9d9978e-6db5-4a05-8eab-1531795d7004',
|
||||
'audit_uuid': '770ef053-ecb3-48b0-85b5-d55a2dbc6588',
|
||||
'state': 'RECOMMENDED',
|
||||
'efficacy_indicators': [{'description': 'Indicator 1',
|
||||
'name': 'indicator1',
|
||||
'unit': '%'}],
|
||||
'created_at': datetime.datetime.now().isoformat(),
|
||||
'updated_at': None,
|
||||
'global_efficacy': {
|
||||
"value": 99,
|
||||
"unit": "%",
|
||||
"name": "dummy_global_efficacy",
|
||||
"description": "Dummy Global Efficacy",
|
||||
},
|
||||
'deleted_at': None,
|
||||
}
|
||||
|
||||
@@ -39,7 +48,16 @@ ACTION_PLAN_2 = {
|
||||
'audit_uuid': '239f02a5-9649-4e14-9d33-ac2bf67cb755',
|
||||
'state': 'RECOMMENDED',
|
||||
'created_at': datetime.datetime.now().isoformat(),
|
||||
'efficacy_indicators': [{'description': 'Indicator 2',
|
||||
'name': 'indicator2',
|
||||
'unit': '%'}],
|
||||
'updated_at': None,
|
||||
'global_efficacy': {
|
||||
"value": 87,
|
||||
"unit": "%",
|
||||
"name": "dummy_global_efficacy",
|
||||
"description": "Dummy Global Efficacy",
|
||||
},
|
||||
'deleted_at': None,
|
||||
}
|
||||
|
||||
|
||||
@@ -27,7 +27,7 @@ AUDIT1 = {
|
||||
'id': 1,
|
||||
'uuid': 'f8e47706-efcf-49a4-a5c4-af604eb492f2',
|
||||
'deadline': None,
|
||||
'type': 'ONE_SHOT',
|
||||
'audit_type': 'ONE_SHOT',
|
||||
'audit_template_uuid': '770ef053-ecb3-48b0-85b5-d55a2dbc6588'
|
||||
}
|
||||
|
||||
@@ -35,7 +35,7 @@ AUDIT2 = {
|
||||
'id': 2,
|
||||
'uuid': 'a5199d0e-0702-4613-9234-5ae2af8dafea',
|
||||
'deadline': None,
|
||||
'type': 'ONE_SHOT',
|
||||
'audit_type': 'ONE_SHOT',
|
||||
'audit_template_uuid': '770ef053-ecb3-48b0-85b5-d55a2dbc6588'
|
||||
}
|
||||
|
||||
|
||||
@@ -41,25 +41,43 @@ AUDIT_TEMPLATE_1 = {
|
||||
AUDIT_1 = {
|
||||
'uuid': '5869da81-4876-4687-a1ed-12cd64cf53d9',
|
||||
'deadline': None,
|
||||
'type': 'ONESHOT',
|
||||
'audit_type': 'ONESHOT',
|
||||
'state': 'PENDING',
|
||||
'audit_template_uuid': 'f8e47706-efcf-49a4-a5c4-af604eb492f2',
|
||||
'audit_template_name': 'at1',
|
||||
'created_at': datetime.datetime.now().isoformat(),
|
||||
'updated_at': None,
|
||||
'deleted_at': None,
|
||||
'parameters': None,
|
||||
'interval': None,
|
||||
}
|
||||
|
||||
AUDIT_2 = {
|
||||
'uuid': 'a5199d0e-0702-4613-9234-5ae2af8dafea',
|
||||
'deadline': None,
|
||||
'type': 'ONESHOT',
|
||||
'audit_type': 'ONESHOT',
|
||||
'audit_template_uuid': '770ef053-ecb3-48b0-85b5-d55a2dbc6588',
|
||||
'audit_template_name': 'at2',
|
||||
'state': 'PENDING',
|
||||
'created_at': datetime.datetime.now().isoformat(),
|
||||
'updated_at': None,
|
||||
'deleted_at': None,
|
||||
'parameters': None,
|
||||
'interval': None,
|
||||
}
|
||||
|
||||
AUDIT_3 = {
|
||||
'uuid': '43199d0e-0712-1213-9674-5ae2af8dhgte',
|
||||
'deadline': None,
|
||||
'audit_type': 'CONTINUOUS',
|
||||
'audit_template_uuid': 'f8e47706-efcf-49a4-a5c4-af604eb492f2',
|
||||
'audit_template_name': 'at1',
|
||||
'state': 'PENDING',
|
||||
'created_at': datetime.datetime.now().isoformat(),
|
||||
'updated_at': None,
|
||||
'deleted_at': None,
|
||||
'parameters': None,
|
||||
'interval': 3600,
|
||||
}
|
||||
|
||||
|
||||
@@ -225,7 +243,7 @@ class AuditShellTest(base.CommandTestCase):
|
||||
result)
|
||||
self.m_audit_mgr.create.assert_called_once_with(
|
||||
audit_template_uuid='f8e47706-efcf-49a4-a5c4-af604eb492f2',
|
||||
type='ONESHOT')
|
||||
audit_type='ONESHOT')
|
||||
|
||||
def test_do_audit_create_with_audit_template_name(self):
|
||||
audit = resource.Audit(mock.Mock(), AUDIT_1)
|
||||
@@ -241,7 +259,7 @@ class AuditShellTest(base.CommandTestCase):
|
||||
result)
|
||||
self.m_audit_mgr.create.assert_called_once_with(
|
||||
audit_template_uuid='f8e47706-efcf-49a4-a5c4-af604eb492f2',
|
||||
type='ONESHOT')
|
||||
audit_type='ONESHOT')
|
||||
|
||||
def test_do_audit_create_with_deadline(self):
|
||||
audit = resource.Audit(mock.Mock(), AUDIT_1)
|
||||
@@ -258,7 +276,7 @@ class AuditShellTest(base.CommandTestCase):
|
||||
result)
|
||||
self.m_audit_mgr.create.assert_called_once_with(
|
||||
audit_template_uuid='f8e47706-efcf-49a4-a5c4-af604eb492f2',
|
||||
type='ONESHOT',
|
||||
audit_type='ONESHOT',
|
||||
deadline='2016-04-28T10:48:32.064802')
|
||||
|
||||
def test_do_audit_create_with_type(self):
|
||||
@@ -276,4 +294,40 @@ class AuditShellTest(base.CommandTestCase):
|
||||
result)
|
||||
self.m_audit_mgr.create.assert_called_once_with(
|
||||
audit_template_uuid='f8e47706-efcf-49a4-a5c4-af604eb492f2',
|
||||
type='ONESHOT')
|
||||
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')
|
||||
|
||||
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',
|
||||
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
|
||||
self.m_audit_mgr.create.return_value = audit
|
||||
|
||||
exit_code, result = self.run_cmd(
|
||||
'audit create -a at1 -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',
|
||||
audit_type='CONTINUOUS',
|
||||
interval='3600')
|
||||
|
||||
@@ -28,6 +28,12 @@ GOAL_1 = {
|
||||
'uuid': "fc087747-61be-4aad-8126-b701731ae836",
|
||||
'name': "SERVER_CONSOLIDATION",
|
||||
'display_name': 'Server Consolidation',
|
||||
'efficacy_specification': [
|
||||
{'description': 'Indicator 1', 'name': 'indicator1',
|
||||
'schema': 'Range(min=0, max=100, min_included=True, '
|
||||
'max_included=True, msg=None)',
|
||||
'unit': '%'}
|
||||
],
|
||||
'created_at': datetime.datetime.now().isoformat(),
|
||||
'updated_at': None,
|
||||
'deleted_at': None,
|
||||
@@ -37,6 +43,12 @@ GOAL_2 = {
|
||||
'uuid': "407b03b1-63c6-49b2-adaf-4df5c0090047",
|
||||
'name': "COST_OPTIMIZATION",
|
||||
'display_name': 'Cost Optimization',
|
||||
'efficacy_specification': [
|
||||
{'description': 'Indicator 2', 'name': 'indicator2',
|
||||
'schema': 'Range(min=0, max=100, min_included=True, '
|
||||
'max_included=True, msg=None)',
|
||||
'unit': '%'}
|
||||
],
|
||||
'created_at': datetime.datetime.now().isoformat(),
|
||||
'updated_at': None,
|
||||
'deleted_at': None,
|
||||
@@ -93,10 +105,8 @@ class GoalShellTest(base.CommandTestCase):
|
||||
|
||||
self.assertEqual(0, exit_code)
|
||||
self.assertEqual(
|
||||
[self.resource_as_dict(goal1, self.SHORT_LIST_FIELDS,
|
||||
self.SHORT_LIST_FIELD_LABELS),
|
||||
self.resource_as_dict(goal2, self.SHORT_LIST_FIELDS,
|
||||
self.SHORT_LIST_FIELD_LABELS)],
|
||||
[self.resource_as_dict(goal1, self.FIELDS, self.FIELD_LABELS),
|
||||
self.resource_as_dict(goal2, self.FIELDS, self.FIELD_LABELS)],
|
||||
results)
|
||||
|
||||
self.m_goal_mgr.list.assert_called_once_with(detail=True)
|
||||
@@ -109,8 +119,8 @@ class GoalShellTest(base.CommandTestCase):
|
||||
|
||||
self.assertEqual(0, exit_code)
|
||||
self.assertEqual(
|
||||
self.resource_as_dict(goal, self.SHORT_LIST_FIELDS,
|
||||
self.SHORT_LIST_FIELD_LABELS),
|
||||
self.resource_as_dict(goal, self.FIELDS,
|
||||
self.FIELD_LABELS),
|
||||
result)
|
||||
self.m_goal_mgr.get.assert_called_once_with('SERVER_CONSOLIDATION')
|
||||
|
||||
@@ -123,8 +133,8 @@ class GoalShellTest(base.CommandTestCase):
|
||||
|
||||
self.assertEqual(0, exit_code)
|
||||
self.assertEqual(
|
||||
self.resource_as_dict(goal, self.SHORT_LIST_FIELDS,
|
||||
self.SHORT_LIST_FIELD_LABELS),
|
||||
self.resource_as_dict(goal, self.FIELDS,
|
||||
self.FIELD_LABELS),
|
||||
result)
|
||||
self.m_goal_mgr.get.assert_called_once_with(
|
||||
'fc087747-61be-4aad-8126-b701731ae836')
|
||||
|
||||
@@ -33,6 +33,7 @@ STRATEGY_1 = {
|
||||
'created_at': datetime.datetime.now().isoformat(),
|
||||
'updated_at': None,
|
||||
'deleted_at': None,
|
||||
'parameters_spec': {},
|
||||
}
|
||||
|
||||
STRATEGY_2 = {
|
||||
@@ -44,6 +45,7 @@ STRATEGY_2 = {
|
||||
'created_at': datetime.datetime.now().isoformat(),
|
||||
'updated_at': None,
|
||||
'deleted_at': None,
|
||||
'parameters_spec': {},
|
||||
}
|
||||
|
||||
|
||||
@@ -96,10 +98,10 @@ class StrategyShellTest(base.CommandTestCase):
|
||||
|
||||
self.assertEqual(0, exit_code)
|
||||
self.assertEqual(
|
||||
[self.resource_as_dict(strategy1, self.SHORT_LIST_FIELDS,
|
||||
self.SHORT_LIST_FIELD_LABELS),
|
||||
self.resource_as_dict(strategy2, self.SHORT_LIST_FIELDS,
|
||||
self.SHORT_LIST_FIELD_LABELS)],
|
||||
[self.resource_as_dict(strategy1, self.FIELDS,
|
||||
self.FIELD_LABELS),
|
||||
self.resource_as_dict(strategy2, self.FIELDS,
|
||||
self.FIELD_LABELS)],
|
||||
results)
|
||||
|
||||
self.m_strategy_mgr.list.assert_called_once_with(detail=True)
|
||||
|
||||
@@ -14,8 +14,10 @@
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
from cliff.formatters import yaml_format
|
||||
from openstackclient.common import utils
|
||||
from oslo_utils import uuidutils
|
||||
import six
|
||||
|
||||
from watcherclient._i18n import _
|
||||
from watcherclient.common import command
|
||||
@@ -24,6 +26,19 @@ from watcherclient import exceptions
|
||||
from watcherclient.v1 import resource_fields as res_fields
|
||||
|
||||
|
||||
def format_global_efficacy(global_efficacy):
|
||||
formatted_global_efficacy = None
|
||||
if (global_efficacy.get('value') is not None and
|
||||
global_efficacy.get('unit')):
|
||||
formatted_global_efficacy = "%(value)s %(unit)s" % dict(
|
||||
unit=global_efficacy.get('unit'),
|
||||
value=global_efficacy.get('value'))
|
||||
elif global_efficacy.get('value') is not None:
|
||||
formatted_global_efficacy = global_efficacy.get('value')
|
||||
|
||||
return formatted_global_efficacy
|
||||
|
||||
|
||||
class ShowActionPlan(command.ShowOne):
|
||||
"""Show detailed information about a given action plan."""
|
||||
|
||||
@@ -36,6 +51,20 @@ class ShowActionPlan(command.ShowOne):
|
||||
)
|
||||
return parser
|
||||
|
||||
def _format_indicators(self, action_plan, parsed_args):
|
||||
out = six.StringIO()
|
||||
efficacy_indicators = action_plan.efficacy_indicators
|
||||
fields = ['name', 'description', 'value', 'unit']
|
||||
yaml_format.YAMLFormatter().emit_list(
|
||||
column_names=list(field.capitalize()
|
||||
for field in fields),
|
||||
data=[utils.get_dict_properties(spec, fields)
|
||||
for spec in efficacy_indicators],
|
||||
stdout=out,
|
||||
parsed_args=parsed_args,
|
||||
)
|
||||
return out.getvalue() or ''
|
||||
|
||||
def take_action(self, parsed_args):
|
||||
client = getattr(self.app.client_manager, "infra-optim")
|
||||
|
||||
@@ -49,6 +78,15 @@ class ShowActionPlan(command.ShowOne):
|
||||
except exceptions.HTTPNotFound as exc:
|
||||
raise exceptions.CommandError(str(exc))
|
||||
|
||||
if parsed_args.formatter == 'table':
|
||||
# Update the raw efficacy indicators with the formatted ones
|
||||
action_plan.efficacy_indicators = (
|
||||
self._format_indicators(action_plan, parsed_args))
|
||||
|
||||
# Update the raw global efficacy with the formatted one
|
||||
action_plan.global_efficacy = format_global_efficacy(
|
||||
action_plan.global_efficacy)
|
||||
|
||||
columns = res_fields.ACTION_PLAN_FIELDS
|
||||
column_headers = res_fields.ACTION_PLAN_FIELD_LABELS
|
||||
return column_headers, utils.get_item_properties(action_plan, columns)
|
||||
@@ -88,6 +126,20 @@ class ListActionPlan(command.Lister):
|
||||
|
||||
return parser
|
||||
|
||||
def _format_indicators(self, action_plan, parsed_args):
|
||||
out = six.StringIO()
|
||||
efficacy_indicators = action_plan.efficacy_indicators
|
||||
fields = ['name', 'value', 'unit']
|
||||
yaml_format.YAMLFormatter().emit_list(
|
||||
column_names=list(field.capitalize()
|
||||
for field in fields),
|
||||
data=[utils.get_dict_properties(spec, fields)
|
||||
for spec in efficacy_indicators],
|
||||
stdout=out,
|
||||
parsed_args=parsed_args,
|
||||
)
|
||||
return out.getvalue() or ''
|
||||
|
||||
def take_action(self, parsed_args):
|
||||
client = getattr(self.app.client_manager, "infra-optim")
|
||||
|
||||
@@ -106,6 +158,16 @@ class ListActionPlan(command.Lister):
|
||||
|
||||
data = client.action_plan.list(**params)
|
||||
|
||||
if parsed_args.formatter == 'table':
|
||||
for action_plan in data:
|
||||
# Update the raw efficacy indicators with the formatted ones
|
||||
action_plan.efficacy_indicators = (
|
||||
self._format_indicators(action_plan, parsed_args))
|
||||
|
||||
# Update the raw global efficacy with the formatted one
|
||||
action_plan.global_efficacy = format_global_efficacy(
|
||||
action_plan.global_efficacy)
|
||||
|
||||
return (field_labels,
|
||||
(utils.get_item_properties(item, fields) for item in data))
|
||||
|
||||
@@ -127,9 +189,9 @@ class CreateActionPlan(command.ShowOne):
|
||||
metavar='<deadline>',
|
||||
help=_('Descrition of the audit.'))
|
||||
parser.add_argument(
|
||||
'-t', '--type',
|
||||
dest='type',
|
||||
metavar='<type>',
|
||||
'-t', '--audit_type',
|
||||
dest='audit_type',
|
||||
metavar='<audit_type>',
|
||||
default='ONESHOT',
|
||||
help=_("ActionPlan type."))
|
||||
|
||||
@@ -138,7 +200,7 @@ class CreateActionPlan(command.ShowOne):
|
||||
def take_action(self, parsed_args):
|
||||
client = getattr(self.app.client_manager, "infra-optim")
|
||||
|
||||
field_list = ['audit_template_uuid', 'type', 'deadline']
|
||||
field_list = ['audit_template_uuid', 'audit_type', 'deadline']
|
||||
fields = dict((k, v) for (k, v) in vars(parsed_args).items()
|
||||
if k in field_list and v is not None)
|
||||
if fields.get('audit_template_uuid'):
|
||||
|
||||
@@ -18,7 +18,9 @@ from watcherclient.common import base
|
||||
from watcherclient.common import utils
|
||||
from watcherclient import exceptions as exc
|
||||
|
||||
CREATION_ATTRIBUTES = ['audit_template_uuid', 'deadline', 'type']
|
||||
|
||||
CREATION_ATTRIBUTES = ['audit_template_uuid', 'deadline',
|
||||
'audit_type', 'parameters', 'interval']
|
||||
|
||||
|
||||
class Audit(base.Resource):
|
||||
|
||||
@@ -127,20 +127,35 @@ class CreateAudit(command.ShowOne):
|
||||
metavar='<deadline>',
|
||||
help=_('Descrition of the audit.'))
|
||||
parser.add_argument(
|
||||
'-t', '--type',
|
||||
dest='type',
|
||||
metavar='<type>',
|
||||
'-t', '--audit_type',
|
||||
dest='audit_type',
|
||||
metavar='<audit_type>',
|
||||
default='ONESHOT',
|
||||
help=_("Audit type."))
|
||||
parser.add_argument(
|
||||
'-p', '--parameter',
|
||||
dest='parameters',
|
||||
metavar='<name=value>',
|
||||
action='append',
|
||||
help=_("Record strategy parameter/value metadata. "
|
||||
"Can be specified multiple times."))
|
||||
parser.add_argument(
|
||||
'-i', '--interval',
|
||||
dest='interval',
|
||||
metavar='<interval>',
|
||||
help=_("Audit interval."))
|
||||
|
||||
return parser
|
||||
|
||||
def take_action(self, parsed_args):
|
||||
client = getattr(self.app.client_manager, "infra-optim")
|
||||
|
||||
field_list = ['audit_template_uuid', 'type', 'deadline']
|
||||
field_list = ['audit_template_uuid', 'audit_type',
|
||||
'deadline', 'parameters', 'interval']
|
||||
|
||||
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('audit_template_uuid'):
|
||||
if not uuidutils.is_uuid_like(fields['audit_template_uuid']):
|
||||
fields['audit_template_uuid'] = client.audit_template.get(
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
# under the License.
|
||||
|
||||
from openstackclient.common import utils
|
||||
import six
|
||||
|
||||
from watcherclient._i18n import _
|
||||
from watcherclient.common import command
|
||||
@@ -36,6 +37,16 @@ class ShowGoal(command.ShowOne):
|
||||
)
|
||||
return parser
|
||||
|
||||
def _format_indicator_spec_table(self, spec, parsed_args):
|
||||
out = six.StringIO()
|
||||
self.formatter.emit_one(
|
||||
column_names=list(field.capitalize() for field in spec.keys()),
|
||||
data=utils.get_dict_properties(spec, spec.keys()),
|
||||
stdout=out,
|
||||
parsed_args=parsed_args,
|
||||
)
|
||||
return out.getvalue() or ''
|
||||
|
||||
def take_action(self, parsed_args):
|
||||
client = getattr(self.app.client_manager, "infra-optim")
|
||||
|
||||
@@ -47,6 +58,15 @@ class ShowGoal(command.ShowOne):
|
||||
columns = res_fields.GOAL_FIELDS
|
||||
column_headers = res_fields.GOAL_FIELD_LABELS
|
||||
|
||||
if parsed_args.formatter == 'table':
|
||||
indicator_specs = ''
|
||||
# Format complex data types:
|
||||
for indicator_spec in goal.efficacy_specification:
|
||||
indicator_specs += self._format_indicator_spec_table(
|
||||
indicator_spec, parsed_args)
|
||||
# Update the raw efficacy specs with the formatted one
|
||||
goal.efficacy_specification = indicator_specs
|
||||
|
||||
return column_headers, utils.get_item_properties(goal, columns)
|
||||
|
||||
|
||||
@@ -80,6 +100,20 @@ class ListGoal(command.Lister):
|
||||
|
||||
return parser
|
||||
|
||||
def _format_indicator_spec_table(self, goal, parsed_args):
|
||||
out = six.StringIO()
|
||||
efficacy_specification = goal.efficacy_specification
|
||||
fields = ['name', 'unit']
|
||||
self.formatter.emit_list(
|
||||
column_names=list(field.capitalize()
|
||||
for field in fields),
|
||||
data=[utils.get_dict_properties(spec, fields)
|
||||
for spec in efficacy_specification],
|
||||
stdout=out,
|
||||
parsed_args=parsed_args,
|
||||
)
|
||||
return out.getvalue() or ''
|
||||
|
||||
def take_action(self, parsed_args):
|
||||
client = getattr(self.app.client_manager, "infra-optim")
|
||||
|
||||
@@ -100,5 +134,11 @@ class ListGoal(command.Lister):
|
||||
except exceptions.HTTPNotFound as ex:
|
||||
raise exceptions.CommandError(str(ex))
|
||||
|
||||
if parsed_args.formatter == 'table':
|
||||
for goal in data:
|
||||
# Update the raw efficacy specs with the formatted one
|
||||
goal.efficacy_specification = (
|
||||
self._format_indicator_spec_table(goal, parsed_args))
|
||||
|
||||
return (field_labels,
|
||||
(utils.get_item_properties(item, fields) for item in data))
|
||||
|
||||
@@ -34,28 +34,33 @@ AUDIT_TEMPLATE_SHORT_LIST_FIELD_LABELS = ['UUID', 'Name', 'Goal', 'Strategy']
|
||||
|
||||
# Audit
|
||||
AUDIT_FIELDS = ['uuid', 'created_at', 'updated_at', 'deleted_at',
|
||||
'deadline', 'state', 'type', 'audit_template_uuid',
|
||||
'audit_template_name']
|
||||
'deadline', 'state', 'audit_type', 'audit_template_uuid',
|
||||
'audit_template_name', 'parameters', 'interval']
|
||||
|
||||
AUDIT_FIELD_LABELS = ['UUID', 'Created At', 'Updated At', 'Deleted At',
|
||||
'Deadline', 'State', 'Type', 'Audit Template uuid',
|
||||
'Audit Template Name']
|
||||
'Deadline', 'State', 'Audit Type', 'Audit Template uuid',
|
||||
'Audit Template Name', 'Parameters', 'Interval']
|
||||
|
||||
AUDIT_SHORT_LIST_FIELDS = ['uuid', 'type', 'audit_template_name', 'state']
|
||||
AUDIT_SHORT_LIST_FIELDS = [
|
||||
'uuid', 'audit_type', 'audit_template_name', 'state']
|
||||
|
||||
AUDIT_SHORT_LIST_FIELD_LABELS = ['UUID', 'Type', 'Audit Template Name',
|
||||
'State']
|
||||
AUDIT_SHORT_LIST_FIELD_LABELS = [
|
||||
'UUID', 'Audit Type', 'Audit Template', 'State']
|
||||
|
||||
# Action Plan
|
||||
ACTION_PLAN_FIELDS = ['uuid', 'created_at', 'updated_at', 'deleted_at',
|
||||
'audit_uuid', 'state']
|
||||
'audit_uuid', 'state', 'efficacy_indicators',
|
||||
'global_efficacy']
|
||||
|
||||
ACTION_PLAN_FIELD_LABELS = ['UUID', 'Created At', 'Updated At', 'Deleted At',
|
||||
'Audit', 'State']
|
||||
'Audit', 'State', 'Efficacy indicators',
|
||||
'Global efficacy']
|
||||
|
||||
ACTION_PLAN_SHORT_LIST_FIELDS = ['uuid', 'audit_uuid', 'state', 'updated_at']
|
||||
ACTION_PLAN_SHORT_LIST_FIELDS = ['uuid', 'audit_uuid', 'state',
|
||||
'updated_at', 'global_efficacy']
|
||||
|
||||
ACTION_PLAN_SHORT_LIST_FIELD_LABELS = ['UUID', 'Audit', 'State', 'Updated At']
|
||||
ACTION_PLAN_SHORT_LIST_FIELD_LABELS = ['UUID', 'Audit', 'State',
|
||||
'Updated At', 'Global efficacy']
|
||||
|
||||
# Action
|
||||
ACTION_FIELDS = ['uuid', 'created_at', 'updated_at', 'deleted_at', 'next_uuid',
|
||||
@@ -73,9 +78,9 @@ ACTION_SHORT_LIST_FIELD_LABELS = ['UUID', 'Next Action', 'State',
|
||||
'Action Plan', 'Action']
|
||||
# Goals
|
||||
|
||||
GOAL_FIELDS = ['uuid', 'name', 'display_name']
|
||||
GOAL_FIELDS = ['uuid', 'name', 'display_name', 'efficacy_specification']
|
||||
|
||||
GOAL_FIELD_LABELS = ['UUID', 'Name', 'Display name']
|
||||
GOAL_FIELD_LABELS = ['UUID', 'Name', 'Display name', 'Efficacy specification']
|
||||
|
||||
GOAL_SHORT_LIST_FIELDS = ['uuid', 'name', 'display_name']
|
||||
|
||||
@@ -83,14 +88,15 @@ GOAL_SHORT_LIST_FIELD_LABELS = ['UUID', 'Name', 'Display name']
|
||||
|
||||
# Strategies
|
||||
|
||||
STRATEGY_FIELDS = ['uuid', 'name', 'display_name', 'goal_uuid']
|
||||
STRATEGY_FIELDS = ['uuid', 'name', 'display_name', 'goal_name',
|
||||
'parameters_spec']
|
||||
|
||||
STRATEGY_FIELD_LABELS = ['UUID', 'Name', 'Display name', 'Goal UUID']
|
||||
STRATEGY_FIELD_LABELS = ['UUID', 'Name', 'Display name', 'Goal',
|
||||
'Parameters spec']
|
||||
|
||||
STRATEGY_SHORT_LIST_FIELDS = ['uuid', 'name', 'display_name', 'goal_uuid']
|
||||
STRATEGY_SHORT_LIST_FIELDS = ['uuid', 'name', 'display_name', 'goal_name']
|
||||
|
||||
STRATEGY_SHORT_LIST_FIELD_LABELS = ['UUID', 'Name', 'Display name',
|
||||
'Goal UUID']
|
||||
STRATEGY_SHORT_LIST_FIELD_LABELS = ['UUID', 'Name', 'Display name', 'Goal']
|
||||
|
||||
# Metric Collector
|
||||
METRIC_COLLECTOR_FIELDS = ['uuid', 'created_at', 'updated_at', 'deleted_at',
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
import json
|
||||
from openstackclient.common import utils
|
||||
|
||||
from watcherclient._i18n import _
|
||||
@@ -35,6 +36,13 @@ class ShowStrategy(command.ShowOne):
|
||||
)
|
||||
return parser
|
||||
|
||||
def _format_spec(self, strategy):
|
||||
parameters_spec = strategy.parameters_spec.get('properties')
|
||||
if parameters_spec:
|
||||
return json.dumps(parameters_spec, indent=2)
|
||||
|
||||
return {}
|
||||
|
||||
def take_action(self, parsed_args):
|
||||
client = getattr(self.app.client_manager, "infra-optim")
|
||||
|
||||
@@ -43,6 +51,7 @@ class ShowStrategy(command.ShowOne):
|
||||
except exceptions.HTTPNotFound as exc:
|
||||
raise exceptions.CommandError(str(exc))
|
||||
|
||||
strategy.parameters_spec = self._format_spec(strategy)
|
||||
columns = res_fields.STRATEGY_FIELDS
|
||||
column_headers = res_fields.STRATEGY_FIELD_LABELS
|
||||
|
||||
|
||||
Reference in New Issue
Block a user