def Test(): "Private: Unit test" sgs = deployAppTgz("exapp.tgz") print sgs s = aspAmf.Session() s.Startup(sgs)
def extendSg(sg, nodes, basename=None, index=None, amfSession=None): """Extend a SG by adding SUs with all the components defined in the SG @param sg Service group name (string) or entity (aspAmfEntity.ServiceGroup) to extend @param nodes A list of strings or entities (aspAmfEntity.Node) onto which you want to extend the SG @param basename (optional) The name prefix for the new SUs & other created entities. If None, the SG's basename will be used @param index (optional) What number to start the SU name with (eg N in: mySUiN). If None, the number of current SUs will be used @param amfSession (optional) aspAmf.Session object used to install the new work into the AMF -- if not passed a temporary session will be created @returns (newEntities,modifiedEntities) a tuple of 2 lists containing the new and modified entities """ # Translate the incoming variables into a canonical format if type(sg) in StringTypes: sg = ci.entities[sg] if type(nodes) is not ListType: nodes = [nodes] nl = [] for n in nodes: if type(n) in StringTypes: nl.append(ci.entities[n]) else: nl.append(n) nodes = nl csiTypes = calcCompToCsiType(sg) appCfg = sg.appVer.cfg.values( )[0] # GAS TODO: Right now, just picking the first defined application in the bundle comps = appCfg.programNames.values() # Note: We do not verify that a new SU is not created on the same node as an existing one... should we do so? if index is None: index = len(flatten([x.comp for x in sg.su])) if basename is None: basename = sg.name[0:sg.name.find("SG")] (newEntities, modifiedEntities, appInstLut) = CreateServiceUnits(sg, nodes, comps, appCfg, basename, csiTypes, index) # Always extend by adding actives # GAS TODO: Add the same logic in Create to recalculate the best values for these fields. sg.activeServiceUnits = sg.cconfig.numPrefActiveSUs + len(nodes) sg.instantiatedServiceUnits = sg.cconfig.numPrefInserviceSUs + len(nodes) # Create all the new SUs et al. if not amfSession: amfSession = aspAmf.Session() amfSession.InstallApp(newEntities, modifiedEntities) ci.load() return (newEntities, modifiedEntities)
def installModel(appname, appver, entities, amfSession=None): notes = [] errors = [] # Commit these entities into the AMF if amfSession is None: amfSession = aspAmf.Session() #log.debug("Entities: %s" % entities) for e in entities: log.debug("%s" % e.name) try: amfSession.InstallApp(entities) except aspAmf.AmfError, e: notes.append( T("Error committing the configuration. Application may be partially deployed: $err", err=str(e)))
def updateSgCfg(sg, cfgDict, amfSession=None): """Modify the SG's configuration by the values in cfgDict @param sg Service group name (string) or entity (aspAmfEntity.ServiceGroup) to modify @param cfgDict A Dot() object or other entity with SG configuration parameters expressed as member variables. The SG configuration parameters are exactly as written in ClAmsSGConfigT C structure located in clAmsEntities.h @param amfSession (optional) aspAmf.Session object used to install the new work into the AMF -- if not passed a temporary session will be created @returns Nothing """ # Translate the incoming variables into a canonical format if type(sg) in StringTypes: sg = ci.entities[sg] print "CFGDICT: ", str(cfgDict) Modifiers2Sg(cfgDict, sg) Log("Modified SG: %s" % str(sg.__dict__)) if not amfSession: amfSession = aspAmf.Session() amfSession.InstallSgConfig(sg)
def addWork(sg, workName, kvdict, amfSession=None): """Extend a SG by adding SUs with all the components defined in the SG @param sg Service group name (string) or entity (aspAmfEntity.ServiceGroup) to add the SI to @param workName Name of the work (SAF SI) to be created @param kvdict Dictionary of name/value pairs to put in all of the CSIs @param amfSession (optional) aspAmf.Session object used to install the new work into the AMF -- if not passed a temporary session will be created @returns (newEntities,modifiedEntities) a tuple of 2 lists containing the new and modified entities """ # Translate the incoming variables into a canonical format if type(sg) in StringTypes: sg = ci.entities[sg] (newEntities, modifiedEntities) = CreateServiceInstance(sg, workName, kvdict) if not amfSession: amfSession = aspAmf.Session() amfSession.InstallApp(newEntities, modifiedEntities) ci.load() return (newEntities, modifiedEntities)
# Boilerplate ASP setup code # Connect to ASP *MUST BE DONE FIRST* import amfpy amfpy.initializeAmf() # Import Python ASP class layers import clusterinfo import aspApp import aspAmf import upgrade import appdeploy # Hook into the various services ci = clusterinfo.ci # The clusterinfo.ci objects reflect the entire state of the cluster amf = aspAmf.Session( ) # The aspAmf.Session class lets you modify the cluster state appDb = aspApp.AppDb(os.getenv("ASP_DIR", "/tmp") + "/apps") # application database umgr = upgrade.UpgradeMgr() # Upgrade manager ci.setAppDb(appDb) # connect clusterinfo to application versions # Optional add some application bundles if 0: appDb.NewAppFile( "/code/vipapp1.4.0.0.tgz" ) # Of course these would need to be changed to valid locations in your system appDb.NewAppFile("/code/vipapp1.4.0.1.tgz") # Refresh the clusterinfo database periodically.
def clone(sgName, newName, index, numClones=1, _nodeList=None): created = [] modified = [] xlat = {} # Conversion from the old to the new objects idx = 0 if 1: # try: error = [] ci = clusterinfo.ci # The clusterinfo.ci objects reflect the entire state of the cluster ci.load() amf = aspAmf.Session( ) # The aspAmf.Session class lets you modify the cluster state namesTaken = NameMgr(ci.d.entities.keys()) try: osg = ci.sgs[sgName] except KeyError: error.append("SG %s does not exist" % sgName) raise if _nodeList: # Convert an integer (slot number) or string (node name) to the node object nodeList = [] for n in _nodeList: if type(n) in StringTypes or type(n) is IntType: nodeList.append(ci.nodes[n]) else: nodeList.append(n) if len(osg.su) != len(nodeList): error.append("Number of deployment nodes != number of SUs" % sgName) raise else: # Deploy onto the same nodes nodeList = [None] * len(osg.su) # Try to split the name based on our standard nomenclature to figure out the base and index. If it does not work, that's ok, just use the raw name. #namespl = osg.name.split("SG") #basename = osg.name.split("SG")[0] #if len(namespl)>1: # try: # index = int(namespl[1][1:])+1 # except: # index = 0 #else: index = 0 basename = newName # create the service group nsg = AmfServiceGroup( namesTaken.fix(basename + "SG" + "i" + str(index))) nsg.cconfig = copy.copy(osg.cconfig) created.append(nsg) # create the service units & components nsu = [] for (osu, dstNode) in zip(osg.su, nodeList): if dstNode is None: dstNode = osu.node su = AmfServiceUnit( namesTaken.fix(basename + "SU" + "i" + str(index) + "_on_" + osu.node.name), nsg, dstNode) su.cconfig = copy.copy(osu.cconfig) dstNode.su.append(su) # Add this SU into the node nsg.su.append(su) # Add this SU into the SG nsu.append(su) modified.append(dstNode) created.append(su) # ncomp = [] for ocomp in osu.comp: app = str(ocomp.cconfig.instantiateCommand) comp = AmfComponent( namesTaken.fix(basename + "Ci" + str(index) + "_" + app + "_on_" + dstNode.name)) comp.cconfig = copy.copy(ocomp.cconfig) comp.supportedCsis.add(ocomp.cconfig.pSupportedCSITypes.value) comp.su = su # Hook the SU up to the comp su.comp.append(comp) # Hook the comp up to the SU # ncomp.append(comp) created.append(comp) # create the service instances & component service instances for osi in osg.si: siname = osi.name.split("SI")[0] svcInst = AmfServiceInstance( namesTaken.fix(basename + "SIi" + str(index))) # si has no cconfig... svcInst.cconfig = copy.copy(svcInst.cconfig) nsg.si.append(svcInst) # Add this SI into the SG created.append(svcInst) for ocsi in osi.csi: csiname = ocsi.name.split("CSI")[0] d = dict(ocsi.kvdict) csiType = str(ocsi.csiType) print "CSI type: ", csiType csi = AmfComponentServiceInstance( namesTaken.fix(csiname + "CSIi" + str(index) + ocsi.csiType), d, csiType) #csi.cconfig = copy.copy(csi.cconfig) svcInst.csi.append(csi) created.append(csi) amf.InstallApp(created, modified) if 0: # except: pass return (created, modified, {})