Revision 3e7b1de1 commissioning/highlevel/api.py

b/commissioning/highlevel/api.py
99 99
        )
100 100
        return len(entity_owner_list) == 1 # TODO: any other check here?
101 101

  
102

  
102 103
    @returns(str)
103 104
    def ensure_resources_node(self):
104 105
        """
......
120 121
        """
121 122
        Ensure that the node 'system/users' exists.
122 123
        """
123
        return self.ensure_node(HighLevelAPI.NameOfUsersNode)
124
        return self.ensure_node(NameOfUsersNode)
125

  
126

  
127
    @method_accepts(str, str)
128
    @returns(str)
129
    def normalize_child_node_name(self, child_node_name, parent_node_name):
130
        check_node_name(child_node_name)
131
        check_node_name(parent_node_name)
132
        last_part_child_node_name = self.last_part_of_node_name(child_node_name)
133
        normalized_child_node_name = '%s/%s' % (
134
            parent_node_name,
135
            last_part_child_node_name
136
        ) # recreate full node name
137
        return normalized_child_node_name
138

  
124 139

  
125 140
    @method_accepts(str)
126 141
    @returns(str)
127
    def normalize_group_name(self, group_name):
128
        check_node_name(group_name)
129
        group_name = group_name.split('/')[-1:] # collapse and keep the last part
130
        group_name = '%s/%s' % (HighLevelAPI.NameOfGroupsNode, group_name) # recreate full node name
131
        return group_name
142
    def normalize_group_node_name(self, group_node_name):
143
        return self.normalize_child_node_name(group_node_name, NameOfGroupsNode)
144

  
145

  
146
    @method_accepts(str)
147
    @returns(str)
148
    def last_part_of_node_name(self, node_name):
149
        """
150
        Collapses a full node name to its last part, that is the name after the last slash,
151
        and returns that last part.
152

  
153
        So, a name 'system/groups/foogrooop' is collapsed to 'foogrooop' and the
154
        latter is returned.
155
        """
156
        check_node_name(node_name)
157
        bottom_node_name = node_name.split('/')[-1:] # collapse and keep the last part
158
        return bottom_node_name
159

  
132 160

  
133 161
    @method_accepts(str, str)
134 162
    @returns(str)
......
136 164
        """
137 165
        Creates a new group under 'system/groups'.
138 166

  
139
        The ``group_name`` can either be a full path (e.g. 'system/groups/mygroup') or just the last part
167
        The ``group_node_name`` can either be a full path (e.g. 'system/groups/mygroup') or just the last part
140 168
        (e.g. 'mygroup'). Note that if it is the full path, then everything but the last part is ignored.
169
        You must always use the returned ``group_node_name`` as the most authoritative value instead of
170
        the one passed as a parameter.
171

  
172
        No further resource assignment is done, you must use ````.
141 173

  
142 174
        ``group_name`` - The name of the new group.
143 175
        ``group_key``  - The key (password) for the new group.
......
147 179
        """
148 180
        check_node_name(group_node_name)
149 181
        check_node_key(group_node_key)
182

  
150 183
        groups_node_name = self.ensure_groups_node()
151
        group_node_name = self.normalize_group_name(group_node_name) # We are forgiving and accept simple name
152
        created_group_name = self.qh_create_node(group_node_name, groups_node_name, group_node_key, self.__groups_key)
184

  
185
        group_node_name = self.normalize_group_node_name(group_node_name) # We are forgiving...
186
        group_node_name = self.qh_create_node(
187
            group_node_name,
188
            groups_node_name,
189
            group_node_key,
190
            self.__groups_key)
153 191
        self.set_cached_node_key(group_node_name, group_node_key)
154 192

  
155
        
193
        return group_node_name
194

  
195

  
196
    @method_accepts(str, str, int, int, int)
197
    @returns(str)
198
    def group_define_resource(self,
199
                              group_node_name,
200
                              resource_node_name,
201
                              limit_per_user,
202
                              bucket_quantity,
203
                              bucket_capacity):
204
        """
205
        Defines a resource that a group provides to its users.
206
        """
207
        check_node_name(group_node_name)
208
        check_node_name(resource_node_name)
209

  
210
        # 1. Create a definitional resource node under the group.
211
        #    This resource defines the limit per user.
212
        #    E.g. A resource named 'pithos+' gives rise to a resource/node named 'def_pithos+'
213
        last_resource_node_name = self.last_part_of_node_name(resource_node_name)
214
        def_last_resource_node_name = 'def_%s' % (last_resource_node_name,)
215
        def_resource_node_name = self.normalize_child_node_name(
216
            def_last_resource_node_name,
217
            group_node_name
218
        )
219
        if not self.qh_has_node(def_resource_node_name):
220
            def_resource_node_name = self.qh_create_node(def_resource_node_name)
221
        # TODO: make policy with the limit
222

  
223
        # 2. Create the operational resource node under the group.
224
        #    This resource is a big bucket with the operational quantity and capacity.
225
        #    Everything is put into and out of this bucket.
226

  
227

  
228

  
229

  

Also available in: Unified diff