Coder Social home page Coder Social logo

paicli's Introduction

PyPI version Python version License MIT

paicli

A CLI tool for OpenPAI, which supports basic opperations like listing up jobs, submitting a new job, suspending a running job, and executing ssh into a running container.

demo

How to install

One can install paicli from PyPI.

$ pip install paicli

Motivating examples

One can utilize and combine the paicli subcommands to achieve several practical operations.

1. Ssh into a running container

When you want to ssh into a running container, all you have to do is just type pai ssh:

$ pai ssh

Then, you can choose a container from your running job list. There is no need to download the key and specify the host explicitly. You can also give a job name of your running job as argument:

$ pai ssh example_job_001

2. Submit multiple jobs with one line

One can use pai submit and some template engine like envsubst.

$ head template.json -n 2
{
  "jobName": "example_job_${JOBID}"
$ for i in `seq 1 3`; do cat example.json | JOBID=$i envsubst | pai submit; done

3. Stop multiple jobs with one line

One can combine pai jobs and pai stop.

$ pai jobs -u sotetsuk -s RUNNING | grep example_job | awk '{print $1}' | xargs pai stop

4. Ssh into multiple running containers and run the same command

One can combine pai jobs and pai ssh. In this example, it shows python processes in multiple jobs with one line.

$ pai jobs -u sotetsuk -s RUNNING | grep example_job | awk '{print $1}' | xargs -n 1 pai ssh -c "ps -aux | grep python"

5. Show all tensorboard URLs in running jobs

One can combine pai jobs and pai host to show all tensorboard URLs. One can use some browser extention to open all URLs (e.g., OpenList)

$ pai jobs -u sotetsuk -s RUNNING | grep example_job | xargs -n 1 pai host | grep tensorboard | awk '{printf "http://%s:%s\n",$2,$4}'
http://10.0.0.1:9999
http://10.0.0.2:9999
http://10.0.0.3:9999

Basic usage

For more detailed usage, one can use --help option for each subcommand like pai config --help.

$ pai --help
Usage: pai [OPTIONS] COMMAND [ARGS]...

  A CLI tool for OpenPAI.

Options:
  --help  Show this message and exit.

Commands:
  config  Write your configuration to a file.
  host    Show host information of the specified job.
  jobs    Show job list.
  ssh     SSH into a running container.
  stop    Stop a running job.
  submit  Submit your job.
  token   Generate a new access token

Configuration

Before utilizing paicli subcommands, you have to initialize your configuration about your PAI environment.

  • Config file: To initialize your config file, run pai config. Then your config file will be located in $HOME/.paicli. You should set your host, port, and username. You can use --profile option to use multiple PAI environments.
  • Access token: Before submitting/stopping a job, you should issue your access token by executing pai token and entering your password. You can skip entering password everytime if you write your password directly to your config file (not recommended).

Author

Sotetsu KOYAMADA

paicli's People

Contributors

sotetsuk avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

alan-2018

paicli's Issues

strange error message

 paicli ssh --profile euro
shell-init: error retrieving current directory: getcwd: cannot access parent directories: No such file or directory
shell-init: error retrieving current directory: getcwd: cannot access parent directories: No such file or directory
chdir: error retrieving current directory: getcwd: cannot access parent directories: No such file or directory
chdir: error retrieving current directory: getcwd: cannot access parent directories: No such file or directory
shell-init: error retrieving current directory: getcwd: cannot access parent directories: No such file or directory
shell-init: error retrieving current directory: getcwd: cannot access parent directories: No such file or directory
shell-init: error retrieving current directory: getcwd: cannot access parent directories: No such file or directory
shell-init: error retrieving current directory: getcwd: cannot access parent directories: No such file or directory
shell-init: error retrieving current directory: getcwd: cannot access parent directories: No such file or directory
shell-init: error retrieving current directory: getcwd: cannot access parent directories: No such file or directory
shell-init: error retrieving current directory: getcwd: cannot access parent directories: No such file or directory
shell-init: error retrieving current directory: getcwd: cannot access parent directories: No such file or directory
chdir: error retrieving current directory: getcwd: cannot access parent directories: No such file or directory
sh: 0: getcwd() failed: No such file or directory

Release v0.5.0

  • rename command to just pai
  • -p alias for --profile
  • add test
  • add build
  • update readme
  • #21 store password in config file
  • #37 fix save path of ssh key
  • #40 stop using print
  • #41 enable lower case for state specification of jobs subcommand
  • #43 automatic token update fails
  • #54 delete username option in ssh (or make sure it works)

Error in ssh

 paicli ssh
Traceback (most recent call last):
  File "/home/sotetsuk/.pyenv/versions/miniconda2-latest/bin/paicli", line 11, in <module>
    load_entry_point('paicli==0.2.2', 'console_scripts', 'paicli')()
  File "/home/sotetsuk/.pyenv/versions/miniconda2-latest/lib/python2.7/site-packages/click/core.py", line 722, in __call__
    return self.main(*args, **kwargs)
  File "/home/sotetsuk/.pyenv/versions/miniconda2-latest/lib/python2.7/site-packages/click/core.py", line 697, in main
    rv = self.invoke(ctx)
  File "/home/sotetsuk/.pyenv/versions/miniconda2-latest/lib/python2.7/site-packages/click/core.py", line 1066, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/home/sotetsuk/.pyenv/versions/miniconda2-latest/lib/python2.7/site-packages/click/core.py", line 895, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/home/sotetsuk/.pyenv/versions/miniconda2-latest/lib/python2.7/site-packages/click/core.py", line 535, in invoke
    return callback(*args, **kwargs)
  File "build/bdist.linux-x86_64/egg/paicli/main.py", line 96, in sshcmd
  File "build/bdist.linux-x86_64/egg/paicli/ssh.py", line 20, in run_ssh
IndexError: list index out of range

image

wrong error message in ssh

paicli ssh -j dev0069
SSH failed.
It seems that SSH is not ready yet. Wait a minute and try again.

404 Client Error: Not Found for url: xxx

Return key error when wrong profile is specified

It should raise error like no such profile.

Traceback (most recent call last):
  File "/home/sotetsuk/.pyenv/versions/miniconda3-latest/bin/paicli", line 11, in <module>
    sys.exit(main())
  File "/home/sotetsuk/.pyenv/versions/miniconda3-latest/lib/python3.6/site-packages/click-6.7-py3.6.egg/click/core.py", line 722, in __call__
    return self.main(*args, **kwargs)
  File "/home/sotetsuk/.pyenv/versions/miniconda3-latest/lib/python3.6/site-packages/click-6.7-py3.6.egg/click/core.py", line 697, in main
    rv = self.invoke(ctx)
  File "/home/sotetsuk/.pyenv/versions/miniconda3-latest/lib/python3.6/site-packages/click-6.7-py3.6.egg/click/core.py", line 1066, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/home/sotetsuk/.pyenv/versions/miniconda3-latest/lib/python3.6/site-packages/click-6.7-py3.6.egg/click/core.py", line 895, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/home/sotetsuk/.pyenv/versions/miniconda3-latest/lib/python3.6/site-packages/click-6.7-py3.6.egg/click/core.py", line 535, in invoke
    return callback(*args, **kwargs)
  File "/home/sotetsuk/.pyenv/versions/miniconda3-latest/lib/python3.6/site-packages/paicli/main.py", line 86, in sshcmd
    _load(config)
  File "/home/sotetsuk/.pyenv/versions/miniconda3-latest/lib/python3.6/site-packages/paicli/main.py", line 34, in _load
    config.load()
  File "/home/sotetsuk/.pyenv/versions/miniconda3-latest/lib/python3.6/site-packages/paicli/config.py", line 56, in load
    self.host = config[self.profile]["host"]

Warning from yaml loader

/opt/conda/lib/python3.6/site-packages/paicli/config.py:57: YAMLLoadWarning: calling yaml.load() without Loader=... is deprecated, as the default Loader is unsafe. Please read https://msg.pyyaml.org/load for full details.

Fix time expression in job list

This destroys column consistency.

pai jobs | awk '{print $4}'
createdTime
2019-02-07
2019-02-07
2019-02-07
2019-02-07
2019-02-07
2019-02-07
2019-02-07
2019-02-07
2019-02-07
2019-02-07
2019-02-07
2019-02-07
2019-02-07
2019-02-07
2019-02-07
2019-02-07
2019-02-07
2019-02-07
2019-02-07
2019-02-07

Py3 fails to load config saved by py2

Traceback (most recent call last):
  File "/home/sotetsuk/.pyenv/versions/miniconda3-latest/bin/paicli", line 11, in <module>
    load_entry_point('paicli==0.2.1', 'console_scripts', 'paicli')()
  File "/home/sotetsuk/.pyenv/versions/miniconda3-latest/lib/python3.6/site-packages/click-6.7-py3.6.egg/click/core.py", line 722, in __call__
    return self.main(*args, **kwargs)
  File "/home/sotetsuk/.pyenv/versions/miniconda3-latest/lib/python3.6/site-packages/click-6.7-py3.6.egg/click/core.py", line 697, in main
    rv = self.invoke(ctx)
  File "/home/sotetsuk/.pyenv/versions/miniconda3-latest/lib/python3.6/site-packages/click-6.7-py3.6.egg/click/core.py", line 1066, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/home/sotetsuk/.pyenv/versions/miniconda3-latest/lib/python3.6/site-packages/click-6.7-py3.6.egg/click/core.py", line 895, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/home/sotetsuk/.pyenv/versions/miniconda3-latest/lib/python3.6/site-packages/click-6.7-py3.6.egg/click/core.py", line 535, in invoke
    return callback(*args, **kwargs)
  File "/home/sotetsuk/.pyenv/versions/miniconda3-latest/lib/python3.6/site-packages/paicli-0.2.1-py3.6.egg/paicli/main.py", line 87, in jobscmd
  File "/home/sotetsuk/.pyenv/versions/miniconda3-latest/lib/python3.6/site-packages/paicli-0.2.1-py3.6.egg/paicli/main.py", line 30, in load_config
  File "/home/sotetsuk/.pyenv/versions/miniconda3-latest/lib/python3.6/site-packages/paicli-0.2.1-py3.6.egg/paicli/config.py", line 42, in load
  File "/home/sotetsuk/.pyenv/versions/miniconda3-latest/lib/python3.6/site-packages/paicli-0.2.1-py3.6.egg/paicli/config.py", line 68, in load_config
KeyError: 'host'

Release v0.6.0

  • Add test
  • #70 Enable to choose "waiting" jobs in the options for stopping a job
  • #40 Stop using print
  • #73 Add no column title option to jobs subcommand
  • #43 Automatic token update fails
  • #72 Show error message for (failed) job submission
  • #68 Fix time expression in job list
  • #64 Check return code of sub commands
  • #71 Add --vc=XXX option to jobs subcommand
  • #59 To specify item, use (username, jobname) instead of jobname
  • #54 Delete username option in ssh (or make sure it works)
  • #37 Fix save path of ssh key
  • #41 Enable lower case for state specification of jobs subcommand
  • #48 SSH fails when there are two same name jobs

Add practical examples

  • submit multiple jobs (pai submit w/ envsubst)
  • stop multiple jobs (pai stop and pai jobs)
  • run same command to in several jobs (pai ssh and pai jobs)
  • get all tensorboard urls (pai jobs and pai host)

wrong message for wrong token

It gives wrong error message for wrong token like:

$ paicli submit ssh.json
Submission failed.
Access token seems to be expired.

The actual reason was that the wrong virtual cluster

Create asciinema

To hide some information about PAI:

procedure

  1. jobs to check # of running jobs
  2. submit a job
  3. submit a job from templates (two)
  4. ssh into a job intereactively
  5. stop jobs with one command
# pai jobs --username sokoya --state RUNNING
# head -n 2 job_001.json
# pai submit job_001.json
# pai jobs -u sokoya -n 1
# head -n 2 job_template.json
# for i in `seq -f %03g 2 5`; do cat job_template.json | JOBNAME="job_example_$i" envsubst | pai submit; done
# pai jobs -u sokoya -n 5
# pai ssh 
# pai jobs -u sokoya -s RUNNING | grep job_example_00 | awk '{print $1}'
# pai jobs -u sokoya -s RUNNING | grep jobs_example_00 | awk '{print $1}' | xargs pai stop

Release v0.4.0

https://pypi.org/project/paicli/0.4.0/

Updates

  • task selection in ssh (issue: #8, PR: #27, #28)
  • skip host key checking in ssh (PR: #29)
  • --command option for ssh (PR: #30)
  • remove --jobname opptions from ssh and stop (issue: #22, PR #32)
  • --task-name/--task-index option for ssh (issue: #33, PR: #34)
  • allow muptiple arguments to submit and stop (issue: #16, PR: #35)

New feature usage examples

  • ssh into the specified task paicli ssh $JOBNAME -t $TASKNAME
  • check # of python processes for jobname in `paicli jobs -u sotetsuk | grep $PYTHONJOB | awk '{print $1}'`; do echo $jobname; paicli ssh $jobname -c "ps -aux | grep python | wc -l"; done
  • stop multiple jobs; paicli jobs -u sotetsuk -s RUNNING | grep $JOBNAME | awk '{print $1}' | paicli stop

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.