1 /*! \file suppfile_example.py
6 """suppfile_example.py: OpEN API support file generation example"""
12 example_name =
"suppfile_example"
43 class SuppFileExample:
44 """Support File OpEN API Example."""
46 def __init__(self, client):
47 self.m_client = client
48 self.support_filename =
None
50 def support_file_create(self):
51 """Execute 'show tech-support file' command internally to generate file."""
54 max_filename_len_p = OpEN.new_uint32_tp()
55 OpEN.openapiSystemFileNameMaxLengthGet(self.m_client, max_filename_len_p)
56 max_filename_len = OpEN.uint32_tp_value(max_filename_len_p)
57 OpEN.delete_uint32_tp(max_filename_len_p)
61 bufsize = max_filename_len + 1
63 outfile_buf = open_.getStringBuffer(bufsize)
64 except OpENBufferSizeError:
65 print(
"support_file_create: getStringBuffer raised OpENBufferSizeError")
68 print(
"support_file_create: getStringBuffer raised TypeError")
70 outfile_desc = OpEN.open_buffdesc()
71 outfile_desc.pstart = outfile_buf
72 outfile_desc.size = bufsize
75 ret = OpEN.openapiSupportFileGenerate(self.m_client, outfile_desc)
76 if (ret == OpEN.OPEN_E_NONE)
and (len(outfile_buf.cast()) > 0):
77 filename = outfile_buf.cast()
78 print(
"Tech support file created successfully.\n")
80 if ret == OpEN.OPEN_E_UNAVAIL:
81 print(
"Feature not supported on this platform.\n")
82 elif ret == OpEN.OPEN_E_PARAM:
83 print(
"Error: Invalid parameter specified.\n")
85 print(
"Error: Failed to create tech support file.\n")
87 self.support_filename = filename
90 def support_file_display(self, maxout=display_default):
91 """"Display file contents line-by-line. Optional maxout arg controls output:
92 0 : displays entire file
93 >0 : displays specified number of file lines
95 if self.support_filename
is not None:
96 filename = self.support_filename
98 for line
in open(filename):
107 """Demonstrate OpEN usage for generating Tech Support file."""
111 if (numargs > 1)
or ((numargs == 1)
and (argv[0] ==
'?')):
112 print(
"%s.py [display_max]\n" % (example_name,))
113 print(
" display_max: 0=all, >0=number of lines (default %d)\n" % (display_default,))
117 display_max = int(argv[0])
121 print(
"The specified input parameter value must be 0 or greater.\n")
125 display_max = display_default
127 ret = open_.connect(example_name)
128 if ret == OpEN.OPEN_E_NONE:
130 open_.getNetworkOSVersion()
131 open_.getAPIVersion()
132 client = open_.get_client()
133 xmp = SuppFileExample(client)
134 print(
"Creating Tech Support file (this may take a while)...")
135 xmp.support_file_create()
138 lines_msg =
"all lines"
140 lines_msg =
"first line" if display_max == 1
else "first %d lines" % (display_max,)
141 print(
"Displaying %s of file %s:\n" % (lines_msg, xmp.support_filename))
142 xmp.support_file_display(display_max)
145 print(
"Unable to connect.\n")
147 if __name__ ==
'__main__':