1
1
import click
2
+ from subprocess import call
2
3
from virl2_client .exceptions import NodeNotFound
3
4
4
5
from virl .api import VIRLServer
5
- from virl .helpers import (get_cml_client , get_current_lab ,
6
- safe_join_existing_lab )
6
+ from virl .helpers import get_cml_client , get_current_lab , safe_join_existing_lab , get_command
7
7
8
8
9
9
@click .command ()
10
- @click .argument ("node" , nargs = 1 )
10
+ @click .argument ("node" , required = False )
11
+ @click .option ("--id" , required = False , help = "An existing node ID to start (the node name argument is ignored)" )
11
12
def start (node ):
12
13
"""
13
14
start a node
14
15
"""
16
+ if not node and not id :
17
+ exit (call ([get_command (), "start" , "--help" ]))
18
+
15
19
server = VIRLServer ()
16
20
client = get_cml_client (server )
17
21
@@ -20,15 +24,18 @@ def start(node):
20
24
lab = safe_join_existing_lab (current_lab , client )
21
25
if lab :
22
26
try :
23
- node_obj = lab .get_node_by_label (node )
27
+ if id :
28
+ node_obj = lab .get_node_by_id (id )
29
+ else :
30
+ node_obj = lab .get_node_by_label (node )
24
31
25
32
if not node_obj .is_active ():
26
33
node_obj .start (wait = True )
27
34
click .secho ("Started node {}" .format (node_obj .label ))
28
35
else :
29
36
click .secho ("Node {} is already active" .format (node_obj .label ), fg = "yellow" )
30
37
except NodeNotFound :
31
- click .secho ("Node {} was not found in lab {}" .format (node , current_lab ), fg = "red" )
38
+ click .secho ("Node {} was not found in lab {}" .format (id if id else node , current_lab ), fg = "red" )
32
39
exit (1 )
33
40
else :
34
41
click .secho ("Unable to find lab {}" .format (current_lab ), fg = "red" )
0 commit comments