Esempio n. 1
0
 def addContainer(self, containerId, config):
     if "CYGNET_INTERNAL_IP" in config and "CYGNET_INTERNAL_SUBNET" in config:
         addr = "/".join([config["CYGNET_INTERNAL_IP"], config["CYGNET_INTERNAL_SUBNET"]])
     else:
         addr = None
         return False
     exists = filter(lambda x: str(x) == addr, [container.address for container in self.node['containers']])
     if addr and exists:
         return False
     if type(addr) is not str:
         addr= strtypes.cast_unicode(addr)
     if type(containerId) is not str:
         containerId = strtypes.cast_unicode(containerId)
     container = Container(containerId, self.node['id'])
     container.running(True)
     container.address = addr
     self.nodes.remove(self.node)
     self.node['containers'].append(container)
     self.nodes.append(self.node)
     self.session.publish("ovs.hook_container", container)
     self.session.publish("nodes.sync_nodes", self.nodes)
     self.etcd_client.addContainer(container)
     print("Container added", self.nodes)
     return True
Esempio n. 2
0
def main(router_addr, router_realm, etcd_server_addr):
    # click.echo(repr(names))
    """
    We pull from the docker environment variable set during --link
    with this we can point to the correctly named sibling container.
    """
    # if environ['WAMP_WEBSOCKET_URL']:
    #     runner = HybridRunner(
    #         environ['WAMP_WEBSOCKET_URL'],
    #         environ['WAMP_REALM'])
    # elif:
    #     runner = HybridRunner(
    #         environ['WAMP_WEBSOCKET_URL'],
    #         environ['WAMP_REALM'])
    ClusterState.etcd_addr = (etcd_server_addr.split(':')[0],
                              etcd_server_addr.split(':')[1])
    runner = HybridRunner(''.join([u"ws://", router_addr, "/ws"]),
                          strtypes.cast_unicode(router_realm))
    adapter = getAdapter()
    reactor.listenTCP(80, adapter)
    runner.run(RouterClient, adapter)
    reactor.run()
Esempio n. 3
0
 def addNode(self):
     node_key = "nodes/" + self.nodeId
     try:
         self.write(node_key, None, dir=True)
         self.write(node_key+"/state", 1, ttl=60)
         self.write(node_key+"/containers", None, dir=True)
         return []
     except etcd.EtcdNotFile:
         self.write(node_key+"/state", 1, ttl=60)
     # If we get here, node is not empty nor new
     containers = self.get(node_key+"/containers/")
     read_containers = []
     if containers._children:
         for container in containers.children:
             container = self.get(container.key)
             empty = {"Id": None,
                      "Name": None,
                      "Node": None,
                      "State": 0,
                      "Address": None}
             for leaf in container.children:
                 print(leaf)
                 try:
                     if leaf.value is not str:
                         leaf.value = strtypes.cast_unicode(leaf.value)
                 except:
                     pass
                 empty[leaf.key.split("/")[-1]] = leaf.value
             container = Container(empty['Id'], self.nodeId)
             container.name = empty['Name']
             container.address = empty['Address']
             container.running(empty['State'])
             read_containers.append(container)
             print("")
     print("Read containers", read_containers)
     return read_containers
 def connect(self):
     print(self.args['router-addr'])
     runner = ApplicationRunner(u"ws://" + self.args['router-addr'] + "/ws", strtypes.cast_unicode(self.args['router-realm']))
     runner.run(Client)
Esempio n. 5
0
 def connect(self):
     print(self.args['router-addr'])
     runner = ApplicationRunner(
         u"ws://" + self.args['router-addr'] + "/ws",
         strtypes.cast_unicode(self.args['router-realm']))
     runner.run(Client)