summaryrefslogtreecommitdiffstats
path: root/nova/compute
diff options
context:
space:
mode:
authorJoshua McKenty <jmckenty@joshua-mckentys-macbook-pro.local>2010-07-07 12:06:34 -0700
committerVishvananda Ishaya <vishvananda@gmail.com>2010-07-07 12:06:34 -0700
commitb7ea2f70581f6acd927ea7b65adaffeeb4b8d2ba (patch)
tree6f00bf4a6207486478b0142f0297081ebcf85d8d /nova/compute
parent5e8337aec03f5a697c90779eb66a457aae4e7ae0 (diff)
Capture signals from dnsmasq and use them to update network state.
Diffstat (limited to 'nova/compute')
-rw-r--r--nova/compute/linux_net.py9
-rw-r--r--nova/compute/network.py14
2 files changed, 19 insertions, 4 deletions
diff --git a/nova/compute/linux_net.py b/nova/compute/linux_net.py
index 0bd5ce007..b44cf9437 100644
--- a/nova/compute/linux_net.py
+++ b/nova/compute/linux_net.py
@@ -62,6 +62,9 @@ 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))
def vlan_create(net):
""" create a vlan on on a bridge device unless vlan already exists """
@@ -98,7 +101,8 @@ def dnsmasq_cmd(net):
' --dhcp-range=%s,static,120s' % (net.dhcp_range_start),
' --dhcp-lease-max=61',
' --dhcp-hostsfile=%s' % dhcp_file(net['vlan'], 'conf'),
- ' --dhcp-leasefile=%s' % dhcp_file(net['vlan'], 'leases')]
+ ' --dhcp-leasefile=%s' % dhcp_file(net['vlan'], 'leases'),
+ ' ---dhcp-script=%s' % bin_file('dhcpleasor.py')]
return ''.join(cmd)
def hostDHCP(network, host, mac):
@@ -154,6 +158,9 @@ def dhcp_file(vlan, kind):
return os.path.abspath("%s/nova-%s.%s" % (FLAGS.networks_path, vlan, kind))
+def bin_file(script):
+ return os.path.abspath(os.path.join(__file__, "../../../bin", script))
+
def dnsmasq_pid_for(network):
""" the pid for prior dnsmasq instance for a vlan,
returns None if no pid file exists
diff --git a/nova/compute/network.py b/nova/compute/network.py
index 911d0344a..7a347aa11 100644
--- a/nova/compute/network.py
+++ b/nova/compute/network.py
@@ -162,12 +162,16 @@ class BaseNetwork(datastore.RedisModel):
return address
raise exception.NoMoreAddresses()
- def deallocate_ip(self, ip_str):
+ def release_ip(self, ip_str):
if not ip_str in self.assigned:
raise exception.AddressNotAllocated()
self.deexpress(address=ip_str)
self._rem_host(ip_str)
+ def deallocate_ip(self, ip_str):
+ # Do nothing for now, cleanup on ip release
+ pass
+
def list_addresses(self):
for address in self.hosts:
yield address
@@ -197,7 +201,7 @@ class BridgedNetwork(BaseNetwork):
def get_network_for_project(cls, user_id, project_id, security_group):
vlan = get_vlan_for_project(project_id)
network_str = get_subnet_from_vlan(vlan)
- logging.debug("creating network on vlan %s with network string %s" % (vlan, network_str))
+ # logging.debug("creating network on vlan %s with network string %s" % (vlan, network_str))
return cls.create(user_id, project_id, security_group, vlan, network_str)
def __init__(self, *args, **kwargs):
@@ -221,7 +225,7 @@ class DHCPNetwork(BridgedNetwork):
def __init__(self, *args, **kwargs):
super(DHCPNetwork, self).__init__(*args, **kwargs)
- logging.debug("Initing DHCPNetwork object...")
+ # logging.debug("Initing DHCPNetwork object...")
self.dhcp_listen_address = self.network[1]
self.dhcp_range_start = self.network[3]
self.dhcp_range_end = self.network[-(1 + FLAGS.cnt_vpn_clients)]
@@ -372,6 +376,7 @@ class PublicNetworkController(BaseNetwork):
def deexpress(self, address=None):
addr = self.get_host(address)
private_ip = addr['private_ip']
+ linux_net.unbind_public_ip(address, FLAGS.public_interface)
linux_net.remove_rule("PREROUTING -t nat -d %s -j DNAT --to %s"
% (address, private_ip))
linux_net.remove_rule("POSTROUTING -t nat -s %s -j SNAT --to %s"
@@ -416,8 +421,11 @@ def get_vlan_for_project(project_id):
def get_network_by_address(address):
+ logging.debug("Get Network By Address:")
for project in users.UserManager.instance().get_projects():
+ logging.debug(" looking at project %s", project.id)
net = get_project_network(project.id)
+ logging.debug(" is %s in %s ?" % (address, str(net.assigned)))
if address in net.assigned:
return net
raise exception.AddressNotAllocated()