Created
April 4, 2011 20:41
-
-
Save mpvvliet/902383 to your computer and use it in GitHub Desktop.
Deployit 1.3 CLI export sample
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
create Environment label="Test" description="" members="[Host1, Tomcat1]" | |
create Ear label="PetClinic-ear/1.0/PetClinic-1.0.ear" description="" location=/opt/deployit-1.3-beta-2-enterprise-edition/data/2.dat name=PetClinic | |
create Application label="PetClinic-ear" description="" | |
create DeploymentPackage label="PetClinic-ear/1.0" description="" application="PetClinic-ear" deployableArtifacts="[PetClinic-ear/1.0/PetClinic-1.0.ear]" middlewareResources="[]" version=1.0 | |
create Ear label="PetClinic-ear/2.0/PetClinic-2.0.ear" description="" location=/opt/deployit-1.3-beta-2-enterprise-edition/data/5.dat name=PetClinic | |
create DeploymentPackage label="PetClinic-ear/2.0" description="" application="PetClinic-ear" deployableArtifacts="[PetClinic-ear/2.0/PetClinic-2.0.ear]" middlewareResources="[]" version=2.0 | |
create Host label="Host1" description="" operatingsystemfamily=UNIX accessmethod=LOCAL address=localhost | |
create TomcatUnmanagedServer label="Tomcat1" description="" host="Host1" tomcathome=/tmp/tomcat ajpport=8009 baseurl=localhost startcommand=start.sh stopcommand=stop.sh |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
import sys | |
import re | |
def displaymatch(match): | |
if match is None: | |
return None | |
return '<Match: %r, groups=%r>' % (match.group(), match.groups()) | |
def parseParams(allparams): | |
result = {} | |
# Match a=b | a="b" | a="b\"c" | |
params = re.findall("([^\s=]*)=(\"(?:\\\\.|[^\"\\\\]+)*\"|[^\"\s]*)", allparams) | |
for param in params: | |
name = param[0] | |
value = param[1] | |
value = re.sub("\"(.*)\"", "\g<1>", value) | |
result[name] = value | |
return result | |
def renameParam(paramDict, oldname, newname): | |
if oldname in paramDict: | |
value = paramDict[oldname] | |
del paramDict[oldname] | |
paramDict[newname] = value | |
def generateId(typeInfo, paramDict): | |
instanceId = paramDict['name'] if 'name' in paramDict else paramDict['label'] | |
rootNodeName = typeInfo.rootNodeName | |
#print "rootNodeName: " + str(rootNodeName) | |
#print "typeInfo: " + str(typeInfo) | |
if rootNodeName != None: | |
return rootNodeName + "/" + instanceId | |
if type == "DeploymentPackage": | |
return "Applications/" + paramDict['label'] | |
return instanceId | |
def removeKey(paramDict, name): | |
if name in paramDict: | |
del paramDict[name] | |
def keyInTypeInfo(key, typeInfo): | |
return findPropertyByName(key, typeInfo) != None | |
def findPropertyByName(name, typeInfo, compare = lambda a,b: a.lower() == b.lower()): | |
for prop in typeInfo.propertyDescriptors: | |
if compare(name, prop.name): | |
return prop | |
return None | |
def mapParamDictToCIType(typeInfo, paramDict): | |
# Remove unknown properties | |
toRemove = set() | |
for key in paramDict.iterkeys(): | |
if not keyInTypeInfo(key, typeInfo): | |
toRemove.add(key) | |
for key in toRemove: | |
removeKey(paramDict, key) | |
# Fix parameter name case | |
toRename = {} | |
for key in paramDict.iterkeys(): | |
prop = findPropertyByName(key, typeInfo) | |
if prop != None and not findPropertyByName(key, typeInfo, lambda a,b: a == b): | |
toRename[key] = prop.name | |
for key in toRename.iterkeys(): | |
renameParam(paramDict, key, toRename[key]) | |
def createObject(type, typeInfo, allparams): | |
paramDict = parseParams(allparams) | |
#print "Creating object of type " + type + " with params " + str(paramDict) | |
id = generateId(typeInfo, paramDict) | |
# Map all keys in the paramDict to properties on the type | |
mapParamDictToCIType(typeInfo, paramDict) | |
print "ci = factory.configurationItem(\"" + type + "\", " + str(paramDict) + ")" | |
print "repository.create(\"" + id + "\", ci)" | |
print "" | |
def loadCITypes(allTypes): | |
allDescriptors = proxies.descriptors.list().entity.descriptors | |
for d in allDescriptors: | |
allTypes[d.simpleName] = d | |
# | |
# Main | |
# | |
# Sample invocation: bin/cli.sh -username admin -password admin -expose-proxies -source ~martin/tmp/convert.py > import-deployit-3.py | |
# | |
# Load all CI types from Deployit 3 | |
allTypes = {} | |
loadCITypes(allTypes) | |
#f = open('/tmp/deployit-1.3.txt', 'r') | |
f = open('/tmp/export-20110405.txt', 'r') | |
for line in f: | |
m = re.match(r"create (\w+) (.*)", line) | |
#print displaymatch(m) | |
if m: | |
type = m.group(1) | |
params = m.group(2) | |
if type in allTypes: | |
createObject(type, allTypes[type], params) | |
else: | |
print >> sys.stderr, "Type " + type + " unknown in Deployit 3, skipping." | |
f.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment