Skip to content

Commit da8071d

Browse files
committed
First draft of collection and OC registration.
1 parent 7326b2b commit da8071d

1 file changed

Lines changed: 40 additions & 0 deletions

File tree

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
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+
17+
def register_collection_atoms(collection):
18+
'''Given a collection return a registry of all of its atoms (elements).
19+
20+
Registries are dictionaries with selfLink keys, and PathElement values.
21+
A registry provides a snapshot of all resources of a type on the device.
22+
'''
23+
resource_registry = {}
24+
for resource in collection.get_collection():
25+
resource_registry[resource.selfLink] = resource
26+
return resource_registry
27+
28+
29+
def register_OC_atoms(organizing_collection):
30+
'''Given an OrganizingCollection (OC) return a registry of its atoms.
31+
32+
Registries are dictionaries with selfLink keys, and PathElement values.
33+
A registry provides a snapshot of all resources of a type on the device.
34+
'''
35+
OC_atoms_registry = {}
36+
OC_types = organizing_collection._meta_data['allowed_lazy_attributes']
37+
for OC_type in OC_types:
38+
collection = getattr(organizing_collection, OC_type.__name__.lower())
39+
OC_atoms_registry.update(register_collection_atoms(collection))
40+
return OC_atoms_registry

0 commit comments

Comments
 (0)