Example #1
0
def add(ctx, name, forward_type, local_port, remote_port, ssh_server,
        server_port, remote_host, login_user, ssh_argument):
    try:
        AddCommand(name, ssh_argument, forward_type, remote_host, remote_port,
                   local_port, ssh_server, server_port, login_user,
                   ctx.obj["config"]).run()
    except RuntimeError as error:
        logger.warn("Failed to register...")
        logger.warn(error)
Example #2
0
def check_remote_port_is_used(new_target, targets):
    remote_port = new_target["remote_port"]
    remote_host = get_remote_host(new_target)

    for target_name in targets:
        target = targets[target_name]
        target_remote_host = get_remote_host(target)

        if target_remote_host == remote_host and target[
                "remote_port"] == remote_port:
            logger.warn(
                "remote port {} in host {} is already used in {} ".format(
                    str(remote_port), remote_host, target_name))
Example #3
0
    def run(self):
        f = open(self.config_path, 'r')
        targets = json.load(f)
        if self.name in targets:
            target = targets[self.name]
            self.update(target)
        else:
            logger.warn("Port forward setting named " + self.name + "is not registered")

        # write the target
        f = open(self.config_path, 'w')
        f.write(json.dumps(targets, indent=4))
        f.close()
Example #4
0
    def run(self):
        f = open(self.config_path, 'r')
        targets = json.load(f)
        if self.name in targets:
            targets.pop(self.name)
            logger.info('Deleted target ' + self.name + '...')
        else:
            logger.warn("Port forward setting named " + self.name + "is not registered")
        f.close()

        # write the target
        f = open(self.config_path, 'w')
        f.write(json.dumps(targets, indent=4))
        f.close()
Example #5
0
def check_local_port_is_used(local_port, targets):
    for target_name in targets:
        target = targets[target_name]
        if local_port == target["local_port"]:
            logger.warn("local port {} is already used in {}".format(
                str(local_port), target_name))