1313# limitations under the License.
1414#
1515
16+ import logging
17+ from pprint import pprint as pp
18+
19+ from f5 .bigip .mixins import UnsupportedTmosVersion
20+ from f5 .bigip .resource import OrganizingCollection
21+ from f5 .bigip .resource import Collection
1622
1723def register_collection_atoms (collection ):
1824 '''Given a collection return a registry of all of its atoms (elements).
@@ -21,8 +27,17 @@ def register_collection_atoms(collection):
2127 A registry provides a snapshot of all resources of a type on the device.
2228 '''
2329 resource_registry = {}
24- for resource in collection .get_collection ():
25- resource_registry [resource .selfLink ] = resource
30+ try :
31+ resources = collection .get_collection ()
32+ except Exception as ex :
33+ logging .debug (ex )
34+ return resource_registry
35+ for resource in resources :
36+ try :
37+ resource_registry [resource .selfLink ] = resource
38+ except KeyError as ex :
39+ pp (resource .raw )
40+ raise ex
2641 return resource_registry
2742
2843
@@ -35,6 +50,38 @@ def register_OC_atoms(organizing_collection):
3550 OC_atoms_registry = {}
3651 OC_types = organizing_collection ._meta_data ['allowed_lazy_attributes' ]
3752 for OC_type in OC_types :
38- collection = getattr (organizing_collection , OC_type .__name__ .lower ())
39- OC_atoms_registry .update (register_collection_atoms (collection ))
53+ try :
54+ lazy_instance = \
55+ getattr (organizing_collection , OC_type .__name__ .lower ())
56+ except UnsupportedTmosVersion as ex :
57+ logging .debug (ex )
58+ continue
59+ if isinstance (lazy_instance , Collection ):
60+ OC_atoms_registry .update (register_collection_atoms (lazy_instance ))
61+ elif isinstance (lazy_instance , OrganizingCollection ):
62+ OC_atoms_registry .update (register_OC_atoms (lazy_instance ))
63+ #else:
64+ # OC_atoms_registry.update({lazy_instance.selfLink: lazy_instance})
4065 return OC_atoms_registry
66+
67+
68+ def register_loadbalancer_elements (mgmt_rt ):
69+ monitor_registry = register_OC_atoms (mgmt_rt .tm .ltm .monitor )
70+ pool_registry = register_collection_atoms (mgmt_rt .tm .ltm .pools )
71+ snat_registry = register_collection_atoms (mgmt_rt .tm .ltm .snats )
72+ virtual_registry = register_collection_atoms (mgmt_rt .tm .ltm .virtuals )
73+ virtual_address_s_registry = \
74+ register_collection_atoms (mgmt_rt .tm .ltm .virtual_address_s )
75+ member_registry = {}
76+ for pool in pool_registry .values ():
77+ mc = pool .members_s
78+ member_registry .update (reqister_collection_atoms (mc ))
79+ folder_registry = register_collection_atoms (mgmt_rt .tm .sys .folders )
80+ registries = {'monitor_registry' : monitor_registry ,
81+ 'pool_registry' : pool_registry ,
82+ 'snat_registry' : snat_registry ,
83+ 'virtual_registry' : virtual_registry ,
84+ 'virtual_address_s_registry' : virtual_address_s_registry ,
85+ 'member_registry' : member_registry ,
86+ 'folder_registry' : folder_registry }
87+ return registries
0 commit comments