Skip to content

Commit d371022

Browse files
authored
Merge pull request #523 from jasonrahm/feature.dg
Feature.dg
2 parents c4a0d2b + 43ae225 commit d371022

5 files changed

Lines changed: 211 additions & 0 deletions

File tree

f5/bigip/tm/ltm/__init__.py

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

3030

3131
from f5.bigip.resource import OrganizingCollection
32+
from f5.bigip.tm.ltm.data_group import Data_Group
3233
from f5.bigip.tm.ltm.monitor import Monitor
3334
from f5.bigip.tm.ltm.nat import Nats
3435
from f5.bigip.tm.ltm.node import Nodes
@@ -49,6 +50,7 @@ class Ltm(OrganizingCollection):
4950
def __init__(self, tm):
5051
super(Ltm, self).__init__(tm)
5152
self._meta_data['allowed_lazy_attributes'] = [
53+
Data_Group,
5254
Monitor,
5355
Nats,
5456
Nodes,

f5/bigip/tm/ltm/data_group.py

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
# coding=utf-8
2+
#
3+
# Copyright 2014-2016 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+
"""BIG-IP® LTM data-group submodule.
18+
19+
REST URI
20+
``http://localhost/mgmt/tm/ltm/data-group/``
21+
22+
GUI Path
23+
``Local Traffic --> iRules --> Data Group List``
24+
25+
REST Kind
26+
``tm:ltm:data-group*``
27+
"""
28+
29+
from f5.bigip.resource import Collection
30+
from f5.bigip.resource import OrganizingCollection
31+
from f5.bigip.resource import Resource
32+
33+
34+
class Data_Group(OrganizingCollection):
35+
def __init__(self, ltm):
36+
super(Data_Group, self).__init__(ltm)
37+
self._meta_data['allowed_lazy_attributes'] = [
38+
Internals,
39+
Internal,
40+
Externals,
41+
External
42+
]
43+
44+
45+
class Internals(Collection):
46+
def __init__(self, data_groups):
47+
super(Internals, self).__init__(data_groups)
48+
self._meta_data['allowed_lazy_attributes'] = [Internal]
49+
self._meta_data['required_json_kind'] = \
50+
u'tm:ltm:data-group:internal:internalcollectionstate'
51+
self._meta_data['attribute_registry'] = \
52+
{u'tm:ltm:data-group:internal:internalstate': Internal}
53+
self._meta_data['uri'] = self._meta_data['uri'].replace('_', '-')
54+
55+
56+
class Internal(Resource):
57+
def __init__(self, internals):
58+
super(Internal, self).__init__(internals)
59+
self._meta_data['required_json_kind'] = \
60+
u'tm:ltm:data-group:internal:internalstate'
61+
self._meta_data['required_creation_parameters'].update(
62+
('name', 'type', 'records')
63+
)
64+
65+
def update(self, **kwargs):
66+
if 'type' in self.__dict__:
67+
del self.__dict__['type']
68+
return self._update(**kwargs)
69+
70+
71+
class Externals(Collection):
72+
def __init__(self, data_groups):
73+
super(Externals, self).__init__(data_groups)
74+
self._meta_data['allowed_lazy_attributes'] = [External]
75+
self._meta_data['required_json_kind'] =\
76+
u'tm:ltm:data-group:external:externalcollectionstate'
77+
self._meta_data['attribute_registry'] =\
78+
{u'tm:ltm:data-group:external:externalstate': External}
79+
self._meta_data['uri'] = self._meta_data['uri'].replace('_', '-')
80+
81+
82+
class External(Resource):
83+
def __init__(self, externals):
84+
super(External, self).__init__(externals)
85+
self._meta_data['required_json_kind'] =\
86+
u'tm:ltm:data-group:external:externalstate'
87+
self._meta_data['required_creation_parameters'].update(
88+
('name', 'externalFileName')
89+
)
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
# Copyright 2015 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 mock
17+
import pytest
18+
19+
20+
from f5.bigip import ManagementRoot
21+
from f5.bigip.resource import MissingRequiredCreationParameter
22+
from f5.bigip.tm.ltm.data_group import External
23+
from f5.bigip.tm.ltm.data_group import Internal
24+
25+
26+
@pytest.fixture
27+
def FakeData_Group_Internal():
28+
fake_dg = mock.MagicMock()
29+
fake_dg = Internal(fake_dg)
30+
return fake_dg
31+
32+
33+
@pytest.fixture
34+
def FakeData_Group_External():
35+
fake_dg = mock.MagicMock()
36+
fake_dg = External(fake_dg)
37+
return fake_dg
38+
39+
40+
class TestCreate(object):
41+
def test_create_internal_two(self, fakeicontrolsession):
42+
mgmt = ManagementRoot('172.16.44.15', 'admin', 'admin')
43+
dg1 = mgmt.tm.ltm.data_group.internals.internal
44+
dg2 = mgmt.tm.ltm.data_group.internals.internal
45+
assert dg1 is not dg2
46+
47+
def test_create_external_two(self, fakeicontrolsession):
48+
mgmt = ManagementRoot('172.16.44.15', 'admin', 'admin')
49+
dg1 = mgmt.tm.ltm.data_group.externals.external
50+
dg2 = mgmt.tm.ltm.data_group.externals.external
51+
assert dg1 is not dg2
52+
53+
def test_create_internal_no_args(self, FakeData_Group_Internal):
54+
with pytest.raises(MissingRequiredCreationParameter):
55+
FakeData_Group_Internal.create()
56+
57+
def test_create_external_no_args(self, FakeData_Group_External):
58+
with pytest.raises(MissingRequiredCreationParameter):
59+
FakeData_Group_External.create()

f5/bigip/tm/sys/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
from f5.bigip.tm.sys.db import Dbs
3535
from f5.bigip.tm.sys.dns import Dns
3636
from f5.bigip.tm.sys.failover import Failover
37+
from f5.bigip.tm.sys.file import File
3738
from f5.bigip.tm.sys.folder import Folders
3839
from f5.bigip.tm.sys.global_settings import Global_Settings
3940
from f5.bigip.tm.sys.httpd import Httpd
@@ -49,6 +50,7 @@ def __init__(self, tm):
4950
self._meta_data['allowed_lazy_attributes'] = [
5051
Config,
5152
Crypto,
53+
File,
5254
Folders,
5355
Application,
5456
Performances,

f5/bigip/tm/sys/file.py

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
# coding=utf-8
2+
#
3+
# Copyright 2016 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+
"""BIG-IP® system file module
18+
19+
REST URI
20+
``http://localhost/mgmt/tm/sys/file``
21+
22+
GUI Path
23+
N/A
24+
25+
REST Kind
26+
``tm:sys:file:*``
27+
"""
28+
from f5.bigip.resource import Collection
29+
from f5.bigip.resource import OrganizingCollection
30+
from f5.bigip.resource import Resource
31+
32+
33+
class File(OrganizingCollection):
34+
def __init__(self, sys):
35+
super(File, self).__init__(sys)
36+
self._meta_data['allowed_lazy_attributes'] = [
37+
Data_Groups
38+
]
39+
40+
41+
class Data_Groups(Collection):
42+
def __init__(self, File):
43+
super(Data_Groups, self).__init__(File)
44+
self._meta_data['allowed_lazy_attributes'] = [Data_Group]
45+
self._meta_data['required_json_kind'] = \
46+
u'tm:sys:file:data-group:data-groupcollectionstate'
47+
self._meta_data['attribute_registry'] =\
48+
{u'tm:sys:file:data-group:data-groupstate': Data_Group}
49+
self._meta_data['uri'] = self._meta_data['uri'].replace('_', '-')
50+
51+
52+
class Data_Group(Resource):
53+
def __init__(self, data_groups):
54+
super(Data_Group, self).__init__(data_groups)
55+
self._meta_data['required_json_kind'] =\
56+
u'tm:sys:file:data-group:data-groupstate'
57+
self._meta_data['required_creation_parameters'].update(
58+
('name', 'sourcePath', 'type')
59+
)

0 commit comments

Comments
 (0)