This repository has been archived by the owner on Sep 18, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
tn
executable file
·733 lines (650 loc) · 22.4 KB
/
tn
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
#!/usr/bin/env python3
import sys
import getopt
import argparse
import pprint
import pydot
import yaml
class AppInfo:
verbose = False
host = None
name = ''
specfile = ''
version = 'TiNet version 0.0 alpha'
command = ''
namespace = ''
data = []
def __init__(self):
self.specfile = 'spec.yaml'
self.verbose = False
self.host = None
self.name = ''
self.command = 'version'
if self.host != None:
sys.stderr.write('remote host isn\'t supported.\n')
sys.exit(1)
if self.name != '':
sys.stderr.write('project-name isn\'t supported.\n')
sys.exit(1)
def read_yaml(self, filename):
filename = appinfo.specfile
f = open(filename, "r+")
appinfo.data = yaml.load(f, Loader=yaml.SafeLoader)
print('## Check META config')
if 'meta' in appinfo.data:
if 'namespace' in appinfo.data['meta']:
appinfo.namespace = appinfo.data['meta']['namespace']
print('# namespace was configured as {}'.format(appinfo.namespace))
appinfo = AppInfo()
template_spec='''
postinit:
- cmds:
- cmd: echo slankdev
meta:
namespace: ns_
nodes:
- name: C0
type: docker #optional (default:docker)
image: slankdev/ubuntu:18.04
interfaces:
- { name: net0, type: direct, args: C1#net0 }
- { name: net1, type: bridge, args: B0 }
- { name: net2, type: veth , args: peer0 }
- { name: net3, type: phys }
- name: C1
type: netns #optional (default:docker)
interfaces:
- { name: net0, type: direct, args: C0#net0 }
- { name: net1, type: bridge, args: B0 }
switches:
- name: B0
interfaces:
- { name: net0, type: docker, args: C0 }
- { name: net0, type: netns, args: C0 }
node_configs:
- name: C0
cmds:
- cmd: ip link set dev net0 up
- name: C1
cmds:
- cmd: echo slankdev slankdev
- cmd: >-
echo slankdev &&
echo slnakdev
test:
- name: p2p
cmds:
- cmd: docker exec C0 ping -c2 10.0.0.2
- cmd: echo slankdev slankdev
- name: lo
cmds:
- cmd: docker exec C0 ping -c2 10.255.0.1
- cmd: echo slankdev slankdev
'''
text__mount_docker_netns='''
mount_docker_netns () {
if [ $# -ne 2 ]; then
echo "Usage: $0 <container> <netns>"
exit 1
fi
mkdir -p /var/run/netns
PID=`docker inspect $1 -f "{{.State.Pid}}"`
ln -s /proc/$PID/ns/net /var/run/netns/$2
}
'''
text__kokobr='''
kokobr () {
if [ $# -ne 3 ]; then
echo "Usage: $0 <bridge> <container> <ifname>"
exit 1
fi
mount_docker_netns $2 $2
ip link add name $3 type veth peer name $2$3
ip link set dev $3 netns $2
ip link set $2$3 up
ip netns exec $2 ip link set $3 up
ip netns del $2
ovs-vsctl add-port $1 $2$3
}
'''
text__kokobr_netns='''
kokobr_netns () {
if [ $# -ne 3 ]; then
echo "Usage: $0 <bridge> <netns> <ifname>"
exit 1
fi
ip link add name $3 type veth peer name $2$3
ip link set dev $3 netns $2
ip link set $2$3 up
ip netns exec $2 ip link set $3 up
ovs-vsctl add-port $1 $2$3
}
'''
text__koko_physnet ='''
koko_physnet () {
if [ $# -ne 2 ]; then
echo "Usage: $0 <container> <netif>"
exit 1
fi
mount_docker_netns $1 $1
ip link set dev $2 netns $1
ip netns exec $1 ip link set $2 up
ip netns del $1
}
'''
text__detach_physif_from_docker='''
detach_physif_from_docker () {
if [ $# -ne 2 ]; then
echo "Usage: $0 <container> <netif>"
exit 1
fi
mount_docker_netns $1 $1
ip netns exec $1 ip link set $2 netns 1
ip netns del $1
}
'''
def generate_mount_docker_netns():
print(text__mount_docker_netns)
def generate_kokobr():
print(text__kokobr)
def generate_kokobr_netns():
print(text__kokobr_netns)
def generate_koko_physnet():
print(text__koko_physnet)
def generate_detach_physif_from_docker():
print(text__detach_physif_from_docker)
def precmd():
if 'precmd' in appinfo.data:
for node in appinfo.data['precmd']:
for cmd in node['cmds']:
print('{}'.format(cmd['cmd']))
def command_ps(args):
print('docker ps --format "table {{.ID}}\\t{{.Names}}"')
def postinit():
print('\n#####################')
print('# POST-INIT COMMANDS #')
print('#####################')
if 'postinit' in appinfo.data:
for node in appinfo.data['postinit']:
for cmd in node['cmds']:
print('{}'.format(cmd['cmd']))
def command_up(args):
def preinit():
print('\n#####################')
print('# PRE-INIT COMMANDS #')
print('#####################')
if 'preinit' in appinfo.data:
for node in appinfo.data['preinit']:
for cmd in node['cmds']:
print('{}'.format(cmd['cmd']))
print("set -ue")
precmd()
generate_mount_docker_netns()
generate_kokobr()
generate_kokobr_netns()
generate_koko_physnet()
preinit()
print('\n#####################')
print('# INIT COMMANDS #')
print('#####################')
# CREATE NODES
print('\n# generate nodes')
if 'nodes' in appinfo.data:
for node in appinfo.data['nodes']:
nodetype = node.get('type', 'docker')
net_base = node.get('net_base', None)
volume_base = node.get('volume', '/tmp/tinet')
tinet_volume_option = '-v {}:/tinet'.format(volume_base)
docker_run_extra_args = node.get('docker_run_extra_args', '')
entrypoint = node.get('entrypoint', None)
entrypoint_option = ''
if entrypoint is not None:
entrypoint_option = '--entrypoint {}'.format(entrypoint)
if nodetype == 'docker':
if net_base == None:
net_base = 'none'
print('docker run -td --hostname {} --net {} '
'--name {}{} --rm --privileged {} {} {} {}'
.format(node['name'], net_base, appinfo.namespace, node['name'],
entrypoint_option, tinet_volume_option, docker_run_extra_args, node['image']))
elif nodetype == 'netns':
if net_base != None:
print('You cannot use net_base with type: netns')
sys.exit(1)
print('ip netns add {}{}'.format(appinfo.namespace, node['name']))
print('ip netns exec {}{} ip link set lo up'.format(appinfo.namespace, node['name']))
else:
print('unknown node-type {}'.format(node['type']))
sys.exit(1)
# CREATE SWITCHES
if 'switches' in appinfo.data:
for sw in appinfo.data['switches']:
print('ovs-vsctl add-br {}{} && ip link set {} up'.format(appinfo.namespace, sw['name'], sw['name']));
links = []
# CREATE Node to Node LINKS
class n2n_link:
left_node_name = None
left_iface_name = None
left_isset = False
left_node_type = None
right_node_name = None
right_iface_name = None
right_isset = False
right_node_type = None
def __init__(self, ln_name, ln_iface, rn_name=None, rn_iface=None):
self.left_node_name = ln_name
self.left_iface_name = ln_iface
self.right_node_name = rn_name
self.right_iface_name = rn_iface
self.left_isset = True
def koko(self):
# EXAMPLE:
# sudo ip link add net0 netns C0 type veth \
# peer name net0 netns C1
print('\n# connect {} to {}'.format(self.left_node_name, self.right_node_name))
if self.left_node_type == 'docker':
print('mount_docker_netns {}{} {}{}'.format(
appinfo.namespace,
self.left_node_name,
appinfo.namespace,
self.left_node_name))
if self.right_node_type == 'docker':
print('mount_docker_netns {}{} {}{}'.format(
appinfo.namespace,
self.right_node_name,
appinfo.namespace,
self.right_node_name))
print('ip link add {} netns {}{} type veth peer name {} netns {}{}'.format(
self.left_iface_name,
appinfo.namespace,
self.left_node_name,
self.right_iface_name,
appinfo.namespace,
self.right_node_name))
print('ip netns exec {}{} ip link set {} up'.format(
appinfo.namespace,
self.left_node_name, self.left_iface_name))
print('ip netns exec {}{} ip link set {} up'.format(
appinfo.namespace,
self.right_node_name, self.right_iface_name))
if self.left_node_type == 'docker':
print('ip netns del {}{}'.format(appinfo.namespace, self.left_node_name))
if self.right_node_type == 'docker':
print('ip netns del {}{}'.format(appinfo.namespace, self.right_node_name))
def check(self):
if not (self.right_isset and self.left_isset):
Exception('n2n_link state is not correct')
if 'nodes' in appinfo.data:
for node in appinfo.data['nodes']:
for i in range(len(node['interfaces'])):
iface = node['interfaces'][i]
if (iface['type']=='direct'):
r_nname = iface['args'].split('#')[0]
r_ifname = iface['args'].split('#')[1]
peer_found = False
for link in links:
if link.right_isset == False:
b0 = link.left_node_name == r_nname
b1 = link.left_iface_name == r_ifname
if b0 and b1: # found peer
link.right_node_name = node['name']
link.right_iface_name = iface['name']
link.right_node_type = node.get('type', 'docker')
link.right_isset = True
peer_found = True
if peer_found == False:
new_link = n2n_link(node['name'], iface['name'], r_nname, r_ifname)
new_link.left_node_type = node.get('type', 'docker')
links.append(new_link)
for link in links:
link.check()
link.koko()
links = []
# CREATE Node to Switch LINKS
class s2n_link:
node_name = None
node_iface = None
node_isset = False
node_type = None
switch_name = None
switch_isset = False
def __init__(self, n_name, n_iface, n_type, s_name):
self.node_name = n_name
self.node_iface = n_iface
self.node_type = n_type
self.switch_name = s_name
def koko(self):
if self.node_type == 'docker':
print('kokobr {} {} {}'.format(self.switch_name, self.node_name, self.node_iface))
elif self.node_type == 'netns':
print('kokobr_netns {} {} {}'.format(self.switch_name, self.node_name, self.node_iface))
else:
print('unknown node-type {}'.format(self.node_type))
def check(self):
if not (self.node_isset and self.switch_isset):
Exception('s2n_link state is not correct')
if ('nodes' in appinfo.data) and ('switches' in appinfo.data):
for node in appinfo.data['nodes']:
for i in range(len(node['interfaces'])):
iface = node['interfaces'][i]
if (iface['type']=='bridge'):
print('\n# connect {} and {}'
.format(node['name'], iface['args']))
new_link = s2n_link(node['name'], iface['name'],
node.get('type', 'docker'), iface['args'])
new_link.node_isset = True
new_link.switch_isset = False
links.append(new_link)
for sw in appinfo.data['switches']:
for i in range(len(sw['interfaces'])):
iface = sw['interfaces'][i]
for link in links:
if link.switch_isset == False:
b0 = iface['args'] == link.node_name
b1 = iface['name'] == link.node_iface
b2 = sw['name'] == link.switch_name
if b0 and b1 and b2:
link.switch_isset = True
for link in links:
link.check()
link.koko()
# Attach PhysNetIf to Conitaner
if 'nodes' in appinfo.data:
for node in appinfo.data['nodes']:
for i in range(len(node['interfaces'])):
iface = node['interfaces'][i]
if (iface['type']=='phys'):
print('koko_physnet {}{} {}'.format(appinfo.namespace, node['name'], iface['name']))
# Attach raw veth to Conitaner
if 'nodes' in appinfo.data:
for node in appinfo.data['nodes']:
for i in range(len(node['interfaces'])):
iface = node['interfaces'][i]
if (iface['type']=='veth'):
print('ip link add {} type veth peer name {}'.format(
iface['name'], iface['args']))
print('koko_physnet {}{} {}'.format(appinfo.namespace, node['name'], iface['name']))
print('ip link set {} up'.format(iface['args']))
postinit()
def command_down(args):
def prefini():
print('\n#####################')
print('# PRE-FINI COMMANDS #')
print('#####################')
if 'prefini' in appinfo.data:
for node in appinfo.data['prefini']:
for cmd in node['cmds']:
print('{}'.format(cmd['cmd']))
def postfini():
print('\n#####################')
print('# POST-FINI COMMANDS #')
print('#####################')
if 'postfini' in appinfo.data:
for node in appinfo.data['postfini']:
for cmd in node['cmds']:
print('{}'.format(cmd['cmd']))
precmd()
generate_mount_docker_netns()
generate_detach_physif_from_docker()
print('\n################')
print('# FINI Commands #')
print('################')
if 'nodes' in appinfo.data:
for node in appinfo.data['nodes']:
for i in range(len(node['interfaces'])):
iface = node['interfaces'][i]
if (iface['type']=='phys'):
print('detach_physif_from_docker {}{} {}'.format(appinfo.namespace, node['name'], iface['name']))
for node in appinfo.data['nodes']:
nodetype = node.get('type', 'docker')
if nodetype=='docker':
print('docker rm -f {}{}'.format(appinfo.namespace, node['name']))
elif nodetype=='netns':
print('ip netns del {}{}'.format(appinfo.namespace, node['name']))
else:
print('unknown nodetype {}'.format(nodetype))
sys.exit(1)
if 'switches' in appinfo.data:
for sw in appinfo.data['switches']:
print('ovs-vsctl del-br {}{}'.format(appinfo.namespace, sw['name']));
postfini()
def command_pull(args):
precmd()
print('{}()'.format(sys._getframe().f_code.co_name))
print('\n######################')
print('# PULL DOCKER IMAGES #')
print('######################')
if 'nodes' in appinfo.data:
for node in appinfo.data['nodes']:
if node['type'] == 'docker':
print('docker pull {}'.format(node['image']))
def command_exec(args):
node = None
for n in appinfo.data['nodes']:
if n['name'] == args.NODE:
node = n
break
if node == None:
sys.stderr.write('no such node...\n')
sys.exit(1)
cmdstr = ''
node_type = node.get('type', 'docker')
if node_type == 'docker':
cmdstr = 'docker exec -it {}{}'.format(appinfo.namespace, args.NODE)
elif node_type == 'netns':
cmdstr = 'ip netns exec {}{}'.format(appinfo.namespace, args.NODE)
else:
sys.stderr.write('no such node type...\n')
sys.exit(1)
for s in args.COMMAND:
cmdstr = '{} {}'.format(cmdstr, s)
print('{}'.format(cmdstr))
def command_build(args):
print('{}()'.format(sys._getframe().f_code.co_name))
sys.stderr.write('ATODE\n')
sys.exit(1)
def command_conf(args):
def preconf(data):
print('\n#####################')
print('# PRE-CONF COMMANDS #')
print('#####################')
if 'preconf' in appinfo.data:
for node in appinfo.data['preconf']:
for cmd in node['cmds']:
print('{}'.format(cmd['cmd']))
def postconf(data):
print('\n#####################')
print('# POST-CONF COMMANDS #')
print('#####################')
if 'postconf' in appinfo.data:
for node in appinfo.data['postconf']:
for cmd in node['cmds']:
print('{}'.format(cmd['cmd']))
def get_node_type_from_nodes(name, default):
if 'nodes' in appinfo.data:
for node in appinfo.data['nodes']:
if node['name'] == name:
return node.get('type', default)
print('not found node {}'.format(name))
sys.exit(1)
print("set -ue")
precmd()
preconf(appinfo.data)
print('\n################')
print('# NODE CONFIG #')
print('################')
if 'node_configs' in appinfo.data:
for node in appinfo.data['node_configs']:
print('echo {}::[config]::start'.format(node['name']))
nodetype = get_node_type_from_nodes(node['name'], 'docker')
for cmd in node['cmds']:
if nodetype=='docker':
print('docker exec {}{} {} > /dev/null'.format(appinfo.namespace, node['name'], cmd['cmd']))
elif nodetype=='netns':
print('ip netns exec {}{} {} > /dev/null'.format(appinfo.namespace, node['name'], cmd['cmd']))
else:
print('unknown node-type {}'.format(nodetype))
print('echo {}::[config]::fin'.format(node['name']))
postconf(appinfo.data)
def command_upconf(args):
precmd()
command_up(args)
command_conf(args)
def command_reconf(args):
precmd()
command_reup(args)
command_conf(args)
def command_reup(args):
precmd()
command_down(args)
command_up(args)
def command_version(args):
print(appinfo.version)
def command_test(args):
precmd()
test_name = args.NAME
print('\n#####################')
print('# INTEGRATION TEST #')
print('#####################')
if 'test' in appinfo.data:
print('set -eu')
for node in appinfo.data['test']:
if (node['name'] == test_name):
for cmd in node['cmds']:
cmd_str = cmd['cmd']
print('echo -n execute [{}]...'.format(cmd_str))
print('{} >> /dev/null'.format(cmd_str))
print('echo done\n')
return
print('test \'{}\' was not found'.format(test_name))
def command_postinit(args):
print("set -ue")
precmd()
postinit()
def command_init(args):
print(template_spec)
def command_img(args):
def is_exist(graph, me):
edge_list = graph.get_edge_list()
for edge in edge_list:
pair = edge.obj_dict['points']
me_pair = me.obj_dict['points']
b0 = (pair[0]==me_pair[0] and pair[1]==me_pair[1])
b1 = (pair[1]==me_pair[0] and pair[0]==me_pair[1])
if (b0 or b1):
return True
return False
graph = pydot.Dot(graph_type='graph', overlap=False, splines=True)
for i in range(len(appinfo.data['nodes'])):
node_name = appinfo.data["nodes"][i]["name"]
graph.add_node(pydot.Node(node_name, label=node_name))
iface_info = appinfo.data["nodes"][i]["interfaces"]
for j in range(len(iface_info)):
args_name = iface_info[j]['args'].split("#")[0]
new_edge = pydot.Edge(node_name, args_name)
new_edge = pydot.Edge(node_name, args_name)
iface_name_label = iface_info[j]['name']
new_edge.set_headlabel(iface_info[j]['args'].split("#")[1])
new_edge.set_taillabel(iface_info[j]['name'])
new_edge.set_fontsize(8)
if not is_exist(graph, new_edge):
graph.add_edge(new_edge)
graph.write_png('topo.png', prog='sfdp')
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')
parser.add_argument('--dry-run', action='store_true')
# 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
# img Generate topology png file
# '''
subparsers = parser.add_subparsers(dest='command')
subparsers.required = True
parser_ps = subparsers.add_parser('ps',
help='List services')
parser_ps.set_defaults(func=command_ps)
parser_up = subparsers.add_parser('up',
help='Create and start containers')
parser_up.set_defaults(func=command_up)
parser_down = subparsers.add_parser('down',
help='Stop and remove containers')
parser_down.set_defaults(func=command_down)
parser_pull = subparsers.add_parser('pull',
help='Pull service images')
parser_pull.set_defaults(func=command_pull)
parser_exec = subparsers.add_parser('exec',
help='Execute a command in a running container')
parser_exec.add_argument('NODE')
parser_exec.add_argument('COMMAND', nargs='+')
parser_exec.set_defaults(func=command_exec)
parser_build = subparsers.add_parser('build',
help='Generate a Docker bundle from the spec file')
parser_build.set_defaults(func=command_build)
parser_conf = subparsers.add_parser('conf',
help='Execute config-cmd in a running container')
parser_conf.set_defaults(func=command_conf)
parser_reconf = subparsers.add_parser('upconf',
help='Create, start and config')
parser_reconf.set_defaults(func=command_upconf)
parser_reconf = subparsers.add_parser('reconf',
help='Stop, remove, create, start and config')
parser_reconf.set_defaults(func=command_reconf)
parser_reup = subparsers.add_parser('reup',
help='Stop, remove, create and start')
parser_reup.set_defaults(func=command_reup)
parser_version = subparsers.add_parser('version',
help='Show the tinet version information')
parser_version.set_defaults(func=command_version)
parser_test = subparsers.add_parser('test',
help='Execute tests')
parser_test.set_defaults(func=command_test)
parser_test.add_argument('NAME')
parser_init = subparsers.add_parser('init',
help='Generate template spec file')
parser_init.set_defaults(func=command_init)
parser_img = subparsers.add_parser('img',
help='Generate topology png file')
parser_img.set_defaults(func=command_img)
parser_postinit = subparsers.add_parser('postinit',
help='Generate post init script')
parser_postinit.set_defaults(func=command_postinit)
args = parser.parse_args()
# print('------------')
# print('verbose {}'.format(args.verbose))
# print('specfile {}'.format(args.specfile))
# print('host {}'.format(args.host))
# print('pjname {}'.format(args.project_name))
# print('command {}'.format(args.command))
# print('------------')
appinfo.verbose=args.verbose
appinfo.specfile=args.specfile
appinfo.host=args.host
appinfo.name=args.project_name
appinfo.command=args.command
need_data = {'ps', 'up', 'down', 'pull', 'exec',
'build', 'conf', 'upconf', 'reconf', 'reup', 'test', 'img',
'postinit'}
if args.command in need_data:
try:
appinfo.read_yaml(appinfo.specfile)
except IOError:
sys.stderr.write('IOError: file {} not found.\n'.format(appinfo.specfile))
sys.exit(1)
except:
sys.stderr.write('Yaml {} maybe invalid...?\n'.format(appinfo.specfile))
sys.exit(1)
args.func(args)
main()