pyats.utils.fileutils.plugins.localhost package

Submodules

File utils base class for Linux servers.

class pyats.utils.fileutils.plugins.localhost.fileutils.FileUtils(*args, os='localhost', protocol=None, **kwargs)

Bases: pyats.utils.fileutils.bases.fileutils.FileUtilsBase

Initialize an instance of FileUtils

Parameters
  • os (str) – The operating system of the device acting as a file transfer client.

  • testbed (pyats.topology.Testbed) – The testbed object that contains auth and address details for servers referenced by file transfer URLs.

DEFAULT_COPY_TIMEOUT_SECONDS = 1200
DEFAULT_TIMEOUT_SECONDS = 60
chmod(target, mode, timeout_seconds=60, *args, **kwargs)

Change file permissions

Parameters
  • target (str) – The URL of the file whose permissions are to be changed.

  • mode (int) – Same format as os.chmod.

  • timeout_seconds (int) – Maximum allowed amount of time for the operation.

Returns

Return type

None if operation succeeded.

close()

Deallocate any resources being held.

copyfile(source, destination, timeout_seconds=1200, *args, **kwargs)

Copy a single file.

Copy a single file either from local to remote, or remote to local. Remote to remote transfers are not supported. Users are expected to make two calls to this API to do this.

Parameters
  • source (str) – The URL of the file to be copied from.

  • destination (str) – The URL of the file name to be copied to.

  • timeout_seconds (int) – Maximum allowed amount of time for the operation.

Raises

Exception – When a remote to remote transfer is requested.

deletefile(target, timeout_seconds=60, *args, **kwargs)

Delete a file

Parameters
  • target (str) – The URL of the file to be deleted.

  • timeout_seconds (int) – Maximum allowed amount of time for the operation.

dir(target, timeout_seconds=60, *args, **kwargs)

Retrieve filenames contained in a directory.

Do not recurse into subdirectories, only list files at the top level of the given directory.

Parameters
  • target (str) – The URL of the directory whose contained files are to be retrieved.

  • timeout_seconds (int) – The number of seconds to wait before aborting the operation.

Returns

`list`

Return type

List of filename URLs. Directory names are ignored.

get_child(abstraction_scheme, **kwargs)

Attempt to load a protocol implementation.

First, attempt to load a native Python implementation. If none is available, then attempt to load a curl-based implementation.

Raises

Exception – if the requested protocol is not supported, this occurs when no plugin can be found.

getspace(target, timeout_seconds=60, *args, **kwargs)

get the available disk space from the file server, in bytes.

Parameters
  • target (str) – The URL of the directory to check available space.

  • timeout_seconds (int) – Maximum allowed amount of time for the operation.

is_valid_ip(ip)
renamefile(source, destination, timeout_seconds=60, *args, **kwargs)

Rename a file

Parameters
  • source (str) – The URL of the file to be renamed.

  • destination (str) – The URL of the new file name.

  • timeout_seconds (int) – Maximum allowed amount of time for the operation.

stat(target, timeout_seconds=60, *args, **kwargs)

Retrieve file details such as length and permissions.

Parameters
  • target (str) – The URL of the file whose details are to be retrieved.

  • timeout_seconds (int) – The number of seconds to wait before aborting the operation.

Returns

`os.stat_result`

Return type

Filename details including size.

Raises
validate_and_parse_url(url, calling_method)
Returns

Return type

server name, server port, resource path