~vishvananda/nova/network-refactor

« back to all changes in this revision

Viewing changes to nova/network/model.py

  • Committer: Vishvananda Ishaya
  • Date: 2010-08-09 22:34:05 UTC
  • Revision ID: vishvananda@gmail.com-20100809223405-3mtbs0l0rjnsxrn4
initial cleanup of tests for network

Show diffs side-by-side

added added

removed removed

Lines of Context:
141
141
 
142
142
class BaseNetwork(datastore.BasicModel):
143
143
    override_type = 'network'
144
 
    NUM_STATIC_IPS = 3 # Network, Gateway, and CloudPipe
145
144
 
146
145
    @property
147
146
    def identifier(self):
215
214
 
216
215
    @property
217
216
    def available(self):
218
 
        # the .2 address is always CloudPipe
219
 
        # and the top <n> are for vpn clients
220
 
        for idx in range(self.num_static_ips, len(self.network)-(1 + FLAGS.cnt_vpn_clients)):
 
217
        for idx in range(self.num_bottom_reserved_ips,
 
218
                         len(self.network) - self.num_top_reserved_ips):
221
219
            address = str(self.network[idx])
222
220
            if not address in self.hosts.keys():
223
221
                yield address
224
222
 
225
223
    @property
226
 
    def num_static_ips(self):
227
 
        return BaseNetwork.NUM_STATIC_IPS
 
224
    def num_bottom_reserved_ips(self):
 
225
        return 2 # Network, Gateway
 
226
 
 
227
    @property
 
228
    def num_top_reserved_ips(self):
 
229
        return 1 # Broadcast
228
230
 
229
231
    def allocate_ip(self, user_id, project_id, mac):
230
232
        for address in self.available:
306
308
    def __init__(self, *args, **kwargs):
307
309
        super(DHCPNetwork, self).__init__(*args, **kwargs)
308
310
        # logging.debug("Initing DHCPNetwork object...")
309
 
        self.dhcp_listen_address = self.network[1]
310
 
        self.dhcp_range_start = self.network[3]
311
 
        self.dhcp_range_end = self.network[-(1 + FLAGS.cnt_vpn_clients)]
 
311
        self.dhcp_listen_address = self.gateway
 
312
        self.dhcp_range_start = self.network[self.num_bottom_reserved_ips]
 
313
        self.dhcp_range_end = self.network[-self.num_top_reserved_ips]
312
314
        try:
313
315
            os.makedirs(FLAGS.networks_path)
314
316
        # NOTE(todd): I guess this is a lazy way to not have to check if the
318
320
        except Exception, err:
319
321
            pass
320
322
 
 
323
    @property
 
324
    def num_bottom_reserved_ips(self):
 
325
        # For cloudpipe
 
326
        return super(DHCPNetwork, self).num_bottom_reserved_ips + 1
 
327
 
 
328
    @property
 
329
    def num_top_reserved_ips(self):
 
330
        return super(DHCPNetwork, self).num_top_reserved_ips + \
 
331
                FLAGS.cnt_vpn_clients
 
332
 
321
333
    def express(self, address=None):
322
334
        super(DHCPNetwork, self).express(address=address)
323
335
        if len(self.assigned) > 0:
389
401
        self.express()
390
402
 
391
403
    @property
392
 
    def available(self):
393
 
        for idx in range(2, len(self.network)-1):
394
 
            address = str(self.network[idx])
395
 
            if not address in self.hosts.keys():
396
 
                yield address
397
 
 
398
 
    @property
399
404
    def host_objs(self):
400
405
        for address in self.assigned:
401
406
            yield PublicAddress(address)
415
420
 
416
421
    def deallocate_ip(self, ip_str):
417
422
        # NOTE(vish): cleanup is now done on release by the parent class
418
 
        self.release_ip(ip_str)
 
423
        self.release_ip(ip_str)
419
424
 
420
425
    def associate_address(self, public_ip, private_ip, instance_id):
421
426
        if not public_ip in self.assigned: