def plugin_register(self, uri, password, timeout, flags=0): self.uri = uri_parse(uri) self.password = password self.tmo = timeout user = self.uri.get('username', DEFAULT_USER) port = self.uri.get('port', DEFAULT_PORT) self.host_with_port = "%s:%s" % (self.uri['host'], port) if self.uri['scheme'].lower() == 'targetd+ssl': self.scheme = 'https' else: self.scheme = 'http' self.url = urlparse.urlunsplit( (self.scheme, self.host_with_port, PATH, None, None)) auth = ('%s:%s' % (user, self.password)).encode('base64')[:-1] self.headers = {'Content-Type': 'application/json', 'Authorization': 'Basic %s' % (auth,)} try: self._jsonrequest('access_group_list', default_error_handler=False) except TargetdError as te: if te.errno == TargetdError.INVALID_METHOD: self._flag_ag_support = False else: raise
def plugin_register(self, uri, password, timeout, flags=0): self.uri = uri_parse(uri) self.password = password self.tmo = timeout user = self.uri.get('username', DEFAULT_USER) port = self.uri.get('port', DEFAULT_PORT) self.host_with_port = "%s:%s" % (self.uri['host'], port) if self.uri['scheme'].lower() == 'targetd+ssl': self.scheme = 'https' else: self.scheme = 'http' self.url = urlparse.urlunsplit( (self.scheme, self.host_with_port, PATH, None, None)) auth = ('%s:%s' % (user, self.password)).encode('base64')[:-1] self.headers = { 'Content-Type': 'application/json', 'Authorization': 'Basic %s' % (auth, ) } try: self._jsonrequest('access_group_list', default_error_handler=False) except TargetdError as te: if te.errno == TargetdError.INVALID_METHOD: self._flag_ag_support = False else: raise
def __init__(self, uri, plain_text_password=None, timeout_ms=30000, flags=0): self._uri = uri self._password = plain_text_password self._timeout = timeout_ms self._uds_path = Client._plugin_uds_path() u = uri_parse(uri, ['scheme']) scheme = u['scheme'] if "+" in scheme: (plug, proto) = scheme.split("+") scheme = plug self.plugin_path = os.path.join(self._uds_path, scheme) if os.path.exists(self.plugin_path): self._tp = _TransPort(_TransPort.get_socket(self.plugin_path)) else: #At this point we don't know if the user specified an incorrect #plug-in in the URI or the daemon isn't started. We will check #the directory for other unix domain sockets. if Client._check_daemon_exists(): raise LsmError(ErrorNumber.PLUGIN_NOT_EXIST, "Plug-in %s not found!" % self.plugin_path) else: _raise_no_daemon() self.__start(uri, plain_text_password, timeout_ms, flags)
def plugin_register(self, uri, password, timeout, flags=Client.FLAG_RSVD): if os.geteuid() != 0: raise LsmError(ErrorNumber.INVALID_ARGUMENT, "This plugin requires root privilege both daemon and client") uri_parsed = uri_parse(uri) self._sacli_bin = uri_parsed.get("parameters", {}).get("hpssacli") if not self._sacli_bin: self._find_sacli() self._sacli_exec(["version"], flag_convert=False)
def plugin_register(self, uri, password, timeout, flags=0): self.uri = uri_parse(uri) self.password = password self.tmo = timeout user = self.uri.get('username', DEFAULT_USER) port = self.uri.get('port', DEFAULT_PORT) self.host_with_port = "%s:%s" % (self.uri['host'], port) if self.uri['scheme'].lower() == 'targetd+ssl': self.scheme = 'https' else: self.scheme = 'http' self.url = urlunsplit( (self.scheme, self.host_with_port, PATH, None, None)) user_name_pass = '******' % (user, self.password) auth = base64.b64encode(user_name_pass.encode('utf-8')).decode('utf-8') self.headers = { 'Content-Type': 'application/json', 'Authorization': 'Basic %s' % (auth, ) } if "no_ssl_verify" in self.uri["parameters"] \ and self.uri["parameters"]["no_ssl_verify"] == 'yes': self.no_ssl_verify = True if "ca_cert_file" in self.uri["parameters"]: # Check for file existence and throw error now if not present self.ca_cert_file = self.uri["parameters"]["ca_cert_file"] if not os.path.isfile(self.ca_cert_file): raise LsmError( ErrorNumber.INVALID_ARGUMENT, 'ca_cert_file URI parameter does not exist %s' % self.ca_cert_file) if self.no_ssl_verify and self.ca_cert_file: raise LsmError( ErrorNumber.INVALID_ARGUMENT, "Specifying 'no_ssl_verify' and 'ca_cert_file' " "is unsupported combination.") if not SSL_DEFAULT_CONTEXT and (self.no_ssl_verify or self.ca_cert_file): raise LsmError( ErrorNumber.INVALID_ARGUMENT, "Cannot specify no_ssl_verify or ca_cert_file for this" "version of python!") try: self._jsonrequest('access_group_list', default_error_handler=False) except TargetdError as te: if te.errno == TargetdError.INVALID_METHOD: self._flag_ag_support = False else: raise
def plugin_register(self, uri, password, timeout, flags=Client.FLAG_RSVD): if os.geteuid() != 0: raise LsmError( ErrorNumber.INVALID_ARGUMENT, "This plugin requires root privilege both daemon and client") uri_parsed = uri_parse(uri) self._arcconf_bin = uri_parsed.get('parameters', {}).get('arcconf') if not self._arcconf_bin: self._find_arcconf()
def plugin_register(self, uri, password, timeout, flags=Client.FLAG_RSVD): if os.geteuid() != 0: raise LsmError( ErrorNumber.INVALID_ARGUMENT, "This plugin requires root privilege both daemon and client") uri_parsed = uri_parse(uri) self._sacli_bin = uri_parsed.get('parameters', {}).get('hpssacli') if not self._sacli_bin: self._find_sacli() self._sacli_exec(['version'], flag_convert=False)
def plugin_register(self, uri, password, timeout, flags=Client.FLAG_RSVD): if os.geteuid() != 0: raise LsmError( ErrorNumber.INVALID_ARGUMENT, "This plugin requires root privilege both daemon and client") uri_parsed = uri_parse(uri) self._storcli_bin = uri_parsed.get('parameters', {}).get('storcli') if not self._storcli_bin: self._find_storcli() # change working dir to "/tmp" as storcli will create a log file # named as 'MegaSAS.log'. os.chdir("/tmp") self._storcli_exec(['-v'], flag_json=False)
def plugin_register(self, uri, password, timeout, flags=0): self.uri = uri self.password = password # The caller may want to start clean, so we allow the caller to specify # a file to store and retrieve individual state. qp = uri_parse(uri) if 'parameters' in qp and 'statefile' in qp['parameters'] \ and qp['parameters']['statefile'] is not None: self.sim_array = SimArray(qp['parameters']['statefile'], timeout) else: self.sim_array = SimArray(None, timeout) return None
def plugin_register(self, uri, password, timeout, flags=Client.FLAG_RSVD): if os.geteuid() != 0: raise LsmError( ErrorNumber.INVALID_ARGUMENT, "This plugin requires root privilege both daemon and client", ) uri_parsed = uri_parse(uri) self._storcli_bin = uri_parsed.get("parameters", {}).get("storcli") # change working dir to tmp folder as storcli will create a log file # named as 'MegaSAS.log'. os.chdir(self._tmp_dir) if self._storcli_bin: self._storcli_exec("-v", flag_json=False) else: self._find_storcli()
def __init__(self): self.uri = None self.c = None self.parser = None self.unknown_args = None self.args = self.cli() self.cleanup = None self.tmo = int(self.args.wait) if not self.tmo or self.tmo < 0: raise ArgError("[-w|--wait] requires a non-zero positive integer") self._read_configfile() if os.getenv('LSMCLI_URI') is not None: self.uri = os.getenv('LSMCLI_URI') self.password = os.getenv('LSMCLI_PASSWORD') if self.args.uri is not None: self.uri = self.args.uri if self.uri is None: # We need a valid plug-in to instantiate even if all we are trying # to do is list the plug-ins at the moment to keep that code # the same in all cases, even though it isn't technically # required for the client library (static method) # TODO: Make this not necessary. if ('type' in self.args and self.args.type == "PLUGINS"): self.uri = "sim://" self.password = None else: raise ArgError("--uri missing or export LSMCLI_URI") # Lastly get the password if requested. if self.args.prompt: self.password = getpass.getpass() if self.password is not None: #Check for username u = uri_parse(self.uri) if u['username'] is None: raise ArgError("password specified with no user name in uri")
def plugin_register(self, uri, password, timeout, flags=Client.FLAG_RSVD): self._tmo_ms = timeout supported_plugins = set(LocalPlugin._KMOD_PLUGIN_MAP.values()) if os.geteuid() != 0: raise LsmError( ErrorNumber.INVALID_ARGUMENT, "This plugin requires root privilege both daemon and client") uri_parsed = uri_parse(uri) uri_vars = uri_parsed.get("parameters", {}) ignore_init_error = bool(uri_vars.get("ignore_init_error", "false")) sub_uri_paras = {} for plugin_name in supported_plugins: sub_uri_paras[plugin_name] = [] for key in uri_vars.keys(): for plugin_name in supported_plugins: if key.startswith("%s_" % plugin_name): sub_uri_paras[plugin_name].append( "%s=%s" % (key[len("%s_" % plugin_name):], uri_vars[key])) only_plugin = uri_vars.get("only", "") if only_plugin and only_plugin not in supported_plugins: raise LsmError( ErrorNumber.INVALID_ARGUMENT, "Plugin defined in only=%s is not supported" % only_plugin) if only_plugin: requested_plugins = [only_plugin] else: # Check kernel module to determine which plugin to load requested_plugins = [] cur_kmods = os.listdir("/sys/module/") for kmod_name, plugin_name in LocalPlugin._KMOD_PLUGIN_MAP.items(): if kmod_name in cur_kmods: requested_plugins.append(plugin_name) # smartpqi could be managed both by hpsa and arcconf plugin, hence # need extra care here: if arcconf binary tool is installed, we use # it, if not, we try hpsa binary tool. If none was installed, we # raise error generated by arcconf plugin. if "smartpqi" in cur_kmods: if Arcconf.find_arcconf(): requested_plugins.append("arcconf") elif SmartArray.find_sacli(): requested_plugins.append("hpsa") else: # None was found, still use arcconf plugin which will # generate proper error to user if ignore_init_error=false. requested_plugins.append("arcconf") requested_plugins = set(requested_plugins) if not requested_plugins: raise LsmError(ErrorNumber.NO_SUPPORT, "No supported hardware found") for plugin_name in requested_plugins: plugin_uri = "%s://" % plugin_name if sub_uri_paras[plugin_name]: plugin_uri += "?%s" % "&".join(sub_uri_paras[plugin_name]) try: conn = Client(plugin_uri, None, timeout, flags) # So far, no local plugins require password self.conns.append(conn) if plugin_name == 'nfs': self.nfs_conn = conn except LsmError as lsm_err: if ignore_init_error: pass else: raise lsm_err for conn in self.conns: for sys in conn.systems(): self.sys_con_map[sys.id] = conn self.syss.append(sys) if not self.sys_con_map: raise LsmError(ErrorNumber.NO_SUPPORT, "No supported systems found")