Coder Social home page Coder Social logo

pfm's Introduction

Build status

pfm -- a ssh port forward manager for data scientists

Data scientists launch a Jupyter Notebook servers to tackle each machine learning task. Usually local computers are not enough to handle multiple machine learning tasks. And therefore data scientists do their experiments in servers launched in remote hosts such as EC2 instances.

To connect Jupyter Notebook servers in remote hosts, we use ssh port forwarding. Port forwarding is useful since we do not consume resources in local PC.

Unfortunately, when connecting servers in multiple remote hosts and ports numbers, we easily forget the port number or assign the local port number which is used in another task. Especially when there are multiple remote hosts and ssh servers as the following image, understanding the combinations of remote hosts and local ports are difficult.

images/port-forwarding.jpeg

pfm manages the remote hosts and port numbers used in port forwarding. Users understand which local ports are used and which ports are not. Once users register the port forwarding information, pfm generates ssh parameters any time specifying the task name.

Install

We can install pfm with pip.

pip install pfm

Usage

Register settings of ssh port forwarding

pfm add registers port forward settings.

Register settings with options

The following is a sample of adding port forward settings with command line options.

$ pfm add -n image-classification --local-port 9999 --remote-port 8888 --ssh-server myml.aws.com --remote-host localhost

pfm add provides the following options.

Usage: pfm add [OPTIONS]

add port forwarding target

Options:
    -n, --name TEXT        name of port fowarding
    --forward-type TEXT    port forwarding type [L (local) or R (remote)]
    --local-port INTEGER   local port
    --remote-port INTEGER  remote host port
    --ssh-server TEXT      server to ssh login
    --server-port INTEGER  server port
    --remote-host TEXT     remote host for port forwarding
    --login-user TEXT      login user of ssh server
    --help                 Show this message and exit.

Note that when local port number (--local-port) is not specified, pfm add automatically assigns the local port not to collide to other port forward settings.

Register settings with a argument

If you think adding many options are tedious, pfm add also provides argument style of registration.

The following is a sample of registration which forwards port 8888 in takahi-i-ml.aws.com to port 9999 of localhost with a local port forward setting.

$pfm add -n image-classification "9999:localhost:8888 takahi-i-ml.aws.com"

As we see the above example is simple and just uses -n option. Note that default forward type is set to local (L). If you want to set forward type to remote please specify the type with --forward_type parameter.

Generate ssh port forward parameters

After the registration of port forward settings with pfm add , we can generate ssh parameters with pfm param.

$ ssh `pfm param image-classification`

Or we can also use pfm connect in order to do same (Note that this command includes -A ssh option).

$ pfm connect image-classification

Update port forward settings

After the registration of port forward settings with pfm add , we can modify ssh parameters with pfm update. For example, the following command changes the port forwarding type of image-classification setting from local to remote.

$ pfm update --name image-classification --forward-type R

List registered ssh port forward settings

We can see the list of registered port forward settings.

$ pfm list
+----------------------+------------+------------+--------------------------------+--------------+-----------------+--------------------------------+--------------+
|         name         |    type    | local_port |          remote_host           | remote_port  |   login_user    |           ssh_server           | server_port  |
+======================+============+============+================================+==============+=================+================================+==============+
| image-processing     | L          | 9999       | localhost                      | 8888         | None            | my-ml-instance.aws.com         |              |
+----------------------+------------+------------+--------------------------------+--------------+-----------------+--------------------------------+--------------+
| text-processing      | L          | 7777       | localhost                      | 8888         | None            | my-ml-instance-2.aws.com       |              |
+----------------------+------------+------------+--------------------------------+--------------+-----------------+--------------------------------+--------------+

Delete registered forwarding setting

When a port forward settings is not needed, we can remove the setting with pfm delete command

$ pfm delete image-process

License

  • Free software: MIT license

Resources

Slides on pfm.

For developers

We are welcome any contribution. For details, please see CONTRIBUTING.rst.

pfm's People

Contributors

takahi-i avatar yoheikikuta avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

yoheikikuta

pfm's Issues

Cannot add new stuff with the same local port

  • pfm version:0.3.0
  • Python version:pyton:3.5.2
  • Operating System:mac OS 10.13

Description

I cannot add a new element using a local port that was used before.

What I Did

$ pfm list
+----------------------+------------+------------+--------------------------------+------------+-----------------+--------------------------------+--------------+
|         name         |    type    | local_port |          remote_host           | remote_por |   login_user    |           ssh_server           | server_port  |
|                      |            |            |                                |     t      |                 |                                |              |
+======================+============+============+================================+============+=================+================================+==============+
| test1                | L          | 8888       | localhost                      | 10003      | None            |  test-server                   |              |
|                      |            |            |                                |            |                 |                                |     None     |
+----------------------+------------+------------+--------------------------------+------------+-----------------+--------------------------------+--------------+

Then

$ pfm add --name test2 --local-port 8888 --ssh-server test-server
local_port is not specified
allocating remote_port for test2...
remote_port of test2 is set to 49152
Failed to register...
local port 8888 is already used in test1

Support user name in ssh parameter

  • pfm version:
  • Python version:
  • Operating System:

Description

Describe what you were trying to get done.
Tell us what happened, what went wrong, and what you expected to happen.

What I Did

Paste the command(s) you ran and the output.
If there was a crash, please include the traceback here.

Support `-A` option

I would like to support -A option for param command. Setting the default value of the parameter true would be preferred.

Automatic local port assignment

  • pfm version:
  • Python version:
  • Operating System:

Description

Describe what you were trying to get done.
Tell us what happened, what went wrong, and what you expected to happen.

What I Did

Paste the command(s) you ran and the output.
If there was a crash, please include the traceback here.

How about setting default local port, remote port and ssh-server

Description

I think it's better for us not to care about port numbers.
So how about setting default local & remote port numbers as simple incrementing numbers even across different remote servers.

Also, how about setting default ssh-server as localhost; almost all of the case for analysis in a remote server, we use localhost.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.