Revision ba6ad346 snf-cyclades-app/synnefo/logic/subnets.py

b/snf-cyclades-app/synnefo/logic/subnets.py
41 41

  
42 42
from snf_django.lib import api
43 43
from snf_django.lib.api import faults
44
from synnefo.logic import utils
44 45

  
45 46
from synnefo.db.models import Subnet, Network, IPPoolTable
46 47

  
......
108 109
    else:
109 110
        validate_subnet_params(subnet=cidr, gateway=gateway)
110 111

  
111
    name = check_name_length(name)
112
    name = utils.check_name_length(name, Subnet.SUBNET_NAME_LENGTH, "Subnet "
113
                                   "name is too long")
112 114
    sub = Subnet.objects.create(name=name, network=network, cidr=cidr,
113 115
                                ipversion=ipversion, gateway=gateway,
114 116
                                dhcp=dhcp, host_routes=host_routes,
......
178 180
    if user_id != subnet.network.userid:
179 181
        raise api.faults.Unauthorized("Unauthorized operation")
180 182

  
181
    check_name_length(name)
183
    utils.check_name_length(name, Subnet.SUBNET_NAME_LENGTH, "Subnet name is "
184
                            " too long")
182 185

  
183 186
    subnet.name = name
184 187
    subnet.save()
......
207 210
                                    "network is allowed")
208 211

  
209 212

  
210
def check_name_length(name):
211
    """Check if the length of a name is within acceptable value"""
212
    if len(str(name)) > Subnet.SUBNET_NAME_LENGTH:
213
        raise api.faults.BadRequest("Subnet name too long")
214
    return name
215

  
216

  
217 213
def validate_pools(pool_list, cidr, gateway):
218 214
    """Validate IP Pools
219 215

  

Also available in: Unified diff