Statistics
| Branch: | Tag: | Revision:

root / snf-cyclades-app / synnefo / logic / management / commands / util.py @ d7841399

History | View | Annotate | Download (1.9 kB)

1 0eed6cf8 Christos Stavrakakis
# Copyright 2012 GRNET S.A. All rights reserved.
2 0eed6cf8 Christos Stavrakakis
#
3 0eed6cf8 Christos Stavrakakis
# Redistribution and use in source and binary forms, with or
4 0eed6cf8 Christos Stavrakakis
# without modification, are permitted provided that the following
5 0eed6cf8 Christos Stavrakakis
# conditions are met:
6 0eed6cf8 Christos Stavrakakis
#
7 0eed6cf8 Christos Stavrakakis
#   1. Redistributions of source code must retain the above
8 0eed6cf8 Christos Stavrakakis
#      copyright notice, this list of conditions and the following
9 0eed6cf8 Christos Stavrakakis
#      disclaimer.
10 0eed6cf8 Christos Stavrakakis
#
11 0eed6cf8 Christos Stavrakakis
#   2. Redistributions in binary form must reproduce the above
12 0eed6cf8 Christos Stavrakakis
#      copyright notice, this list of conditions and the following
13 0eed6cf8 Christos Stavrakakis
#      disclaimer in the documentation and/or other materials
14 0eed6cf8 Christos Stavrakakis
#      provided with the distribution.
15 0eed6cf8 Christos Stavrakakis
#
16 0eed6cf8 Christos Stavrakakis
# THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS
17 0eed6cf8 Christos Stavrakakis
# OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 0eed6cf8 Christos Stavrakakis
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19 0eed6cf8 Christos Stavrakakis
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR
20 0eed6cf8 Christos Stavrakakis
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 0eed6cf8 Christos Stavrakakis
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 0eed6cf8 Christos Stavrakakis
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
23 0eed6cf8 Christos Stavrakakis
# USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
24 0eed6cf8 Christos Stavrakakis
# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 0eed6cf8 Christos Stavrakakis
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
26 0eed6cf8 Christos Stavrakakis
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27 0eed6cf8 Christos Stavrakakis
# POSSIBILITY OF SUCH DAMAGE.
28 0eed6cf8 Christos Stavrakakis
#
29 0eed6cf8 Christos Stavrakakis
# The views and conclusions contained in the software and
30 0eed6cf8 Christos Stavrakakis
# documentation are those of the authors and should not be
31 0eed6cf8 Christos Stavrakakis
# interpreted as representing official policies, either expressed
32 0eed6cf8 Christos Stavrakakis
# or implied, of GRNET S.A.
33 0eed6cf8 Christos Stavrakakis
34 0eed6cf8 Christos Stavrakakis
from synnefo.db.models import MacPrefixPoolTable, BridgePoolTable
35 0eed6cf8 Christos Stavrakakis
36 0eed6cf8 Christos Stavrakakis
37 0eed6cf8 Christos Stavrakakis
def pool_table_from_type(type_):
38 0eed6cf8 Christos Stavrakakis
    if type_ == "mac-prefix":
39 0eed6cf8 Christos Stavrakakis
        return MacPrefixPoolTable
40 0eed6cf8 Christos Stavrakakis
    elif type_ == "bridge":
41 0eed6cf8 Christos Stavrakakis
        return BridgePoolTable
42 0eed6cf8 Christos Stavrakakis
    # elif type == "ip":
43 0eed6cf8 Christos Stavrakakis
    #     return IPPoolTable
44 0eed6cf8 Christos Stavrakakis
    else:
45 0eed6cf8 Christos Stavrakakis
        raise ValueError("Invalid pool type")
46 0eed6cf8 Christos Stavrakakis
47 0eed6cf8 Christos Stavrakakis
48 0eed6cf8 Christos Stavrakakis
def pool_map_chunks(smap, step=64):
49 0eed6cf8 Christos Stavrakakis
    for i in xrange(0, len(smap), step):
50 0eed6cf8 Christos Stavrakakis
        yield smap[i:i + step]