74
74
'Bridge for simple network instances')
75
75
flags.DEFINE_string('flat_network_dns', '8.8.4.4',
76
76
'Dns for simple network')
77
flags.DEFINE_bool('flat_injected', True,
77
flags.DEFINE_bool('flat_injected', False,
78
78
'Whether to attempt to inject network setup into guest')
79
79
flags.DEFINE_string('flat_interface', None,
80
80
'FlatDhcp will bridge into this interface if set')
449
449
fixed_ips = kwargs.get('fixed_ips') or \
450
450
self.db.fixed_ip_get_by_instance(context, instance_id)
451
except exceptions.FixedIpNotFoundForInstance:
451
except exception.FixedIpNotFoundForInstance:
453
453
LOG.debug(_("network deallocation for instance |%s|"), instance_id,
546
549
def _allocate_mac_addresses(self, context, instance_id, networks):
547
550
"""Generates mac addresses and creates vif rows in db for them."""
548
551
for network in networks:
549
vif = {'address': self.generate_mac_address(),
552
self.add_virtual_interface(context, instance_id, network['id'])
554
def add_virtual_interface(self, context, instance_id, network_id):
555
vif = {'address': self.generate_mac_address(),
550
556
'instance_id': instance_id,
551
'network_id': network['id'],
557
'network_id': network_id,
552
558
'uuid': str(utils.gen_uuid())}
553
# try FLAG times to create a vif record with a unique mac_address
554
for i in range(FLAGS.create_unique_mac_address_attempts):
556
self.db.virtual_interface_create(context, vif)
558
except exception.VirtualInterfaceCreateException:
559
vif['address'] = self.generate_mac_address()
561
self.db.virtual_interface_delete_by_instance(context,
559
# try FLAG times to create a vif record with a unique mac_address
560
for _ in xrange(FLAGS.create_unique_mac_address_attempts):
562
return self.db.virtual_interface_create(context, vif)
563
except exception.VirtualInterfaceCreateException:
564
vif['address'] = self.generate_mac_address()
566
self.db.virtual_interface_delete_by_instance(context,
563
raise exception.VirtualInterfaceMacAddressException()
568
raise exception.VirtualInterfaceMacAddressException()
565
570
def generate_mac_address(self):
566
571
"""Generate an Ethernet MAC address."""
789
794
self._create_fixed_ips(context, network['id'])
797
def delete_network(self, context, fixed_range, require_disassociated=True):
799
network = db.network_get_by_cidr(context, fixed_range)
801
if require_disassociated and network.project_id is not None:
802
raise ValueError(_('Network must be disassociated from project %s'
803
' before delete' % network.project_id))
804
db.network_delete_safe(context, network.id)
793
807
def _bottom_reserved_ips(self): # pylint: disable=R0201
794
808
"""Number of reserved ips at the bottom of the range."""