Revision 6c997921 snf-pithos-app/pithos/api/management/commands/pithos-set-quota.py

b/snf-pithos-app/pithos/api/management/commands/pithos-set-quota.py
60 60
table['nodes'] = backend.node.nodes
61 61
table['versions'] = backend.node.versions
62 62
table['statistics'] = backend.node.statistics
63
table['policy'] = backend.node.policy
63 64
conn = backend.node.conn
64 65

  
65 66
def _compute_statistics(nodes):
......
90 91
            cluster=cluster))
91 92
    return statistics
92 93

  
93
def _get_verified_quota(statistics):
94
def _get_verified_quota(statistics, default_quota=0):
94 95
    """ Verify statistics and set quotaholder account quota """
95 96
    add_quota = []
96 97
    append = add_quota.append
......
109 110
            print e
110 111
            continue
111 112
        else:
113
            s = select([table['policy'].c.value])
114
            s = s.where(table['policy'].c.node == item.node)
115
            s = s.where(table['policy'].c.key == 'quota')
116
            policy = conn.execute(s).fetchone()
117
            capacity = policy.value if policy else 0
118
            if capacity:
119
                capacity -= default_quota
112 120
            append(AddQuotaPayload(
113 121
                holder=item.path,
114 122
                resource='pithos+.diskspace',
115 123
                key=ENTITY_KEY,
116 124
                quantity=db_item.size,
117
                capacity=0,
125
                capacity=capacity,
118 126
                import_limit=0,
119 127
                export_limit=0))
120 128
    return add_quota
......
138 146
            account_nodes = conn.execute(s).fetchall()
139 147
            
140 148
            # compute account statistics
141
            statistics = _compute_statistics(account_nodes)
149
            statistics = _compute_statistics(
150
                account_nodes, default_quota=backend.DEFAULT_QUOTA)
142 151

  
143 152
            # verify and send quota
144 153
            add_quota = _get_verified_quota(statistics)

Also available in: Unified diff