Revision 5061546f

b/snf-cyclades-app/synnefo/api/management/commands/listnetworks.py
67 67

  
68 68
        networks = Network.objects.all()
69 69
        if options['deleted']:
70
            networks = networks.filter(state='DELETED')
70
            networks = networks.filter(deleted=True)
71 71
        else:
72
            networks = networks.exclude(state='DELETED')
72
            networks = networks.exclude(deleted=True)
73 73

  
74 74
        if options['public']:
75 75
            networks = networks.filter(public=True)
......
88 88
                      network.name,
89 89
                      network.userid or '',
90 90
                      network.state,
91
                      network.link.name,
91
                      network.link,
92 92
                      str(network.machines.count()),
93 93
                      format_bool(network.public))
94 94

  
b/snf-cyclades-app/synnefo/api/networks.py
40 40
from django.template.loader import render_to_string
41 41
from django.utils import simplejson as json
42 42

  
43
from synnefo.api import faults, util
43
from synnefo import settings
44
from synnefo.api import util
44 45
from synnefo.api.actions import network_actions
45 46
from synnefo.api.common import method_not_allowed
46 47
from synnefo.api.faults import BadRequest, OverLimit, Unauthorized
47
from synnefo.db.models import Network, NetworkLink
48
from synnefo.db.models import Network, BridgePool, MacPrefixPool
48 49
from synnefo.logic import backend
49 50

  
50 51

  
......
118 119
        if not user_networks:
119 120
            return HttpResponse(status=304)
120 121
    else:
121
        user_networks = user_networks.filter(state='ACTIVE')
122
        user_networks = user_networks.filter(deleted=False)
122 123

  
123 124
    networks = [network_to_dict(network, request.user_uniq, detail)
124 125
                for network in user_networks]
......
149 150
    try:
150 151
        d = req['network']
151 152
        name = d['name']
153
        # TODO: Fix this temp values:
154
        subnet = d.get('subnet', '192.168.1.0/24')
155
        gateway = d.get('gateway', None)
156
        type = d.get('type', 'PRIVATE_FILTERED')
157
        dhcp = d.get('dhcp', True)
152 158
    except (KeyError, ValueError):
153 159
        raise BadRequest('Malformed request.')
154 160

  
155
    count = Network.objects.filter(userid=request.user_uniq,
156
                                          state='ACTIVE').count()
157

  
158
    # get user limit
159
    networks_limit_for_user = \
160
        settings.NETWORKS_USER_QUOTA.get(request.user_uniq,
161
                settings.MAX_NETWORKS_PER_USER)
162

  
163
    if count >= networks_limit_for_user:
164
        raise faults.OverLimit("Network count limit exceeded for your account.")
165

  
166
    try:
167
        network = backend.create_network(name, request.user_uniq)
168
    except NetworkLink.NotAvailable:
169
        raise faults.OverLimit('No networks available.')
161
    link = None
162
    mac_prefix = None
163
    if type == 'PUBLIC_ROUTED':
164
        pass
165
        # raise Exception (user can not create public)
166
    if type == 'PRIVATE_FILTERED':
167
        link = BridgePool.get_available().value
168
        mac_prefix = MacPrefixPool.get_available().value
169
        state = 'PENDING'
170
    else:
171
        link = settings.GANETI_PRIVATE_BRIDGE
172
        # Physical-Vlans are pre-provisioned
173
        state = 'ACTIVE'
174

  
175
    network = Network.objects.create(
176
            name=name,
177
            userid=request.user_uniq,
178
            subnet=subnet,
179
            gateway=gateway,
180
            dhcp=dhcp,
181
            type=type,
182
            link=link,
183
            mac_prefix=mac_prefix,
184
            state=state)
185

  
186
    network = backend.create_network(network)
187
    if not network:
188
        raise OverLimit('Network count limit exceeded for your account.')
170 189

  
171 190
    networkdict = network_to_dict(network, request.user_uniq)
172 191
    return render_network(request, networkdict, status=202)
......
229 248
    net = util.get_network(network_id, request.user_uniq)
230 249
    if net.public:
231 250
        raise Unauthorized('Can not delete the public network.')
251

  
252
    net.action = 'DESTROY'
253
    net.save()
254

  
232 255
    backend.delete_network(net)
233 256
    return HttpResponse(status=204)
234 257

  
b/snf-cyclades-app/synnefo/app_settings/default/api.py
21 21
# Network Configuration
22 22
#
23 23

  
24
# Name of the public network in Ganeti. An IP pool should be associated with
25
# this network by the Ganeti administrator.
26
GANETI_PUBLIC_NETWORK = 'snf_public'
24
# Synnefo assigns this link id to NICs connected on the public network.
25
# An IP pool should be associated with this link by the Ganeti administrator.
26
GANETI_PUBLIC_NETWORK = 'snf-1'
27
GANETI_PRIVATE_BRIDGE = 'br2990'
27 28
# This link id is assigned to NICs that should be isolated from anything else
28 29
# (e.g., right before the NIC gets deleted).
29 30
# This value is also hardcoded in a fixture in db/fixtures/initial_data.json.

Also available in: Unified diff