-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathmaps_clear.py
More file actions
182 lines (154 loc) · 8.05 KB
/
Copy pathmaps_clear.py
File metadata and controls
182 lines (154 loc) · 8.05 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
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
#!/usr/bin/python
# -*- coding: utf-8 -*-
"""
Copyright 2023, 2024, 2025, 2026 Jack Consoli. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
the License. You may also obtain a copy of the License at https://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific
language governing permissions and limitations under the License.
The license is free for single customer use (internal applications). Use of this module in the production,
redistribution, or service delivery for commerce requires an additional license. Contact jack_consoli@yahoo.com for
details.
:mod:`maps_clear.py` - Clear the MAPS dashboard
**Version Control**
+-----------+---------------+---------------------------------------------------------------------------------------+
| Version | Last Edit | Description |
+===========+===============+=======================================================================================+
| 4.0.0 | 04 Aug 2023 | Re-Launch |
+-----------+---------------+---------------------------------------------------------------------------------------+
| 4.0.1 | 06 Mar 2024 | Set verbose debug via brcdapi.brcdapi_rest.verbose_debug() |
+-----------+---------------+---------------------------------------------------------------------------------------+
| 4.0.2 | 25 Aug 2025 | Replaced obsolete "supress" in call to brcdapi_log.open_log with "suppress". |
+-----------+---------------+---------------------------------------------------------------------------------------+
| 4.0.3 | 19 Oct 2025 | Updated comments only. |
+-----------+---------------+---------------------------------------------------------------------------------------+
| 4.0.4 | 20 Feb 2026 | Updated copyright notice. |
+-----------+---------------+---------------------------------------------------------------------------------------+
"""
__author__ = 'Jack Consoli'
__copyright__ = 'Copyright 2024, 2025, 2026 Jack Consoli'
__date__ = '20 Feb 2026'
__license__ = 'Apache License, Version 2.0'
__email__ = 'jack_consoli@yahoo.com'
__maintainer__ = 'Jack Consoli'
__status__ = 'Released'
__version__ = '4.0.4'
import argparse
import brcdapi.util as brcdapi_util
import brcdapi.brcdapi_rest as brcdapi_rest
import brcdapi.fos_auth as brcdapi_auth
import brcdapi.log as brcdapi_log
_DOC_STRING = False # Should always be False. Prohibits any actual I/O. Only useful for building documentation
# When _DEBUG is True, use _DEBUG_xxx below instead of parameters passed from the command line. I did it this way,
# rather than rely on parameter passing with IDE tools because the API examples are typically used as programming
# examples, not stand-alone scripts. It's easier to modify the inputs this way.
_DEBUG = False
_DEBUG_ip = 'xx.xxx.x.69'
_DEBUG_id = 'admin'
_DEBUG_pw = 'password'
_DEBUG_s = None # HTTPS is the default. Use 'none' for HTTP.
_DEBUG_FID = '128'
_DEBUG_VERBOSE = True # When True, all content and responses are formatted and printed (pprint).
_DEBUG_LOG = '_logs'
_DEBUG_NL = False
def parse_args():
"""Parses the module load command line
:return ip: IP address
:rtype ip: str
:return id: User ID
:rtype id: str
:return pw: Password
:rtype pw: str
:return s: Type of HTTP security. None if not specified
:rtype s: str, None
:return fid: Fabric ID
:rtype fid: int
:return d: True - enable log debug
:rtype d: bool
"""
global _DEBUG_IP, _DEBUG_ID, _DEBUG_PW, _DEBUG_SEC, _DEBUG_FID, _DEBUG_VERBOSE, _DEBUG_LOG, _DEBUG_NL
if _DEBUG:
args_ip, args_id, args_pw, args_s, args_fid, args_d, args_log, args_nl =\
_DEBUG_IP, _DEBUG_ID, _DEBUG_PW, _DEBUG_SEC, _DEBUG_FID, _DEBUG_VERBOSE, _DEBUG_LOG, _DEBUG_NL
else:
buf = 'Clears the MAPS dashboard.'
parser = argparse.ArgumentParser(description=buf)
parser.add_argument('-ip', help='IP address', required=True)
parser.add_argument('-id', help='User ID', required=True)
parser.add_argument('-pw', help='Password', required=True)
parser.add_argument('-s', help='Optional. "none" for HTTP. The default is "self" for HTTPS mode.',
required=False,)
parser.add_argument('-fid', help='FID number', required=True,)
buf = 'Enable debug logging. Prints the formatted data structures (pprint) to the log and console.'
parser.add_argument('-d', help=buf, action='store_true', required=False)
buf = '(Optional) Directory where log file is to be created. Default is to use the current directory. The ' \
'log file name will always be "Log_xxxx" where xxxx is a time and date stamp.'
parser.add_argument('-log', help=buf, required=False, )
buf = '(Optional) No parameters. When set, a log file is not created. The default is to create a log file.'
parser.add_argument('-nl', help=buf, action='store_true', required=False)
args = parser.parse_args()
args_ip, args_id, args_pw, args_s, args_fid, args_d, args_log, args_nl =\
args.ip, args.id, args.pw, args.s, args.fid, args.d, args.log, args.nl
# Default security
if args_s is None:
args_s = 'self'
return args_ip, args_id, args_pw, args_s, args_fid, args_d, args_log, args_nl
def _clear_dashboard(session, fid):
"""Clears the MAPS dashboard
:return fid: Fabric ID
:rtype fid: int
"""
content = {'clear-data': True}
obj = brcdapi_rest.send_request(session, 'running/brocade-maps/dashboard-misc', 'PUT', content, fid)
if brcdapi_auth.is_error(obj):
brcdapi_log.log(brcdapi_auth.formatted_error_msg(obj), echo=True)
return -1
return 0
def pseudo_main():
"""Basically the main().
:return: Exit code
:rtype: int
"""
ml = ['WARNING!!! Debug is enabled'] if _DEBUG else list()
ip, user_id, pw, sec, fids, vd, log, nl = parse_args()
if vd:
brcdapi_rest.verbose_debug(True)
brcdapi_log.open_log(folder=args_log, suppress=False, version_d=brcdapi_util.get_import_modules(), no_log=args_nl)
fid = int(fids)
ml.append('FID: ' + fids)
if sec is None:
sec = 'none'
brcdapi_log.log(ml, echo=True)
# Login
brcdapi_log.log('Attempting login', True)
session = brcdapi_rest.login(user_id, pw, ip, sec)
if brcdapi_auth.is_error(session):
brcdapi_log.log('Login failed', True)
brcdapi_log.log(brcdapi_auth.formatted_error_msg(session), echo=True)
return -1
brcdapi_log.log('Login succeeded', True)
try:
ec = _clear_dashboard(session, fid)
except brcdapi_util.VirtualFabricIdError:
brcdapi_log.log('Software error. Search the log for "Invalid FID" for details.', echo=True)
ec = -1
except BaseException as e:
brcdapi_log.exception(['Programming error encountered.', str(type(e)) + ': ' + str(e)], echo=True)
ec = -1
obj = brcdapi_rest.logout(session)
if brcdapi_auth.is_error(obj):
brcdapi_log.log(['Logout failed:', brcdapi_auth.formatted_error_msg(obj)], echo=True)
ec = -1
return ec
###################################################################
#
# Main Entry Point
#
###################################################################
if _DOC_STRING:
print('_DOC_STRING is True. No processing')
exit(0)
_ec = pseudo_main()
brcdapi_log.close_log(str(_ec))
exit(_ec)