Skip to main content

A set of useful APIs for cloudmesh

Project description

Cloudmesh Common

image Python License Format Status Travis

Installation and Documentation

Please note that several packages are available which are pointed to in the installation documentation.

Links
Documentation https://cloudmesh.github.io/cloudmesh-cloud
Code https://github.com/cloudmesh/cloudmesh-cloud
Installation Instructions https://github.com/cloudmesh/get

Highlighted features

This library contains a number of useful functions and APIs that we highlight here. They are used to interact with the system and provide a number of functions to implement command line programs and shells.

Console

The console provides convenient way to print colored messages types in the terminal, such as errors, info, and regular messages

from cloudmesh.common.console import Console

Console.error("this is an error printed in red with prefix ERROR:")
Console.msg("this is a msg printed in black")
Console.ok("this is an ok message printed in green")

Shell

We have lots of shell commands that call linux commands, but also have a convenient execution command that returns the results in a string.

For more information we like you to inspect the source code:

from cloudmesh.common.Shell import Shell

shell = Shell()

print(shell.terminal_type())

# prints after the command is finished
r = shell.execute('pwd') 
print(r)

# prints while the command is executed
r = shell.live('pwd') 
print(r)

# open a new terminal and start the command ls in it (for OSX and Gnome)
shell.terminal("ls")

# an example of a build in command
shell.pip("install cloudmesh-common")

We have many such build in commands, please see the source

Printer

A convenient way to print dictionaries and lists with repeated entries as tables, csv, json, yaml. The dictionaries can even be hierarchical.

Let us assume we have

data = [
    {
        "name": "Gregor",
        "address": {
            "street": "Funny Lane 11",
            "city": "Cloudville"
        {
    },
    {
        "name": "Albert",
        "address": {
            "street": "Memory Lane 1901",
            "city": "Cloudnine"
        }
    }
]

Then we can print it nicely with

print(Printer.flatwrite(self.data,
                    sort_keys=["name"],
                    order=["name", "address.street", "address.city"],
                    header=["Name", "Street", "City"],
                    output="table")
          )

Other formats such as csv, json, dict are also supported.

In addition we have also printers for printing attribute lists. Please consult the source code.

StopWatch

See: https://colab.research.google.com/drive/1tG7IcP-XMQiNVxU05yazKQYciQ9GpMat#scrollTo=TZAjATZiQh4q&uniqifier=1 for an example

Using Cloudmesh StopWatch Inline

from cloudmesh.common.StopWatch import StopWatch
import time

StopWatch.start("a")
time.sleep(3)
StopWatch.stop("a")
StopWatch.status("a", True)
StopWatch.benchmark()

Using Cloudmesh Benchmark wrapped in Functions

If it is not wrapped in functions, do not use it this way.

from cloudmesh.common.Benchmark import Benchmark
import time
  
def b():
  Benchmark.Start()
  time.sleep(3)
  Benchmark.Stop()

def c():
  Benchmark.Start()
  time.sleep(1)
  Benchmark.Stop()

 b()
 c()

Benchmark.print()

dotdict

One dimensional Dictionaries in dot format.

from cloudmesh.common.dotdict import doctict

# convert a simple dict to a dotdict
d = dotdict({"name": "Gregor"})
# Now you can say
print(d["name"])
print(d.name)

ssh

util

Very useful functions are included in util

Especially useful are

  • generating passwords
  • banners
  • yn_choices
  • path_expansion
  • grep (simple line matching)
  • HEADING() which without parameter identifies the name of the function and prints its name within a banner

Changes

  • added support for terminals with dark background

Acknowledgments

Continued work was in part funded by the NSF CyberTraining: CIC: CyberTraining for Students and Technologies from Generation Z with the award numbers 1829704 and 2200409.

Project details


Release history Release notifications | RSS feed

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

cloudmesh-common-5.0.60.tar.gz (112.9 kB view details)

Uploaded Source

Built Distribution

cloudmesh_common-5.0.60-py2.py3-none-any.whl (112.5 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file cloudmesh-common-5.0.60.tar.gz.

File metadata

  • Download URL: cloudmesh-common-5.0.60.tar.gz
  • Upload date:
  • Size: 112.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.12.0

File hashes

Hashes for cloudmesh-common-5.0.60.tar.gz
Algorithm Hash digest
SHA256 cdb0b925b73c868540ce7effd47d632de1321a7a7b62bf0526640405bd57d8af
MD5 a9589339d6fb06a69f99f5d5ec09c6b1
BLAKE2b-256 935ac746e74c20d67736801af34d4cfce05cac3ec6a8aaaeec5476c5cc369fa2

See more details on using hashes here.

File details

Details for the file cloudmesh_common-5.0.60-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for cloudmesh_common-5.0.60-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 cbe300752cd4e0ee172e5f78a764a702954f9f892b788c5eb68cbcf7856525b4
MD5 02fe244be5d8999990b0166fa7d22370
BLAKE2b-256 56deb20735f6a298668f7ab75f7c1743cd8d74a05782b7879d68781c4551e3e3

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page