Skip to content

Commit 8dac190

Browse files
hemantskcaphrim007
authored andcommitted
Added dos-vis-common endpoints for analytics (#1458)
* Added dos-vis-common endpoints for analytics
1 parent 41a34a6 commit 8dac190

8 files changed

Lines changed: 351 additions & 0 deletions

File tree

f5/bigip/tm/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
from f5.bigip.resource import OrganizingCollection
2020

21+
from f5.bigip.tm.analytics import Analytics
2122
from f5.bigip.tm.asm import Asm
2223
from f5.bigip.tm.auth import Auth
2324
from f5.bigip.tm.cm import Cm
@@ -37,6 +38,7 @@ class Tm(OrganizingCollection):
3738
def __init__(self, bigip):
3839
super(Tm, self).__init__(bigip)
3940
self._meta_data['allowed_lazy_attributes'] = [
41+
Analytics,
4042
Asm,
4143
Auth,
4244
Cm,

f5/bigip/tm/analytics/__init__.py

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# coding=utf-8
2+
#
3+
# Copyright 2018 F5 Networks Inc.
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
#
17+
18+
"""BIG-IP® Application Visibility and Reporting™ (AVR®) module.
19+
20+
REST URI
21+
``http://localhost/mgmt/tm/analytics/``
22+
23+
GUI Path
24+
``Statistics --> Analytics``
25+
26+
REST Kind
27+
``tm:analytics:*``
28+
"""
29+
30+
from f5.bigip.resource import OrganizingCollection
31+
from f5.bigip.tm.analytics.dos_vis_common import Dos_Vis_Common
32+
33+
34+
class Analytics(OrganizingCollection):
35+
"""BIG-IP® Application Visibility and Reporting (AVR) organizing
36+
37+
collection.
38+
"""
39+
40+
def __init__(self, tm):
41+
super(Analytics, self).__init__(tm)
42+
self._meta_data['allowed_lazy_attributes'] = [
43+
Dos_Vis_Common,
44+
]
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
# coding=utf-8
2+
#
3+
# Copyright 2018 F5 Networks Inc.
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
#
17+
18+
""" BIG-IP® Application Visibility and Reporting™ (AVR®) DoS Visibility sub-module.
19+
20+
REST URI
21+
``http://localhost/mgmt/tm/analytics/dos-vis-common/``
22+
23+
GUI Path
24+
``Security --> Reporting --> DoS``
25+
26+
REST Kind
27+
``tm:analytics:dos-vis-common:``
28+
"""
29+
from f5.bigip.resource import AsmResource as AvrResource
30+
from f5.bigip.resource import Collection
31+
from f5.bigip.resource import OrganizingCollection
32+
from f5.sdk_exception import UnsupportedOperation
33+
34+
35+
class Dos_Vis_Common(OrganizingCollection):
36+
"""BIG-IP® AVR DoS Visibility organizing collection."""
37+
def __init__(self, analytics):
38+
super(Dos_Vis_Common, self).__init__(analytics)
39+
self._meta_data['object_has_stats'] = False
40+
self._meta_data['allowed_lazy_attributes'] = [
41+
Generate_Reports,
42+
Report_Results_s,
43+
]
44+
45+
46+
class Generate_Reports(Collection):
47+
"""BIG-IP® AVR Generate Report Collection."""
48+
def __init__(self, dos_vis_common):
49+
super(Generate_Reports, self).__init__(dos_vis_common)
50+
self._meta_data['object_has_stats'] = False
51+
self._meta_data['allowed_lazy_attributes'] = [Generate_Report]
52+
self._meta_data['attribute_registry'] = {
53+
'tm:analytics:dos-vis-common:generate-report:avrgeneratereporttaskitemstate': Generate_Report}
54+
55+
56+
class Generate_Report(AvrResource):
57+
"""BIG-IP® AVR Generate Report Resource."""
58+
def __init__(self, generate_reports):
59+
super(Generate_Report, self).__init__(generate_reports)
60+
self._meta_data['required_json_kind'] =\
61+
'tm:analytics:dos-vis-common:generate-report:avrgeneratereporttaskitemstate'
62+
self._meta_data['required_creation_parameters'] = {'viewDimensions',
63+
'reportFeatures',
64+
}
65+
66+
def modify(self, **kwargs):
67+
"""Modify is not supported for Generate Report resource
68+
69+
:raises: UnsupportedOperation
70+
"""
71+
raise UnsupportedOperation(
72+
"%s does not support the modify method" % self.__class__.__name__
73+
)
74+
75+
76+
class Report_Results_s(Collection):
77+
"""BIG-IP® AVR Report Results Collection."""
78+
def __init__(self, dos_vis_common):
79+
super(Report_Results_s, self).__init__(dos_vis_common)
80+
self._meta_data['object_has_stats'] = False
81+
self._meta_data['allowed_lazy_attributes'] = [Report_Results]
82+
self._meta_data['attribute_registry'] = {
83+
'tm:analytics:dos-vis-common:report-results:avrreportresultitemstate':
84+
Report_Results}
85+
86+
87+
class Report_Results(AvrResource):
88+
"""BIG-IP® AVR Report Results Resource."""
89+
def __init__(self, report_results_s):
90+
super(Report_Results, self).__init__(report_results_s)
91+
self._meta_data['required_json_kind'] =\
92+
'tm:analytics:dos-vis-common:report-results:avrreportresultitemstate'
93+
94+
def create(self, **kwargs):
95+
"""Create is not supported for Report Results resource
96+
97+
:raises: UnsupportedOperation
98+
"""
99+
raise UnsupportedOperation(
100+
"%s does not support the create method" % self.__class__.__name__
101+
)
102+
103+
def modify(self, **kwargs):
104+
"""Modify is not supported for Report Results resource
105+
106+
:raises: UnsupportedOperation
107+
"""
108+
raise UnsupportedOperation(
109+
"%s does not support the modify method" % self.__class__.__name__
110+
)

f5/bigip/tm/analytics/test/__init__.py

Whitespace-only changes.

f5/bigip/tm/analytics/test/functional/__init__.py

Whitespace-only changes.
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
# Copyright 2018 F5 Networks Inc.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
#
15+
16+
import pytest
17+
import time
18+
19+
from distutils.version import LooseVersion
20+
from f5.bigip.tm.analytics.dos_vis_common import Generate_Report
21+
from f5.bigip.tm.analytics.dos_vis_common import Report_Results
22+
23+
24+
@pytest.fixture(scope='function')
25+
def generate_report(mgmt_root):
26+
task = mgmt_root.tm.analytics.dos_vis_common.generate_reports.generate_report.create(
27+
reportFeatures=['entities-count'],
28+
viewDimensions=[{'dimensionName': 'dos-profile'}],
29+
)
30+
while True:
31+
task.refresh()
32+
if task.status in ['FINISHED', 'FAILURE']:
33+
break
34+
time.sleep(1)
35+
yield task
36+
task.delete()
37+
38+
39+
@pytest.fixture(scope='function')
40+
def get_reports(mgmt_root):
41+
task = mgmt_root.tm.analytics.dos_vis_common.generate_reports.load()
42+
while True:
43+
task.refresh()
44+
if task.status in ['FINISHED', 'FAILURE']:
45+
break
46+
time.sleep(1)
47+
yield task
48+
task.delete()
49+
50+
51+
@pytest.mark.skipif(
52+
LooseVersion(pytest.config.getoption('--release')) < LooseVersion('13.1.0'),
53+
reason='Generating a report returns an unexpected error in 13.0.0.'
54+
)
55+
class TestGenerateReport(object):
56+
def test_create_rep_arg(self, generate_report):
57+
rep1 = generate_report
58+
endpoint = str(rep1.id)
59+
base_uri = 'https://localhost/mgmt/tm/analytics/dos-vis-common/generate-report/'
60+
final_uri = base_uri + endpoint
61+
assert rep1.selfLink.startswith(final_uri)
62+
assert rep1.kind == 'tm:analytics:dos-vis-common:generate-report:avrgeneratereporttaskitemstate'
63+
64+
65+
@pytest.mark.skipif(
66+
LooseVersion(pytest.config.getoption('--release')) < LooseVersion('13.1.0'),
67+
reason='Generating a report returns an unexpected error in 13.0.0.'
68+
)
69+
class TestGenerateReportCollection(object):
70+
def test_collection_gen_rep(self, generate_report, mgmt_root):
71+
rep1 = generate_report
72+
reports = mgmt_root.tm.analytics.dos_vis_common.generate_reports.get_collection()
73+
assert isinstance(reports[0], Generate_Report)
74+
assert rep1.id in [report.id for report in reports]
75+
76+
77+
@pytest.mark.skipif(
78+
LooseVersion(pytest.config.getoption('--release')) < LooseVersion('13.1.0'),
79+
reason='Generating a report returns an unexpected error in 13.0.0.'
80+
)
81+
class TestReportResults(object):
82+
def test_create_rep(self, generate_report, mgmt_root):
83+
rep = generate_report
84+
result_id = rep.reportResultsLink.split('/')[-1]
85+
result = mgmt_root.tm.analytics.dos_vis_common.report_results_s.report_results.load(id=result_id)
86+
assert result.kind == 'tm:analytics:dos-vis-common:report-results:avrreportresultitemstate'
87+
88+
89+
@pytest.mark.skipif(
90+
LooseVersion(pytest.config.getoption('--release')) < LooseVersion('13.1.0'),
91+
reason='Generating a report returns an unexpected error in 13.0.0.'
92+
)
93+
class TestReportResultsCollection(object):
94+
def test_collection_rep_res(self, generate_report, mgmt_root):
95+
rep = generate_report
96+
result_id = rep.reportResultsLink.split('/')[-1]
97+
results = mgmt_root.tm.analytics.dos_vis_common.report_results_s.get_collection()
98+
assert isinstance(results[0], Report_Results)
99+
assert result_id in [result.id for result in results]

f5/bigip/tm/analytics/test/unit/__init__.py

Whitespace-only changes.
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
# Copyright 2018 F5 Networks Inc.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
#
15+
16+
from f5.bigip import ManagementRoot
17+
from f5.bigip.resource import OrganizingCollection
18+
from f5.bigip.tm.analytics.dos_vis_common import Generate_Report
19+
from f5.bigip.tm.analytics.dos_vis_common import Report_Results
20+
from f5.sdk_exception import MissingRequiredCreationParameter
21+
from f5.sdk_exception import UnsupportedOperation
22+
23+
24+
import mock
25+
import pytest
26+
from six import iterkeys
27+
28+
29+
@pytest.fixture
30+
def FakeGenerateReport():
31+
fake_analytics = mock.MagicMock()
32+
fake_genrep = Generate_Report(fake_analytics)
33+
fake_genrep._meta_data['bigip'].tmos_version = '13.1.0'
34+
return fake_genrep
35+
36+
37+
@pytest.fixture
38+
def FakeReportResults():
39+
fake_analytics = mock.MagicMock()
40+
fake_repres = Report_Results(fake_analytics)
41+
return fake_repres
42+
43+
44+
class TestDosVisCommonOC(object):
45+
def test_collection(self, fakeicontrolsession):
46+
b = ManagementRoot('192.168.1.1', 'admin', 'admin')
47+
t1 = b.tm.analytics.dos_vis_common
48+
assert isinstance(t1, OrganizingCollection)
49+
assert hasattr(t1, 'generate_reports')
50+
assert hasattr(t1, 'report_results_s')
51+
52+
53+
class TestGenerateReport(object):
54+
def test_modify_raises(self, FakeGenerateReport):
55+
with pytest.raises(UnsupportedOperation):
56+
FakeGenerateReport.modify()
57+
58+
def test_create_no_args(self, FakeGenerateReport):
59+
with pytest.raises(MissingRequiredCreationParameter):
60+
FakeGenerateReport.create()
61+
62+
def test_create_two(self, fakeicontrolsession):
63+
b = ManagementRoot('192.168.1.1', 'admin', 'admin')
64+
t1 = b.tm.analytics.dos_vis_common.generate_reports.generate_report
65+
t2 = b.tm.analytics.dos_vis_common.generate_reports.generate_report
66+
assert t1 is t2
67+
68+
def test_collection(self, fakeicontrolsession):
69+
b = ManagementRoot('192.168.1.1', 'admin', 'admin')
70+
t = b.tm.analytics.dos_vis_common.generate_reports
71+
test_meta = t._meta_data['attribute_registry']
72+
test_meta2 = t._meta_data['allowed_lazy_attributes']
73+
kind = 'tm:analytics:dos-vis-common:generate-report:avrgeneratereporttaskitemstate'
74+
assert kind in list(iterkeys(test_meta))
75+
assert Generate_Report in test_meta2
76+
assert t._meta_data['object_has_stats'] is False
77+
78+
79+
class TestReportResults(object):
80+
def test_create_raises(self, FakeReportResults):
81+
with pytest.raises(UnsupportedOperation):
82+
FakeReportResults.create()
83+
84+
def test_modify_raises(self, FakeReportResults):
85+
with pytest.raises(UnsupportedOperation):
86+
FakeReportResults.modify()
87+
88+
def test_collection(self, fakeicontrolsession):
89+
b = ManagementRoot('192.168.1.1', 'admin', 'admin')
90+
t = b.tm.analytics.dos_vis_common.report_results_s
91+
test_meta = t._meta_data['attribute_registry']
92+
test_meta2 = t._meta_data['allowed_lazy_attributes']
93+
kind = 'tm:analytics:dos-vis-common:report-results:avrreportresultitemstate'
94+
assert kind in list(iterkeys(test_meta))
95+
assert Report_Results in test_meta2
96+
assert t._meta_data['object_has_stats'] is False

0 commit comments

Comments
 (0)