Cloudshell-sandbox-reporter - Helper modules and classes for writing to Cloudshell sandbox console

Overview

Python 3.7 Lint and Test PyPI version

Cloudshell Sandbox Reporter

This project provides utility classes for formatting and sending html messages to the cloudshell sandbox console. These methods help to semantically color the text and generate custom html elements (headers / anchors / etc.).

The SandboxReporter class is used to chunk together logging messages with the sandbox console print actions into single commands. This reduces duplication in your script if you typically log and print the same messages. There are granular flags for message instances that you only want to log and not print.

The SandboxReporter is also a "logger adapter" - which means it can be passed into functions in place of the original logger. You just instantiate the reporter with your logger instance, and log messages will be delegated to the original logger.

Sample Output

alt text

Installation

pip install cloudshell-sandbox-reporter

General Usage Samples

import logging
from cloudshell.helpers.sandbox_reporter.reporter import SandboxReporter, SandboxConsole
from cloudshell.api.cloudshell_api import CloudShellAPISession

LIVE_SANDBOX_ID = "16df1ea8-27b3-491d-89b9-10d1076f99c5"
logger = logging.Logger("test logger")
api = CloudShellAPISession("localhost", "admin", "admin", "Global")

reporter = SandboxReporter(api, LIVE_SANDBOX_ID, logger)

reporter.warning_header("Add a yellow, italic header to get attention")

reporter.info("standard INFO level message to logs and console")
reporter.debug("DEBUG message to logs and purple text to console ")
reporter.error("ERROR log and red text to console")
reporter.warning("WARNING log and yellow text to console")
reporter.success("INFO log and green text to console")

# generate a clickable anchor tag in console
reporter.console.anchor_tag_print(url="https://www.google.com", text="click to to go to google!")

# pass reporter into functions expecting logger
def some_func(logger: logging.Logger):
    logger.info("running func")
    
some_func(reporter)

# if you want to avoid noise in the console, just pass along internal logger
some_func(reporter.logger)

# if you only care about console without logging, instantiate console independently
console = SandboxConsole(api, LIVE_SANDBOX_ID)
console.sb_print("write to sandbox console only")
  • NOTE: In orchestration scripts the SandboxReporter init dependencies are generally provided (api, sandbox id, logger)
    • (examples in next section)

Orchestration Sample

In cloudshell Orchestration scripts, the sandbox object will provide the sandbox id, api session and logger.

from cloudshell.workflow.orchestration.setup.default_setup_orchestrator import DefaultSetupWorkflow
from cloudshell.workflow.orchestration.sandbox import Sandbox
from cloudshell.helpers.sandbox_reporter.reporter import SandboxReporter


def custom_config_function(sandbox, components=None):
    """
    Functions passed into orchestration flow MUST have (sandbox, components) signature
    :param Sandbox sandbox:
    :param components
    :return:
    """
    sb_id = sandbox.id
    api = sandbox.automation_api
    logger = sandbox.logger
    
    # instantiate reporter
    reporter = SandboxReporter(api, sb_id, logger)
    reporter.info("starting custom config function!!!")
    
    # some more business logic .........

sandbox = Sandbox()

DefaultSetupWorkflow().register(sandbox, enable_configuration=False)
sandbox.workflow.add_to_configuration(custom_config_function, None)
sandbox.execute_setup()

Shell Command Sample

In shell methods, the ResourceCommandContext object will help produce the api, sandbox id, and logger that are passed to SandboxReporter

from cloudshell.shell.core.resource_driver_interface import ResourceDriverInterface
from cloudshell.shell.core.driver_context import InitCommandContext, ResourceCommandContext
from cloudshell.shell.core.session.cloudshell_session import CloudShellSessionContext
from cloudshell.shell.core.session.logging_session import LoggingSessionContext
from cloudshell.helpers.sandbox_reporter.reporter import SandboxReporter
import time


class ReporterTesterDriver (ResourceDriverInterface):

    def __init__(self):
        pass

    def initialize(self, context):
        pass

    def cleanup(self):
        pass
    
    def _some_business_logic(self):
        time.sleep(10)
        
    def cool_service_command(self, context):
        """
        :param ResourceCommandContext context:
        """
        api = CloudShellSessionContext(context).get_api()
        sandbox_id = context.reservation.reservation_id
        with LoggingSessionContext(context) as logger:
            reporter = SandboxReporter(api, sandbox_id, logger)
            reporter.info("Starting Service Command, this may take a while...")
            
            try:
                # simulate long running  action
                self._some_business_logic()
            except Exception as e:
                # logs error and sends red text message to sandbox
                err_msg = f"Error caught during command. {type(e).__name__}: {str(e)}"
                reporter.error(err_msg)
                raise Exception(err_msg)

        return "Service Flow SUCCESSFUL"

License

Free Software: MIT License

You might also like...
Set of classes and tools to communicate with a Noso wallet using NosoP

NosoPy Set of classes and tools to communicate with a Noso wallet using NosoP(Noso Protocol). The data that can be retrieved consist of: Node informat

Stop writing scripts to interact with your APIs. Call them as CLIs instead.
Stop writing scripts to interact with your APIs. Call them as CLIs instead.

Zum Stop writing scripts to interact with your APIs. Call them as CLIs instead. Zum (German word roughly meaning "to the" or "to" depending on the con

โค๏ธ Hi There Im EzilaX โค๏ธ A next gen powerful telegram group manager bot ๐Ÿ˜ฑ for manage your groups and have fun with other cool modules Made By Sadew Jayasekara ๐Ÿ”ฅ
โค๏ธ Hi There Im EzilaX โค๏ธ A next gen powerful telegram group manager bot ๐Ÿ˜ฑ for manage your groups and have fun with other cool modules Made By Sadew Jayasekara ๐Ÿ”ฅ

โค๏ธ EzilaX v1 โค๏ธ Unmaintained. The new repo of @EzilaXBot is Public. (It is no longer based on this source code. The completely rewritten bot available

โค๏ธA next gen powerful telegram group manager bot for manage your groups and have fun with other cool modules
โค๏ธA next gen powerful telegram group manager bot for manage your groups and have fun with other cool modules

Natsuki Based on Python Telegram Bot Contributors Video Tutorial: Complete guide on deploying @TheNatsukiBot's clone on Heroku. โ˜† Video by Sadew Jayas

Amanda-A next gen powerful telegram group manager bot for manage your groups and have fun with other cool modules.
Amanda-A next gen powerful telegram group manager bot for manage your groups and have fun with other cool modules.

Amanda-A next gen powerful telegram group manager bot for manage your groups and have fun with other cool modules.

This Is A Python Program To Showcase Two Modules (Gratient And Fade)

Hellooo, It's PndaBoi Here! This Is A Python Program To Showcase Two Modules (Gratient And Fade). I Really Like Both Of These Modules So I Decided To

Botto - A discord bot written in python that uses the hikari and lightbulb modules to make this bot

โ“ About Botto Hi! This is botto, a discord bot written in python that uses the h

Async boto3 with Autogenerated Data Classes

awspydk Async boto3 with Autogenerated JIT Data Classes Motivation This library is forked from an internal project that works with a lot of backend AW

A simple discord bot named atticus that sends you the timetable of your classes upon request
A simple discord bot named atticus that sends you the timetable of your classes upon request

A simple discord bot named atticus that sends you the timetable of your classes upon request. Soon, it would you ping you before classes too!

Owner
QualiLab
Automating the DevOps lifecycle with Cloud Sandboxes
QualiLab
Async client API for the Telegram Group Calls

PyTgCalls This project allow to make Telegram group call with MTProto Api using Pyrogram and WebRTC, this is possible thanks to the power of NodeJS's

185 Jan 03, 2023
DonLee Robot

๐Ÿค– ๐ƒ๐Ž๐ ๐‹๐„๐„ ๐‘๐Ž๐๐Ž๐“ ๐•๐Ÿ ๐Ÿค– ๐Ÿ‘‹ Hey Muhammed, Iam DonLee RoBoT Make me an admin for your group and channel then connect me.... ๐ŸŽ‰ ๐Ÿ™‚ To build a

Muhammed 27 Dec 01, 2022
A bot written in Python to automate attending classes on MyClass (Codetantra).

codetantrabot This is python program to attend class on myclass(codetantra) Prerequisites You should have Python3 and Pip installed on your system Run

Aniket Kumar 1 Feb 08, 2022
A Python script for rendering glTF files with V-Ray App SDK

V-Ray glTF viewer Overview The V-Ray glTF viewer is a set of Python scripts for the V-Ray App SDK that allow the parsing and rendering of glTF (.gltf

Chaos 24 Dec 05, 2022
Wanna play on the Overwatch NA servers?

OverwatchRegionSwapper-NA- Wanna play on the Overwatch NA servers? Use at you own risk. LIST OF IPs EU Netherlands: From: 5.42.168.0 to: 5.42.175.255

1 Jun 08, 2022
Nasdaq Cloud Data Service (NCDS) provides a modern and efficient method of delivery for realtime exchange data and other financial information. This repository provides an SDK for developing applications to access the NCDS.

Nasdaq Cloud Data Service (NCDS) Nasdaq Cloud Data Service (NCDS) provides a modern and efficient method of delivery for realtime exchange data and ot

Nasdaq 8 Dec 01, 2022
A website application running in Google app engine, deliver rss news to your kindle. generate mobi using python, multilanguages supported.

Readme of english version refers to Readme_EN.md ็ฎ€ไป‹ ่ฟ™ๆ˜ฏไธ€ไธช่ฟ่กŒๅœจGoogle App Engine(GAE)ไธŠ็š„KindleไธชไบบๆŽจ้€ๆœๅŠกๅบ”็”จ๏ผŒ็”ŸๆˆๆŽ’็‰ˆ็ฒพ็พŽ็š„ๆ‚ๅฟ—ๆจกๅผmobi/epubๆ ผๅผ่‡ชๅŠจๆฏๅคฉๆŽจ้€่‡ณๆ‚จ็š„Kindleๆˆ–ๅ…ถไป–้‚ฎ็ฎฑใ€‚ ๆญคๅบ”็”จ็›ฎๅ‰็š„ไธป่ฆ

2.6k Jan 06, 2023
๐Ÿ’€ The first raid tool of its kind. Inject Deadcord and raid servers directly from the Discord client.

๐Ÿ’€ Deadcord The next upcoming Discord raid tool, the best for free. ๐ŸŽ‰ Early Beta Released We have released an early version of Deadcord, please keep

Galaxzy 157 May 24, 2022
A userbot made for telegram

๐šƒ๐™ท๐™ด ๐™ผ๐™ฐ๐™ต๐™ธ๐™ฐ๐™ฑ๐™พ๐šƒ This is a userbot made for telegram. I made this userbot with help of all other userbots available in telegram. All credits go

MafiaBotOP 8 Apr 08, 2022
โœจ Music&Video Userbot

๐ŸŽถ Fizi - UserBot ๐ŸŽถ ๐Ÿค– Telegram UserBot Untuk Memutar Lagu Dan Video Di Obrolan Suara Telegram. โœจ Didukung Oleh PyTgCalls Pyrogram ๐Ÿ“ Persyaratan Pyt

F I Z I โ€ข โฑฎeฦ™รญpres 4 Mar 29, 2022
Discord-Token-Formatter - A simple script to convert discord tokens from email token to token only format

Discord-Token-Formatter A simple script to convert discord tokens from email:pas

2 Oct 23, 2022
A Wide AOI tool for discord.

drkdiscord - drk#1337 A Wide AOI tool for discord. Installation To Install you have to have python 3.x and pip installed on your system. If you have t

Darkest Surface 6 Dec 17, 2022
A Python Module That Uses ANN To Predict A Stocks Price And Also Provides Accurate Technical Analysis With Many High Potential Implementations!

Stox โšก A Python Module For The Stock Market โšก A Module to predict the "close price" for the next day and give "technical analysis". It uses a Neural N

Dopevog 31 Dec 16, 2022
Discord Panel is an AIO panel for Discord that aims to have all the needed tools related to user token interactions, as in nuking and also everything you could possibly need for raids

Discord Panel Discord Panel is an AIO panel for Discord that aims to have all the needed tools related to user token interactions, as in nuking and al

11 Mar 30, 2022
A Discord Tool which checks for valid tokens and adds them to a server

Discord-Server-Botter A Discord Tool which checks for valid tokens and adds them to a server Usage Choice 1 is for checking tokens Choice 2 is for add

Bless 3 Jul 01, 2022
A Discord Self bot written in python

WitheredBot A Discord Self bot written in python Requirement Python = 3.9 How to Configure git clone https://github.com/a-a-a-aa/WitheredBot.git cd W

......... 0 Jan 05, 2023
Improved file host. Change of interface and storage: 15 GB available.

File hosting v2 Improved file host. Change of interface and storage: 15 GB available. This app now uses the Google API to store, view, and delete file

Sarusman 1 Jan 18, 2022
Huggingface transformers for discord

disformers Huggingface transformers for discord base source butyr/huggingface-transformer-chatbots install pip install -U disformers example see examp

SpaceDEVofficial 1 Nov 09, 2021
Messing around with GitHub API to look at omicron build times

gh-workflow-runs This is a very simple tool to dump out basic information about workflow runs for a GitHub repo. The structure is based on gh-subscrip

David Pacheco 1 Nov 30, 2021
โ˜„๏ธ High performance, easy to use and feature-rich Solana SDK for Python.

Solathon is an high performance, easy to use and feature-rich Solana SDK for Python. Easy for beginners, powerful for real world applications.

Bolt 28 Oct 10, 2022