Permalink
Browse files

updates handling of arguments in nova-manage network create.

updates a few of the arguments to nova-manage and related help.
updates nova-manage to raise proper exceptions.

updates network manager create_networks to handle ipv6 more correctly and efficiently.

flat_network_bridge FLAG now defaults to None.


bug810563
changes mirrored in a merge prop to trunk
  • Loading branch information...
tr3buchet authored and Tarmac committed Jul 27, 2011
2 parents 059ffd4 + dcae630 commit adbb5d680c93f3ee9738ce6d23bf7c4cd133a981
Showing with 87 additions and 56 deletions.
  1. +71 −47 bin/nova-manage
  2. +4 −0 nova/exception.py
  3. +10 −8 nova/network/manager.py
  4. +1 −0 nova/tests/fake_flags.py
  5. +1 −1 nova/virt/libvirt/vif.py
View
@@ -631,40 +631,75 @@ class NetworkCommands(object):
"""Class for managing networks."""
@args('--label', dest="label", metavar='<label>',
- help='Label(ex: public)')
- @args('--network', dest="fixed_range", metavar='<x.x.x.x/yy>',
- help='Network')
+ help='Label for network (ex: public)')
+ @args('--fixed_range_v4', dest="fixed_range_v4", metavar='<x.x.x.x/yy>',
+ help='IPv4 subnet (ex: 10.0.0.0/8)')
@args('--num_networks', dest="num_networks", metavar='<number>',
- help='How many networks create')
+ help='Number of networks to create')
@args('--network_size', dest="network_size", metavar='<number>',
- help='How many hosts in network')
+ help='Number of IPs per network')
@args('--vlan', dest="vlan_start", metavar='<vlan id>', help='vlan id')
@args('--vpn', dest="vpn_start", help='vpn start')
- @args('--fixed_range_v6', dest="fixed_range_v6", help='fixed ipv6 range')
+ @args('--fixed_range_v6', dest="fixed_range_v6",
+ help='IPv6 subnet (ex: fe80::/64')
@args('--gateway_v6', dest="gateway_v6", help='ipv6 gateway')
- @args('--flat_network_bridge', dest="flat_network_bridge",
- metavar='<flat network bridge>', help='Flat_network_bridge')
+ @args('--bridge', dest="bridge",
+ metavar='<bridge>',
+ help='VIFs on this network are connected to this bridge')
@args('--bridge_interface', dest="bridge_interface",
- metavar='<bridge interface>', help='Bridge_interface')
+ metavar='<bridge interface>',
+ help='the bridge is connected to this interface')
@args('--multi_host', dest="multi_host", metavar="<'T'|'F'>",
help='Multi host')
@args('--dns1', dest="dns1", metavar="<DNS Address>", help='First DNS')
@args('--dns2', dest="dns2", metavar="<DNS Address>", help='Second DNS')
- def create(self, label=None, fixed_range=None, num_networks=None,
+ def create(self, label=None, fixed_range_v4=None, num_networks=None,
network_size=None, multi_host=None, vlan_start=None,
vpn_start=None, fixed_range_v6=None, gateway_v6=None,
- flat_network_bridge=None, bridge_interface=None,
- dns1=None, dns2=None):
+ bridge=None, bridge_interface=None, dns1=None, dns2=None):
"""Creates fixed ips for host by range"""
+
+ # check for certain required inputs
if not label:
- msg = _('a label (ex: public) is required to create networks.')
- print msg
- raise TypeError(msg)
- if not fixed_range:
- msg = _('Fixed range in the form of 10.0.0.0/8 is '
- 'required to create networks.')
- print msg
- raise TypeError(msg)
+ raise exception.NetworkNotCreated(req='--label')
+ if not fixed_range_v4:
+ raise exception.NetworkNotCreated(req='--fixed_range_v4')
+
+ bridge = bridge or FLAGS.flat_network_bridge
+ if not bridge:
+ bridge_required = ['nova.network.manager.FlatManager',
+ 'nova.network.manager.FlatDHCPManager']
+ if FLAGS.network_manager in bridge_required:
+ # TODO(tr3buchet) - swap print statement and following line for
+ # raise statement in diablo 4
+ print _('--bridge parameter required or FLAG '
+ 'flat_network_bridge must be set to create networks\n'
+ 'WARNING! ACHTUNG! Setting the bridge to br100 '
+ 'automatically is deprecated and will be removed in '
+ 'Diablo milestone 4. Prepare yourself accordingly.')
+ time.sleep(10)
+ bridge = 'br100'
+ #raise exception.NetworkNotCreated(req='--bridge')
+
+ bridge_interface = bridge_interface or FLAGS.flat_interface or \
+ FLAGS.vlan_interface
+ if not bridge_interface:
+ interface_required = ['nova.network.manager.FlatDHCPManager',
+ 'nova.network.manager.VlanManager']
+ if FLAGS.network_manager in interface_required:
+ raise exception.NetworkNotCreated(req='--bridge_interface')
+
+ if FLAGS.use_ipv6:
+ fixed_range_v6 = fixed_range_v6 or FLAGS.fixed_range_v6
+ if not fixed_range_v6:
+ raise exception.NetworkNotCreated(req='with use_ipv6, '
+ '--fixed_range_v6')
+ gateway_v6 = gateway_v6 or FLAGS.gateway_v6
+ if not gateway_v6:
+ raise exception.NetworkNotCreated(req='with use_ipv6, '
+ '--gateway_v6')
+
+ # sanitize other input using FLAGS if necessary
if not num_networks:
num_networks = FLAGS.num_networks
if not network_size:
@@ -677,36 +712,25 @@ class NetworkCommands(object):
vlan_start = FLAGS.vlan_start
if not vpn_start:
vpn_start = FLAGS.vpn_start
- if not fixed_range_v6:
- fixed_range_v6 = FLAGS.fixed_range_v6
- if not flat_network_bridge:
- flat_network_bridge = FLAGS.flat_network_bridge
- if not bridge_interface:
- bridge_interface = FLAGS.flat_interface or FLAGS.vlan_interface
- if not gateway_v6:
- gateway_v6 = FLAGS.gateway_v6
if not dns1 and FLAGS.flat_network_dns:
dns1 = FLAGS.flat_network_dns
- net_manager = utils.import_object(FLAGS.network_manager)
- try:
- net_manager.create_networks(context.get_admin_context(),
- label=label,
- cidr=fixed_range,
- multi_host=multi_host,
- num_networks=int(num_networks),
- network_size=int(network_size),
- vlan_start=int(vlan_start),
- vpn_start=int(vpn_start),
- cidr_v6=fixed_range_v6,
- gateway_v6=gateway_v6,
- bridge=flat_network_bridge,
- bridge_interface=bridge_interface,
- dns1=dns1,
- dns2=dns2)
- except ValueError, e:
- print e
- raise e
+ # create the network
+ net_manager = utils.import_object(FLAGS.network_manager)
+ net_manager.create_networks(context.get_admin_context(),
+ label=label,
+ cidr=fixed_range_v4,
+ multi_host=multi_host,
+ num_networks=int(num_networks),
+ network_size=int(network_size),
+ vlan_start=int(vlan_start),
+ vpn_start=int(vpn_start),
+ cidr_v6=fixed_range_v6,
+ gateway_v6=gateway_v6,
+ bridge=bridge,
+ bridge_interface=bridge_interface,
+ dns1=dns1,
+ dns2=dns2)
def list(self):
"""List all created networks"""
View
@@ -373,6 +373,10 @@ class StorageRepositoryNotFound(NotFound):
message = _("Cannot find SR to read/write VDI.")
+class NetworkNotCreated(NovaException):
+ message = _("%(req)s is required to create a network.")
+
+
class NetworkNotFound(NotFound):
message = _("Network %(network_id)s could not be found.")
View
@@ -68,7 +68,7 @@
FLAGS = flags.FLAGS
-flags.DEFINE_string('flat_network_bridge', 'br100',
+flags.DEFINE_string('flat_network_bridge', None,
'Bridge for simple network instances')
flags.DEFINE_string('flat_network_dns', '8.8.4.4',
'Dns for simple network')
@@ -614,12 +614,13 @@ def create_networks(self, context, label, cidr, multi_host, num_networks,
bridge_interface, dns1=None, dns2=None, **kwargs):
"""Create networks based on parameters."""
fixed_net = netaddr.IPNetwork(cidr)
- fixed_net_v6 = netaddr.IPNetwork(cidr_v6)
- significant_bits_v6 = 64
- network_size_v6 = 1 << 64
+ if FLAGS.use_ipv6:
+ fixed_net_v6 = netaddr.IPNetwork(cidr_v6)
+ significant_bits_v6 = 64
+ network_size_v6 = 1 << 64
+
for index in range(num_networks):
start = index * network_size
- start_v6 = index * network_size_v6
significant_bits = 32 - int(math.log(network_size, 2))
cidr = '%s/%s' % (fixed_net[start], significant_bits)
project_net = netaddr.IPNetwork(cidr)
@@ -640,6 +641,7 @@ def create_networks(self, context, label, cidr, multi_host, num_networks,
net['label'] = label
if FLAGS.use_ipv6:
+ start_v6 = index * network_size_v6
cidr_v6 = '%s/%s' % (fixed_net_v6[start_v6],
significant_bits_v6)
net['cidr_v6'] = cidr_v6
@@ -720,9 +722,9 @@ class FlatManager(NetworkManager):
"""Basic network where no vlans are used.
FlatManager does not do any bridge or vlan creation. The user is
- responsible for setting up whatever bridge is specified in
- flat_network_bridge (br100 by default). This bridge needs to be created
- on all compute hosts.
+ responsible for setting up whatever bridges are specified when creating
+ networks through nova-manage. This bridge needs to be created on all
+ compute hosts.
The idea is to create a single network for the host with a command like:
nova-manage network create 192.168.0.0/24 1 256. Creating multiple
View
@@ -42,3 +42,4 @@
FLAGS['verbose'].SetDefault(True)
FLAGS['sqlite_db'].SetDefault("tests.sqlite")
FLAGS['use_ipv6'].SetDefault(True)
+FLAGS['flat_network_bridge'].SetDefault('br100')
View
@@ -126,7 +126,7 @@ def unplug(self, instance, network, mapping):
dev = "tap-%s" % vif_id
try:
utils.execute('sudo', 'ovs-vsctl', 'del-port',
- FLAGS.flat_network_bridge, dev)
+ network['bridge'], dev)
utils.execute('sudo', 'ip', 'link', 'delete', dev)
except:
LOG.warning(_("Failed while unplugging vif of instance '%s'"),

0 comments on commit adbb5d6

Please sign in to comment.