Revision 4e1133ab snf-cyclades-app/synnefo/api/networks.py

b/snf-cyclades-app/synnefo/api/networks.py
164 164
        req = util.get_request_dict(request)
165 165
        log.info('create_network %s', req)
166 166

  
167
        user_id = request.user_uniq
167 168
        try:
168 169
            d = req['network']
169 170
            name = d['name']
170
            # TODO: Fix this temp values:
171
            subnet = d.get('cidr', '192.168.1.0/24')
172
            subnet6 = d.get('cidr6', None)
173
            gateway = d.get('gateway', None)
174
            gateway6 = d.get('gateway6', None)
175
            flavor = d.get('type', 'MAC_FILTERED')
176
            public = d.get('public', False)
177
            dhcp = d.get('dhcp', True)
178
        except (KeyError, ValueError):
179
            raise BadRequest('Malformed request.')
180

  
171
        except KeyError:
172
            raise BadRequest("Malformed request")
173

  
174
        # Get and validate flavor. Flavors are still exposed as 'type' in the
175
        # API.
176
        flavor = d.get("type", None)
177
        if flavor is None:
178
            raise BadRequest("Missing request parameter 'type'")
179
        elif flavor not in Network.FLAVORS.keys():
180
            raise BadRequest("Invalid network type '%s'" % flavor)
181
        elif flavor not in settings.API_ENABLED_NETWORK_FLAVORS:
182
            raise Forbidden("Can not create network of type '%s'" % flavor)
183

  
184
        public = d.get("public", False)
181 185
        if public:
182
            raise Forbidden('Can not create a public network.')
186
            raise Forbidden("Can not create a public network.")
183 187

  
184
        if flavor not in Network.FLAVORS.keys():
185
            raise BadRequest("Invalid network flavors %s" % flavor)
186

  
187
        if flavor not in settings.API_ENABLED_NETWORK_FLAVORS:
188
            raise Forbidden("Can not create %s network" % flavor)
188
        dhcp = d.get('dhcp', True)
189 189

  
190
        # Get and validate network parameters
191
        subnet = d.get('cidr', '192.168.1.0/24')
192
        subnet6 = d.get('cidr6', None)
193
        gateway = d.get('gateway', None)
194
        gateway6 = d.get('gateway6', None)
190 195
        # Check that user provided a valid subnet
191 196
        util.validate_network_params(subnet, gateway, subnet6, gateway6)
192 197

  
193
        user_id = request.user_uniq
198
        # Issue commission
194 199
        serial = quotas.issue_network_commission(user_id)
195 200
        serials.append(serial)
196 201
        # Make the commission accepted, since in the end of this

Also available in: Unified diff