Skip to content

CxTowerServer

Represents a server entity.

Keeps information required to connect and perform routine operations such as configuration, file management etc.

Method test_ssh_connection

Test SSH connection.

Args: raise_on_error (bool, optional): Raise exception in case of error. Defaults to True. return_notification (bool, optional): Show sticky notification Defaults to True. try_command (bool, optional): Try to run a command. Defaults to True. try_file (bool, optional): Try file operations. Defaults to True. timeout (int, optional): SSH connection timeout in seconds. Defaults to 60.

Raises: ValidationError: In case of SSH connection error. ValidationError: In case of no output received. ValidationError: In case of file operations error.

Returns: dict: { "status": int, "response": str, "error": str, }

Method run_command

This is the main function to use for running commands. It renders command code, creates log record and calls command runner.

Args: command (cx.tower.command()): Command record path (Char): directory where command is run. Provide in case you need to override default command value sudo (Boolean): use sudo Defaults to None ssh_connection (SSH client instance, optional): SSH connection. Pass to reuse existing connection. This is useful in case you would like to speed up the ssh command running. jet_template (cx.tower.jet.template()) Jet Template record Pass to run for specific jet template jet (cx.tower.jet()): Jet record Pass to run for specific jet kwargs (dict): extra arguments. Use to pass external values. Following keys are supported by default: - "waypoint", cx.tower.jet.waypoint(): waypoint record when running for a waypoint (e.g. from waypoint plan) - "log", dict(): values passed to logger - "key", dict(): values passed to key parser - "variable_values", dict(): custom variable values in the format of {variable_reference: variable_value} eg {'odoo_version': '16.0'} Will be applied only if user has write access to the server. Context: no_command_log (Bool): set this context key to True to disable log creation. Command running results will be returned instead. If any non command related error occurs in the command running flow an exception will be raised. IMPORTANT: be aware when running commands with no_command_log=True because no Allow Parallel Run check will be done! Returns: dict(): command running result if no_command_log context value == True else None

Method run_flight_plan

Runs flight plan on the current server.

Args: flight_plan (cx.tower.plan()): flight plan to run jet_template (cx.tower.jet.template()): jet template to run the flight plan on jet (cx.tower.jet()): jet to run the flight plan on kwargs (dict): Optional arguments Following are supported but not limited to: - "plan_log": {values passed to flightplan logger} - "log": {values passed to logger} - "key": {values passed to key parser} - "variable_values", dict(): custom variable values in the format of {variable_reference: variable_value} eg {'odoo_version': '16.0'} Will be applied only if user has write access to the server. Returns: log_record (cx.tower.plan.log()): plan log record

Method delete_file

Delete file from remote server

Args: remote_path (Text): full path file location with file type (e.g. /test/my_file.txt).

Method upload_file

Upload file to remote server.

Args: data (Text, Bytes): If the data are text, they are converted to bytes, contains a local file path if from_path=True. remote_path (Text): full path file location with file type (e.g. /test/my_file.txt). from_path (Boolean): set True if data is file path.

Raise: TypeError: incorrect type of file.

Returns: Result (class paramiko.sftp_attr.SFTPAttributes): metadata of the uploaded file.

Method download_file

Download file from remote server

Args: remote_path (Text): full path file location with file type (e.g. /test/my_file.txt).

Raise: ValidationError: raise if file not found.

Returns: Result (Bytes): file content.

Method get_variable_value

Return the value of a variable for the current server. NB: this function follows the value application order. So it will return the global value if server value is not set.

Returns: str: The value of the variable for the current record or None