# plbmng.lib package

## Submodules

## plbmng.lib.database module

class `plbmng.lib.database.``PlbmngDb`

  Bases: `object`

  Class provides basic interaction with plbmng database.

  `close`() → None

    Close connection to plbmng database.

  `connect`() → None

    Connect to plbmng database

  `get_filters_for_access_servers`()

    Return message which filtering options(ssh, ping) are active.

    Return type

      str

  `get_hw_sw_stats`() → dict

    Return stats how many servers responded with version of kernel, gcc, python and how many RAM server has.

    Return type

      dict

  `get_nodes`(check_configuration=True, choose_availability_option=None, choose_software_hardware=None, path='/')

    Return all nodes from default.node file plus all user specified nodes from user_servers.node.

    Parameters

      - check_configuration (bool) – If set to True, check if status of server has been updated.

      - choose_availability_option (int) – Select filter option based on availability of ssh, ping or both.

      - choose_software_hardware (str) – Select filter option from: gcc, python, kernel, mem.

      - path – Path to the source directory of plbmng.

    Type

      str

    Returns

      List of all nodes

    Return type

      list

  `get_stats`() → dict

    Return dictionary which contains stats about ping and ssh responses.

    Return type

      dict

  `set_filtering_options`(tag: str) → None

    Change filtering options based on given tag.

    Parameters

      tag (str) – Number as string. If ‘1’ is given, change ssh to enabled. If ‘2’ is given, change ping to enabled.

## plbmng.lib.full_map module

`plbmng.lib.full_map.``plot_server_on_map`(nodes=None)

  Creates a map of every known node and generates chart with information about their’s latency.

  Returns

    map_full.html file

## plbmng.lib.icmp_map module

`plbmng.lib.icmp_map.``main`()

  Creates a map with ICMP responses for all selected nodes.

  Returns

    map_icmp.html file

## plbmng.lib.lib module

exception `plbmng.lib.library.``NeedToFillPasswdFirstInfo`

  Bases: `Exception`

  Raise when password is not filled

exception `plbmng.lib.library.``NonZeroReturnCode`

  Bases: `Exception`

  Raise when return code is not equal to 0

`plbmng.lib.library.``clear`() → None

  Clear shell.

`plbmng.lib.library.``connect`(mode: int, node: list)

  Connect to a node using ssh or Midnight Commander.

  Parameters

    - mode (int) – If mode is equals to 1, ssh is used. If mode is equals to 2, MC is used to connect to the node. If mode is different from 1 or 2, return None.

    - node (list) – List which contains all information from planetlab network about the node(must follow template from default.node).

  Raises

    ConnectionError

`plbmng.lib.library.``get_all_nodes`()

  Get all nodes from plbmng using planetlab_list_creator script.

  Raise

    NeedToFillPasswdFirstInfo

  Returns

    Create file default.node in plbmng database directory

`plbmng.lib.library.``get_custom_servers`(start_id: str) → list

  Read user_servers.node file in database directory a return all servers from it as list.

  Parameters

    start_id (str) – Starting id as string.

  Returns

    Return all servers from user_servers.node.

  Return type

    list

`plbmng.lib.library.``get_info_from_node`(node: list) → tuple

  Return basic information from node an return it as tuple

  Parameters

    node (list) – List which contains all information from planetlab network about the node(must follow template from default.node).

  Returns

    Return region, city, url, full name, latitude and longitude from the node as tuple.

  Return type

    tuple

`plbmng.lib.library.``get_last_server_access`(path: str) -> (<class 'dict'>, <class 'list'>)

  Return dictionary and list in tuple with all the available information about the last accessed node.

  Parameters

    path (str) – Path to the source directory of plbmng.

  Returns

    info_about_node_dic and chosen_node.

  Return type

    tuple

`plbmng.lib.library.``get_passwd`() → str

  Return password from plbmng conf file as string.

  Returns

    Password as string.

  Return type

    str

`plbmng.lib.library.``get_path`() → str

  Return absolute path to the source directory of plbmng.

  Returns

    absolute path to the source directory of plbmng as str.

  Return type

    str

`plbmng.lib.library.``get_server_info`(server_id: int, option: int, nodes: list) -> (<class 'dict'>, <class 'list'>)

  Retrieve all available info about server from :param node based on :param server_id. Option should be index on which is server id present in node list.

  Parameters

    - server_id (int) – ID of the server.

    - option (int) – Index program should look for server_id in node.

    - nodes (list) – List of all nodes.

  Returns

    Return dictionary with info about node and the node found in node based on server id.

  Return type

    tuple

`plbmng.lib.library.``get_server_params`(ip_or_hostname: str, ssh=False) → list

  Return versions of prepared commands as list.

  Parameters

    - ip_or_hostname (str) – IP address of hostname of the target

    - ssh (bool) –

  Returns

    List of requested info as string

  Return type

    list

`plbmng.lib.library.``get_ssh_key`() → str

  Return path to the ssh key from plbmng conf file as string.

  return: Path to the ssh key as string. :rtype: str

`plbmng.lib.library.``get_ssh_user`() → str

  Return slice name(remote user) from plbmng conf file as string.

  Returns

    Slice name(remote user) as string.

  Return type

    str

`plbmng.lib.library.``get_user`() → str

  Return user name from plbmng conf file as string.

  Returns

    User name as string.

  Return type

    str

`plbmng.lib.library.``is_first_run`() → bool

  Check first.boolean file in database directory if the user is using plbmng for the first time. If so, rewrites the value in the file.

  Returns

    True if user is using plbmng for the first time.

  Return type

    bool

`plbmng.lib.library.``multi_processing_init`(l: multiprocessing.context.BaseContext.Lock, b: multiprocessing.context.BaseContext.Value, i: multiprocessing.context.BaseContext.Value) → None

  Initializer for Pool.

  Parameters

    - l (Lock) – Lock to synchronize processes.

    - b (Value) – Progress of updating the database. Value is used in DIALOG gauge.

    - i (Value) – Incremental value in % added to :param base when process is done.

`plbmng.lib.library.``parallel_copy`(dialog, source_path: str, hosts: list, destination_path: str) → bool
  Parameters

    - dialog – Instance of dialog engine.

    - source_path (str) – File or directory to be copied.

    - hosts (list) – List of hosts(ip addressed or host names).

    - destination_path (str) – Path on the target where should be file or directory copied to.

  Returns

    True if source path has been copied successfully to all hosts.

  Return type

    bool

`plbmng.lib.library.``plot_servers_on_map`(nodes: list, path: str) → None

  Plot every node in nodes on map.

  Parameters

    - nodes (list) – List of Planetlab nodes.

    - path (str) – path to the directory which contains MAP_FILE.

  Return type

    None

`plbmng.lib.library.``run_command`(cmd: str) -> (<class 'int'>, <class 'str'>)

  Executes given cmd param as shell command.

  Parameters

    cmd (str) – shell command as string.

  Returns

    Return exit code and standard outpur of given cmd.

  Return type

    tuple

`plbmng.lib.library.``search_by_location`(nodes: list) -> (<class 'dict'>, <class 'dict'>)

  Return two dictionaries created from :param nodes list based on their continent, country and host name. First dictionary contains continents(eg. EU, AS) as key and all the countries in the list(eg. [“CZ, SK”]) Second dictionary contains country as key(eg. “CZ”) and values are all the server based in the country in list. {“EU”: [“CZ”, “SK”…]}, {“cz”: [“aaaa.cz”, “bbbbb.cz”]}

  Parameters

    nodes (list) – List of all available nodes.

  Return type

    tuple

`plbmng.lib.library.``search_by_regex`(nodes: list, option: int, regex: str) → list

  Return all :param regex matched values from :param nodes at :param option index.

  Parameters

    - nodes (list) – list of nodes.

    - option (str) – Index in the nodes list(check constants at the start of this file).

    - regex (str) – Pattern to be found.

  Returns

    Return list of matched values as list.

`plbmng.lib.library.``search_by_sware_hware`(nodes: list, option: int) → dict

  Return all unique entries in :param nodes list at :param option index as keys and all host names which contains the entry in list as value.

  Parameters

    - nodes (list) – list of nodes.

    - option (int) – Index in the nodes list(check constants at the start of this file).

  Returns

    Return dictionary of unique entries as keys and all host names in list as value.

  Return type

    dict

`plbmng.lib.library.``secure_copy`(host: str)

  Copy :param SOURCE_PATH to the :param DESTINATION_PATH to :param host. Global parameters must be set first!

  Parameters

    host (str) – IP address or host name.

  Returns

    Return True if command has failed. Otherwise return False.

  Return type

    bool

`plbmng.lib.library.``server_choices`(returned_choice: int, chosen_node: list, info_about_node_dic=None) → None

  Prepared choices for user to connect or generate HTML page with map. Based on the :param returned_choice, execute function with given parameters.

  Parameters

    - returned_choice (int) – Number 1-3 specified by user in DIALOG window.

    - chosen_node (list) – List which contains all information from planetlab network about the node(must follow template from default.node).

    - info_about_node_dic (dict) – Dictionary which contains all the info about node.

  Return type

    None

`plbmng.lib.library.``show_on_map`(node: list, node_info='') → None

  Generate and open in default web browser html page with map of the world and show node on the map.

  Parameters

    - node (list) – List which contains all information from planetlab network about the node(must follow template from default.node).

    - node_info (str) – Info about node as string.

  Return type

    None

`plbmng.lib.library.``test_ping`(target: str, return_bool=False)

  Try to ping :param target host and return boolean value or message based on ping command return code from ping tool.

  Parameters

    - target (str) – Host name or IP address.

    - return_bool (bool) – If set to False return message instead of boolean.

  Returns

    Return message or bool value with ping result.

`plbmng.lib.library.``test_ssh`(target: str)

  Scan port 22 of the given :param target.

  Parameters

    target (str) – Host name or IP address.

  Returns

    Result of the port scanning.

`plbmng.lib.library.``update_availability_database`(node: list) → None

  Update database with given information from :param node.

  Parameters

    node (list) – List which contains all information from planetlab network about the node(must follow template from default.node).

  Return type

    None

`plbmng.lib.library.``update_availability_database_parent`(dialog, nodes=None) → None

  Initialize parallel updating of the plbmng database.

  Parameters

    - dialog – Instance of a dialog engine.

    - nodes (list) – List of nodes to update the database.

  Return type

    None

`plbmng.lib.library.``update_last_server_access`(info_about_node_dic: dict, chosen_node: list, path: str) → None

  Update file which contains all the information about last accessed node by user.

  Parameters

    - info_about_node_dic (dict) – Dictionary which contains all the info about node.

    - chosen_node (list) – List which contains all information from planetlab network about the node(must follow template from default.node).

    - path (str) – Path to the source directory of plbmng.

`plbmng.lib.library.``verify_api_credentials_exist`(path: str) → bool

  Verify that user credentials are set in the plbmng conf file.

  Parameters

    path (str) – Path to the source directory of plbmng.

  Returns

    Return False if USERNAME or PASSWORD is not set. If both are set, return True.

  Return type

    bool

`plbmng.lib.library.``verify_ssh_credentials_exist`(path: str) → bool

  Verify that SLICE NAME(user acc on remote host) and path to SSH key are set in the plbmng conf file.

  Parameters

    path (str) – Path to the source directory of plbmng.

  Returns

    Return False if SLICE_NAME or SSH_KEY is not set. If both are set, return True.

  Return type

    bool

## plbmng.lib.map_one module

`plbmng.lib.map_one.``main`()

  Creates a map with location of a node.

  Returns

    map_one.html file

## plbmng.lib.planetlab_list_creator module

`plbmng.lib.planetlab_list_creator.``append_to_file`(node)

  Function for writing information about a node into the file

  Parameters

    node – dictionary containing information about a node

`plbmng.lib.planetlab_list_creator.``arguments`()

  Argument parser for command line usage.

`plbmng.lib.planetlab_list_creator.``get_continent`(country_code)

  Function returns continent based on country code provided as parameter.

  Parameters

    country_code – string containing country code

  Returns

    None if country code is not recognized. Otherwise it will return continent code.

`plbmng.lib.planetlab_list_creator.``get_ip_address`(hostname)

  Function translates hostname to IP address.

  Parameters

    hostname – HOSTNAME

  Returns

    if hostname cannot be translated to IP address returns None. Otherwise it returns IP address as a string.

`plbmng.lib.planetlab_list_creator.``print_info`(node)

  Function prints information about a node.

  Parameters

    node – dictionary containing information about the node

`plbmng.lib.planetlab_list_creator.``run`(path=None, username=None, password=None, start_id=None, quiet=False, return_output=False)

  Function creates output file with all information about the nodes. It takes username and password from Planetlab web to authenticate for the API. In path param you specify the path where output shall be saved. These parameters are required and function will not work properly without them. Start id is optional and you should use it only if you want to use different numbering for nodes. Default value for start id is ‘1’. Quiet is boolean value for printing standard output.

  Parameters

    - path – path to file as string. REQUIRED

    - username – username of your Planetlab web account. REQUIRED

    - password – password of your Planetlab web account. REQUIRED

    - start_id – integer value for numbering. Optional: default=1

    - quiet – boolean value deciding whether to print information as standard output. Optional: default=False

    - return_output – boolean value deciding whether to return output as list of nodes. Optional: default=False

  Returns

    lib/default2.node file, which contains following information about node:

    - ID

    - IP address

    - Hostname

    - Continent

    - Country

    - Region

    - City

    - URL

    - Name of an institution, which owns the node

    - Latitude

    - Longitude

## plbmng.lib.port_scanner module

`plbmng.lib.port_scanner.``test_port_availability`(hostname: str, port: int)

  Test availability of a given port on host.

  Parameters

    - hostname (str) – Host name of a host.

    - port (int) – Port number to check if is availibale.

  Returns

    Return True if given port is available. Otherwise return False. If an error has occurred, return its number.

## plbmng.lib.ssh_map module

`plbmng.lib.ssh_map.``main`()

  Creates a map of nodes with available SSH connection.

  Returns

    map_ssh.html file

## Module contents