def addVirtualHostAlias(self,vhName,aliasHost,aliasPort): """Adds a VirtualHost alias to the VirtualHost.aliases list in WebSphere. PARAMETERS: vhName -- name of the virtual host. aliasHost -- alias host name. aliasPort -- alias port. RETURN: True if successful or False """ ################################################################ # Log the parameters. ################################################################ self.debug( __name__ + ".addVirtualHostAlias(): called.\n" ) self.debug( __name__ + ".addVirtualHostAlias(): vhName=" + str( vhName ) + ".\n" ) self.debug( __name__ + ".addVirtualHostAlias(): aliasHost=" + str( aliasHost ) + ".\n" ) self.debug( __name__ + ".addVirtualHostAlias(): aliasPort=" + str( aliasPort ) + ".\n" ) if not self.checkVirtualHostAlias(vhName,aliasHost,aliasPort): myHostObjectName = self.getVirtualHostObjectName( vhName ) attr1 = Attribute( "hostname", aliasHost ) attr2 = Attribute( "port", aliasPort ) attrList = AttributeList() attrList.add( attr1 ) attrList.add( attr2 ) result = self.configService.createConfigData( self.configService.session, myHostObjectName, "aliases", "HostAlias", attrList ) #self.debug( __name__ + ".addVirtualHostAlias(): result=" + str( result ) + ".\n" ) # Clear teh lastVirtualHost name. self.lastVirtualHost = None if result is not None: return True else: return False #Endif return True
def addAuthAlias(self,alias,userid,password,description="This provider was created by the pylib.Was.AuthAliasManager."): """Add a JAASAuthData entry to websphere. PARAMETERS: alias -- alias name. userid -- userid. password -- password. description -- description text. RETURN: True if successful or the jdbcName exists, or False. """ ################################################################ # Log the parameters. ################################################################ self.debug( __name__ + ".addAuthAlias(): called.\n" ) self.debug( __name__ + ".addAuthAlias(): alias=" + str( alias ) + ".\n" ) self.debug( __name__ + ".addAuthAlias(): userid=" + str( userid ) + ".\n" ) self.debug( __name__ + ".addAuthAlias(): password="******".\n" ) self.debug( __name__ + ".addAuthAlias(): description=" + str( description ) + ".\n" ) ####################################################### # Check to see if the given alias already exists. ####################################################### myvalues = self.getAttributeValues( 'alias' ) for value in myvalues: if value == alias: self.logIt( __name__ + ".addAuthAlias(): AuthAlias " + str( alias ) + " already exists, so it will not be added." + ".\n" ) return True #Endif #Endfor self.logIt( __name__ + ".addAuthAlias(): AuthAlias " + str( alias ) + " doesn't exist, so it will be added." + ".\n" ) ###################################################### # Set up the attributes. ###################################################### nameAttr = Attribute( 'alias', alias ) desAttr = Attribute( 'description', description ) useridAttr = Attribute( 'userId', userid ) passwdAttr = Attribute( 'password', password ) myAttrList = AttributeList() myAttrList.add( nameAttr ) myAttrList.add( desAttr ) myAttrList.add( useridAttr ) myAttrList.add( passwdAttr ) ####################################################### # Create the JAASAuthData record. ####################################################### rc = self.createConfigData( 'authDataEntries', 'JAASAuthData', myAttrList ) return rc
def doWork(): """Do all the real work for this program.""" rVal = True rc = 0 printInfo() wasAdminClient = AdminClient(hostname="dilabvirt31-v1", logger=CONFIG['logger']) myclient = wasAdminClient.createSOAPDefault() configService = ConfigService(adminClient=myclient, logger=CONFIG['logger']) session = Session() # query to get dmgr dmgr = configService.resolve(session, "Node=cell101N2:Server=as_cell101a_01")[0] # query to get the trace service component in dmgr. #pattern = configService.configServiceHelper.createObjectName( None, "TraceService" ) pattern = ConfigServiceHelper.createObjectName(None, "TraceService") traceService = ObjectName( configService.queryConfigObjects(session, dmgr, pattern, None)[0].toString()) # get the current dmgr's trace specification. trace = configService.getAttribute(session, traceService, "startupTraceSpecification") print "trace is " + str(trace) # set the dmgr's trace specification to new value. newTrace = String("*=all=enabled") #newTrace = String( "*=info" ) attrList = AttributeList() attrList.add(Attribute("startupTraceSpecification", newTrace)) configService.setAttributes(session, traceService, attrList) newTrace = String( configService.getAttribute(session, traceService, "startupTraceSpecification")) print "new trace is " + str(newTrace) ## save the chanage. configService.save(session, False) # set it back. #configService.configServiceHelper.setAttributeValue( attrList, "startupTraceSpecification", trace ) ConfigServiceHelper.setAttributeValue(attrList, "startupTraceSpecification", trace) configService.setAttributes(session, traceService, attrList) newTrace = configService.getAttribute(session, traceService, "startupTraceSpecification") print "trace is set back to " + str(newTrace) configService.save(session, False) configService.discard(session) return rc
def addVirtualHost(self,cellName,vhName): """Adds a VirtualHost to WebSphere. PARAMETERS: cellname -- name of the WebSphere cell. vhName -- name of the virtual host. RETURN: True if successful or False """ ################################################################ # Log the parameters. ################################################################ self.debug( __name__ + ".addVirtualHost(): called.\n" ) self.debug( __name__ + ".addVirtualHost(): vhName=" + str( vhName ) + ".\n" ) ########################################################### # First check to see if the virtual host already exists. ########################################################### #query = "Cell=" + str( cellName ) + ":VirtualHost=" + str( vhName ) vObject = self.getVirtualHostObjectName( vhName ) self.debug( __name__ + ".addVirtualHost(): vObject=" + str( vObject ) + ".\n" ) if vObject is None: ############################################################ # The virtual host does not exist in the cell, so add it. ############################################################ query = "Cell=" + str( cellName ) cellObjects = self.configService.resolveObjectName( query ) #self.debug( __name__ + ".addVirtualHost(): cellObjects=" + str( cellObjects ) + ".\n" ) #self.debug( __name__ + ".addVirtualHost(): len(cellObjects)=" + str( len( cellObjects ) ) + ".\n" ) if len( cellObjects ) > 0: attr1 = Attribute( "name", vhName ) attrList = AttributeList() attrList.add( attr1 ) result = self.configService.createConfigData( self.configService.session, cellObjects[0], "VirtualHost", "VirtualHost", attrList ) #self.debug( __name__ + ".addVirtualHost(): result=" + str( result ) + ".\n" ) if result is not None: return True else: self.logIt( __name__ + ".addVirtualHost(): Unable to resolve" + str( query ) + ".\n" ) #Endif else: ##################################################### # Virtual host exists in the cell so return happy. ##################################################### return True #Endif return False
def __setattr__(self, name, value): from javax.management import Attribute return self.server.setAttribute(self.objectname, Attribute(name, value))
def addJDBCProvider( self, jdbcName, templateId, classpath, implementationClass, nativepath="", xa=False, description="This provider was created by the pylib.Was.JDBCProviderManager." ): """Add a JDBC provider. PARAMETERS: jdbcName -- name of the JDBC provider. Something like 'Derby JDBC Provider (XA)' templateId -- name of the JDBC provider template. Something like 'JDBCProvider_3' classpath -- java classpath for the JDBC provider. Something like '${DERBY_JDBC_DRIVER_PATH}/derby.jar:...' must be delimited by ':'. implementationClass -- implementation class name. Something like 'org.apache.derby.jdbc.EmbeddedXADataSource' nativepath -- native path for the JDBCProvider. must be delimited by ':'. xa -- defaults to False. Set to True if this an XA provider. description -- description text. RETURN: True if successful or the jdbcName exists, or False. """ ################################################################ # Log the parameters. ################################################################ self.debug(__name__ + ".addJDBCProvider(): called.\n") self.debug(__name__ + ".addJDBCProvider(): jdbcName=" + str(jdbcName) + ".\n") self.debug(__name__ + ".addJDBCProvider(): templateId=" + str(templateId) + ".\n") self.debug(__name__ + ".addJDBCProvider(): classpath=" + str(classpath) + ".\n") self.debug(__name__ + ".addJDBCProvider(): implementationClass=" + str(implementationClass) + ".\n") self.debug(__name__ + ".addJDBCProvider(): nativepath=" + str(nativepath) + ".\n") self.debug(__name__ + ".addJDBCProvider(): xa=" + str(xa) + ".\n") self.debug(__name__ + ".addJDBCProvider(): description=" + str(description) + ".\n") ####################################################### # Check to see if the given jdbcName already exists. ####################################################### myvalues = self.getAttributeValues('name') for value in myvalues: if value == jdbcName: self.logIt(__name__ + ".addJDBCProvider(): JDBC Provider " + str(jdbcName) + " already exists, so it will not be added." + ".\n") return True #Endif #Endfor self.logIt(__name__ + ".addJDBCProvider(): JDBC Provider " + str(jdbcName) + " doesn't exist, so it will be added." + ".\n") ###################################################### # Set up the attributes. ###################################################### nameAttr = Attribute('name', jdbcName) desAttr = Attribute('description', description) myclassList = java.util.ArrayList() myclassAR = classpath.split(':') for mypath in myclassAR: myclassList.add(mypath) #Endfor classAttr = Attribute('classpath', myclassList) implAttr = Attribute('implementationClassName', implementationClass) mynativeList = java.util.ArrayList() mynativeAR = nativepath.split(':') for mypath in mynativeAR: mynativeList.add(mypath) #Endfor nativeAttr = Attribute('nativepath', mynativeList) xaAttr = Attribute('xa', java.lang.Boolean(xa)) myAttrList = AttributeList() myAttrList.add(nameAttr) myAttrList.add(desAttr) myAttrList.add(implAttr) myAttrList.add(classAttr) myAttrList.add(nativeAttr) myAttrList.add(xaAttr) ####################################################### # Create the JDBCProvider. ####################################################### rc = self.createConfigDataWithTemplate(templateId, 'JDBCProvider', myAttrList) return rc
def setAttributeConnection(remoteServerConnection, objectNameString, attribute, value): obn = javax.management.ObjectName(objectNameString) oAttribute = Attribute(attribute, value) result = remoteServerConnection.setAttribute(obn, oAttribute) return result
def setAttributeHost(host, port, objectNameString, attribute, value): remoteServerConnection = getConnection(host, port) obn = javax.management.ObjectName(objectNameString) oAttribute = Attribute(attribute, value) result = remoteServerConnection.setAttribute(obn, oAttribute) return result
def addEndPoint(self, endPointName, host, port): """Add a DataSource to websphere. PARAMETERS: endPointName -- name of the EndPoint. Something like 'WC_adminhost' host -- name of the host. Something like 'dilabvirt31-v1' port -- port number. RETURN: True if successful or the EndPoint exists, or False. """ ################################################################ # Log the parameters. ################################################################ self.debug(__name__ + ".addEndPoint(): called.\n") self.debug(__name__ + ".addEndPoint(): endPointName=" + str(endPointName) + ".\n") self.debug(__name__ + ".addEndPoint(): host=" + str(host) + ".\n") self.debug(__name__ + ".addEndPoint(): port=" + str(port) + ".\n") ####################################################### # Check to see if the given dataSourceName already exists. ####################################################### if self.isEndPointExist(endPointName): self.logIt(__name__ + ".addEndPoint(): EndPoint " + str(endPointName) + " already exists, so it will not be added." + ".\n") return True #Endif self.logIt(__name__ + ".addEndPoint(): EndPoint " + str(endPointName) + " doesn't exist, so it will be added." + ".\n") ###################################################### # Set up the attributes. ###################################################### endPointList = AttributeList() nameAttr = Attribute('endPointName', endPointName) hostAttr = Attribute('host', host) portAttr = Attribute('port', int(port)) ###################################################### # Build the AttribtueList. ###################################################### myAttrList = AttributeList() myAttrList.add(nameAttr) ####################################################### # Create the NamedEndPoint. ####################################################### attributeName = 'specialEndpoints' configType = 'NamedEndPoint' rc = self.createConfigData(attributeName, configType, myAttrList) if rc: myargs = array(['endPoint'], java.lang.String) endpointAttrs = self.configService.getAttributes( self.configService.session, self.myLastConfiguredObject, myargs, False) self.debug(__name__ + ".addEndPoint(): endpointAttrs" + str(endpointAttrs) + "\n") self.debug(__name__ + ".addEndPoint(): endpointAttrs type" + str(type(endpointAttrs)) + "\n") the_parent = self.myLastConfiguredObject self.debug(__name__ + ".addEndPoint(): the_parent=" + str(the_parent) + "\n") self.debug(__name__ + ".addEndPoint(): the_parent type=" + str(type(the_parent)) + "\n") try: endpointList = AttributeList() endpointList.add(hostAttr) endpointList.add(portAttr) self.configService.createConfigData(self.configService.session, the_parent, 'endPoint', 'EndPoint', endpointList) self.refresh() except com.ibm.websphere.management.exception.ConfigServiceException, e: self.logIt( __name__ + ".addEndPoint(): Unable to create the EndPoint for " + str(endPointName) + ":" + str(e) + "\n") return False except com.ibm.websphere.management.exception.ConnectorException, ce: self.logIt( __name__ + ".addEndPoint(): Unable to create the EndPoint for " + str(endPointName) + ":" + str(ce) + "\n") return False