text
stringlengths
81
112k
Attempt to authenticate to the given transport using any of the private keys available from an SSH agent. def agent_auth(transport, username): """ Attempt to authenticate to the given transport using any of the private keys available from an SSH agent. """ agent = ssh.Agent() agent_key...
read data out of the prefetch buffer, if possible. if the data isn't in the buffer, return None. otherwise, behaves like a normal read. def _read_prefetch(self, size): """ read data out of the prefetch buffer, if possible. if the data isn't in the buffer, return None. otherwise, beh...
Change the mode (permissions) of this file. The permissions are unix-style and identical to those used by python's C{os.chmod} function. @param mode: new permissions @type mode: int def chmod(self, mode): """ Change the mode (permissions) of this file. The permissions...
Change the owner (C{uid}) and group (C{gid}) of this file. As with python's C{os.chown} function, you must pass both arguments, so if you only want to change one, use L{stat} first to retrieve the current owner and group. @param uid: new owner's uid @type uid: int @para...
Set the access and modified times of this file. If C{times} is C{None}, then the file's access and modified times are set to the current time. Otherwise, C{times} must be a 2-tuple of numbers, of the form C{(atime, mtime)}, which is used to set the access and modified times, respective...
Write out any data in the write buffer. This may do nothing if write buffering is not turned on. def flush(self): """ Write out any data in the write buffer. This may do nothing if write buffering is not turned on. """ self._write_all(self._wbuffer.getvalue()) ...
Read one entire line from the file. A trailing newline character is kept in the string (but may be absent when a file ends with an incomplete line). If the size argument is present and non-negative, it is a maximum byte count (including the trailing newline) and an incomplete line may ...
Subclasses call this method to initialize the BufferedFile. def _set_mode(self, mode='r', bufsize=-1): """ Subclasses call this method to initialize the BufferedFile. """ # set bufsize in any event, because it's used for readline(). self._bufsize = self._DEFAULT_BUFSIZE ...
Create an SFTP client channel from an open L{Transport}. @param t: an open L{Transport} which is already authenticated @type t: L{Transport} @return: a new L{SFTPClient} object, referring to an sftp session (channel) across the transport @rtype: L{SFTPClient} def from_trans...
Return a list containing L{SFTPAttributes} objects corresponding to files in the given C{path}. The list is in arbitrary order. It does not include the special entries C{'.'} and C{'..'} even if they are present in the folder. The returned L{SFTPAttributes} objects will each have an a...
Remove the file at the given path. This only works on files; for removing folders (directories), use L{rmdir}. @param path: path (absolute or relative) of the file to remove @type path: str @raise IOError: if the path refers to a folder (directory) def remove(self, path): """...
Remove the folder named C{path}. @param path: name of the folder to remove @type path: str def rmdir(self, path): """ Remove the folder named C{path}. @param path: name of the folder to remove @type path: str """ path = self._adjust_cwd(path) se...
Retrieve information about a file on the remote system. The return value is an object whose attributes correspond to the attributes of python's C{stat} structure as returned by C{os.stat}, except that it contains fewer fields. An SFTP server may return as much or as little info as it w...
Retrieve information about a file on the remote system, without following symbolic links (shortcuts). This otherwise behaves exactly the same as L{stat}. @param path: the filename to stat @type path: str @return: an object containing attributes about the given file @rty...
Create a symbolic link (shortcut) of the C{source} path at C{destination}. @param source: path of the original file @type source: str @param dest: path of the newly created symlink @type dest: str def symlink(self, source, dest): """ Create a symbolic link (shor...
Change the mode (permissions) of a file. The permissions are unix-style and identical to those used by python's C{os.chmod} function. @param path: path of the file to change the permissions of @type path: str @param mode: new permissions @type mode: int def chmod(self,...
Return the target of a symbolic link (shortcut). You can use L{symlink} to create these. The result may be either an absolute or relative pathname. @param path: path of the symbolic link file @type path: str @return: target path @rtype: str def readlink(self, path): ...
Return the normalized path (on the server) of a given path. This can be used to quickly resolve symbolic links or determine what the server is considering to be the "current folder" (by passing C{'.'} as C{path}). @param path: path to be normalized @type path: str @retu...
Copy a remote file (C{remotepath}) from the SFTP server to the local host as C{localpath}. Any exception raised by operations will be passed through. This method is primarily provided as a convenience. @param remotepath: the remote file to copy @type remotepath: str @param loc...
Return an adjusted path if we're emulating a "current working directory" for the server. def _adjust_cwd(self, path): """ Return an adjusted path if we're emulating a "current working directory" for the server. """ if type(path) is unicode: path = path.encode...
Register a resource to be closed with an object is collected. When the given C{obj} is garbage-collected by the python interpreter, the C{resource} will be closed by having its C{close()} method called. Any exceptions are ignored. @param obj: the object to track ...
Perform HTTP request for REST API. def _request(self, method, path, data=None, reestablish_session=True): """Perform HTTP request for REST API.""" if path.startswith("http"): url = path # For cases where URL of different form is needed. else: url = self._format_path(pat...
Validate a REST API version is supported by the library and target array. def _check_rest_version(self, version): """Validate a REST API version is supported by the library and target array.""" version = str(version) if version not in self.supported_rest_versions: msg = "Library is...
Return the newest REST API version supported by target array. def _choose_rest_version(self): """Return the newest REST API version supported by target array.""" versions = self._list_available_rest_versions() versions = [LooseVersion(x) for x in versions if x in self.supported_rest_versions] ...
Return a list of the REST API versions supported by the array def _list_available_rest_versions(self): """Return a list of the REST API versions supported by the array""" url = "https://{0}/api/api_version".format(self._target) data = self._request("GET", url, reestablish_session=False) ...
Use username and password to obtain and return an API token. def _obtain_api_token(self, username, password): """Use username and password to obtain and return an API token.""" data = self._request("POST", "auth/apitoken", {"username": username, "password": password}, ...
Create snapshots of the listed volumes. :param volumes: List of names of the volumes to snapshot. :type volumes: list of str :param \*\*kwargs: See the REST API Guide on your array for the documentation on the request: **POST volume** ...
Create a volume and return a dictionary describing it. :param volume: Name of the volume to be created. :type volume: str :param size: Size in bytes, or string representing the size of the volume to be created. :type size: int or str :param \*\*kwargs: See t...
Extend a volume to a new, larger size. :param volume: Name of the volume to be extended. :type volume: str :type size: int or str :param size: Size in bytes, or string representing the size of the volume to be created. :returns: A dictionary mapping "name" ...
Truncate a volume to a new, smaller size. :param volume: Name of the volume to truncate. :type volume: str :param size: Size in bytes, or string representing the size of the volume to be created. :type size: int or str :returns: A dictionary mapping "name" ...
Create a connection between a host and a volume. :param host: Name of host to connect to volume. :type host: str :param volume: Name of volume to connect to host. :type volume: str :param \*\*kwargs: See the REST API Guide on your array for the documen...
Create a shared connection between a host group and a volume. :param hgroup: Name of hgroup to connect to volume. :type hgroup: str :param volume: Name of volume to connect to hgroup. :type volume: str :param \*\*kwargs: See the REST API Guide on your array for the ...
Return a dictionary describing the connected offload target. :param offload: Name of offload target to get information about. :type offload: str :param \*\*kwargs: See the REST API Guide on your array for the documentation on the request: **...
Create a subnet. :param subnet: Name of subnet to be created. :type subnet: str :param prefix: Routing prefix of subnet to be created. :type prefix: str :param \*\*kwargs: See the REST API Guide on your array for the documentation on the request: ...
Create a vlan interface :param interface: Name of interface to be created. :type interface: str :param subnet: Subnet associated with interface to be created :type subnet: str :param \*\*kwargs: See the REST API Guide on your array for the documentatio...
Set an admin's password. :param admin: Name of admin whose password is to be set. :type admin: str :param new_password: New password for admin. :type new_password: str :param old_password: Current password of admin. :type old_password: str :returns: A dictionary...
Disable the directory service. :param check_peer: If True, disables server authenticity enforcement. If False, disables directory service integration. :type check_peer: bool, optional :returns: A dictionary describing the status of the dire...
Enable the directory service. :param check_peer: If True, enables server authenticity enforcement. If False, enables directory service integration. :type check_peer: bool, optional :returns: A dictionary describing the status of the directo...
Create an SNMP manager. :param manager: Name of manager to be created. :type manager: str :param host: IP address or DNS name of SNMP server to be used. :type host: str :param \*\*kwargs: See the REST API Guide on your array for the documentation on th...
Connect this array with another one. :param address: IP address or DNS name of other array. :type address: str :param connection_key: Connection key of other array. :type connection_key: str :param connection_type: Type(s) of connection desired. :type connection_type: li...
Create snapshot of pgroup from specified source. :param source: Name of pgroup of which to take snapshot. :type source: str :param \*\*kwargs: See the REST API Guide on your array for the documentation on the request: **POST pgroup** ...
Send an existing pgroup snapshot to target(s) :param source: Name of pgroup snapshot to send. :type source: str :param \*\*kwargs: See the REST API Guide on your array for the documentation on the request: **POST pgroup** :type \*\*k...
Create snapshots of pgroups from specified sources. :param sources: Names of pgroups of which to take snapshots. :type sources: list of str :param \*\*kwargs: See the REST API Guide on your array for the documentation on the request: **POST ...
Eradicate a destroyed pgroup. :param pgroup: Name of pgroup to be eradicated. :type pgroup: str :param \*\*kwargs: See the REST API Guide on your array for the documentation on the request: **DELETE pgroup/:pgroup** :type \*\*kwargs:...
Clone an existing pod to a new one. :param source: Name of the pod the be cloned. :type source: str :param dest: Name of the target pod to clone into :type dest: str :param \*\*kwargs: See the REST API Guide on your array for the documentation on the r...
Remove arrays from a pod. :param pod: Name of the pod. :type pod: str :param array: Array to remove from pod. :type array: str :param \*\*kwargs: See the REST API Guide on your array for the documentation on the request: **DE...
Get the attributes of the current array certificate. :param \*\*kwargs: See the REST API Guide on your array for the documentation on the request: **GET cert** :type \*\*kwargs: optional :returns: A dictionary describing the configured arra...
Get the attributes of the current array certificate. :param \*\*kwargs: See the REST API Guide on your array for the documentation on the request: **GET cert** :type \*\*kwargs: optional :returns: A list of dictionaries describing all confi...
Construct a certificate signing request (CSR) for signing by a certificate authority (CA). :param \*\*kwargs: See the REST API Guide on your array for the documentation on the request: **GET cert/certificate_signing_request** :type \*\*kwarg...
Modify an existing certificate, creating a new self signed one or importing a certificate signed by a certificate authority (CA). :param \*\*kwargs: See the REST API Guide on your array for the documentation on the request: **PUT cert** :typ...
Return an iterator over all pages of a REST operation. :param page_size: Number of elements to retrieve per call. :param function: FlashArray function that accepts limit as an argument. :param \*args: Positional arguments to be passed to function. :param \*\*kwargs: Keyword arguments to...
Change a file's attributes on the local filesystem. The contents of C{attr} are used to change the permissions, owner, group ownership, and/or modification & access time of the file, depending on which attributes are present in C{attr}. This is meant to be a handy helper function for t...
Read as close to N bytes as possible, blocking as long as necessary. @param n: number of bytes to read @type n: int @return: the data read @rtype: str @raise EOFError: if the socket was closed before all the bytes could be read def read_all(self, n, check_rekey=Fals...
Read a line from the socket. We assume no data is pending after the line, so it's okay to attempt large reads. def readline(self, timeout): """ Read a line from the socket. We assume no data is pending after the line, so it's okay to attempt large reads. """ buf = self...
Write a block of data using the current cipher, as an SSH block. def send_message(self, data): """ Write a block of data using the current cipher, as an SSH block. """ # encrypt this sucka data = str(data) cmd = ord(data[0]) if cmd in MSG_NAMES: cmd_n...
Only one thread should ever be in this function (no other locking is done). @raise SSHException: if the packet is mangled @raise NeedRekeyException: if the transport should rekey def read_message(self): """ Only one thread should ever be in this function (no other locking is ...
Create a tar file from all the files under 'base_dir'. This file may be compressed. :param compress: Compression algorithms. Supported algorithms are: 'gzip': (the default) 'compress' 'bzip2' None For 'gzip' and 'bzip2' the internal tarfile module will be used. For 'comp...
response_list = handler(title, instructions, prompt_list) def auth_interactive(self, username, handler, event, submethods=''): """ response_list = handler(title, instructions, prompt_list) """ self.transport.lock.acquire() try: self.auth_event = event sel...
Parses the given line of text to find the names for the host, the type of key, and the key data. The line is expected to be in the format used by the openssh known_hosts file. Lines are expected to not have leading or trailing whitespace. We don't bother to check for comments or empty l...
Returns a string in OpenSSH known_hosts file format, or None if the object is not in a valid state. A trailing newline is included. def to_line(self): """ Returns a string in OpenSSH known_hosts file format, or None if the object is not in a valid state. A trailing newline is ...
Read a file of known SSH host keys, in the format used by openssh. This type of file unfortunately doesn't exist on Windows, but on posix, it will usually be stored in C{os.path.expanduser("~/.ssh/known_hosts")}. If this method is called multiple times, the host keys are merged, ...
Save host keys into a file, in the format used by openssh. The order of keys in the file will be preserved when possible (if these keys were loaded from a file originally). The single exception is that combined lines will be split into individual key lines, which is arguably a bug. @p...
Find a hostkey entry for a given hostname or IP. If no entry is found, C{None} is returned. Otherwise a dictionary of keytype to key is returned. The keytype will be either C{"ssh-rsa"} or C{"ssh-dss"}. @param hostname: the hostname (or IP) to lookup @type hostname: str @retu...
Return True if the given key is associated with the given hostname in this dictionary. @param hostname: hostname (or IP) of the SSH server @type hostname: str @param key: the key to check @type key: L{PKey} @return: C{True} if the key is associated with the hostname; C{F...
Return a "hashed" form of the hostname, as used by openssh when storing hashed hostnames in the known_hosts file. @param hostname: the hostname to hash @type hostname: str @param salt: optional salt to use when hashing (must be 20 bytes long) @type salt: str @return: the...
turns a normalized byte string into a long-int (adapted from Crypto.Util.number) def inflate_long(s, always_positive=False): "turns a normalized byte string into a long-int (adapted from Crypto.Util.number)" out = 0L negative = 0 if not always_positive and (len(s) > 0) and (ord(s[0]) >= 0x80): ...
turns a long-int into a normalized byte string (adapted from Crypto.Util.number) def deflate_long(n, add_sign_padding=True): "turns a long-int into a normalized byte string (adapted from Crypto.Util.number)" # after much testing, this algorithm was deemed to be the fastest s = '' n = long(n) while ...
Given a password, passphrase, or other human-source key, scramble it through a secure hash into some keyworthy bytes. This specific algorithm is used for encrypting/decrypting private key files. @param hashclass: class from L{Crypto.Hash} that can be used as a secure hashing function (like C{MD5} ...
Retries function until it doesn't raise an EINTR error def retry_on_signal(function): """Retries function until it doesn't raise an EINTR error""" while True: try: return function() except EnvironmentError, e: if e.errno != errno.EINTR: raise
Generate a new private RSA key. This factory function can be used to generate a new host key or authentication key. @param bits: number of bits the generated key should be. @type bits: int @param progress_func: an optional function to call at key points in key generation (u...
turn a 20-byte SHA1 hash into a blob of data as large as the key's N, using PKCS1's \"emsa-pkcs1-v1_5\" encoding. totally bizarre. def _pkcs1imify(self, data): """ turn a 20-byte SHA1 hash into a blob of data as large as the key's N, using PKCS1's \"emsa-pkcs1-v1_5\" encoding. totally...
Generate a new private DSS key. This factory function can be used to generate a new host key or authentication key. @param bits: number of bits the generated key should be. @type bits: int @param progress_func: an optional function to call at key points in key generation (u...
Read an OpenSSH config from the given file object. @param file_obj: a file-like object to read the config file from @type file_obj: file def parse(self, file_obj): """ Read an OpenSSH config from the given file object. @param file_obj: a file-like object to read the config fil...
Return a dict of config options for a given hostname. The host-matching rules of OpenSSH's C{ssh_config} man page are used, which means that all configuration options from matching host specifications are merged, with more specific hostmasks taking precedence. In other words, if C{"Port...
Return a dict of config options with expanded substitutions for a given hostname. Please refer to man ssh_config(5) for the parameters that are replaced. @param config: the config for the hostname @type hostname: dict @param hostname: the hostname that the config belong...
Construct a URL from the given components. def url(proto, server, port=None, uri=None): """Construct a URL from the given components.""" url_parts = [proto, '://', server] if port: port = int(port) if port < 1 or port > 65535: raise ValueError('invalid po...
Create a URL from the specified parts. def make_url(self, container=None, resource=None, query_items=None): """Create a URL from the specified parts.""" pth = [self._base_url] if container: pth.append(container.strip('/')) if resource: pth.append(resource) ...
Send a HEAD request. def head_request(self, container, resource=None): """Send a HEAD request.""" url = self.make_url(container, resource) headers = self._make_headers(None) try: rsp = requests.head(url, headers=self._base_headers, verify=sel...
Send a POST request. def post_request(self, container, resource=None, params=None, accept=None): """Send a POST request.""" url = self.make_url(container, resource) headers = self._make_headers(accept) try: rsp = requests.post(url, data=params, headers=headers, ...
Send a DELETE request. def delete_request(self, container, resource=None, query_items=None, accept=None): """Send a DELETE request.""" url = self.make_url(container, resource) headers = self._make_headers(accept) if query_items and isinstance(query_items, (list, ...
Download a file. If a timeout defined, it is not a time limit on the entire download; rather, an exception is raised if the server has not issued a response for timeout seconds (more precisely, if no bytes have been received on the underlying socket for timeout seconds). If no timeout i...
Upload a single file. def upload_file(self, container, src_file_path, dst_name=None, put=True, content_type=None): """Upload a single file.""" if not os.path.exists(src_file_path): raise RuntimeError('file not found: ' + src_file_path) if not dst_name: ...
Upload a file using multi-part encoding. def upload_file_mp(self, container, src_file_path, dst_name=None, content_type=None): """Upload a file using multi-part encoding.""" if not os.path.exists(src_file_path): raise RuntimeError('file not found: ' + src_file_path) ...
Upload multiple files. def upload_files(self, container, src_dst_map, content_type=None): """Upload multiple files.""" if not content_type: content_type = "application/octet.stream" url = self.make_url(container, None, None) headers = self._base_headers multi_files =...
Create a new session or attach to existing. Normally, this function is called automatically, and gets its parameter values from the environment. It is provided as a public function for cases when extra control over session creation is required in an automation script that is adapted to...
End the client session. def _end_session(self, kill=None): """End the client session.""" if self._stc: if kill is None: kill = os.environ.get('STC_SESSION_TERMINATE_ON_DISCONNECT') kill = _is_true(kill) self._stc.end_session(kill) self...
This isn't used in Production, but allows this module to be used as a standalone extension. def setup(app): """ This isn't used in Production, but allows this module to be used as a standalone extension. """ app.add_directive('readthedocs-embed', EmbedDirective) app.add_config_value('readt...
Point media files at our media server. def finalize_media(app): """Point media files at our media server.""" if (app.builder.name == 'readthedocssinglehtmllocalmedia' or app.builder.format != 'html' or not hasattr(app.builder, 'script_files')): return # Use local media for dow...
Add Read the Docs content to Sphinx body content. This is the most reliable way to inject our content into the page. def update_body(app, pagename, templatename, context, doctree): """ Add Read the Docs content to Sphinx body content. This is the most reliable way to inject our content into the page....
Generate JSON artifacts for each page. This way we can skip generating this in other build step. def generate_json_artifacts(app, pagename, templatename, context, doctree): """ Generate JSON artifacts for each page. This way we can skip generating this in other build step. """ try: # ...
Copy and patch searchtools This uses the included Sphinx version's searchtools, but patches it to remove automatic initialization. This is a fork of ``sphinx.util.fileutil.copy_asset`` def _copy_searchtools(self, renderer=None): """Copy and patch searchtools This uses the incl...
Return dictionary of STC and API information. If a session already exists, then use it to get STC information and avoid taking the time to start a new session. A session is necessary to get STC information. def stc_system_info(stc_addr): """Return dictionary of STC and API information. If a sess...
Create a new test session. The test session is identified by the specified user_name and optional session_name parameters. If a session name is not specified, then the server will create one. Arguments: user_name -- User name part of session ID. session_name -- Se...
Attach to an existing session. def join_session(self, sid): """Attach to an existing session.""" self._rest.add_header('X-STC-API-Session', sid) self._sid = sid try: status, data = self._rest.get_request('objects', 'system1', ...
End this test session. A session can be ended in three ways, depending on the value of the end_tcsession parameter: - end_tcsession=None: Stop using session locally, do not contact server. - end_tcsession=False: End client controller, but leave te...
Get information on session. If session_id is None, the default, then return information about this session. If a session ID is given, then get information about that session. Arguments: session_id -- Id of session to get info for, if not this session. Return: ...
Get list of files, for this session, on server. def files(self): """Get list of files, for this session, on server.""" self._check_session() status, data = self._rest.get_request('files') return data
Get the BLL version this session is connected to. Return: Version string if session started. None if session not started. def bll_version(self): """Get the BLL version this session is connected to. Return: Version string if session started. None if session not started. ...
Returns the value(s) of one or more object attributes. If multiple arguments, this method returns a dictionary of argument names mapped to the value returned by each argument. If a single argument is given, then the response is a list of values for that argument. Arguments: ...
Create a new automation object. Arguments: object_type -- Type of object to create. under -- Handle of the parent of the new object. attributes -- Dictionary of attributes (name-value pairs). kwattrs -- Optional keyword attributes (name=value pairs). Return: ...