Skip to content
This repository has been archived by the owner on Sep 18, 2021. It is now read-only.

Change install path to /usr/local/bin/ #10

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 31 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,41 @@ You should install docker before following.
$ sudo apt install python3 python3-pip graphviz
$ git clone https://github.com/slankdev/tinet && cd tinet
$ sudo pip3 install -r requirement.txt
$ sudo cp bin/tn /usr/local/tn
$ sudo cp bin/tn /usr/local/bin/tn
$ tn version
```

Usage:
```
$ cd <working_dir>
$ tn // show usage
$ tn -h // show help
$ tn init // generate init shell-script to stdout
$ tn fini // generate fini shell-script to stdout
$ tn init | sudo sh // generate and execute init shell-script
$ tn fini | sudo sh // generate and execute fnit shell-script
$ tn conf | sudo sh // generate and execute config shell-script
$ tn tpl // generate template
$ tn img // generate network topology image file
Usage:
tn [-f <arg>...] [options] [COMMAND] [ARGS...]
tn -h|--help

Options:
--verbose Generate verbose shell
--dry-run Print the recipes that are needed to execute the
targets up to date, but not actually execute them.
--project-name NAME Specify an alternate project name
(default: none)
--H, --host HOST Daemon socket to connect to

COMMAND:
ps List services
start Start services
stop Stop services
create Create services
rm Remove stopped containers
up Create and start containers
down Stop and remove containers
pull Pull service images
exec Execute a command in a running container
build Generate a Docker bundle from the spec file
conf Execute config-cmd in a running container
reconf Remove, create, start and config
restart Remove, create, start
version Show the tinet version information
test Execute tests
init Generate template spec file
img Generate topology png file
```

Running on VM
Expand Down
68 changes: 68 additions & 0 deletions bin/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
#!/usr/bin/env python3

import sys
import getopt
import argparse
import pprint
import pydot
import yaml

usage_text='''
tn [-f <arg>...] [options] [COMMAND] [ARGS...]
tn -h|--help

Options:
-f --specfile NAME Specify specification yaml file
-v, --verbose Generate verbose shell
--dry-run Print the recipes that are needed to execute the
targets up to date, but not actually execute them.
--project-name NAME Specify an alternate project name
(default: none)
--host HOST Daemon socket to connect to

COMMAND:
ps List services
up Create and start containers
down Stop and remove containers
pull Pull service images
exec Execute a command in a running container
build Generate a Docker bundle from the spec file
conf Execute config-cmd in a running container
reconf Stop, remove, create, start and config
reup Stop, remove, create and start
version Show the tinet version information
test Execute tests
init Generate template spec file
img Generate topology png file
'''

def command_exec(args):
print('command_exec')
print(args)

def command_conf(args):
print('command_conf')
print(args)

def main():
parser = argparse.ArgumentParser(
formatter_class=argparse.RawTextHelpFormatter)
parser.add_argument('-f', '--specfile', default='spec.yaml')
parser.add_argument('-H', '--host', default=None)
parser.add_argument('--project-name', default='')
parser.add_argument('--verbose', action='store_true')

subparsers = parser.add_subparsers(dest='command')
subparsers.required = True

exec_parser = subparsers.add_parser('exec', help='see add exec')
exec_parser.add_argument('target')
exec_parser.set_defaults(func=command_exec)

exec_parser = subparsers.add_parser('conf', help='see add conf')
exec_parser.set_defaults(func=command_conf)

args = parser.parse_args()
args.func(args)

main()
Loading