Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Docker image #8

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -122,3 +122,5 @@ dmypy.json

# Pyre type checker
.pyre/

.idea/
41 changes: 41 additions & 0 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
FROM ubuntu:18.04
MAINTAINER Dax Mickelson (dmickels@cisco.com)

# Configure Script and GIT variables
ENV WORK_DIR /usr/src/app
WORKDIR $WORK_DIR
ENV PYTHON_SCRIPT bootstrap.py

# Running APT UPDATE
RUN apt-get -y update

# Install APT-UTILS
RUN apt-get install -y apt-utils

# Running APT DIST-UPGRADE
RUN apt-get -y dist-upgrade

# Running APT AUTOREMOVE
RUN apt-get -y autoremove

# Running APT AUTOCLEAN
RUN apt-get -y autoclean

# Install Python modules
RUN apt-get -y install python3 python3-pip

# Install git
RUN apt-get install -y git

# Install Python modules needed for this script.
COPY requirements.txt $WORK_DIR
RUN python3 -m pip install --no-cache-dir -r $WORK_DIR/requirements.txt

# Provide some examples in case the user doesn't mount their own script dir.
COPY example_scripts/ $WORK_DIR/example_scripts

# Copy over bootstrap file
COPY $PYTHON_SCRIPT $WORK_DIR

# Run script.
CMD python3 $WORK_DIR/$PYTHON_SCRIPT
41 changes: 41 additions & 0 deletions docker/bootstrap.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
"""List any possible scripts to run otherwise exit(0)"""
import os

# Where are the scripts residing? (Should be /usr/src/app/scripts that is mounted at Docker run.)
script_dir = "/usr/src/app/scripts"
if not os.path.isdir(script_dir):
script_dir = os.path.join(os.getcwd(), "example_scripts")
files_in_dir = os.listdir(script_dir)

list_of_scripts = []
# Ensure that we only show the python files. (Those ending in .py)
# Exclude any files that start with "__". This way you can have local "helper" scripts to import.
for file in files_in_dir:
if file[-3:] == ".py" and "__" not in file:
list_of_scripts.append(file)

# Sort list alphabetically by filename.
list_of_scripts.sort()
if list_of_scripts:
# Display a menu
print("")
print("Select which Python script to run:")
for counter, file in enumerate(list_of_scripts):
print(f'\t{counter}: {file}')
qty_of_scripts = len(list_of_scripts)
try:
choice = int(input(f'Select 0-{qty_of_scripts - 1}: '))
if 0 <= choice < qty_of_scripts - 1:
# A valid choice has been made.
os.chdir(script_dir)
os.system(
"/usr/bin/python3 {}".format(
os.path.join(script_dir, list_of_scripts[choice].replace(" ", "\ "))
)
)
else:
print("Inputted value out of range.")
except ValueError:
print("Inputted value out of range.")
else:
print(f"There were no Python scripts in {script_dir}.")
40 changes: 40 additions & 0 deletions docker/example_scripts/dnacentersdk_example.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
"""Testing the use of dnacentersdk Python package."""
from dnacentersdk import DNACenterAPI
import requests
from requests.packages.urllib3.exceptions import InsecureRequestWarning

# Disable annoying HTTP warnings
requests.packages.urllib3.disable_warnings(InsecureRequestWarning)

which_dnac = "devnet"
devnet = {
"debug": False,
"username": "devnetuser",
"password": "Cisco123!",
"base_url": "https://sandboxdnac2.cisco.com:443",
"public_cert": False,
}
if which_dnac == "devnet":
api = DNACenterAPI(
username=devnet["username"],
password=devnet["password"],
base_url=devnet["base_url"],
verify=devnet["public_cert"],
debug=devnet["debug"],
)
else:
print("No DNA Center connection information provided. Exiting.")
exit(0)

results = {}

# print(api.devices.get_device_list()) # Permissions issue

results["workflows"] = api.pnp.get_workflows()
'''
results["client_health"] = api.clients.get_overall_client_health()
results["sites"] = api.sites.get_site()
results["all_device_configs"] = api.devices.get_device_config_for_all_devices()
'''

print(results)
1 change: 1 addition & 0 deletions docker/example_scripts/hello_world.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
print("Hello World")
1 change: 1 addition & 0 deletions docker/example_scripts/hello_world_reply.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
print("Well, hello right back at you!")
2 changes: 2 additions & 0 deletions docker/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
dnacentersdk
requests