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

release 1.0.0 for approval workflow #55

Open
wants to merge 2 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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
3 changes: 3 additions & 0 deletions approval-workflow-for-launching-blueprint/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.vscode
venv
env.sh
67 changes: 67 additions & 0 deletions approval-workflow-for-launching-blueprint/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
-----------
Description
-----------

The blueprint will create 2 playbooks in Prism Central:

* One is for send notification to communication platform, such as Slack or Microsoft Teams
* Another one is accept the feedback from communication platform to decide to launch app or clean the environment.


-------------
How to use it
-------------

1. Prepare Microsoft Teams
++++++++++++++++++++++++++

* Create a public team from scratch, and skip add members.
* Add a connector to `General` channel (or create a dedicated channel first)
* Choose `incoming webhook` connector, click `Add`
* Input the connector name, then click `Create`
* Copy the url like following, then click `Done`

* `https://outlook.office.com/webhook/80b91334-601a-4d2e-aa59-36fbc15bc09e@bb047546-786f-4de1-bd75-24e5b6f79043/IncomingWebhook/18ac0e3f1df2475da0ef744cf3e5204b/2591ac3b-a500-441b-b9c8-079006eb9020`

* (option) you could create playbook with this url and `MS Teams` action in xplay.

2. Prepare ticket system
++++++++++++++++++++++++

git clone and go into this folder and execute following commands

- Change variable: PC_IP to your prism central IP address
- Remeber to change `admin:password` to your really username and password to connect prism central
- ensure your vpn connection established and you could access prism central form localhost

.. code-block::

virtualenv -p python3 venv
source venv/bin/activate
pip install -r requirements.txt
PC_IP=<x.x.x.x> PC_PORT=9440 PC_TOKEN=$(echo -e 'admin:<password>\c' |base64) python single-page.py

3. Import blueprint and launch it
+++++++++++++++++++++++++++++++++

* Upload the `pre_approve_flow` blueprint to you project.

* put the URL (mentioned in step 1) in variable: `msteams_url`
* change the variable: `pc_ip` to your prism central IP address
* change the **password** in variable: `blueprint_name`
* In Credentials, set the password for `null` user

* prepare another blueprint, it should be the really blueprint you want to launch. For example the LAMP blueprint, and ensure it is launchable.

* Launch `pre_approve_flow` blueprint and select really blueprint you want to launch.

* Enjoy it

---------
Changelog
---------

- 2020.12 - 1st release
- 2021.01 - add README.rst


Large diffs are not rendered by default.

11 changes: 11 additions & 0 deletions approval-workflow-for-launching-blueprint/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
certifi==2020.12.5
chardet==4.0.0
click==7.1.2
Flask==1.1.2
idna==2.10
itsdangerous==1.1.0
Jinja2==2.11.2
MarkupSafe==1.1.1
requests==2.25.1
urllib3==1.26.2
Werkzeug==1.0.1
75 changes: 75 additions & 0 deletions approval-workflow-for-launching-blueprint/single-page.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
#! /usr/bin/env python
# server.py
from flask import Flask, render_template, request, session, redirect, url_for, redirect, make_response
import re, sys, os
import json
import requests
import urllib3
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)

app = Flask(__name__, static_folder="./static", template_folder="./templates")
#same url and url with trailing slash
app.url_map.strict_slashes = False
app.secret_key = 'nutanix'

@app.route("/<mystring>")
def string(mystring):
url = "https://%s:%s/api/nutanix/v3/action_rules/trigger" % (app.config.get("pc_ip"), app.config.get("pc_port"))

headers = {
"Content-Type": "application/json",
"Accept": "application/json",
"Authorization": "Basic %s" % app.config.get("pc_token"),
"Cache-Control": "no-cache"
}

# change url string to json
content = re.sub("%7B", "{", mystring)
content = re.sub("%7D", "}", content)
content = re.sub("%5B", "[", content)
content = re.sub("%5D", "]", content)
content = re.sub("%3A", ":", content)
content = re.sub("%22", "\"", content)
content = re.sub("%20", " ", content)
content = re.sub("%2C", ",", content)
content = re.sub("%3B", ";", content)
content = re.sub("%40", "%", content)
content = re.sub("~" , "/", content)

#payload = json.loads(content)
#print(json.dumps(payload, indent=2))
r = requests.post(url, headers=headers, verify=False, data=content)
if r.ok:
return render_template(
"single-page.html",
hostname=os.uname()[1],
title='Workflow',
content=r.text
)
else:
return render_template(
"single-page.html",
hostname=os.uname()[1],
title='Workflow',
content=r.text
)

if __name__ == "__main__":

pc_ip = ""
pc_port = ""
pc_token = ""
if pc_ip == "" or pc_port == "" or pc_token == "":
pc_ip = os.getenv("PC_IP", "")
pc_port = os.getenv("PC_PORT", "")
pc_token = os.getenv("PC_TOKEN", "")
if pc_ip == "" or pc_port == "" or pc_token == "":
print("No PC Environment Variable")
sys.exit(9)

app.debug = True
app.config["pc_ip"] = pc_ip
app.config["pc_port"] = pc_port
app.config["pc_token"] = pc_token
app.run(host='0.0.0.0', port='5000')

Loading