From 0b396e1315a76112ab978a677e96d7b3a371faa9 Mon Sep 17 00:00:00 2001 From: Vishvananda Ishaya Date: Thu, 15 Jul 2010 23:11:33 +0000 Subject: Fixes to dhcp lease code to use a flagfile --- nova/compute/linux_net.py | 16 +++++++++++----- nova/compute/network.py | 6 +++--- 2 files changed, 14 insertions(+), 8 deletions(-) (limited to 'nova/compute') diff --git a/nova/compute/linux_net.py b/nova/compute/linux_net.py index 358f184af..2e5f2519f 100644 --- a/nova/compute/linux_net.py +++ b/nova/compute/linux_net.py @@ -27,12 +27,16 @@ import subprocess from nova import flags FLAGS=flags.FLAGS -def execute(cmd): +flags.DEFINE_string('dhcpbridge_flagfile', + '/etc/nova-dhcpbridge.conf', + 'location of flagfile for dhcpbridge') + +def execute(cmd, addl_env=None): if FLAGS.fake_network: logging.debug("FAKE NET: %s" % cmd) return "fake", 0 else: - return nova.utils.execute(cmd) + return nova.utils.execute(cmd, addl_env=addl_env) def runthis(desc, cmd): if FLAGS.fake_network: @@ -60,7 +64,7 @@ def remove_rule(cmd): def bind_public_ip(ip, interface): runthis("Binding IP to interface: %s", "sudo ip addr add %s dev %s" % (ip, interface)) - + def unbind_public_ip(ip, interface): runthis("Binding IP to interface: %s", "sudo ip addr del %s dev %s" % (ip, interface)) @@ -98,7 +102,7 @@ def dnsmasq_cmd(net): ' --except-interface=lo', ' --dhcp-range=%s,static,600s' % (net.dhcp_range_start), ' --dhcp-hostsfile=%s' % dhcp_file(net['vlan'], 'conf'), - ' --dhcp-script=%s' % bin_file('dhcpleasor.py'), + ' --dhcp-script=%s' % bin_file('nova-dhcpbridge'), ' --leasefile-ro'] return ''.join(cmd) @@ -138,7 +142,9 @@ def start_dnsmasq(network): if os.path.exists(lease_file): os.unlink(lease_file) - Popen(dnsmasq_cmd(network).split(" ")) + # FLAGFILE in env + env = {'FLAGFILE' : FLAGS.dhcpbridge_flagfile} + execute(dnsmasq_cmd(network), addl_env=env) def stop_dnsmasq(network): """ stops the dnsmasq instance for a given network """ diff --git a/nova/compute/network.py b/nova/compute/network.py index 8592d7af7..3904fcff0 100644 --- a/nova/compute/network.py +++ b/nova/compute/network.py @@ -253,7 +253,7 @@ class BaseNetwork(datastore.BasicModel): raise compute_exception.NoMoreAddresses("Project %s with network %s" % (project_id, str(self.network))) - def lease_ip(self, ip_str): + def lease_ip(self, ip_str): logging.debug("Leasing allocated IP %s" % (ip_str)) def release_ip(self, ip_str): @@ -563,10 +563,10 @@ def allocate_ip(user_id, project_id, mac): def deallocate_ip(address): return get_network_by_address(address).deallocate_ip(address) - + def release_ip(address): return get_network_by_address(address).release_ip(address) - + def lease_ip(address): return get_network_by_address(address).lease_ip(address) -- cgit From 680446f0acd8aa7820974d32b5b4093a6d4e7a10 Mon Sep 17 00:00:00 2001 From: Jay Pipes Date: Fri, 16 Jul 2010 12:00:15 -0500 Subject: Adds a fix to the idempotency of the test_too_many_addresses test case by adding a simple property to the BaseNetwork class and calculating the number of available IPs by asking the network class to tell the test how many static and preallocated IP addresses are in use before entering the loop to "blow up" the address allocation... --- nova/compute/network.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'nova/compute') diff --git a/nova/compute/network.py b/nova/compute/network.py index 8592d7af7..2b271d0ca 100644 --- a/nova/compute/network.py +++ b/nova/compute/network.py @@ -164,6 +164,7 @@ class Vlan(datastore.BasicModel): class BaseNetwork(datastore.BasicModel): override_type = 'network' + NUM_STATIC_IPS = 3 # Network, Gateway, and CloudPipe @property def identifier(self): @@ -239,11 +240,15 @@ class BaseNetwork(datastore.BasicModel): def available(self): # the .2 address is always CloudPipe # and the top are for vpn clients - for idx in range(3, len(self.network)-(1 + FLAGS.cnt_vpn_clients)): + for idx in range(self.num_static_ips, len(self.network)-(1 + FLAGS.cnt_vpn_clients)): address = str(self.network[idx]) if not address in self.hosts.keys(): yield str(address) + @property + def num_static_ips(self): + return BaseNetwork.NUM_STATIC_IPS + def allocate_ip(self, user_id, project_id, mac): for address in self.available: logging.debug("Allocating IP %s to %s" % (address, project_id)) -- cgit From ae9e4e81d992fb81c01acd2dfcb1cb3d32956041 Mon Sep 17 00:00:00 2001 From: Vishvananda Ishaya Date: Fri, 16 Jul 2010 19:12:36 +0000 Subject: Removed unused Pool from process.py, added a singleton pool called SharedPool, changed calls in node to use singleton pool --- nova/compute/node.py | 41 +++++++++++++++++++++-------------------- 1 file changed, 21 insertions(+), 20 deletions(-) (limited to 'nova/compute') diff --git a/nova/compute/node.py b/nova/compute/node.py index d681ec661..3abd20120 100644 --- a/nova/compute/node.py +++ b/nova/compute/node.py @@ -87,7 +87,6 @@ class Node(object, service.Service): super(Node, self).__init__() self._instances = {} self._conn = self._get_connection() - self._pool = process.ProcessPool() self.instdir = model.InstanceDirectory() # TODO(joshua): This needs to ensure system state, specifically: modprobe aoe @@ -115,7 +114,7 @@ class Node(object, service.Service): # inst = self.instdir.get(instance_id) # return inst if self.instdir.exists(instance_id): - return Instance.fromName(self._conn, self._pool, instance_id) + return Instance.fromName(self._conn, instance_id) return None @exception.wrap_exception @@ -126,7 +125,7 @@ class Node(object, service.Service): for x in self._conn.listDomainsID()] for name in instance_names: try: - new_inst = Instance.fromName(self._conn, self._pool, name) + new_inst = Instance.fromName(self._conn, name) new_inst.update_state() except: pass @@ -136,7 +135,8 @@ class Node(object, service.Service): def describe_instances(self): retval = {} for inst in self.instdir.by_node(FLAGS.node_name): - retval[inst['instance_id']] = (Instance.fromName(self._conn, self._pool, inst['instance_id'])) + retval[inst['instance_id']] = ( + Instance.fromName(self._conn, inst['instance_id'])) return retval @defer.inlineCallbacks @@ -169,8 +169,7 @@ class Node(object, service.Service): inst['node_name'] = FLAGS.node_name inst.save() # TODO(vish) check to make sure the availability zone matches - new_inst = Instance(self._conn, name=instance_id, - pool=self._pool, data=inst) + new_inst = Instance(self._conn, name=instance_id, data=inst) logging.info("Instances current state is %s", new_inst.state) if new_inst.is_running(): raise exception.Error("Instance is already running") @@ -267,11 +266,8 @@ class Instance(object): SHUTOFF = 0x05 CRASHED = 0x06 - def __init__(self, conn, pool, name, data): + def __init__(self, conn, name, data): """ spawn an instance with a given name """ - # TODO(termie): pool should probably be a singleton instead of being passed - # here and in the classmethods - self._pool = pool self._conn = conn # TODO(vish): this can be removed after data has been updated # data doesn't seem to have a working iterator so in doesn't work @@ -324,11 +320,11 @@ class Instance(object): return libvirt_xml @classmethod - def fromName(cls, conn, pool, name): + def fromName(cls, conn, name): """ use the saved data for reloading the instance """ instdir = model.InstanceDirectory() instance = instdir.get(name) - return cls(conn=conn, pool=pool, name=name, data=instance) + return cls(conn=conn, name=name, data=instance) def set_state(self, state_code, state_description=None): self.datamodel['state'] = state_code @@ -450,12 +446,13 @@ class Instance(object): def _fetch_s3_image(self, image, path): url = _image_url('%s/image' % image) - d = self._pool.simpleExecute('curl --silent %s -o %s' % (url, path)) + d = process.SharedPool().simple_execute( + 'curl --silent %s -o %s' % (url, path)) return d def _fetch_local_image(self, image, path): source = _image_path('%s/image' % image) - d = self._pool.simpleExecute('cp %s %s' % (source, path)) + d = process.SharedPool().simple_execute('cp %s %s' % (source, path)) return d @defer.inlineCallbacks @@ -465,8 +462,10 @@ class Instance(object): basepath = self.basepath # ensure directories exist and are writable - yield self._pool.simpleExecute('mkdir -p %s' % basepath()) - yield self._pool.simpleExecute('chmod 0777 %s' % basepath()) + yield process.SharedPool().simple_execute( + 'mkdir -p %s' % basepath()) + yield process.SharedPool().simple_execute( + 'chmod 0777 %s' % basepath()) # TODO(termie): these are blocking calls, it would be great @@ -492,9 +491,10 @@ class Instance(object): if not os.path.exists(basepath('ramdisk')): yield _fetch_file(data['ramdisk_id'], basepath('ramdisk')) - execute = lambda cmd, input=None: self._pool.simpleExecute(cmd=cmd, - input=input, - error_ok=1) + execute = lambda cmd, input=None: \ + process.SharedPool().simple_execute(cmd=cmd, + input=input, + error_ok=1) key = data['key_data'] net = None @@ -511,7 +511,8 @@ class Instance(object): yield disk.inject_data(basepath('disk-raw'), key, net, execute=execute) if os.path.exists(basepath('disk')): - yield self._pool.simpleExecute('rm -f %s' % basepath('disk')) + yield process.SharedPool().simple_execute( + 'rm -f %s' % basepath('disk')) bytes = (INSTANCE_TYPES[data['instance_type']]['local_gb'] * 1024 * 1024 * 1024) -- cgit From 52f0ec017c04ad9356eb45d96bcab90a0807d914 Mon Sep 17 00:00:00 2001 From: Vishvananda Ishaya Date: Fri, 16 Jul 2010 20:32:51 +0000 Subject: make simple method wrapper for process pool simple_execute --- nova/compute/node.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'nova/compute') diff --git a/nova/compute/node.py b/nova/compute/node.py index 3abd20120..4683f1c8d 100644 --- a/nova/compute/node.py +++ b/nova/compute/node.py @@ -446,13 +446,13 @@ class Instance(object): def _fetch_s3_image(self, image, path): url = _image_url('%s/image' % image) - d = process.SharedPool().simple_execute( + d = process.simple_execute( 'curl --silent %s -o %s' % (url, path)) return d def _fetch_local_image(self, image, path): source = _image_path('%s/image' % image) - d = process.SharedPool().simple_execute('cp %s %s' % (source, path)) + d = process.simple_execute('cp %s %s' % (source, path)) return d @defer.inlineCallbacks @@ -462,9 +462,9 @@ class Instance(object): basepath = self.basepath # ensure directories exist and are writable - yield process.SharedPool().simple_execute( + yield process.simple_execute( 'mkdir -p %s' % basepath()) - yield process.SharedPool().simple_execute( + yield process.simple_execute( 'chmod 0777 %s' % basepath()) @@ -492,7 +492,7 @@ class Instance(object): yield _fetch_file(data['ramdisk_id'], basepath('ramdisk')) execute = lambda cmd, input=None: \ - process.SharedPool().simple_execute(cmd=cmd, + process.simple_execute(cmd=cmd, input=input, error_ok=1) @@ -511,7 +511,7 @@ class Instance(object): yield disk.inject_data(basepath('disk-raw'), key, net, execute=execute) if os.path.exists(basepath('disk')): - yield process.SharedPool().simple_execute( + yield process.simple_execute( 'rm -f %s' % basepath('disk')) bytes = (INSTANCE_TYPES[data['instance_type']]['local_gb'] -- cgit