cloudmesh_client.common package

Submodules

cloudmesh_client.common.BaseConfigDict module

Some simple yaml file reader

class cloudmesh_client.common.BaseConfigDict.BaseConfigDict(*args, **kwargs)[source]

Bases: collections.OrderedDict

A class to obtain an OrderedDict from a yaml file.

attribute(keys)[source]

TODO: document this method

Parameters:keys
dump()[source]

returns the json output of the dict.

error_keys_not_found(keys)[source]

Check if the requested keys are found in the dict.

Parameters:keys – keys to be looked for
get(*keys)[source]

returns the dict of the information as read from the yaml file. To access the file safely, you can use the keys in the order of the access. Example: get(“provisioner”,”policy”) will return the value of config[“provisioner”][“policy”] from the yaml file if it does not exists an error will be printing that the value does not exists. Alternatively you can use the . notation e.g. get(“provisioner.policy”)

json()[source]

returns the json output of the dict.

load(filename)[source]

Loads the yaml file with the given filename.

Parameters:filename – the name of the yaml file
make_a_copy(location=None)[source]

Creates a backup of the file specified in the location. The backup filename appends a .bak.NO where number is a number that is not yet used in the backup directory.

TODO: This function should be moved to another file maybe XShell

Parameters:location – the location of the file to be backed up
pprint()[source]

uses pprint to print the dict

read(filename)[source]

Loads the information in the yaml file. It is the same as load and is used for compatibility reasons.

Parameters:filename – the name of the yaml file
set(value, *keys)[source]

Sets the dict of the information as read from the yaml file. To access the file safely, you can use the keys in the order of the access. Example: set(“{‘project’:{‘fg82’:[i0-i10]}}”, “provisioner”,”policy”) will set the value of config[“provisioner”][“policy”] in the yaml file if it does not exists an error will be printing that the value does not exists. Alternatively you can use the . notation e.g. set(“{‘project’:{‘fg82’:[i0-i10]}}”, “provisioner.policy”)

write(filename=None, output='dict', attribute_indent=4)[source]

This method writes the dict into various outout formats. This includes a dict, json, and yaml

Parameters:
  • filename – the file in which the dict is written
  • output – is a string that is either “dict”, “json”, “yaml”
  • attribute_indent – character indentation of nested attributes in
yaml()[source]

returns the yaml output of the dict.

class cloudmesh_client.common.BaseConfigDict.OrderedJsonEncoder(skipkeys=False, ensure_ascii=True, check_circular=True, allow_nan=True, sort_keys=False, indent=None, separators=None, encoding='utf-8', default=None, use_decimal=True, namedtuple_as_object=True, tuple_as_array=True, bigint_as_string=False, item_sort_key=None, for_json=False, ignore_nan=False, int_as_string_bitcount=None, iterable_as_array=False)[source]

Bases: simplejson.encoder.JSONEncoder

encode(o, depth=0)[source]
indent = 4
cloudmesh_client.common.BaseConfigDict.check_file_for_tabs(filename, verbose=True)[source]

identifies if the file contains tabs and returns True if it does. It also prints the location of the lines and columns. If verbose is set to False, the location is not printed.

Parameters:filename – the filename
Return type:True if there are tabs in the file
cloudmesh_client.common.BaseConfigDict.custom_print(data_structure, indent)[source]
cloudmesh_client.common.BaseConfigDict.ordered_dump(data, stream=None, Dumper=<class 'yaml.dumper.Dumper'>, **kwds)[source]

writes the dict into an ordered yaml.

Parameters:
  • data – The ordered dict
  • stream – the stream
  • Dumper – the dumper such as yaml.SafeDumper
cloudmesh_client.common.BaseConfigDict.ordered_load(stream, Loader=<class 'yaml.loader.Loader'>, object_pairs_hook=<class 'collections.OrderedDict'>)[source]

Loads an ordered dict into a yaml while preserving the order

Parameters:
  • stream – the name of the stream
  • Loader – the yam loader (such as yaml.SafeLoader)
  • object_pairs_hook – the ordered dict
cloudmesh_client.common.BaseConfigDict.read_yaml_config(filename, check=True, osreplace=True, exit=True)[source]

reads in a yaml file from the specified filename. If check is set to true the code will fail if the file does not exist. However if it is set to false and the file does not exist, None is returned.

Parameters:
  • filename – the file name
  • check – if True fails if the file does not exist, if False and the file does not exist return will be None

cloudmesh_client.common.ConfigDict module

class cloudmesh_client.common.ConfigDict.Config[source]

Bases: object

classmethod check_file_for_tabs(filename, verbose=True)[source]

identifies if the file contains tabs and returns True if it does. It also prints the location of the lines and columns. If verbose is set to False, the location is not printed. :param filename: the filename :type filename: str :rtype: True if there are tabs in the file

classmethod find_file(filename, load_order=None, verbose=False)[source]

find the specified file in the list of directories that are given in the array load_order :param filename: the file name :type filename: str :param load_order: an array with path names in with the filename is looked for. :type load_order: list of str :param verbose: :type verbose: bool :return: file name if successful :rtype: string if the file exists or None otherwise

classmethod path_expand(path)[source]

expands the path while replacing environment variables, ./, and ~/ :param path: the path to be expanded :type path: string :return:the new path :rtype: string

class cloudmesh_client.common.ConfigDict.ConfigDict(filename, load_order=None, verbose=False, etc=False, reload=False)[source]

Bases: object

classmethod check(filename)[source]

checks the filename if it is syntactically correct and does not include tabs :param filename: :type filename: string :return:

data = {}
filename = None
classmethod getUser(cloud)[source]
info()[source]

prints out the dict type and its content

json
Parameters:start – start key in dot notation

returns the dict in json format :return: json string version :rtype: string

load(filename)[source]

loads the configuration from the yaml filename :param filename: :type filename: string :return:

make_a_copy(location=None)[source]

Creates a backup of the file specified in the location. The backup filename appends a .bak.NO where number is a number that is not yet used in the backup directory. TODO: This function should be moved to another file maybe XShell :param location: the location of the file to be backed up

save(filename=None)[source]

saves the configuration in the given filename, if it is none the filename at load time is used. :param filename: the file name :type filename: string :return:

versions = ['4.1']
write(filename=None, output='dict', attribute_indent=4)[source]

This method writes the dict into various outout formats. This includes a dict, json, and yaml :param filename: the file in which the dict is written :param output: is a string that is either “dict”, “json”, “yaml” :param attribute_indent: character indentation of nested attributes in

yaml

returns the dict in yaml format :return: returns the yaml output of the dict :rtype: string:

cloudmesh_client.common.ConfigDict.Username()[source]
cloudmesh_client.common.ConfigDict.custom_print(data_structure, indent, attribute_indent=4)[source]
cloudmesh_client.common.ConfigDict.dprint(OD, mode='dict', s='', indent=' ', level=0)[source]
cloudmesh_client.common.ConfigDict.main()[source]
cloudmesh_client.common.ConfigDict.ordered_dump(data, stream=None, Dumper=<class 'yaml.dumper.Dumper'>, **kwds)[source]

writes the dict into an ordered yaml. :param data: The ordered dict :param stream: the stream :param Dumper: the dumper such as yaml.SafeDumper

cloudmesh_client.common.DictDB module

class cloudmesh_client.common.DictDB.DictDB(filename, d=None, attributes=None)[source]

Bases: dict

Implements a persistent dictionary using sqlite

Usage:

element = {“name”:, “abc”,
“address”: “here”, “email”: “abc@example.com”}

The name in the dict is identifies where to store it.

d = PersistentData(os.path.join(“~”, “.cloudmesh/cloudmesh.db”))

d.add(element)

d.delete(“name”: “abc”)
# deletes all elements from the db where ethe name is matching abc
d.json
# exports to json
d.yaml
# exports a yaml as a string
d.get(“name”: “abc”)
gets the first match
d.find(“name”: “abc”)
finds the first match
add(d)[source]

adds the dict to the database. The attribute “name” is used to define a unique name for the object in the database

Parameters:d – the dict that at minimum must contain a name attribute
attributes(attribute_names)[source]

defines the attributes that each record can have. If a database has previously defined and new attributes are added the database records are updated.

Parameters:attribute_names – The attribute names
backup(filename=None)[source]

backs up the current database. If the filename is omitted, the backup will be created in the same directory as the database with the postfix .bak.# where # is the largest number that has not yet been assigned. For example., lets assume a backup exists with the name file.bak.9, than the next higher number is used (e.g. 10) and the backup file file.back.10 is used.

Parameters:filename – the backup filename.
Returns:
delete(operator='and', **kwargs)[source]

deletes all elements in that match the query formulated by kwargs and the operator operators that are allowed are = and, or

Parameters:
  • kwargs – the attributes that we look for
  • operator – the operator and / or
find(operator='and', **kwargs)[source]

finds all elements in that match the query formulated by kwargs and the operator operators that are allowed are = and, or

Parameters:
  • kwargs – the attributes that we look for
  • operator – the operator and / or
get(operator='and', **kwargs)[source]

finds the first elements in that match the query formulated by kwargs and the operator operators that are allowed are = and, or

Parameters:
  • kwargs – the attributes that we look for
  • operator – the operator and / or
json
Returns:the json object of the database
yaml
Returns:a yaml string of the database

cloudmesh_client.common.DynamicClass module

class cloudmesh_client.common.DynamicClass.DynamicClass[source]

Bases: object

classmethod add_classmethod(f)[source]
add_instance_method(f)[source]
classmethod load_classmethod(location)[source]
load_instancemethod(location)[source]

cloudmesh_client.common.Error module

class cloudmesh_client.common.Error.Error[source]

Bases: object

classmethod debug(msg)[source]
classmethod exit(msg)[source]
classmethod info(msg)[source]
classmethod msg(error=None, debug=True, trace=True)[source]
classmethod traceback(error=None, debug=True, trace=True)[source]
classmethod warning(msg)[source]

cloudmesh_client.common.FlatDict module

class cloudmesh_client.common.FlatDict.FlatDict(d)[source]

Bases: dict

A data structure to manage a flattened dict. It is initialized by passing the dict at time of initialization.

add(key, value)[source]
dict
keys()[source]
values()[source]
cloudmesh_client.common.FlatDict.flatten(d, parent_key='', sep='__')[source]

flattens the dict into a one dimensional dictionary

Parameters:
  • d – multidimensional dict
  • parent_key – replaces from the parent key
  • sep – the separation character used when fattening. the default is __
Returns:

the flattened dict

cloudmesh_client.common.FlatDict.key_prefix_replace(d, prefix, new_prefix='')[source]

replaces the list of prefix in keys of a flattened dict

Parameters:
  • d – the flattened dict
  • prefix (list of str) – a list of prefixes that are replaced with a new prefix. Typically this will be “”
  • new_prefix – The new prefix. By default it is set to “”
Returns:

the dict with the keys replaced as specified

cloudmesh_client.common.FlatDict2 module

class cloudmesh_client.common.FlatDict2.FlatDict2[source]

Bases: object

classmethod convert(obj, flatten=True)[source]

This function converts object into a Dict optionally Flattening it :param obj: Object to be converted :param flatten: boolean to specify if the dict has to be flattened :return dict: the dict of the object (Flattened or Un-flattened)

classmethod is_primitive(thing)[source]
classmethod object_to_dict(obj)[source]

This function converts Objects into Dictionary

primitive = (<type 'int'>, <type 'str'>, <type 'bool'>, <type 'unicode'>, <type 'dict'>, <type 'list'>)

cloudmesh_client.common.GitInfo module

managing information from GIT

class cloudmesh_client.common.GitInfo.GitInfo[source]

Bases: object

This class can be used to return some elementary information about the git hub directory. This includes the:

  • version number of the code
  • the list of people contributing to the code
  • emails of the people contributing
  • a statistic about canged code by person

Example:

gitinfo = GitInfo()
print gitinfo.authors()
pprint(gitinfo.authors("dict"))
pprint(gitinfo.emails())
pprint(gitinfo.emails("dict"))
pprint(gitinfo.info())
print gitinfo.stat("laszewski@gmail.com")
stats = gitinfo.compute()
print stats
authors(format_arg=None)[source]

returns the authors of the authors either as a text or as a dict. The format is specified as an argument.

Parameters:format_arg – if “dict” is specified a dict will be returned
compute()[source]

computes the statistic of all authors in a git repository and returns the result as a dict. :rtype: a dict with the values

emails(format_arg=None)[source]

returns the emails of the authors either as a text or as a dict. The format is specified as an argument.

Parameters:format_arg – if “dict” is specified a dict will be returned
Return type:dict or arry of e-mails dependent on format_arg
info()[source]

returns the information about authors, emails, and commits in a dict. :rtype: a dict with the information

stat(email)[source]

returns a statistic of a git author with the given e_mail.

Parameters:email – name of the author
Return type:a dict with the statistics
version()[source]

retruns the verison of the code from github :rtype: the git tags

cloudmesh_client.common.GitInfo.print_authors()[source]

cloudmesh_client.common.LibcloudDict module

class cloudmesh_client.common.LibcloudDict.LibcloudDict[source]

Bases: object

Libcloud_category_list = ['chameleon-ec2', 'cybera-ec2', 'aws']
static convert_libcloud_vm_to_dict(node_obj)[source]
static handle_key_details(key_obj)[source]
static handle_vm_extra_args(extra_args)[source]
static handle_vm_image_details(node_image_obj, is_image_dict=True)[source]
static handle_vm_image_extra_args(extra_args)[source]
static handle_vm_size_details(node_size_obj)[source]
static handle_vm_size_extra_args(node_size_extra_args)[source]

cloudmesh_client.common.LogUtil module

class cloudmesh_client.common.LogUtil.LogUtil[source]

Bases: object

DEFAULT_LOG_LEVEL = 'ERROR'
FORMAT = '%(asctime)s [%(levelname)s] %(filename)s:%(lineno)s %(funcName)s() %(message)s'
LOG_LEVEL_KEY = 'log_level'
category = 'general'
static get_level()[source]

get the log level from database :param cloudname: The name of the cloud :return: the log level

static get_level_obj(log_level)[source]

gets the log level when passing a string :param log_level: case insensitive string. Valid values are debug,

info, warning, critical, error
Returns:a logging level
static get_logger()[source]

get caller file name :return: file name based on the context where the logger is caller

static initialize_logging()[source]

reads the log level from the cloudmesh.yaml file from cloudmesh.logging.level. If the value is not set the logging will be set to the default which is “ERROR” :return: the loglevel

static save()[source]

save the loglevel for a cloud to the cloudmesh.yaml file

static set_level(log_level)[source]

sets th eloglevel in the database and the loglevel file from cloudmesh.yaml :param log_level: the loglevel :return:

cloudmesh_client.common.Printer module

Convenient methods and classes to print tables

class cloudmesh_client.common.Printer.Printer[source]

Bases: object

classmethod attribute(d, header=None, order=None, sort_keys=True, output='table')[source]
classmethod csv(d, order=None, header=None, sort_keys=True)[source]

prints a table in csv format

Parameters:d (dict) – A a dict with dicts of the same type.
:param order:The order in which the columns are printed.
The order is specified by the key names of the dict.
Parameters:
  • header (list or tuple of field names) – The Header of each of the columns
  • sort_keys (bool) – TODO: not yet implemented
Returns:

a string representing the table in csv format

classmethod dict(d, order=None, header=None, output='table', sort_keys=True, show_none='')[source]

TODO :param d: A a dict with dicts of the same type. :type d: dict :param order:The order in which the columns are printed.

The order is specified by the key names of the dict.
Parameters:
  • header (list or tuple of field names) – The Header of each of the columns
  • output (string) – type of output (table, csv, json, yaml or dict)
  • sort_keys (bool) –
Returns:

classmethod dict_table(d, order=None, header=None, sort_keys=True, show_none='', max_width=40)[source]

prints a pretty table from an dict of dicts :param d: A a dict with dicts of the same type.

Each key will be a column
Parameters:
  • order – The order in which the columns are printed. The order is specified by the key names of the dict.
  • header (A list of string) – The Header of each of the columns
  • sort_keys (string or a tuple of string (for sorting with multiple columns)) – Key(s) of the dict to be used for sorting. This specify the column(s) in the table for sorting.
classmethod list(l, order=None, header=None, output='table', sort_keys=True, show_none='')[source]
Parameters:
  • l – l is a lsit not a dict
  • order
  • header
  • output
  • sort_keys
  • show_none
  • key
Returns:

classmethod print_list(l, output='table')[source]
classmethod row_table(d, order=None, labels=None)[source]

prints a pretty table from data in the dict. :param d: A dict to be printed :param order: The order in which the columns are printed.

The order is specified by the key names of the dict.
classmethod write(table, order=None, header=None, output='table', sort_keys=True, show_none='')[source]

cloudmesh_client.common.SSHkey module

class cloudmesh_client.common.SSHkey.SSHkey(file_path=None, keyname=None)[source]

Bases: object

comment
fingerprint
get()[source]
key
read(file_path, keyname=None)[source]
type
cloudmesh_client.common.SSHkey.main()[source]

cloudmesh_client.common.Shell module

class cloudmesh_client.common.Shell.Shell[source]

Bases: object

classmethod VBoxManage(*args)[source]
classmethod bash(*args)[source]
classmethod blockdiag(*args)[source]
classmethod cat(*args)[source]
classmethod check_output(*args, **kwargs)[source]

Thin wrapper around subprocess.check_output()

classmethod cm(*args)[source]
command = {'windows': {}, 'darwin': {}, 'linux': {}}

big question for badi and others

how do we now define dynamically functions based on a list that we want to support

what we want is where args are multiple unlimited parameters to the function

def f(args…):

name = get the name from f a = list of args…

cls.execute(cmd, arguments=a, capture=True, verbose=False)

commands = [‘ps’, ‘ls’, ….. ] for c in commands:

generate this command and add to this class dynamically

or do something more simple

ls = cls.execute(‘cmd’, args…)

classmethod command_exists(name)[source]
cygwin_path = 'bin'
classmethod dialog(*args)[source]
classmethod execute(cmd, arguments='', shell=False, cwd=None, traceflag=True, witherror=True)[source]

Run Shell command

Parameters:
  • cmd – command to run
  • arguments – we dont know yet
  • capture – if true returns the output
Returns:

classmethod fgmetric(*args)[source]
classmethod fgrep(*args)[source]
classmethod find_cygwin_executables()[source]

find the executables

classmethod find_lines_with(lines, what)[source]
classmethod gchproject(*args)[source]
classmethod gchuser(*args)[source]
classmethod git(*args)[source]
classmethod glusers(*args)[source]
classmethod gmkproject(*args)[source]
classmethod grep(*args)[source]
classmethod gstatement(*args)[source]
classmethod head(*args)[source]
classmethod keystone(*args)[source]
classmethod kill(*args)[source]
classmethod list_commands()[source]
classmethod ls(*args)[source]
classmethod mkdir(newdir)[source]

works the way a good mkdir should :) - already exists, silently complete - regular file in the way, raise an exception - parent directory(ies) does not exist, make them as well

classmethod mongod(*args)[source]
classmethod mongoimport(*args)[source]
classmethod mysql(*args)[source]
classmethod nosetests(*args)[source]
classmethod nova(*args)[source]
classmethod operating_system()[source]
classmethod ping(host=None, count=1)[source]
classmethod pip(*args)[source]
classmethod ps(*args)[source]
classmethod pwd(*args)[source]
classmethod rackdiag(*args)[source]
classmethod remove_line_with(lines, what)[source]
classmethod rm(*args)[source]
classmethod rsync(*args)[source]
classmethod scp(*args)[source]
classmethod sh(*args)[source]
classmethod sort(*args)[source]
classmethod ssh(*args)[source]
classmethod sudo(*args)[source]
classmethod tail(*args)[source]
classmethod terminal_type()[source]

returns darwin, cygwin, cmd, or linux

unzip(source_filename, dest_dir)[source]

unzips a file into the destination directory :param dest_dir: the destination directory :return:

classmethod vagrant(*args)[source]
classmethod which(command)[source]
class cloudmesh_client.common.Shell.Subprocess(cmd, cwd=None, stderr=-1, stdout=-1, env=None)[source]

Bases: object

exception cloudmesh_client.common.Shell.SubprocessError(cmd, returncode, stderr, stdout)[source]

Bases: exceptions.Exception

cloudmesh_client.common.Shell.main()[source]

cloudmesh_client.common.StopWatch module

Class for starting and stopping named timers.

This class is based on a similar java class in cyberaide, and java cog kit.

class cloudmesh_client.common.StopWatch.StopWatch[source]

Bases: object

A class to measure times between events.

classmethod clear()[source]

clear start and end timer_start

classmethod get(name)[source]

returns the time of the timer.

Parameters:name (string) – the name of the timer
Return type:the elapsed time
classmethod keys()[source]

returns the names of the timers

classmethod start(name)[source]

starts a timer with the given name.

Parameters:name (string) – the name of the timer
classmethod stop(name)[source]

stops the timer with a given name.

Parameters:name (string) – the name of the timer
timer_end = {}
timer_start = {}

cloudmesh_client.common.TableParser module

class cloudmesh_client.common.TableParser.TableParser(output='dict', header=True, index=None, change=None, strip=True, lower=True, strip_seperator=True, seperator='|', comment_chars='+#')[source]

Bases: object

clean(line)[source]
Parameters:line – cleans the string
Returns:
classmethod convert(table=None, output='dict', header=True, index=None, change=None, strip=True, lower=True, strip_seperator=True, seperator='|', comment_chars='+#')[source]
extract_lines(table)[source]
json()[source]
to_dict(table)[source]
Parameters:table (string) – converts a stream called line to a dict
Returns:the dict
to_list(table)[source]
Parameters:table (string) – converts a stream called line to a list
Returns:the list

cloudmesh_client.common.borg module

cloudmesh_client.common.borg.borg(cls)[source]

cloudmesh_client.common.dotdict module

class cloudmesh_client.common.dotdict.dotdict[source]

Bases: dict

dot.notation access to dictionary attributes

cloudmesh_client.common.hostlist module

Handle hostlist expressions. This module provides operations to expand and collect hostlist expressions. The hostlist expression syntax is the same as in several programs developed at LLNL (https://computing.llnl.gov/linux/). However in corner cases the behaviour of this module have not been compared for compatibility with pdsh/dshbak/SLURM et al.

exception cloudmesh_client.common.hostlist.BadHostlist[source]

Bases: exceptions.Exception

class cloudmesh_client.common.hostlist.Parameter[source]

Bases: object

classmethod expand(parameter, allow_duplicates=False, sort=False)[source]
cloudmesh_client.common.hostlist.collect_hostlist(hosts, silently_discard_bad=False)[source]

Collect a hostlist string from a Python list of hosts. We start grouping from the rightmost numerical part. Duplicates are removed. A bad hostname raises an exception (unless silently_discard_bad is true causing the bad hostname to be silently discarded instead).

cloudmesh_client.common.hostlist.collect_hostlist_1(left_right)[source]

Collect a hostlist string from a list of hosts (left+right). The input is a list of tuples (left, right). The left part is analyzed, while the right part is just passed along (it can contain already collected range expressions).

cloudmesh_client.common.hostlist.expand_hostlist(hostlist, allow_duplicates=False, sort=False)[source]

Expand a hostlist expression string to a Python list. Example: expand_hostlist(“n[9-11],d[01-02]”) ==>

[‘n9’, ‘n10’, ‘n11’, ‘d01’, ‘d02’]

Unless allow_duplicates is true, duplicates will be purged from the results. If sort is true, the output will be sorted.

cloudmesh_client.common.hostlist.expand_part(s)[source]

Expand a part (e.g. “x[1-2]y[1-3][1-3]”) (no outer level commas).

cloudmesh_client.common.hostlist.expand_range(prefix, range_)[source]

Expand a range (e.g. 1-10 or 14), putting a prefix before.

cloudmesh_client.common.hostlist.expand_rangelist(prefix, rangelist)[source]

Expand a rangelist (e.g. “1-10,14”), putting a prefix before.

cloudmesh_client.common.hostlist.format_range(low, high, width)[source]

Format a range from low to high inclusively, with a certain width.

cloudmesh_client.common.hostlist.handle_int_nonint(int_nonint_tuple)[source]
cloudmesh_client.common.hostlist.numeric_sort_key(x)[source]
cloudmesh_client.common.hostlist.numerically_sorted(l)[source]

Sort a list of hosts numerically. E.g. sorted order should be n1, n2, n10; not n1, n10, n2.

cloudmesh_client.common.hostlist.parse_slurm_tasks_per_node(s)[source]
cloudmesh_client.common.hostlist.remove_duplicates(l)[source]

Remove duplicates from a list (but keep the order).

cloudmesh_client.common.menu module

Ascii menu class

cloudmesh_client.common.menu.ascii_menu(title=None, menu_list=None)[source]

creates a simple ASCII menu from a list of tuples containing a label and a functions reference. The function should not use parameters. :param title: the title of the menu :param menu_list: an array of tuples [(‘label’, f1), …]

cloudmesh_client.common.menu.dict_choice(d)[source]
cloudmesh_client.common.menu.menu_return_num(title=None, menu_list=None, tries=1, with_display=True)[source]

creates a simple ASCII menu from a list of labels :param title: the title of the menu :param menu_list: a list of labels to choose :param tries: num of tries till discard :return: choice num (head: 0), quit: return ‘q’

cloudmesh_client.common.menu.num_choice(n, tries=1)[source]

cloudmesh_client.common.ssh_config module

class cloudmesh_client.common.ssh_config.ssh_config(filename=None)[source]

Bases: object

execute(name, command)[source]

executes the command on the named host

generate(key='india', host='india.futuresystems.org', username=None, force=False, verbose=False)[source]
list()[source]
load()[source]

list the hosts defined in the ssh config file

local(command)[source]
login(name)[source]

logs into the host defined by name in ssh config into an interactive shell

names()[source]
status()[source]

executes a test with the given ssh config if a login is possible

username(host)[source]

cloudmesh_client.common.todo module

class cloudmesh_client.common.todo.TODO[source]

Bases: object

classmethod implement(msg='Please implement')[source]

temporary function to use to indicate that the code is not yet implemented

cloudmesh_client.common.type module

class cloudmesh_client.common.type.Type[source]

Bases: object

flat = 'flat'
flavor = 'flavor'
image = 'image'
vm = 'vm'

cloudmesh_client.common.util module

cloudmesh_client.common.util.HEADING(txt=None)[source]

Prints a message to stdout with #### surrounding it. This is useful for nosetests to better distinguish them.

Parameters:txt (string) – a text message to be printed
cloudmesh_client.common.util.auto_create_requirements(requirements)[source]

creates a requirement.txt file form the requirements in the list. If the file exists, it get changed only if the requirements in the list are different from the existing file

Parameters:requirements – the requirements in a list
cloudmesh_client.common.util.auto_create_version(class_name, version, filename='__init__.py')[source]
cloudmesh_client.common.util.backup_name(filename)[source]
Parameters:filename (string) – given a filename creates a backup name of the form filename.bak.1. If the filename already exists the number will be increased as much as needed so the file does not exist in the given location. The filename can consists a path and is expanded with ~ and environment variables.
Return type:string
cloudmesh_client.common.util.banner(txt=None, c='#', debug=True)[source]

prints a banner of the form with a frame of # arround the txt:

############################
# txt
############################

.

Parameters:
  • txt (string) – a text message to be printed
  • c (character) – the character used instead of c
cloudmesh_client.common.util.check_python()[source]
cloudmesh_client.common.util.convert_from_unicode(data)[source]
cloudmesh_client.common.util.copy_files(files_glob, source_dir, dest_dir)[source]
Parameters:
  • files_glob*.yaml
  • source_dir – source directiry
  • dest_dir – destination directory
Returns:

cloudmesh_client.common.util.dict_replace(content, replacements=None)[source]
cloudmesh_client.common.util.exponential_backoff(fn, sleeptime_s_max=1800)[source]

Calls fn until it returns True, with an exponentially increasing wait time between calls

cloudmesh_client.common.util.generate_password(length=8, lower=True, upper=True, number=True)[source]
cloudmesh_client.common.util.get_python()[source]
cloudmesh_client.common.util.grep(pattern, filename)[source]

Very simple grep that returns the first matching line in a file. String matching only, does not do REs as currently implemented.

cloudmesh_client.common.util.path_expand(text)[source]

returns a string with expanded variable.

Parameters:
  • text – the path to be expanded, which can include ~ and $ variables
  • text – string
cloudmesh_client.common.util.readfile(filename)[source]
cloudmesh_client.common.util.search(lines, pattern)[source]
cloudmesh_client.common.util.str_banner(txt=None, c='#', debug=True)[source]

prints a banner of the form with a frame of # arround the txt:

############################
# txt
############################

.

Parameters:
  • txt (string) – a text message to be printed
  • c (character) – the character used instead of c
cloudmesh_client.common.util.tempdir(*args, **kwds)[source]

A contextmanager to work in an auto-removed temporary directory

Arguments are passed through to tempfile.mkdtemp

example:

>>> with tempdir() as path:
...    pass
cloudmesh_client.common.util.writefile(filename, content)[source]
cloudmesh_client.common.util.yn_choice(message, default='y', tries=None)[source]

asks for a yes/no question. :param message: the message containing the question :param default: the default answer

cloudmesh_client.common.vmname module

class cloudmesh_client.common.vmname.VMName[source]

Bases: object

static format(name=None)[source]

given a name that returns the following information as a tuple.

prefix - the prefix of the vm name index - the current index padding - the padding factor to fill the index with leading 0

The input name format is as follows prefix-0011 upon return you will get

(prefix, 11, 4)

if None is specified the current os user name will be used, the index will start as 1, and we will use four digits all in all for the padding.

Parameters:name – the name that derives a format for
Returns:prefix, index, padding
static get(prefix=None, idx=None, user=None)[source]

Return a vm name to use next time. prefix or index can be given to update a vm name (optional)

Args:
prefix (str, optional): the name of prefix idx (int, str, optional): the index to increment. This can be a digit or arithmetic e.g. +5 or -3 can be used
static next()[source]

Module contents