diff options
| author | Vishvananda Ishaya <vishvananda@gmail.com> | 2010-07-02 10:39:04 -0500 |
|---|---|---|
| committer | Vishvananda Ishaya <vishvananda@gmail.com> | 2010-07-02 10:39:04 -0500 |
| commit | 95e7571a597abdafc638747e2d28c725df96bb17 (patch) | |
| tree | 6fc597b56993c07fd2003f75373c64855fa87d7b | |
| parent | f8a19693b5d4172ce3207c63acf0209ed8b3d636 (diff) | |
Simple Network avoids vlans
| -rw-r--r-- | nova/compute/network.py | 21 | ||||
| -rw-r--r-- | nova/compute/node.py | 9 | ||||
| -rw-r--r-- | nova/endpoint/cloud.py | 24 |
3 files changed, 44 insertions, 10 deletions
diff --git a/nova/compute/network.py b/nova/compute/network.py index 2de8bea4d..ce156967e 100644 --- a/nova/compute/network.py +++ b/nova/compute/network.py @@ -58,6 +58,13 @@ flags.DEFINE_integer('cnt_vpn_clients', 5, flags.DEFINE_integer('cloudpipe_start_port', 12000, 'Starting port for mapped CloudPipe external ports') +flags.DEFINE_boolean('simple_network', False, + 'Use simple networking instead of vlans') +flags.DEFINE_string('simple_network_bridge', 'br100', + 'Bridge for instances') +flags.DEFINE_list('simple_network_ips', ['192.168.1.1'], + 'Available ips for network') + logging.getLogger().setLevel(logging.DEBUG) # CLEANUP: @@ -418,6 +425,20 @@ def get_network_by_address(address): return net raise exception.AddressNotAllocated() +def allocate_simple_ip(): + redis = datastore.Redis.instance() + if not redis.exists('ips') and not len(redis.keys('instances:*')): + for address in FLAGS.simple_network_ips: + redis.sadd('ips', address) + address = redis.spop('ips') + if not address: + raise exception.NoMoreAddresses() + return address + +def deallocate_simple_ip(address): + datastore.Redis.instance().sadd('ips', address) + + def allocate_vpn_ip(user_id, project_id, mac): return get_project_network(project_id).allocate_vpn_ip(mac) diff --git a/nova/compute/node.py b/nova/compute/node.py index 65eb4bf3e..1b4714d67 100644 --- a/nova/compute/node.py +++ b/nova/compute/node.py @@ -57,7 +57,7 @@ from nova.objectstore import image # for image_path flag FLAGS = flags.FLAGS flags.DEFINE_string('libvirt_xml_template', utils.abspath('compute/libvirt.xml.template'), - 'Network XML Template') + 'Libvirt XML Template') flags.DEFINE_bool('use_s3', True, 'whether to get images from s3 or use local copy') flags.DEFINE_string('instances_path', utils.abspath('../instances'), @@ -151,9 +151,10 @@ class Node(object, service.Service): """ launch a new instance with specified options """ logging.debug("Starting instance %s..." % (instance_id)) inst = self.instdir.get(instance_id) - # TODO: Get the real security group of launch in here - security_group = "default" - net = network.BridgedNetwork.get_network_for_project(inst['user_id'], + if not FLAGS.simple_network: + # TODO: Get the real security group of launch in here + security_group = "default" + net = network.BridgedNetwork.get_network_for_project(inst['user_id'], inst['project_id'], security_group).express() inst['node_name'] = FLAGS.node_name diff --git a/nova/endpoint/cloud.py b/nova/endpoint/cloud.py index 931c6c6e1..50c087f2d 100644 --- a/nova/endpoint/cloud.py +++ b/nova/endpoint/cloud.py @@ -516,7 +516,12 @@ class CloudController(object): key_data = key_pair.public_key # TODO: Get the real security group of launch in here security_group = "default" - bridge_name = network.BridgedNetwork.get_network_for_project(context.user.id, context.project.id, security_group)['bridge_name'] + if FLAGS.simple_network: + bridge_name = FLAGS.simple_network_bridge + else: + net = network.BridgedNetwork.get_network_for_project( + context.user.id, context.project.id, security_group) + bridge_name = net['bridge_name'] for num in range(int(kwargs['max_count'])): inst = self.instdir.new() # TODO(ja): add ari, aki @@ -532,12 +537,19 @@ class CloudController(object): inst['mac_address'] = utils.generate_mac() inst['ami_launch_index'] = num inst['bridge_name'] = bridge_name - if inst['image_id'] == FLAGS.vpn_image_id: - address = network.allocate_vpn_ip( - inst['user_id'], inst['project_id'], mac=inst['mac_address']) + if FLAGS.simple_network: + network.allocate_simple_ip(mac=inst['mac_address']) else: - address = network.allocate_ip( - inst['user_id'], inst['project_id'], mac=inst['mac_address']) + if inst['image_id'] == FLAGS.vpn_image_id: + address = network.allocate_vpn_ip( + inst['user_id'], + inst['project_id'], + mac=inst['mac_address']) + else: + address = network.allocate_ip( + inst['user_id'], + inst['project_id'], + mac=inst['mac_address']) inst['private_dns_name'] = str(address) # TODO: allocate expresses on the router node inst.save() |
