Skip to main content

A set of useful APIs for cloudmesh

Project description

Cloudmesh Common

DOI Version License Python Format Format 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 wth 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

A convenient way on using named timers

from cloudmesh.common.StopWatch import StopWatch
import os

watch = StopWatch()

watch.start("test")
os.sleep(1)
watch.stop("test")

print (watch["test"])

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

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-4.1.29.tar.gz (43.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

cloudmesh_common-4.1.29-py2.py3-none-any.whl (53.9 kB view details)

Uploaded Python 2Python 3

File details

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

File metadata

  • Download URL: cloudmesh-common-4.1.29.tar.gz
  • Upload date:
  • Size: 43.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.32.2 CPython/3.7.4

File hashes

Hashes for cloudmesh-common-4.1.29.tar.gz
Algorithm Hash digest
SHA256 827e49b8a4c0334a57ce3d400ee5c091db0efe0d7c7ba07aa5504c516eb76d19
MD5 44f4cdf45a1f80cf69431918d5873161
BLAKE2b-256 d9eb3706beab83532373ff78db675137fb9d21fb411951f94e45bba40cebd68b

See more details on using hashes here.

File details

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

File metadata

  • Download URL: cloudmesh_common-4.1.29-py2.py3-none-any.whl
  • Upload date:
  • Size: 53.9 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.32.2 CPython/3.7.4

File hashes

Hashes for cloudmesh_common-4.1.29-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 5fe09575dfc1207b00edf84474524acb14eebcae08d707e61db28fc8c7e83b57
MD5 04031ec1304931c7197900f6bbbd5417
BLAKE2b-256 885206863053d461b93972be3e8d15d6a88ee61f2291dbd325b05becc54ead66

See more details on using hashes here.

Supported by

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