IcsUtils.Misc Common Library

Misc: Library for Misc

This is the Misc common library.
class opslib.icsutils.misc.IcsSysCfg[source]

ICS Library for System Configuration

__del__()[source]
__dict__ = dict_proxy({'__module__': 'opslib.icsutils.misc', 'parse_sshpub': <function parse_sshpub at 0x4884410>, '__del__': <function __del__ at 0x4884320>, 'update_cfg': <function update_cfg at 0x4884578>, 'recurmatch': <function recurmatch at 0x4884668>, 'update_host_name': <function update_host_name at 0x4884488>, 'update_sshpub': <function update_sshpub at 0x4884398>, 'to_dict': <function to_dict at 0x48845f0>, '__dict__': <attribute '__dict__' of 'IcsSysCfg' objects>, 'update_hosts_file': <function update_hosts_file at 0x4884500>, '__weakref__': <attribute '__weakref__' of 'IcsSysCfg' objects>, '__doc__': '\n ICS Library for System Configuration\n ', '__init__': <function __init__ at 0x48842a8>})
__init__()[source]
__module__ = 'opslib.icsutils.misc'
__weakref__

list of weak references to the object (if defined)

parse_sshpub(sshpub=None)[source]

Parse SSH Public Key

Parameters:sshpub (string) – SSH public key contents
recurmatch(path)[source]

Get augeas output via recursive solution (low-level)

Parameters:path (string) – augeas string
to_dict(data)[source]

Convert augeas output as dict format (low-level)

Parameters:data (generator) – augeas output data
Return type:dict
Returns:a dictionary contains augeas output data
update_cfg(path, value)[source]

Update configuration via augeas library (low-level)

Parameters:
update_host_name(hostname)[source]

Update hostname

Parameters:hostname (string) – hostname need to udpate
update_hosts_file(ipaddr, hostname)[source]

Update /etc/hosts with (ipaddr, hostname) pair

Parameters:
  • ipaddr (string) – IP address
  • hostname (string) – hostname
update_sshpub(user='ics-user', sshpub=None)[source]

Update SSH Public Key

Parameters:
  • user (string) – to determine which user to update
  • sshpub (string) – SSH public key contents
class opslib.icsutils.misc.Retry(tries, interval=0, exceptions=None)[source]
__call__(f)[source]

retry calling your function

__dict__ = dict_proxy({'__module__': 'opslib.icsutils.misc', 'default_exceptions': <type 'exceptions.Exception'>, '__dict__': <attribute '__dict__' of 'Retry' objects>, '__call__': <function __call__ at 0x4882c80>, '__weakref__': <attribute '__weakref__' of 'Retry' objects>, '__doc__': None, '__init__': <function __init__ at 0x4882b18>})
__init__(tries, interval=0, exceptions=None)[source]

Decorator for retrying function if exception occurs

Parameters:
  • tries (int) – how many times to retry your function
  • exceptions (Exception) – which exceptions you need to be caught to retry your function
__module__ = 'opslib.icsutils.misc'
__weakref__

list of weak references to the object (if defined)

default_exceptions

alias of Exception

opslib.icsutils.misc.check_error(response_data)[source]

A helper function that prints out the error message recieved in the response_data and raises an error when there is an error.

opslib.icsutils.misc.clean_empty_items(dict_json)[source]

Clean Empty Items in the Dictionary: None, {}, [], “”

opslib.icsutils.misc.convert_keyname(obj)[source]
opslib.icsutils.misc.dict_merge(a, b)[source]

recursively merges dict’s. not just simple a[‘key’] = b[‘key’], if both a and bhave a key who’s value is a dict then dict_merge is called on both values and the result stored in the returned dictionary.

opslib.icsutils.misc.drop_null_items(obj)[source]
opslib.icsutils.misc.exec_shell(cmd)[source]

Execute Shell Commands

(not support for pipe in shell command)

Parameters:cmd (string) – shell commands
Return type:tuple
Returns:a tuple containing (exitstatus, stdout, stderr)
opslib.icsutils.misc.exec_shell_pipe(cmd)[source]

Execute Shell Commands

Parameters:cmd (string) – shell commands
Return type:string or bool
Returns:False or error reason
opslib.icsutils.misc.fetch_used_params(service_name, cmd_name, params)[source]

Fetch used parameters from the whole configuration

opslib.icsutils.misc.filter_resource_from_json(names=None, filter=None, raw_data=None)[source]

Filter the resource with specified filter on JSON data

Parameters:
  • names (list) – specify the list of resoure names to filter Ex: [“AutoScalingGroupName”, “LaunchConfigurationName”]
  • filter (dict) – describe the filter in details
  • raw_data (dict) – resource data in JSON format
Return type:

list

Returns:

a list containing all the names for filtered resources

opslib.icsutils.misc.format_aws_tags(resource_id, tags)[source]

Refine the format of tags under AWS tag syntax

Parameters:
  • resource_id (string) – AWS Resource Id
  • tags (list) – a list of tags to refine
opslib.icsutils.misc.gen_timestamp(format='%Y%m%d-%H%M%S')[source]
opslib.icsutils.misc.get_data(search_path)[source]

Get the complete data paths under the path to search

Parameters:search_path (string) – describes the folder path to search
opslib.icsutils.misc.get_search_file(name, search_paths)[source]

Get the complete data path matched with the specified name

Parameters:
  • name (string) – specified name need to match
  • search_paths (list) – a list of folder paths to search
opslib.icsutils.misc.get_search_files(search_paths)[source]

Get the complete data paths under all the folder paths to search

Parameters:search_paths (list) – a list of folder paths to search
opslib.icsutils.misc.get_search_path(search_paths)[source]

Return the complete folder path used when searching for data files.

Parameters:search_paths (list) – a list of folder paths to search
opslib.icsutils.misc.get_userdata(version='latest', url='http://169.254.169.254', timeout=None, num_retries=5)[source]

Returns the instance userdata as a string by default.

If the timeout is specified, the connection to the specified url will time out after the specified number of seconds.

Parameters:
  • version (str) – API version from AWS
  • timeout (int) – socket timeout
  • num_retries (int) – how many times of retrying
Return type:

string

Returns:

a string containing user data

opslib.icsutils.misc.init_botocore_service(name, region)[source]

Initialize the proper service with botocore

opslib.icsutils.misc.is_valid_ip(ip_address)[source]

Check Validity of an IP address

opslib.icsutils.misc.keyname_format(fp_json)[source]

Convert the key name of JSON data: from camel case to a “pythonic” name.

Parameters:fp_json (object) – opened file object
opslib.icsutils.misc.keyname_formatd(dict_json)[source]

Convert the key name of JSON data: from camel case to a “pythonic” name.

Parameters:dict_json (dict) – JSON data
opslib.icsutils.misc.keyname_formats(str_json)[source]

Convert the key name of JSON data: from camel case to a “pythonic” name.

Parameters:str_json (string) – JSON data
opslib.icsutils.misc.operate(service, cmd, kwargs)[source]

A helper function that universally calls any command by taking in the service, name of the command, and any additional parameters required in the call.

opslib.icsutils.misc.traverse_json(data, delimiter='/', path='', output=None)[source]

Traverse all the items in JSON data

Parameters:
  • data (dict, list, element) – JSON data
  • delimiter (string) – path delimiter for each JSON node
  • path (string) – record the parent path on this JSON data
  • output (dict) – record each item with full path
opslib.icsutils.misc.user_data_decode(user_data)[source]

Indices and tables

Read the Docs v: latest
Versions
latest
Downloads
PDF
HTML
Epub
On Read the Docs
Project Home
Builds

Free document hosting provided by Read the Docs.