diff options
author | Teemu Suo-Anttila <teemusa@vaadin.com> | 2015-06-12 11:23:39 +0300 |
---|---|---|
committer | Vaadin Code Review <review@vaadin.com> | 2015-07-07 10:10:46 +0000 |
commit | 771da038480192a2d49a3672a33850ec3f8e3269 (patch) | |
tree | ba6fd711656e343e416771dfe9534f75b031335a /scripts/DeployHelpers.py | |
parent | 73d4e770751a3d78f9f177c82b2aa8c7281ec77f (diff) | |
download | vaadin-framework-771da038480192a2d49a3672a33850ec3f8e3269.tar.gz vaadin-framework-771da038480192a2d49a3672a33850ec3f8e3269.zip |
Add DeployHelpers python module for adding wildfly auto deployment
Change-Id: I1b3570a96d8406aa502171eb8065f1359d458450
Diffstat (limited to 'scripts/DeployHelpers.py')
-rw-r--r-- | scripts/DeployHelpers.py | 79 |
1 files changed, 79 insertions, 0 deletions
diff --git a/scripts/DeployHelpers.py b/scripts/DeployHelpers.py new file mode 100644 index 0000000000..c12c38d293 --- /dev/null +++ b/scripts/DeployHelpers.py @@ -0,0 +1,79 @@ +#coding=UTF-8 + +### Helper class for wildfly deployments. ### +# Related files $HOME/.deploy-url $HOME/.deploy-credentials + +import sys, json +try: + import requests +except Exception as e: + print("DeployHelpers depends on requests library. Install it with `pip install requests`") + sys.exit(1) +from requests.auth import HTTPDigestAuth +from os.path import join, expanduser, basename + +# .deploy-url in home folder +deployUrlFile = join(expanduser("~"), ".deploy-url") + +# .deploy-credentials in home folder +deployCredFile = join(expanduser("~"), ".deploy-credentials") + +# Helper for handling the full deployment +# name should end with .war +def deployWar(warFile, name=None): + if name is None: + name = basename(warFile) + + print("Deploying to context %s" % (name[:-4])) + # Undeploy/Remove old version if needed + if deploymentExists(name): + removeDeployment(name) + # Do upload war file + hash = doUploadWarFile(warFile) + # Do deployment under name + doDeploy(hash, name) + +def deploymentExists(name): + # Deployment existence check data + data = {"operation" : "read-attribute", "name": "runtime-name", "address": [{"deployment" : name}]} + result = doPostJson(url=getUrl(), auth=getAuth(), data=json.dumps(data)) + return result.json()["outcome"] == "success" + +def doDeploy(hash, name): + # Deployment data + data = {} + data["content"] = [{"hash" : hash}] + data["address"] = [{"deployment" : name}] + data["operation"] = "add" + data["enabled"] = True + return doPostJson(data=json.dumps(data), auth=getAuth(), url=getUrl()) + +# Helper for adding Content-Type to headers +def doPostJson(**kwargs): + return requests.post(headers={"Content-Type" : "application/json"}, **kwargs) + +def doUploadWarFile(warFile): + # Upload request, just see the outcome + result = requests.post("%s/add-content" % (getUrl()), files={"file" : open(warFile, 'rb')}, auth=getAuth()).json() + if "outcome" not in result or result["outcome"] != "success": + raise Exception("File upload failed.", result) + return result["result"] + +# Method for removing an existing deployment +def removeDeployment(name): + data = {} + data["address"] = [{"deployment" : name}] + for i in ["undeploy", "remove"]: + print("%s old deployment of %s" % (i, name)) + data["operation"] = i + doPostJson(data=json.dumps(data), auth=getAuth(), url=getUrl()) + +# Read credentials file and return a HTTPDigestAuth object +def getAuth(): + (deployUser, deployPass) = open(deployCredFile).read().strip().split(",") + return HTTPDigestAuth(deployUser, deployPass) + +# Read the deploy url file and return the url +def getUrl(): + return open(deployUrlFile).read().strip() + |