From 5bbce4783a2406267315d681c158bd6a67296a04 Mon Sep 17 00:00:00 2001 From: Jerome Petazzoni Date: Tue, 3 Sep 2019 06:51:15 -0500 Subject: [PATCH] Better modularize card generation Most parameters used by the Jinja template for the cards can now be specified in settings.yaml. This should make the generation of cards for admin training much easier. --- prepare-vms/README.md | 51 +++++++++++++--------- prepare-vms/lib/ips-txt-to-html.py | 26 +++++------ prepare-vms/settings/admin-dmuc.yaml | 2 + prepare-vms/settings/admin-kubenet.yaml | 3 ++ prepare-vms/settings/admin-kuberouter.yaml | 3 ++ prepare-vms/settings/admin-test.yaml | 2 + prepare-vms/settings/jerome.yaml | 1 - prepare-vms/templates/cards.html | 31 +++++++++---- 8 files changed, 76 insertions(+), 43 deletions(-) diff --git a/prepare-vms/README.md b/prepare-vms/README.md index f325946b..c86c4c81 100644 --- a/prepare-vms/README.md +++ b/prepare-vms/README.md @@ -87,26 +87,37 @@ You're all set! ``` workshopctl - the orchestration workshop swiss army knife Commands: -ami Show the AMI that will be used for deployment -amis List Ubuntu AMIs in the current region -build Build the Docker image to run this program in a container -cards Generate ready-to-print cards for a group of VMs -deploy Install Docker on a bunch of running VMs -ec2quotas Check our EC2 quotas (max instances) -help Show available commands -ids List the instance IDs belonging to a given tag or token -ips List the IP addresses of the VMs for a given tag or token -kube Setup kubernetes clusters with kubeadm (must be run AFTER deploy) -kubetest Check that all notes are reporting as Ready -list List available groups in the current region -opensg Open the default security group to ALL ingress traffic -pull_images Pre-pull a bunch of Docker images -retag Apply a new tag to a group of VMs -start Start a group of VMs -status List instance status for a given group -stop Stop (terminate, shutdown, kill, remove, destroy...) instances -test Run tests (pre-flight checks) on a group of VMs -wrap Run this program in a container +build Build the Docker image to run this program in a container +cards Generate ready-to-print cards for a group of VMs +deploy Install Docker on a bunch of running VMs +disableaddrchecks Disable source/destination IP address checks +disabledocker Stop Docker Engine and don't restart it automatically +helmprom Install Helm and Prometheus +help Show available commands +ids (FIXME) List the instance IDs belonging to a given tag or token +kubebins Install Kubernetes and CNI binaries but don't start anything +kubereset Wipe out Kubernetes configuration on all nodes +kube Setup kubernetes clusters with kubeadm (must be run AFTER deploy) +kubetest Check that all nodes are reporting as Ready +listall List VMs running on all configured infrastructures +list List available groups for a given infrastructure +netfix Disable GRO and run a pinger job on the VMs +opensg Open the default security group to ALL ingress traffic +ping Ping VMs in a given tag, to check that they have network access +pssh Run an arbitrary command on all nodes +pull_images Pre-pull a bunch of Docker images +quotas Check our infrastructure quotas (max instances) +remap_nodeports Remap NodePort range to 10000-10999 +retag (FIXME) Apply a new tag to a group of VMs +ssh Open an SSH session to the first node of a tag +start Start a group of VMs +stop Stop (terminate, shutdown, kill, remove, destroy...) instances +tags List groups of VMs known locally +test Run tests (pre-flight checks) on a group of VMs +weavetest Check that weave seems properly setup +webssh Install a WEB SSH server on the machines (port 1080) +wrap Run this program in a container +www Run a web server to access card HTML and PDF ``` ### Summary of What `./workshopctl` Does For You diff --git a/prepare-vms/lib/ips-txt-to-html.py b/prepare-vms/lib/ips-txt-to-html.py index 5bc1873c..6f0891cc 100755 --- a/prepare-vms/lib/ips-txt-to-html.py +++ b/prepare-vms/lib/ips-txt-to-html.py @@ -4,17 +4,12 @@ import sys import yaml import jinja2 -def prettify(l): - l = [ip.strip() for ip in l] - ret = [ "node{}: {}".format(i+1, s) for (i, s) in zip(range(len(l)), l) ] - return ret # Read settings from user-provided settings file -SETTINGS = yaml.load(open(sys.argv[1])) - -clustersize = SETTINGS["clustersize"] +context = yaml.safe_load(open(sys.argv[1])) ips = list(open("ips.txt")) +clustersize = context["clustersize"] print("---------------------------------------------") print(" Number of IPs: {}".format(len(ips))) @@ -30,7 +25,9 @@ while ips: ips = ips[clustersize:] clusters.append(cluster) -template_file_name = SETTINGS["cards_template"] +context["clusters"] = clusters + +template_file_name = context["cards_template"] template_file_path = os.path.join( os.path.dirname(__file__), "..", @@ -39,18 +36,19 @@ template_file_path = os.path.join( ) template = jinja2.Template(open(template_file_path).read()) with open("ips.html", "w") as f: - f.write(template.render(clusters=clusters, **SETTINGS)) + f.write(template.render(**context)) print("Generated ips.html") + try: import pdfkit with open("ips.html") as f: pdfkit.from_file(f, "ips.pdf", options={ - "page-size": SETTINGS["paper_size"], - "margin-top": SETTINGS["paper_margin"], - "margin-bottom": SETTINGS["paper_margin"], - "margin-left": SETTINGS["paper_margin"], - "margin-right": SETTINGS["paper_margin"], + "page-size": context["paper_size"], + "margin-top": context["paper_margin"], + "margin-bottom": context["paper_margin"], + "margin-left": context["paper_margin"], + "margin-right": context["paper_margin"], }) print("Generated ips.pdf") except ImportError: diff --git a/prepare-vms/settings/admin-dmuc.yaml b/prepare-vms/settings/admin-dmuc.yaml index d4587009..6ac252c0 100644 --- a/prepare-vms/settings/admin-dmuc.yaml +++ b/prepare-vms/settings/admin-dmuc.yaml @@ -26,3 +26,5 @@ machine_version: 0.14.0 # Password used to connect with the "docker user" docker_user_password: training + +image: diff --git a/prepare-vms/settings/admin-kubenet.yaml b/prepare-vms/settings/admin-kubenet.yaml index b18cb5de..e283b10e 100644 --- a/prepare-vms/settings/admin-kubenet.yaml +++ b/prepare-vms/settings/admin-kubenet.yaml @@ -26,3 +26,6 @@ machine_version: 0.14.0 # Password used to connect with the "docker user" docker_user_password: training + +clusternumber: 100 +image: diff --git a/prepare-vms/settings/admin-kuberouter.yaml b/prepare-vms/settings/admin-kuberouter.yaml index 97f5283d..9e6c4133 100644 --- a/prepare-vms/settings/admin-kuberouter.yaml +++ b/prepare-vms/settings/admin-kuberouter.yaml @@ -26,3 +26,6 @@ machine_version: 0.14.0 # Password used to connect with the "docker user" docker_user_password: training + +clusternumber: 200 +image: diff --git a/prepare-vms/settings/admin-test.yaml b/prepare-vms/settings/admin-test.yaml index 7390a51c..691b60f8 100644 --- a/prepare-vms/settings/admin-test.yaml +++ b/prepare-vms/settings/admin-test.yaml @@ -26,3 +26,5 @@ machine_version: 0.14.0 # Password used to connect with the "docker user" docker_user_password: training + +image: diff --git a/prepare-vms/settings/jerome.yaml b/prepare-vms/settings/jerome.yaml index a618cc5a..4f68a3e4 100644 --- a/prepare-vms/settings/jerome.yaml +++ b/prepare-vms/settings/jerome.yaml @@ -26,4 +26,3 @@ machine_version: 0.14.0 # Password used to connect with the "docker user" docker_user_password: training - diff --git a/prepare-vms/templates/cards.html b/prepare-vms/templates/cards.html index 1f58b8f6..7a30cd41 100644 --- a/prepare-vms/templates/cards.html +++ b/prepare-vms/templates/cards.html @@ -1,12 +1,23 @@ -{# Feel free to customize or override anything in there! #} +{# + The variables below can be customized here directly, or in your + settings.yaml file. Any variable in settings.yaml will be exposed + in here as well. +#} -{%- set url = "http://FIXME.container.training/" -%} -{%- set pagesize = 9 -%} -{%- set lang = "en" -%} -{%- set event = "training session" -%} -{%- set backside = False -%} -{%- set image = "kube" -%} -{%- set clusternumber = 100 -%} +{%- set url = url + | default("http://FIXME.container.training/") -%} +{%- set pagesize = pagesize + | default(9) -%} +{%- set lang = lang + | default("en") -%} +{%- set event = event + | default("training session") -%} +{%- set backside = backside + | default(False) -%} +{%- set image = image + | default("kube") -%} +{%- set clusternumber = clusternumber + | default(None) -%} {%- set image_src = { "docker": "https://s3-us-west-2.amazonaws.com/www.breadware.com/integrations/docker.png", @@ -161,7 +172,9 @@ img.kube {

{{ intro }}

+ {% if image_src %} + {% endif %} {% if clusternumber != None %} @@ -187,8 +200,10 @@ img.kube {

+ {% if url %} {{ slides_are_at }}

{{ url }}
+ {% endif %}

{% if loop.index%pagesize==0 or loop.last %}
cluster: