Example #1
0
    def run(self):
        if self.action == 'set':
            addr = Address.deserialize(
                re.search(r'Connection:(?P<addr>\S+):alive',
                          self.channel).group('addr'))
            logging.debug(
                "VlanWorker responding to 'set' on connection '%s' alive status",
                addr)
            connection = DB.Connection(addr)

            # If this connection is not alive, this worker reacted to the connection being killed
            if connection.alive:
                user = connection.user
                vpn = connection.vpn

                ensure_veth_up(vpn)

                vlan_if = vlan_if_name(vpn.veth, user.vlan)

                link_status = vpn.links[user.vlan]
                if link_status == 'bridged':
                    logging.info(
                        "New connection %s traversing existing vlan link %s",
                        connection.id, vlan_if)

                else:
                    if not link_status or link_status == 'down':
                        self.bring_up_link(vpn, user)

                    self.bridge_cluster(vpn, user)

        else:
            logging.debug("VlanWorker not responding to '%s' event",
                          self.action)
Example #2
0
    def bridge_link_if_ready(self, user, vpn, cluster):
        # Bridge in the vlan interface if it is ready to go
        bridge_id = get_bridge_id(cluster.id)
        if vpn.links[user.vlan] == 'up':
            vlan_if = vlan_if_name(vpn.veth, user.vlan)
            BrctlCmd(BrctlCmd.ADDIF, bridge_id, vlan_if).run()
            vpn.links[user.vlan] = 'bridged'
            logging.info("Added %s to bridge %s for cluster %s", vlan_if,
                         bridge_id, cluster.id)

        # Strip the IP address form the bridge to prevent host attacks.
        # Hopefully this will be replaced by an option to never give the bridge an ip at all
        IpFlushCmd(bridge_id).run()
Example #3
0
    def bridge_cluster(self, vpn, user):
        cluster = DB.Cluster(user, vpn.chal)
        vlan_if = vlan_if_name(vpn.veth, user.vlan)

        if cluster.exists() and cluster.status == 'up':
            bridge_id = get_bridge_id(cluster.id)
            BrctlCmd(BrctlCmd.ADDIF, bridge_id, vlan_if).run()
            vpn.links[user.vlan] = 'bridged'
            logging.info("Added %s to bridge %s for cluster %s", vlan_if,
                         bridge_id, cluster.id)

        else:
            logging.info(
                "Cluster %s not up. Defering addition of %s to a bridge",
                cluster.id, vlan_if)