Revision 75c3fc42
b/kamaki/cli/__init__.py | ||
---|---|---|
79 | 79 |
|
80 | 80 |
def _num_of_matching_terms(basic_list, attack_list): |
81 | 81 |
if not attack_list: |
82 |
return 1
|
|
82 |
return len(basic_list)
|
|
83 | 83 |
|
84 | 84 |
matching_terms = 0 |
85 | 85 |
for i, term in enumerate(basic_list): |
... | ... | |
379 | 379 |
_exec_cmd(executable, unparsed, parser.print_help) |
380 | 380 |
|
381 | 381 |
|
382 |
from command_shell import _fix_arguments, Shell |
|
383 |
|
|
384 |
|
|
385 |
def _start_shell(): |
|
386 |
shell = Shell() |
|
387 |
shell.set_prompt(basename(argv[0])) |
|
388 |
from kamaki import __version__ as version |
|
389 |
shell.greet(version) |
|
390 |
shell.do_EOF = shell.do_exit |
|
391 |
return shell |
|
392 |
|
|
393 |
|
|
394 |
def run_shell(arguments): |
|
395 |
_fix_arguments() |
|
396 |
shell = _start_shell() |
|
397 |
_config = _arguments['config'] |
|
398 |
from kamaki.cli.command_tree import CommandTree |
|
399 |
shell.cmd_tree = CommandTree( |
|
400 |
'kamaki', 'A command line tool for poking clouds') |
|
382 |
def run_shell(exe_string, arguments): |
|
383 |
from command_shell import _init_shell |
|
384 |
shell = _init_shell(exe_string, arguments) |
|
385 |
# Load all commands in shell CommandTree |
|
386 |
_config = arguments['config'] |
|
401 | 387 |
for spec in [spec for spec in _config.get_groups()\ |
402 |
if arguments['config'].get(spec, 'cli')]:
|
|
388 |
if _config.get(spec, 'cli')]:
|
|
403 | 389 |
try: |
404 | 390 |
spec_module = _load_spec_module(spec, arguments, '_commands') |
405 | 391 |
spec_commands = getattr(spec_module, '_commands') |
... | ... | |
433 | 419 |
parser.print_help() |
434 | 420 |
_groups_help(_arguments) |
435 | 421 |
else: |
436 |
run_shell(_arguments) |
|
422 |
run_shell(exe, _arguments)
|
|
437 | 423 |
except CLIError as err: |
438 | 424 |
if _debug: |
439 | 425 |
raise err |
b/kamaki/cli/command_shell.py | ||
---|---|---|
43 | 43 |
from kamaki.cli.errors import CLIError |
44 | 44 |
|
45 | 45 |
|
46 |
def _fix_arguments(): |
|
47 |
_arguments.pop('version', None) |
|
48 |
_arguments.pop('options', None) |
|
49 |
_arguments.pop('history', None) |
|
46 |
def _init_shell(exe_string, arguments): |
|
47 |
arguments.pop('version', None) |
|
48 |
arguments.pop('options', None) |
|
49 |
arguments.pop('history', None) |
|
50 |
shell = Shell() |
|
51 |
shell.set_prompt(exe_string) |
|
52 |
from kamaki import __version__ as version |
|
53 |
shell.greet(version) |
|
54 |
shell.do_EOF = shell.do_exit |
|
55 |
from kamaki.cli.command_tree import CommandTree |
|
56 |
shell.cmd_tree = CommandTree( |
|
57 |
'kamaki', 'A command line tool for poking clouds') |
|
58 |
return shell |
|
50 | 59 |
|
51 | 60 |
|
52 | 61 |
class Shell(Cmd): |
b/kamaki/cli/commands/cyclades_cli.py | ||
---|---|---|
113 | 113 |
def _print(self, server): |
114 | 114 |
addr_dict = {} |
115 | 115 |
if 'attachments' in server: |
116 |
for addr in server['attachments']['values']: |
|
116 |
atts = server.pop('attachments') |
|
117 |
for addr in atts['values']: |
|
117 | 118 |
ips = addr.pop('values', []) |
118 | 119 |
for ip in ips: |
119 | 120 |
addr['IPv%s' % ip['version']] = ip['addr'] |
120 | 121 |
if 'firewallProfile' in addr: |
121 | 122 |
addr['firewall'] = addr.pop('firewallProfile') |
122 | 123 |
addr_dict[addr.pop('id')] = addr |
123 |
server['attachments'] = addr_dict if addr_dict is not {} else None
|
|
124 |
server['attachments'] = addr_dict if addr_dict else None |
|
124 | 125 |
if 'metadata' in server: |
125 | 126 |
server['metadata'] = server['metadata']['values'] |
126 | 127 |
print_dict(server, ident=2) |
b/kamaki/cli/commands/test_cli.py | ||
---|---|---|
34 | 34 |
from kamaki.cli import get_cmd_terms, command |
35 | 35 |
from kamaki.cli.commands import _command_init |
36 | 36 |
from kamaki.cli.command_tree import CommandTree |
37 |
from kamaki.cli.argument import FlagArgument
|
|
37 |
from kamaki.clients import tests
|
|
38 | 38 |
|
39 |
sample_cmds = CommandTree( |
|
40 |
'sample', |
|
41 |
'Sample commands for developing your own') |
|
42 |
test_cmds = CommandTree( |
|
43 |
'test', |
|
44 |
'Test commands for testing clients') |
|
45 |
_commands = [sample_cmds, test_cmds] |
|
39 |
test_cmds = CommandTree('test', 'Unitest clients') |
|
40 |
_commands = [test_cmds] |
|
46 | 41 |
|
47 | 42 |
|
48 |
print('Command Terms: ', get_cmd_terms()) |
|
43 |
#print('Command Terms: ', get_cmd_terms())
|
|
49 | 44 |
|
50 | 45 |
|
51 | 46 |
class _test_init(_command_init): |
52 | 47 |
|
53 |
def main(self, *args, **kwargs): |
|
54 |
print(self.__class__) |
|
55 |
for v in args: |
|
56 |
print('\t\targ: %s' % v) |
|
57 |
for k, v in kwargs.items(): |
|
58 |
print('\t\tkwarg: %s: %s' % (k, v)) |
|
48 |
def main(self, client, method=None): |
|
49 |
if method: |
|
50 |
tests.main([client, method]) |
|
51 |
else: |
|
52 |
tests.main([client]) |
|
59 | 53 |
|
60 | 54 |
|
61 |
@command(sample_cmds) |
|
62 |
class sample_cmd0(_test_init): |
|
63 |
""" test cmd |
|
64 |
This is the zero command test and this is the long description of it |
|
65 |
""" |
|
66 |
|
|
67 |
def main(self, mant): |
|
68 |
super(self.__class__, self).main(mant) |
|
69 |
|
|
70 |
|
|
71 |
@command(sample_cmds) |
|
72 |
class sample_cmd_all(_test_init): |
|
73 |
"""test cmd all""" |
|
55 |
@command(test_cmds) |
|
56 |
class test_all(_test_init): |
|
57 |
"""test all clients""" |
|
74 | 58 |
|
75 | 59 |
def main(self): |
76 |
super(self.__class__, self).main() |
|
60 |
for client in ('pithos', 'cyclades', 'image', 'astakos'): |
|
61 |
super(self.__class__, self).main(client) |
|
77 | 62 |
|
78 | 63 |
|
79 |
@command(sample_cmds)
|
|
80 |
class sample_cmd_some(_test_init):
|
|
81 |
"""test_cmd_some"""
|
|
64 |
@command(test_cmds)
|
|
65 |
class test_pithos(_test_init):
|
|
66 |
""" test Pithos client"""
|
|
82 | 67 |
|
83 |
def main(self, opt='lala'):
|
|
84 |
super(self.__class__, self).main(opt=opt)
|
|
68 |
def main(self, method=None):
|
|
69 |
super(self.__class__, self).main('pithos', method)
|
|
85 | 70 |
|
86 | 71 |
|
87 | 72 |
@command(test_cmds) |
88 |
class test_cmd0(_test_init):
|
|
89 |
""" test cmd"""
|
|
73 |
class test_cyclades(_test_init):
|
|
74 |
""" test Cyclades client"""
|
|
90 | 75 |
|
91 |
def main(self, mant):
|
|
92 |
super(self.__class__, self).main(mant)
|
|
76 |
def main(self, method=None):
|
|
77 |
super(self.__class__, self).main('cyclades', method)
|
|
93 | 78 |
|
94 | 79 |
|
95 | 80 |
@command(test_cmds) |
96 |
class test_cmd_all(_test_init): |
|
97 |
"""test cmd all""" |
|
98 |
|
|
99 |
def __init__(self, arguments={}): |
|
100 |
super(self.__class__, self).__init__(arguments) |
|
101 |
self.arguments['testarg'] = FlagArgument('a test arg', '--test') |
|
81 |
class test_image(_test_init): |
|
82 |
""" test Image client""" |
|
102 | 83 |
|
103 |
def main(self): |
|
104 |
super(self.__class__, self).main() |
|
84 |
def main(self, method=None):
|
|
85 |
super(self.__class__, self).main('image', method)
|
|
105 | 86 |
|
106 | 87 |
|
107 | 88 |
@command(test_cmds) |
108 |
class test_cmdion(_test_init):
|
|
109 |
"""test_cmd_some"""
|
|
89 |
class test_astakos(_test_init):
|
|
90 |
""" test Astakos client"""
|
|
110 | 91 |
|
111 |
def main(self, opt='lala'):
|
|
112 |
super(self.__class__, self).main(opt=opt)
|
|
92 |
def main(self, method=None):
|
|
93 |
super(self.__class__, self).main('astakos', method)
|
|
113 | 94 |
|
114 | 95 |
|
115 | 96 |
@command(test_cmds) |
116 |
class test_cmd_cmdion_comedian(_test_init):
|
|
117 |
"""test_cmd_some"""
|
|
97 |
class test_lala_lele(_test_init):
|
|
98 |
"""test lala lele"""
|
|
118 | 99 |
|
119 |
def main(self, opt='lala'): |
|
120 |
super(self.__class__, self).main(opt=opt) |
|
100 |
def main(self, *args): |
|
101 |
print('Do smth') |
b/kamaki/clients/tests.py | ||
---|---|---|
912 | 912 |
def test_get_server_console(self): |
913 | 913 |
"""Test get_server_console""" |
914 | 914 |
self.server2 = self._create_server(self.servname2, |
915 |
self.flavorid + 1,
|
|
915 |
self.flavorid + 2,
|
|
916 | 916 |
self.img) |
917 |
self._wait_for_status(self.server2['id'], 'BUILD') |
|
917 | 918 |
self._test_get_server_console() |
918 | 919 |
|
919 | 920 |
def _test_get_server_console(self): |
920 |
self._wait_for_status(self.server2['id'], 'BUILD') |
|
921 | 921 |
r = self.client.get_server_console(self.server2['id']) |
922 | 922 |
self.assertTrue('host' in r) |
923 | 923 |
self.assertTrue('password' in r) |
... | ... | |
1073 | 1073 |
r = self.client.list_server_nics(self.server1['id']) |
1074 | 1074 |
len0 = len(r) |
1075 | 1075 |
self.assertTrue(len0 > 0) |
1076 |
print(' ' + net) |
|
1076 | 1077 |
self.assertTrue('1' in [net['network_id'] for net in r]) |
1077 | 1078 |
|
1078 | 1079 |
self.client.connect_server(self.server1['id'], self.network2['id']) |
... | ... | |
2289 | 2290 |
help="Show this help message and exit") |
2290 | 2291 |
return parser |
2291 | 2292 |
|
2292 |
if __name__ == '__main__': |
|
2293 |
parser = init_parser() |
|
2294 |
args, argv = parser.parse_known_args() |
|
2295 | 2293 |
|
2296 |
if len(argv) > 2 or getattr(args, 'help') or len(argv) < 1: |
|
2297 |
raise Exception('\tusage: tests.py <group> [command]') |
|
2298 |
suiteFew = unittest.TestSuite() |
|
2294 |
def main(argv): |
|
2299 | 2295 |
|
2296 |
suiteFew = unittest.TestSuite() |
|
2300 | 2297 |
if len(argv) == 0 or argv[0] == 'pithos': |
2301 | 2298 |
if len(argv) == 1: |
2302 | 2299 |
suiteFew.addTest(unittest.makeSuite(testPithos)) |
... | ... | |
2320 | 2317 |
suiteFew.addTest(testAstakos('test_' + argv[1])) |
2321 | 2318 |
|
2322 | 2319 |
unittest.TextTestRunner(verbosity=2).run(suiteFew) |
2320 |
|
|
2321 |
if __name__ == '__main__': |
|
2322 |
parser = init_parser() |
|
2323 |
args, argv = parser.parse_known_args() |
|
2324 |
if len(argv) > 2 or getattr(args, 'help') or len(argv) < 1: |
|
2325 |
raise Exception('\tusage: tests.py <group> [command]') |
|
2326 |
main(argv) |
Also available in: Unified diff