Hallo, dies ist ein Test.
PWD: /www/data-lst1/unixsoft/unixsoft/kaempfer/.public_html
Running in File Mode
Relative path: ./../.././../../../.././bin/sstoreadm
Real path: /usr/bin/sstoreadm
Zurück
#!/usr/bin/python3.7 -Es import solaris.no_site_packages # # Copyright (c) 2013, 2023, Oracle and/or its affiliates. # """sstoreadm - administrative interface for the sstore daemon""" import getopt import sys import sstore_util import errno import rad.connect as radcon import rad.client as radcli import rad.bindings.com.oracle.solaris.rad.bemgr_1 as bemgr import rad.bindings.com.oracle.solaris.rad.zfsmgr_1 as zfsmgr from libsstore import (SStore, SSErrConnectionBroken, ss_collection, SSException, SSTORE_COLLECTION_STATE_DISABLED, SSTORE_COLLECTION_STATE_ENABLED, SS_RET_ERROR, SS_RET_INVALID_COMMAND, SS_RET_SUCCESS, SS_RET_WARNING, SS_RET_UNKNOWN_ERROR) from sstore_util import _ from solaris.smf.smf_rad import SCF_STATE_STRING_DISABLED, SMFInstance, \ ServicesError SSTORE_DS = "/VARSHARE/sstore" _FMRI = "svc:/system/sstore:default" SSTORE = SStore() def usage(cmd=None): """print a usage message for the given cmd and exit""" basic_usage = {} basic_cmds = ["purge", "disable-collection", "enable-collection"] basic_usage["purge"] = _("sstoreadm purge [[-t start-time] " "[-e end-time]\n\t[-i step]] " "ssid[ ssid... ]\n\n" "\tsstoreadm purge -a \n" "\t[[-t start-time] [-e end-time] [-i step]]\n") basic_usage["disable-collection"] = _("sstoreadm disable-collection" " ssid[ ssid... ]\n") basic_usage["enable-collection"] = _("sstoreadm enable-collection" " ssid[ ssid... ]\n") cmd_dic = basic_usage cmd_list = basic_cmds print("Usage:") if cmd: if cmd not in cmd_dic: # need error handling, but should never happen print(_("Error: cmd not in cmd_dic")) sys.exit(SS_RET_ERROR) print("\t{}".format(cmd_dic[cmd])) else: for cmd in cmd_list: if cmd not in cmd_dic: # need error handling, but should never happen print(_("Error: cmd not in cmd_dic")) sys.exit(SS_RET_ERROR) print("\t{}".format(cmd_dic[cmd])) sys.exit(SS_RET_INVALID_COMMAND) def subcmd_purge(cmd=None, aargs=None, no_warn=False): """Deletes all logs for a given stat""" exp_opts = ['-e', '-i', '-t'] queries = [] try: opts, largs = getopt.getopt(aargs, "ae:i:t:", []) except getopt.GetoptError: usage(cmd) # After this call the appropriate FLAGS will be set opt_groups = sstore_util.process_opts(opts, exp_opts, ['-a']) # The only things left in largs should be statids sstore_util.append_statids(largs, queries, usage, cmd) # if we have largs, set zflag sstore_util.FLAGS['-z'] = bool(largs) if sstore_util.FLAGS['-a']: # option 'a' does not accept any ssids, zflag should be false if sstore_util.FLAGS['-z']: usage(cmd) # if time-stamp is specified, purge stats by deleting the logs if sstore_util.FLAGS['-e'] or sstore_util.FLAGS['-t']: queries.append("//:class.*//:*") else: # destroy the sstore dataset to clear the logs # Keep sstore service disabled while deleting the dataset. try: purge_dataset() except Exception: # sstore_util.handle_daemon_exception(err) print(_("Cannot perform purge operation")) return SS_RET_ERROR return SS_RET_SUCCESS else: # the id specification options are mutually exclusive if sstore_util.multiple_id_opts(): usage(cmd) # if we have made it this far and queries is still empty, return usage if not queries: usage(cmd) trange = sstore_util.build_timerange(usage, cmd, opt_groups) # purge stats try: SSTORE.purge(queries, trange) warnings = sstore_util.format_warnings(SSTORE) except OSError as err: sstore_util.handle_daemon_exception(err) sstore_util.pprint_warnings(warnings, no_warn) return SS_RET_WARNING if warnings else SS_RET_SUCCESS def purge_dataset(instance='default'): smf = SMFInstance(_FMRI, instance) if (smf.state == SCF_STATE_STRING_DISABLED): print(_("SMF Service '%(fmri)s' is disabled " "enable the service to perform the purge") % {'fmri': smf.instance.fmri}) raise ServicesError() else: smf.perform_action("disable") # clear the repo and create a new zfs dataset zfs_dataset_destroy() # enable the service smf.perform_action("enable") def zfs_dataset_destroy(): with radcon.connect_private(daemon_suffix=radcon.RAD_DAEMON_39) as rc: # get rpool info rpool_name = rc.get_object(bemgr.BEManager()).getActiveBE().zpool # Sstore Dataset try: dataset_name = rpool_name + SSTORE_DS name_pattern = radcli.ADRGlobPattern({'name': dataset_name}) zfs_obj = rc.get_object(zfsmgr.ZfsDataset(), name_pattern) # store the mountpoint req_props = [zfsmgr.ZfsPropRequest(name='mountpoint')] mountpoint = zfs_obj.get_props(req_props)[0].value # destroy the dataset zfs_obj.destroy(options=[zfsmgr.ZfsOpOption.recurse_filesystems]) except (radcli.ObjectError, radcli.NotFoundError) as error: print("RAD exception detected. Failed to destroy " "{}, {}".format(dataset_name, error)) def subcmd_disable_collection(cmd=None, aargs=None, no_warn=False): """Disables collections for a given collection id""" queries = [] ret_flag = False try: largs = getopt.getopt(aargs, [], [])[1] except getopt.GetoptError: usage(cmd) # The only things left in largs should be statids sstore_util.append_statids(largs, queries, usage, cmd) # if we have largs, set zflag sstore_util.FLAGS['-z'] = bool(largs) # if we have made it this far and queries is still empty, return usage if not queries: usage(cmd) for col_id in queries: try: ns_iter = SSTORE.namespace_list([col_id]) warnings = sstore_util.format_warnings(SSTORE) except SSException as err: sstore_util.handle_daemon_exception(err) for query, dummy_start_ts, dummy_end_ts in ns_iter: collection = ss_collection(SSTORE, query) try: collection.set_state(SSTORE_COLLECTION_STATE_DISABLED) collection.write() except SSException as err: sstore_util.handle_daemon_exception(err) sstore_util.pprint_warnings(warnings, no_warn) if warnings: ret_flag = True return SS_RET_SUCCESS if not ret_flag else SS_RET_WARNING def subcmd_enable_collection(cmd=None, aargs=None, no_warn=False): """Enables collections for a given collection id""" queries = [] ret_flag = False try: largs = getopt.getopt(aargs, [], [])[1] except getopt.GetoptError: usage(cmd) # The only things left in largs should be statids sstore_util.append_statids(largs, queries, usage, cmd) # if we have largs, set zflag sstore_util.FLAGS['-z'] = bool(largs) # if we have made it this far and queries is still empty, return usage if not queries: usage(cmd) for col_id in queries: try: ns_iter = SSTORE.namespace_list([col_id]) warnings = sstore_util.format_warnings(SSTORE) except SSException as err: sstore_util.handle_daemon_exception(err) for query, dummy_start_ts, dummy_end_ts in ns_iter: collection = ss_collection(SSTORE, query) try: collection.set_state(SSTORE_COLLECTION_STATE_ENABLED) collection.write() except SSException as err: sstore_util.handle_daemon_exception(err) sstore_util.pprint_warnings(warnings, no_warn) if warnings: ret_flag = True return SS_RET_SUCCESS if not ret_flag else SS_RET_WARNING def subcmd_exit(cmd=None, aargs=None): """causes stats store to exit for svcadm restart""" try: getopt.getopt(aargs, [], []) except getopt.GetoptError: usage(cmd) try: SSTORE.close() except OSError as err: sstore_util.handle_daemon_exception(err) except SSErrConnectionBroken as err: pass # already stopped or exited during call return SS_RET_SUCCESS def main(): """main function for sstoreadm""" return sstore_util.opts_to_cmd(globals(), usage, SSTORE) if __name__ == "__main__": try: sys.exit(main()) except KeyboardInterrupt: print("") sys.exit(SS_RET_ERROR) except IOError as err: if err.errno == errno.EPIPE: pass except SystemExit: raise except Exception: import traceback traceback.print_exc() sys.exit(SS_RET_UNKNOWN_ERROR)