Ejemplo n.º 1
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()
Ejemplo n.º 2
0
    def __init__(self, name, ssh_param_str, forward_type, remote_host,
                 remote_port, local_port, ssh_server, server_port, login_user,
                 config):
        super(AddCommand, self).__init__(config)
        self.name = name
        self.ssh_param_str = ssh_param_str

        if forward_type is None:
            logger.info("No port forward type is specified")
            self.forward_type = AddCommand.DEFAULT_TYPE
        else:
            self.forward_type = forward_type

        self.remote_host = remote_host
        self.remote_port = remote_port
        self.local_port = local_port
        self.ssh_server = ssh_server
        self.server_port = server_port
        self.login_user = login_user
Ejemplo n.º 3
0
def automatic_remote_port_assignment(new_target, targets):
    if new_target["remote_port"] is None:
        logger.info("remote_port is not specified")
        logger.info("allocating remote_port for " + new_target["name"] + "...")
        remote_server_name = get_remote_host(new_target)

        used_ports = set()
        for target_name in targets:
            target = targets[target_name]
            if target["remote_host"] == remote_server_name:
                used_ports.add(target["remote_port"])
            if target["remote_host"] == "localhost" and target[
                    "ssh_server"] == remote_server_name:
                used_ports.add(target["remote_port"])
            if target["ssh_server"] == remote_server_name and target[
                    "server_port"] is not None:
                used_ports.add(target["server_port"])

        for port_number in range(AddCommand.PFM_BASE_PORT,
                                 AddCommand.PFM_MAX_INFERRING_PORT, 1):
            if not str(port_number) in used_ports:
                new_target["remote_port"] = str(port_number)
                logger.info("remote_port of " + new_target["name"] +
                            " is set to " + str(port_number))
                return
Ejemplo n.º 4
0
    def __init__(self, config_path):
        self.config_path = config_path

        if self.config_path is None:
            logger.info('config_path set to None...')
            logger.info('Skip creating setting file...')
            return

        if not os.path.exists(self.config_path):
            logger.info('Creating setting file of pfm in ' + self.config_path +
                        '...')
            f = open(self.config_path, 'w')
            f.write('{}')
            f.close()
Ejemplo n.º 5
0
def automatic_local_port_assignment(new_target, targets):
    if new_target["local_port"] is None:
        logger.info("local_port is not specified")
        logger.info("allocating local_port for " + new_target["name"] + "...")
        used_ports = set()
        for target_name in targets:
            used_ports.add(targets[target_name]["local_port"])

        for port_number in range(AddCommand.PFM_BASE_PORT,
                                 AddCommand.PFM_MAX_INFERRING_PORT, 1):
            if not str(port_number) in used_ports:
                new_target["local_port"] = str(port_number)
                logger.info("local_port of " + new_target["name"] +
                            " is set to " + str(port_number))
                return
Ejemplo n.º 6
0
 def generate_target(self):
     new_target = self.__extract_target_from_params()
     if self.ssh_param_str is not None:
         logger.info("found argument...")
         new_target = self.__generate_target_from_argument(new_target)
     return new_target