-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtoggle-node
More file actions
executable file
·64 lines (51 loc) · 2.5 KB
/
toggle-node
File metadata and controls
executable file
·64 lines (51 loc) · 2.5 KB
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
#!/usr/bin/python
import sys
import requests
from requests.auth import HTTPBasicAuth
import json
from requests.packages.urllib3.exceptions import InsecureRequestWarning
import pprint
import argparse
import logging
parser = argparse.ArgumentParser(description='Stop or start the named node in a named simulation.')
parser.add_argument('--host', required='True', dest='virl_host', action='store', help='IP address or FQDN the VIRL host.')
parser.add_argument('-u', '--user', required='True', dest='virl_user', action='store', help='VIRL user name.')
parser.add_argument('-p', '--password', required='True', dest='virl_pwd', action='store', help='VIRL password.')
parser.add_argument('-s', '--simulation', required='True', dest='sim_name', action='store', help='Simulation name.')
parser.add_argument('-n', '--node', required='True', dest='node_name', action='store', help='Node name.')
group = parser.add_mutually_exclusive_group()
group.add_argument('--start', action='store_true', help='Start the node')
group.add_argument('--stop', action='store_true', help='Stop the node')
args = parser.parse_args()
parser.format_help()
try:
import http.client as http_client
except ImportError:
import httplib as http_client
http_client.HTTPConnection.debuglevel = 1
# Initialize the logging function data structures
logging.basicConfig()
logging.getLogger().setLevel(logging.DEBUG)
requests_log = logging.getLogger("requests.packages.urllib3")
requests_log.setLevel(logging.DEBUG)
requests_log.propagate = True
def main():
requests.packages.urllib3.disable_warnings(InsecureRequestWarning)
if args.stop:
r = stop_node(args.virl_host, args.virl_user, args.virl_pwd, args.sim_name, args.node_name)
elif args.start:
r = start_node(args.virl_host, args.virl_user, args.virl_pwd, args.sim_name, args.node_name)
exit(0)
def stop_node(virl_host, virl_user, virl_pwd, sim_name, node_name):
url = "http://%s:19399/simengine/rest/update/%s/stop" % (virl_host, sim_name)
headers = {'content-type': 'text/xml'}
payload = {'nodes': node_name}
r = requests.put(url, auth=(virl_user, virl_pwd), params=payload, headers=headers)
return r
def start_node(virl_host, virl_user, virl_pwd, sim_name, node_name):
url = "http://%s:19399/simengine/rest/update/%s/start" % (virl_host, sim_name)
headers = {'content-type': 'text/xml'}
payload = {'nodes': node_name}
r = requests.put(url, auth=(virl_user, virl_pwd), params=payload, headers=headers)
return r
main()