- Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathparse_cmd.py
More file actions
Latest commit
106 lines (100 loc) · 3.93 KB
/
Copy pathparse_cmd.py
File metadata and controls
106 lines (100 loc) · 3.93 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
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
importipaddress
importre
fromprocessdbimportprocess_json
fromget_propertyimportget_policy_directory
defparse_commands(node_object,init_config,set_notation):
"""
This function generates the commands in a form of a list so that
it can be passed into the method of the object.
"""
commands=initialize.configuration
config_list= []
ifnode_object['hardware_vendor'] =='juniper'andset_notation!=True:
config_list.append('load replace terminal')
elifnode_object['hardware_vendor'] =='f5':
config_list.append('load sys config merge from-terminal')
forconfig_lineininit_config:
strip_config=config_line.strip('\n')
config_list.append(strip_config)
ifnode_object['hardware_vendor'] =='juniper'andset_notation!=Trueornode_object['hardware_vendor'] =='f5':
config_list.append('\x04')
commands.append(config_list)
returncommands
defcisco_parse_negation_commands(remediate_missing):
commands= []
iflen(remediate_missing) ==0:
pass
else:
fornegateinremediate_missing:
iflen(negate) ==1:
remediate_missing_config='no '+negate[0]
commands.append(remediate_missing_config)
else:
commands.append(negate[0])
forno_configinnegate[1:]:
ifno_config[0].isspace():
remediate_missing_config='no '+no_config.lstrip()
else:
remediate_missing_config='no '+no_config
commands.append(remediate_missing_config)
returncommands
defcitrix_parse_negation_commands(remediate_missing):
remediate_missing=list(itertools.chain.from_iterable(remediate_missing))
command_split= []
commands= []
forlineinremediate_missing:
command_split=line.split()
"""
The below if statement will negate binding configurations associated with policy on the Citrix Netscaler.
"""
ifcommand_split[0] =='bind'andcommand_split[1] =='policy':
command_split[0] ='unbind'
command=' '.join(command_split[0:5])
commands.append(command)
elifcommand_split[0] =='add'andcommand_split[1] =='policy':
command_split[0] ='rm'
command=' '.join(command_split[0:4])
commands.append(command)
elifcommand_split[0] =='add'andcommand_split[1] =='server':
command_split[0] ='rm'
command=' '.join(command_split[0:3])
commands.append(command)
elifcommand_split[0] =='add'andcommand_split[1] =='service':
command_split[0] ='rm'
command=' '.join(command_split[0:3])
commands.append(command)
elifcommand_split[0] =='bind'andcommand_split[1] =='service':
command_split[0] ='unbind'
command=' '.join(command_split[0:3])
commands.append(command)
elifcommand_split[0] =='add'andcommand_split[1] =='serviceGroup':
command_split[0] ='rm'
command=' '.join(command_split[0:3])
commands.append(command)
elifcommand_split[0] =='add'andcommand_split[1] =='lb'andcommand_split[2] =='vserver':
command_split[0] ='rm'
command=' '.join(command_split[0:4])
commands.append(command)
elifcommand_split[0] =='bind'andcommand_split[1] =='lb'andcommand_split[2] =='vserver':
command_split[0] ='unbind'
command=' '.join(command_split[0:5])
commands.append(command)
elifcommand_split[0] =='add'andcommand_split[1] =='cs'andcommand_split[2] =='vserver':
command_split[0] ='rm'
command=' '.join(command_split[0:4])
commands.append(command)
elifcommand_split[0] =='bind'andcommand_split[1] =='cs'andcommand_split[2] =='vserver':
command_split[0] ='unbind'
command=' '.join(command_split[0:4])
commands.append(command)
elifcommand_split[0] =='bind'andcommand_split[1] =='ssl 'andcommand_split[2] =='vserver':
command_split[0] ='unbind'
command=' '.join(command_split[0:4])
commands.append(command)
elifcommand_split[0] =='set'andcommand_split[1] =='ssl 'andcommand_split[2] =='vserver':
command_split[0] ='unset'
command=' '.join(command_split[0:4])
commands.append(command)
else:
commands.append(line)
returncommands