Skip to main content
Python Software Foundation 20th Year Anniversary Fundraiser  Donate today!

A python library for CONS3RT assets

Project description

# pycons3rt Python Library for CONS3RT Assets

## Features

* Gathers CONS3RT deployment info
* Runs Linux commands from python
* Configures networking on Linux
* Configuring AWS EC2 instance networking
* Downloads and uploads files to AWS S3
* Downloads files from a Nexus Artifact Repository
* Posts CONS3RT run info to Slack
* Establishes a logging infrastructure for python CONS3RT assets

## Installation

### Install from pip

If you have Python 2.7 installed, you can run:

`pip install pycons3rt`

Also you can install specific versions:

`pip install pycons3rt==0.0.2`

### Install from source

git clone
cd pycons3rt

### Install with CONS3RT assets

Search for community `pycons3rt` software assets in HmC or to use.

To create your own pycons3rt assets, from the pycons3rt repo root directory, run:

$ ./scripts/

This will create your own Linux and Windows pycons3rt assets for import:


## Configuration

Once installed, run the following command to set up pycons3rt:


### Asset Prerequisites

1. Git
1. Python 2.7.x
1. pip

### Asset Exit Codes (Linux):

* 0 - Success
* Non-zero - See log file in /var/log/cons3rt/ for additional details

### Asset Exit Codes (Windows)

* 0 - Success
* 1 - Asset install failed:
* pycons3rt install script not found, git clone may not have succeeded
* There was a problem setting up pycons3rt
* pycons3rt osutil not found
* There was a problem running osutil

# pycons3rt documentation

## Configuration

When installed, pycons3rt creates a system directory (`pycons3rt_system_home`) and
a local user directory (`pycons3rt_user_home`).

The `pycons3rt_system_home` directory is located on your system here:

* Linux: `/etc/pycons3rt`
* MacOS: `~/.pycons3rt`
* Windows: `C:\pycons3rt`

The `pycons3rt_user_home` directory is here on all OS types:

* `~/.pycons3rt`

The following assets are also created:

* System pycons3rt config dir: `pycons3rt_system_home/conf/`
* User log dir (default): `pycons3rt_user_home/log/`
* Pycons3rt source dir: `pycons3rt_user_home/src/`

The asset clones the pycons3rt source code here for installation:

* `pycons3rt_user_home/src/pycons3rt`

The logging configuration file is installed here:

* `pycons3rt_system_home/conf/pycons3rt-logging.conf`

By default, pycons3rt log files will output here:

* `pycons3rt_user_home/log/pycons3rt-info.log`
* `pycons3rt_user_home/log/pycons3rt-warn.log`
* `pycons3rt_user_home/log/pycons3rt-debug.log`

## Logify

With the default configuration log files go to: `~/.pycons3rt/log/`, and INFO
level is printed to stdout. To customize pycons3rt logging, modify the
`pycons3rt-logging.conf` file.

import logging
from pycons3rt.logify import Logify

mod_logger = Logify.get_name() + '.your_module'

# Then use in a function or class:

class MyClass(object):
def __init__(self, dep=None):
self.cls_logger = mod_logger + '.MyCLass'
def class_method(self):
log = logging.getLogger(self.cls_logger + '.class_method')'Class Method Logging')

def main():
log = logging.getLogger(mod_logger + '.main')


This module provides a set of useful utilities for accessing CONS3RT
deployment related info. It is intended to be imported and used in
other python-based CONS3RT assets.

from pycons3rt.deployment import Deployment

# Create a new Deployment object
dep = new Deployment()

# Deployment name

# Get the role name

# Deployment properties

# Get a specific deployment property value by name
my_value = dep.get_value('cons3rt.user')

# Scenario network info



This module provides an interface for posting anything to Slack!

from pycons3rt.slack import SlackMessage
from pycons3rt.slack import SlackAttachments

# Create a message
slack_msg = SlackMessage(
text='This is a Slack message',

# Create and add an attachment
slack_attachment = SlackAttachment(
fallback='This is the fallback text',
text='Moar text!')


# Send a message

## Nexus

This module provides simple method of fetching artifacts from a nexus

from pycons3rt import nexus


## Bash (Linux)

Executes commands on a Linux system. See the source code for specific available
commands but the most commonly used `run_command` is shown below.

### run_command(command, timeout_sec=3600.0, output=True)


* command: List containing the command and any additional args
* timeout_sec: (optional) Float specifying how long to wait before
terminating the command. Default is 3600.0.
* output: (boolean) True collects the output of the command. In some cases
supressing the command output improves stability.


* A dictionary containing "code", the numeric exit code from the command, and
"output" which captures the stdout/strerrif output was set `True`. Sample output:

Raises: `CommandError` when there is a problem running the command.

"code": "0",
"output": "stdout/stderr from the command"

Example Usage:

from pycons3rt.bash import run_command
from pycons3rt.bash import CommandError
command = ['ls', '/root']
result = run_command(command, timeout_sec=60.0)
code = result['code']
output = result['output']
except CommandError:
if code == 0:'Successfully executed command {c}'.format(s=command))
msg = 'There was a problem running command returned code {c} and produced output: {o}'.format(
c=code, o=output)
raise CommandError(msg)

## Alias IP (Linux)

Utility for setting IP address aliases in Linux.

## Cons3rtUtil

Utility for running CONS3RT CLI commands. Only useful for CONS3RT site
administrators with CLI access.

## OsUtil

Handles the initial pycons3rt configuration based on the detected OS type.

## PyGit

Utility for cloning a git repo from python.

## PyJavaKeys

Utility for importing Root Certificate Authority (CA) certificates into a
Java keystore.

## Windows

Basic Windows utlities like adding host file entries.

Project details

Download files

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

Files for pycons3rt, version 0.0.13
Filename, size File type Python version Upload date Hashes
Filename, size pycons3rt-0.0.13-py2-none-any.whl (86.3 kB) File type Wheel Python version py2 Upload date Hashes View
Filename, size pycons3rt-0.0.13.tar.gz (74.9 kB) File type Source Python version None Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring DigiCert DigiCert EV certificate Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page