diff options
| author | Ewan Mellor <ewan.mellor@citrix.com> | 2010-07-24 02:49:20 +0100 |
|---|---|---|
| committer | Ewan Mellor <ewan.mellor@citrix.com> | 2010-07-24 02:49:20 +0100 |
| commit | effbd4b4c7077043c0ff2ddcb91607b4e79796f6 (patch) | |
| tree | a9a4c628533c64211b349c9c3d713ddd9b113c8f /nova/compute | |
| parent | 1046fd21fad35fdb9922f667017937ec94774498 (diff) | |
| parent | 809a1fe80b9922a36c64bce948588a5797cae87b (diff) | |
Merged with trunk, since a lot of useful things have gone in there recently.
Diffstat (limited to 'nova/compute')
| -rw-r--r-- | nova/compute/linux_net.py | 16 | ||||
| -rw-r--r-- | nova/compute/network.py | 13 | ||||
| -rw-r--r-- | nova/compute/node.py | 20 |
3 files changed, 28 insertions, 21 deletions
diff --git a/nova/compute/linux_net.py b/nova/compute/linux_net.py index 00c64d81a..48e07da66 100644 --- a/nova/compute/linux_net.py +++ b/nova/compute/linux_net.py @@ -28,12 +28,16 @@ from nova import utils 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 utils.execute(cmd) + return utils.execute(cmd, addl_env=addl_env) def runthis(desc, cmd): if FLAGS.fake_network: @@ -61,7 +65,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)) @@ -99,7 +103,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) @@ -139,7 +143,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 90d6b2dc6..43011f696 100644 --- a/nova/compute/network.py +++ b/nova/compute/network.py @@ -162,6 +162,7 @@ class Vlan(datastore.BasicModel): class BaseNetwork(datastore.BasicModel): override_type = 'network' + NUM_STATIC_IPS = 3 # Network, Gateway, and CloudPipe @property def identifier(self): @@ -237,11 +238,15 @@ class BaseNetwork(datastore.BasicModel): def available(self): # the .2 address is always CloudPipe # and the top <n> 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)) @@ -251,7 +256,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): @@ -566,10 +571,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) diff --git a/nova/compute/node.py b/nova/compute/node.py index 7146d1279..533670b12 100644 --- a/nova/compute/node.py +++ b/nova/compute/node.py @@ -58,7 +58,6 @@ class Node(object, service.Service): super(Node, self).__init__() self._instances = {} self._conn = virt_connection.get_connection() - self._pool = process.ProcessPool() self.instdir = model.InstanceDirectory() # TODO(joshua): This needs to ensure system state, specifically: modprobe aoe @@ -70,7 +69,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 @@ -80,7 +79,7 @@ class Node(object, service.Service): instance_names = self._conn.list_instances() 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 @@ -90,7 +89,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 @@ -123,8 +123,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") @@ -220,11 +219,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 @@ -263,11 +259,11 @@ class Instance(object): logging.debug("Finished init of Instance with id of %s" % name) @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 |
