Skip to content

Commit c4de3ac

Browse files
authored
Merge pull request #510 from zancas/registry_tools
Registry tools
2 parents 7326b2b + d3430bd commit c4de3ac

6 files changed

Lines changed: 104 additions & 5 deletions

File tree

f5/bigip/tm/cm/device_group.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ def __init__(self, cm):
3737
super(Device_Groups, self).__init__(cm)
3838
self._meta_data['allowed_lazy_attributes'] = [Device_Group]
3939
self._meta_data['attribute_registry'] =\
40-
{'tm:cm:device:device-groupstate': Device_Group}
40+
{'tm:cm:device-group:device-groupstate': Device_Group}
4141

4242

4343
class Device_Group(Resource):

f5/bigip/tm/ltm/persistence.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,11 @@
2929

3030

3131
from f5.bigip.resource import Collection
32+
from f5.bigip.resource import OrganizingCollection
3233
from f5.bigip.resource import Resource
3334

3435

35-
class Persistences(Collection):
36+
class Persistences(OrganizingCollection):
3637
'''A Collection concrete subclass docstring.'''
3738
def __init__(self, ltm):
3839
'''Auto generated constructor.'''

f5/bigip/tm/net/fdb.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,11 @@
2929

3030

3131
from f5.bigip.resource import Collection
32+
from f5.bigip.resource import OrganizingCollection
3233
from f5.bigip.resource import Resource
3334

3435

35-
class Fdbs(Collection):
36+
class Fdbs(OrganizingCollection):
3637
'''A Collection concrete subclass docstring.'''
3738
def __init__(self, net):
3839
'''Auto generated constructor.'''

f5/bigip/tm/net/tunnels.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,11 @@
2828
"""
2929

3030
from f5.bigip.resource import Collection
31+
from f5.bigip.resource import OrganizingCollection
3132
from f5.bigip.resource import Resource
3233

3334

34-
class Tunnels_s(Collection):
35+
class Tunnels_s(OrganizingCollection):
3536
"""BIG-IP® network tunnels collection"""
3637
def __init__(self, net):
3738
super(Tunnels_s, self).__init__(net)

f5/bigip/tm/sys/application.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,13 @@
2929

3030
from f5.bigip.resource import Collection
3131
from f5.bigip.resource import KindTypeMismatch
32+
from f5.bigip.resource import OrganizingCollection
3233
from f5.bigip.resource import Resource
3334

3435
from requests import HTTPError
3536

3637

37-
class Applications(Collection):
38+
class Applications(OrganizingCollection):
3839
"""BIG-IP® iApp collection."""
3940
def __init__(self, sys):
4041
super(Applications, self).__init__(sys)
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
# Copyright 2016 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 logging
17+
from pprint import pprint as pp
18+
19+
from f5.bigip.mixins import UnsupportedTmosVersion
20+
from f5.bigip.resource import Collection
21+
from f5.bigip.resource import OrganizingCollection
22+
23+
24+
def register_collection_atoms(collection):
25+
'''Given a collection return a registry of all of its atoms (elements).
26+
27+
Registries are dictionaries with selfLink keys, and PathElement values.
28+
A registry provides a snapshot of all resources of a type on the device.
29+
'''
30+
resource_registry = {}
31+
try:
32+
resources = collection.get_collection()
33+
except Exception as ex:
34+
logging.debug(ex)
35+
return resource_registry
36+
for resource in resources:
37+
try:
38+
resource_registry[resource.selfLink] = resource
39+
except KeyError as ex:
40+
pp(resource.raw)
41+
raise ex
42+
return resource_registry
43+
44+
45+
def register_OC_atoms(organizing_collection):
46+
'''Given an OrganizingCollection (OC) return a registry of its atoms.
47+
48+
Registries are dictionaries with selfLink keys, and PathElement values.
49+
A registry provides a snapshot of all resources of a type on the device.
50+
'''
51+
OC_atoms_registry = {}
52+
OC_types = organizing_collection._meta_data['allowed_lazy_attributes']
53+
for OC_type in OC_types:
54+
try:
55+
lazy_instance =\
56+
getattr(organizing_collection, OC_type.__name__.lower())
57+
except UnsupportedTmosVersion as ex:
58+
logging.debug(ex)
59+
continue
60+
if isinstance(lazy_instance, Collection):
61+
OC_atoms_registry.update(register_collection_atoms(lazy_instance))
62+
elif isinstance(lazy_instance, OrganizingCollection):
63+
OC_atoms_registry.update(register_OC_atoms(lazy_instance))
64+
return OC_atoms_registry
65+
66+
67+
def register_device(mgmt_rt):
68+
OCs = [getattr(mgmt_rt, c.__name__.lower())
69+
for c in mgmt_rt._meta_data['allowed_lazy_attributes']]
70+
grand_registry = {}
71+
for OC in OCs:
72+
grand_registry.update(register_OC_atoms(OC))
73+
return grand_registry
74+
75+
76+
def register_loadbalancer_elements(mgmt_rt):
77+
monitor_registry = register_OC_atoms(mgmt_rt.tm.ltm.monitor)
78+
pool_registry = register_collection_atoms(mgmt_rt.tm.ltm.pools)
79+
snat_registry = register_collection_atoms(mgmt_rt.tm.ltm.snats)
80+
virtual_registry = register_collection_atoms(mgmt_rt.tm.ltm.virtuals)
81+
virtual_address_s_registry =\
82+
register_collection_atoms(mgmt_rt.tm.ltm.virtual_address_s)
83+
member_registry = {}
84+
for pool in pool_registry.values():
85+
mc = pool.members_s
86+
member_registry.update(register_collection_atoms(mc))
87+
folder_registry = register_collection_atoms(mgmt_rt.tm.sys.folders)
88+
registries = {'monitor_registry': monitor_registry,
89+
'pool_registry': pool_registry,
90+
'snat_registry': snat_registry,
91+
'virtual_registry': virtual_registry,
92+
'virtual_address_s_registry': virtual_address_s_registry,
93+
'member_registry': member_registry,
94+
'folder_registry': folder_registry}
95+
return registries

0 commit comments

Comments
 (0)