Example #1
0
 def initContainerNetwork(self, network=None):
     if not network:
         try:
             network = Network(None)
             network.name = 'cygnet_internal'
             network.address = self['internal_ip']
             if not self.ovs_client.bridgeExists(network.name):
                 self.ovs_client.addBridge(network.name)
                 self.ovs_client.setBridgeProperty(network.name,
                                                   'stp_enable', True)
         except KeyError as e:
             print("OpenvSwitch: CYGNET_INTERNAL_IP \
                     environment variable not found")
             raise e
     else:
         network.name = "cygnet_" + network.id[:8]
         if not self.ovs_client.bridgeExists(network.name):
             self.ovs_client.addBridge(network.name)
             self.ovs_client.setBridgeProperty(network.name, 'stp_enable',
                                               True)
     ip = IPDB()
     ifaces = ip.interfaces
     ifaces[network.name].begin()
     ifaces[network.name].add_ip(network.address, network.mask)
     ifaces[network.name].up()
     ifaces[network.name].commit()
     ip.release()
     self.interfaces.append(network)
     return network
Example #2
0
 def initContainerNetwork(self, network=None):
     if not network:
         try:
             network = Network(None)
             network.name = 'cygnet_internal'
             network.address = self['internal_ip']
             if not self.ovs_client.bridgeExists(network.name):
                 self.ovs_client.addBridge(network.name)
                 self.ovs_client.setBridgeProperty(network.name,
                                                   'stp_enable',
                                                   True)
         except KeyError as e:
             print("OpenvSwitch: CYGNET_INTERNAL_IP \
                     environment variable not found")
             raise e
     else:
         network.name = "cygnet_" + network.id[:8]
         if not self.ovs_client.bridgeExists(network.name):
             self.ovs_client.addBridge(network.name)
             self.ovs_client.setBridgeProperty(network.name,
                                               'stp_enable',
                                               True)
     ip = IPDB()
     ifaces = ip.interfaces
     ifaces[network.name].begin()
     ifaces[network.name].add_ip(network.address, network.mask)
     ifaces[network.name].up()
     ifaces[network.name].commit()
     ip.release()
     self.interfaces.append(network)
     return network
    def addNode(self):
        node_key = "nodes/" + self.nodeId
        try:
            self.write(node_key, None, dir=True)
            self.write(node_key+"/state", ttl=60)
        except etcd.EtcdNotFile:
            self.write(node_key+"/state", 1, ttl=60)

        try:
            self.write(node_key+"/networks",None, dir=True)
        except etcd.EtcdNotFile:
            pass

        networks = self.get(node_key+"/networks/")
        read_networks = []
        if networks._children:
            for network in networks.children:
                network = self.get(network.key)
                empty = {"Id": None,
                         "Name": None,
                         "Address":None,
                         "Config": None
                         }
                for leaf in network.children:
                    for foo in leaf.children:
                        print(foo)
                    empty[leaf.key.split("/")[-1]] = leaf.value
                network = Network(empty['Id'], config=empty['Config'])
                network.name = empty['Name']
                read_networks.append(network)
        return read_networks