2 Replies Latest reply on Jun 15, 2016 8:33 AM by hpulkkinen RSS
    hpulkkinen Explorer

    Enabling tunneling and adding a tunnel with a script

    Hi

     

    I'm planning to write a script which would

     

    1. Enable tunneling for a thing which is based on remoteThingWithTunnels

    2. Create a new tunnel with these parameters:

    name: ssh

    host: 127.0.0.1

    port: 22

    App URI: undefined

    # Connections: 1

    Protocol: tcp

     

    I have tried to use AddTunnel-method as following

     

    var params = {

      numConnects: "1" /* STRING */,

      port: "22" /* STRING */,

      proto: "tcp" /* STRING */,

      name: "ssh" /* STRING */,

      host: "127.0.0.1" /* STRING */,

      description: "ssh tunnel" /* STRING */

    };

     

    me.AddTunnel(params);

     

    However, it gives me this error:

     

    Wrapped java.lang.Exception: No service handler defined for service AddTunnel on thing [TestThing] Cause: No service handler defined for service AddTunnel on thing [TestThing]

      • Re: Enabling tunneling and adding a tunnel with a script
        aanjan Heavyweight Champ

        Heikki, this is a known bug and it is active in our Jira database. As a workaround for the moment, you would have to use GetConfigurationTable, with the tableName as Tunnels, and add new rows to the resulting InfoTable. Once you've added all rows, you would need to call SetMultiRowConfigurationTable to reflect changes. Please do note that this will overwrite all current settings; and that's why we use Get in the beginning to get/ keep our current settings intact.

          • Re: Enabling tunneling and adding a tunnel with a script
            hpulkkinen Explorer

            Very good! I have now this script to automatically create a correct configuration for a ssh tunnel

             

            var confTable = me.GetConfigurationTable({tableName: "Tunnels"});

             

            var tunnel = {

                name: "ssh",

                host: "127.0.0.1",

                port: "22",

                description: "ssh tunnel",

                numConnects: 1,

                appUri: "",

                proto: "tcp"

            };

             

            confTable.AddRow(tunnel);

             

            var setTableParams = {

              configurationTable: confTable /* INFOTABLE */,

              persistent: true /* BOOLEAN */,

              tableName: "Tunnels" /* STRING */

            };

             

            me.SetMultiRowConfigurationTable(setTableParams);

             

            result = confTable

             

            I also realized that I can configure the tunnel setting to the whole thing template at once. So in the end I didn't need to use this script myself.