Skip to main content
# 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 https://github.com/cons3rt/pycons3rt
cd pycons3rt
python setup.py
~~~

### Install with CONS3RT assets

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

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

$ ./scripts/make-assets.sh

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

./build/asset-pycons3rt-linux.zip
./build/asset-pycons3rt-windows.zip

## Configuration

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

`pycons3rt_setup`

### 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')
log.info('Class Method Logging')

def main():
log = logging.getLogger(mod_logger + '.main')
log.debug('DEBUG')
log.info('INFO')
log.warn('WARN')
log.error('ERROR')
~~~

Deployment
---

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
print(dep.deployment_name)

# Get the role name
print(dep.cons3rt_role_name)

# Deployment properties
print(dep.properties)

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

# Scenario network info
print(dep.scenario_network_info)

# ASSET_DIR
print(dep.asset_dir)
~~~

Slack
---

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(
my_webhook_url,
channel='#DevOps',
icon_url='http://cool-icon-url',
text='This is a Slack message',
user='@sender_username')

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

slack_msg.add_attachment(slack_attachment)

# Send a message
slack_msg.send()
~~~

## Nexus

This module provides simple method of fetching artifacts from a nexus
repository.

~~~
from pycons3rt import nexus

nexus.get_artifact(
username=nexus_username,
password=nexus_password,
suppress_status=True,
nexus_url=nexus_url,
timeout_sec=45,
overwrite=False,
group_id='com.cons3rt',
artifact_id='cons3rt-backend-install',
version=`18.11.1`,
packaging='zip',
classifier='package-otto',
destination_dir=dest_dir)
~~~

## 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)

Parameters

* 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.

Returns:

* 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']
try:
result = run_command(command, timeout_sec=60.0)
code = result['code']
output = result['output']
except CommandError:
raise
if code == 0:
log.info('Successfully executed command {c}'.format(s=command))
else:
msg = 'There was a problem running command returned code {c} and produced output: {o}'.format(
c=code, o=output)
log.error(msg)
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.

Metadata

Release files for pycons3rt 0.0.13

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pycons3rt 0.0.13
File Size Uploaded Provenance Actions
pycons3rt-0.0.13.tar.gz 74.9 kB Without provenance Details for pycons3rt-0.0.13.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for pycons3rt 0.0.13
File Interpreter ABI Platform Actions
pycons3rt-0.0.13-py2-none-any.whl Python 2 none any Details for pycons3rt-0.0.13-py2-none-any.whl

Total release size: 161.3 kB

Release files / pycons3rt-0.0.13.tar.gz

Download URL pycons3rt-0.0.13.tar.gz
Size 74.9 kB
Tags Source
SHA-256 checksum
How to use checksums
978ed7b32c59e7ac9256d8e192e422ec9f063bb9108e7bc00f6779540fe86fee
BLAKE2b-256 checksum
How to use checksums
d571b84e926d94c949557bd9ef21124b1e52b55f77018388109d29b11abb2c7c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.11.0 pkginfo/1.4.2 requests/2.10.0 setuptools/40.8.0 requests-toolbelt/0.8.0 tqdm/4.23.4 CPython/2.7.15

Release files / pycons3rt-0.0.13-py2-none-any.whl

Download URL pycons3rt-0.0.13-py2-none-any.whl
Size 86.3 kB
Tags Python 2
SHA-256 checksum
How to use checksums
38f9ffea0522d6e510420bc48e5d8dff4c076dde3978d5f34be60047b8df609c
BLAKE2b-256 checksum
How to use checksums
590ded864fd3a0595e0aa15772147afec187ebff73caffa7967a7b5cd3b71016
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.11.0 pkginfo/1.4.2 requests/2.10.0 setuptools/40.8.0 requests-toolbelt/0.8.0 tqdm/4.23.4 CPython/2.7.15

Security for pycons3rt 0.0.13

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page