Skip to content

Commit

Permalink
Merge pull request #20 from cidrblock/update_p3
Browse files Browse the repository at this point in the history
Update to py3
  • Loading branch information
cidrblock authored Aug 19, 2020
2 parents 2eff5d4 + a524c61 commit 54f9928
Show file tree
Hide file tree
Showing 12 changed files with 51 additions and 48 deletions.
4 changes: 2 additions & 2 deletions Dockerfile → Containerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM python:2.7.14-alpine3.6
FROM python:3.8.5-alpine3.12

# Update the packages
RUN apk update
Expand All @@ -8,7 +8,7 @@ RUN apk add gcc libffi-dev musl-dev openssl-dev sshpass make
# RUN apk add py-crypto python-dev

# Install td4a
RUN pip install td4a==1.7
RUN pip install td4a==2.0.3

# Clear out extras
RUN rm -rf /var/cache/apk/*
Expand Down
41 changes: 21 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,16 @@ https://td4a.codethenetwork.com

TD4A is a visual design aid for building and testing jinja2 templates. It will combine data in yaml format with a jinja2 template and render the output.

All jinja2 filters are supported along with the filter plugins from Ansible version 2.4.1.0.
All jinja2 filters are supported along with the filter plugins from Ansible version 2.9.12

### Installation:

#### using docker:

##### using podman (or docker):
```
docker pull cidrblock/td4a
podman pull cidrblock/td4a
```

The docker hub page can be found here:
The container registry page can be found here:

https://hub.docker.com/r/cidrblock/td4a/

Expand All @@ -39,9 +38,9 @@ https://pypi.python.org/pypi/td4a

#### Simple

##### using docker:
##### using podman (or docker):
```
docker run -p 5000:5000 cidrblock/td4a
podman run -p 5000:5000 cidrblock/td4a
```

##### using the cli:
Expand All @@ -61,10 +60,9 @@ TD4A support two different modes of operation.

#### Enabling a mode

##### using docker:

##### using podman (or docker):
```
docker run -p 5000:5000 \
podman run -p 5000:5000 \
-it \
cidrblock/td4a \
td4a-server -m mode
Expand All @@ -81,13 +79,14 @@ where `mode` is either jinja2 (default) or schema

#### Loading custom filter plugins (jinja2 mode only)

##### using docker:

TD4A supports custom filter plugins within the container. Pass your custom filter_plugins directory as a volume and use the -f option to specify to custom filter plugin directory.

##### using podman (or docker):
```
docker run -p 5000:5000 \
podman run -p 5000:5000 \
-it \
-v `pwd`/my_filter_plugins:/filter_plugins
-v `pwd`/my_filter_plugins:/filter_plugins \
cidrblock/td4a \
td4a-server -f /filter_plugins
```
Expand All @@ -101,11 +100,13 @@ td4a-server -f ./my_filter_plugins

#### Loading an ansible inventory (jinja2 and schema mode)

##### using docker:

Mount the inventory as `/inventory` in the container, and run TD4A with the `-i` option.


##### using podman (or docker):

```
docker run -p 5000:5000 \
podman run -p 5000:5000 \
-it \
-v '/Users/me/github/ansible_network_inventory:/inventory' \
cidrblock/td4a \
Expand All @@ -114,7 +115,7 @@ docker run -p 5000:5000 \

If environment variables are needed for a dynamic inventory, they can be passed to the docker container.
```
docker run -p 5000:5000 \
podman run -p 5000:5000 \
-it \
-v `pwd`/my_filter_plugins:/filter_plugins \
-v '/Users/me/github/ansible_network_inventory:/inventory' \
Expand Down Expand Up @@ -142,10 +143,10 @@ The CouchDB needs to previously created.

To enable link support, and add the link button to the UI, set the following environ variables:

##### using docker:
##### using podman (or docker):

```
docker run -p 5000:5000 \
podman run -p 5000:5000 \
-v `pwd`/my_filter_plugins:/filter_plugins \
-e "COUCH_USERNAME=admin" \
-e "COUCH_PASSWORD=password" \
Expand Down Expand Up @@ -182,7 +183,7 @@ The UI is broken into three sections:

### Python version

To date, this has only been tested with python 2.7.
To date, this has only been tested with python 3.8.5.

### Development

Expand Down
2 changes: 2 additions & 0 deletions gcp/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
FROM cidrblock/td4a:2.0.3
EXPOSE 5000
2 changes: 0 additions & 2 deletions now/Dockerfile

This file was deleted.

16 changes: 8 additions & 8 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
ansible==2.4.1.0
Flask==0.12.2
netaddr==0.7.19
Twisted==17.9.0
requests==2.18.4
ruamel.yaml==0.15.35
genson==0.2.3
jsonschema==2.6.0
ansible==2.9.12
Flask==1.1.2
netaddr==0.8.0
Twisted==20.3.0
requests==2.24.0
ruamel.yaml==0.16.10
genson==1.2.1
jsonschema==3.2.0
16 changes: 9 additions & 7 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from setuptools import setup

setup(name='td4a',
version='1.7',
version='2.0.3',
description='A browser based jinja template renderer',
url='http://github.com/cidrblock/td4a',
author='Bradley A. Thornton',
Expand All @@ -13,11 +13,13 @@
],
scripts=['td4a-server'],
install_requires=[
'ansible==2.4.1.0',
'Flask==0.12.2',
'netaddr==0.7.19',
'Twisted==17.9.0',
'requests==2.18.4',
'ruamel.yaml==0.15.35'
'ansible==2.9.12',
'Flask==1.1.2',
'netaddr==0.8.0',
'Twisted==20.3.0',
'requests==2.24.0',
'ruamel.yaml==0.16.10',
'genson==1.2.1',
'jsonschema==3.2.0'
],
zip_safe=False)
4 changes: 2 additions & 2 deletions td4a-server
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def parse_args():
return args

def main():
print "Loading..."
print("Loading...")
app.args = parse_args()
app.filters = filters_load(app.args.custom_filters)
if app.args.inventory_source:
Expand All @@ -51,7 +51,7 @@ def main():
reactor_args['installSignalHandlers'] = 0
import werkzeug.serving
wsgi = werkzeug.serving.run_with_reloader(wsgi)
print "Ready."
print("Ready.")
wsgi()

if __name__ == '__main__':
Expand Down
4 changes: 2 additions & 2 deletions td4a/controllers/render.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,9 @@ def rest_render():
""" render path
"""
try:
print "Checking and parsing data..."
print("Checking and parsing data...")
response = render(payload=request.json, filters=app.filters, typ="page")
print "Done."
print("Done.")
return jsonify(response)
except HandledException as error:
return jsonify(error.json())
2 changes: 1 addition & 1 deletion td4a/controllers/validate.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def validation(payload):
if errors:
return {"p3": yaml.dump({"messages":errors})}
return {"p3": yaml.dump({"messages":["validation passed"]})}
except UnknownType, error:
except UnknownType as error:
error_message = str(error)
lines = error_message.splitlines()
message = [x for x in lines if x.startswith('Unknown type')]
Expand Down
4 changes: 2 additions & 2 deletions td4a/models/exception_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def __init__(self, function):
def __call__(self, *args, **kwargs):
try:
return self.function(*args, **kwargs)
except Exception, error:
except Exception as error:
self.error = error
self.exc_type, self.exc_value, self.exc_traceback = sys.exc_info()
self.tback = traceback.extract_tb(self.exc_traceback)
Expand Down Expand Up @@ -115,7 +115,7 @@ def type_error(self):
line_number=line_number)

def unhandled(self):
print self.exc_type, self.exc_value, self.exc_traceback, self.tback, self.error
print(self.exc_type, self.exc_value, self.exc_traceback, self.tback, self.error)
line_numbers = [x for x in self.tback if re.search('^<.*>$', x[0])]
if line_numbers:
line_number = line_numbers[0][1]
Expand Down
2 changes: 1 addition & 1 deletion td4a/models/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def load_dir(directory):
for entry in os.listdir(directory):
if entry != '__init__.py' and entry.split('.')[-1] == 'py':
filters = importlib.import_module(entry[:-3]).FilterModule().filters()
for key, value in filters.iteritems():
for key, value in filters.items():
filter_list.append((key, value))
return filter_list

Expand Down
2 changes: 1 addition & 1 deletion td4a/static/template.j2
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{% for key, value in interfaces.iteritems() %}
{% for key, value in interfaces.items() %}
{% if value['name'].startswith('Ethernet') %}
- parents:
- interface {{ value['name'] }}
Expand Down

0 comments on commit 54f9928

Please sign in to comment.