本文整理汇总了Python中java.util.Properties.setProperty方法的典型用法代码示例。如果您正苦于以下问题:Python Properties.setProperty方法的具体用法?Python Properties.setProperty怎么用?Python Properties.setProperty使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.util.Properties
的用法示例。
在下文中一共展示了Properties.setProperty方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _sapJmxConnect
# 需要导入模块: from java.util import Properties [as 别名]
# 或者: from java.util.Properties import setProperty [as 别名]
def _sapJmxConnect(credId, ip, Framework):
r'''@types: str, str, Framework -> Result
'''
message = None
status = False
for version in SAPJmxAgent.getAvailableVersions():
props = Properties()
props.setProperty(AgentConstants.VERSION_PROPERTY, version)
logger.debug('Trying to connect to ip=%s by \'%s\' '\
'protocol (assuming version %s)...' % (ip,
_PROTOCOL_NAME,
version))
try:
sap = Framework.getAgent(AgentConstants.SAP_JMX_AGENT,
ip, credId, props)
sap.connect()
except:
message = 'error: %s' % sys.exc_info()[1]
logger.debug('connection to ip=%s by \'%s\' '\
'protocol failed. %s' % (ip,
_PROTOCOL_NAME, message))
continue
else:
logger.debug('connection to ip=%s by \'%s\' '\
'protocol is successful' % (ip, _PROTOCOL_NAME))
status = True
break
finally:
sap and sap.disconnect()
return Result(status, message)
示例2: __init__
# 需要导入模块: from java.util import Properties [as 别名]
# 或者: from java.util.Properties import setProperty [as 别名]
def __init__(self):
self.originalOut = sys.stdout
# Setup pig
props = Properties()
props.putAll(javasystem.getProperties())
for f in os.environ.get("DEFAULT_PIG_OPTS_FILES").split(","):
PropertiesUtil.loadPropertiesFromFile(props, f)
props.setProperty('log4jconf', os.environ.get('LOG4J_CONF'))
pigOpts = os.environ.get('PIG_OPTS')
if pigOpts:
for opt in pigOpts.strip().split(' '):
opt = opt.split('=')
props.setProperty(opt[0], opt[1])
pigContext = PigContext(ExecType.LOCAL, props)
params = ArrayList()
paramFiles = ArrayList()
pigContext.setParams(params)
pigContext.setParamFiles(paramFiles)
PigMain.configureLog4J(props, pigContext)
pigInputStream = PigInputStream()
reader = ConsoleReader(pigInputStream, OutputStreamWriter(javasystem.out))
inputStream = ConsoleReaderInputStream(reader)
self.pigBufferedReader = PigBufferedReader(InputStreamReader(pigInputStream))
self.grunt = PigGrunt(self.pigBufferedReader, pigContext)
self.grunt.setConsoleReader(reader)
self.pigServer = self.grunt.pig
示例3: getApplicationHierarchy
# 需要导入模块: from java.util import Properties [as 别名]
# 或者: from java.util.Properties import setProperty [as 别名]
def getApplicationHierarchy(self):
appsProps = []
params = HashMap()
params.put('OBJECT_TYPE', 'FUGR')
params.put('REFRESH', 'X')
# function = self.__client.getFunction('RS_COMPONENT_VIEW')
# function.getImportParameterList().setValue("FUGR", "OBJECT_TYPE");
# function.getImportParameterList().setValue("X", "REFRESH");
fields = ArrayList()
fields.add('ID')
fields.add('TYPE')
fields.add('NAME')
fields.add('PARENT')
fields.add('TEXT')
appsRS = self.__client.executeFunction('RS_COMPONENT_VIEW', params, 'NODETAB', fields)
while appsRS.next():
prop = Properties()
prop.setProperty('id', appsRS.getString("ID"))
prop.setProperty('type', appsRS.getString("TYPE"))
prop.setProperty('data_name', appsRS.getString("NAME"))
prop.setProperty('parent', appsRS.getString("PARENT"))
prop.setProperty('description', appsRS.getString("TEXT"))
appsProps.append(prop)
return appsProps;
示例4: DiscoveryMain
# 需要导入模块: from java.util import Properties [as 别名]
# 或者: from java.util.Properties import setProperty [as 别名]
def DiscoveryMain(Framework):
OSHVResult = ObjectStateHolderVector()
CmdbOIDFactory = CmdbObjectID.Factory
hostId = CmdbOIDFactory.restoreObjectID(Framework.getDestinationAttribute('hostId'))
sqlServerId = CmdbOIDFactory.restoreObjectID(Framework.getDestinationAttribute('id'))
try:
props = Properties()
instance_name = Framework.getDestinationAttribute('instanceName')
if instance_name and instance_name != 'NA' and instance_name.find('\\') != -1:
props.setProperty('sqlprotocol_dbsid', instance_name[instance_name.find('\\')+1:])
mssqlClient = Framework.createClient(props)
connection = SqlServerConnection.ClientSqlServerConnection(mssqlClient)
logger.debug("got connection")
discoveryOptions = SqlServerDiscoveryOptions()
discoveryOptions.discoverConfigs = Boolean.parseBoolean(Framework.getParameter('discoverConfigs'))
discoveryOptions.discoverDbUser = Boolean.parseBoolean(Framework.getParameter('discoverDbUser'))
discoveryOptions.discoverSqlFile = Boolean.parseBoolean(Framework.getParameter('discoverSqlFile'))
discoveryOptions.discoverSqlJob = Boolean.parseBoolean(Framework.getParameter('discoverSqlJob'))
discoveryOptions.discoverProcedures = Boolean.parseBoolean(Framework.getParameter('discoverStoredProcedures'))
discoveryOptions.discoverInternalProcedures = Boolean.parseBoolean(Framework.getParameter('discoverInternalProcedures'))
sqlServer = SqlServer.SqlServer(connection, discoveryOptions)
OSHVResult.addAll(sqlServer.collectData(hostId, sqlServerId, discoveryOptions.discoverConfigs))
mssqlClient.close()
except JavaException, ex:
strException = ex.getMessage()
errormessages.resolveAndReport(strException, ClientsConsts.SQL_PROTOCOL_NAME, Framework)
示例5: connectToDb
# 需要导入模块: from java.util import Properties [as 别名]
# 或者: from java.util.Properties import setProperty [as 别名]
def connectToDb(localFramework, ipAddress, dbPort):
try:
theDbClient = None
## Get protocols
protocols = localFramework.getAvailableProtocols(ipAddress, ClientsConsts.SQL_PROTOCOL_NAME)
for protocolID in protocols:
## If this protocol entry is not for a Sybase DB, ignore it
if localFramework.getProtocolProperty(protocolID, CollectorsConstants.SQL_PROTOCOL_ATTRIBUTE_DBTYPE) != 'Sybase':
debugPrint(5, '[' + SCRIPT_NAME + ':DiscoveryMain] Ignoring non Sybase protocol entry...')
continue
## Don't bother reconnecting if a connection has already been established
if not theDbClient:
## Set DB properties
dbConnectionProperties = Properties()
dbConnectionProperties.setProperty(CollectorsConstants.PROTOCOL_ATTRIBUTE_PORT, dbPort)
# Establish JDBC connection
debugPrint(5, '[' + SCRIPT_NAME + ':connectToDb] Attempting connection to CiscoWorks database at port <%s>...' % dbPort)
try:
theDbClient = localFramework.createClient(protocolID, dbConnectionProperties)
except:
theDbClient and theDBClient.close()
return theDbClient
except:
excInfo = logger.prepareJythonStackTrace('')
logger.warn('[' + SCRIPT_NAME + ':connectToDb] Exception: <%s>' % excInfo)
pass
示例6: getShellUtils
# 需要导入模块: from java.util import Properties [as 别名]
# 或者: from java.util.Properties import setProperty [as 别名]
def getShellUtils(Framework, shellName, credentials, ip, codepage, warningsList, errorsList):
failedPorts = []
#check which credential is good for the shell:
client = None
for credentialId in credentials:
try:
port = None
props = Properties()
props.setProperty(BaseAgent.ENCODING, codepage)
props.setProperty(CollectorsConstants.ATTR_CREDENTIALS_ID, credentialId)
logger.debug('try credential %s' % credentialId)
client = Framework.createClient(props)
shellUtils = shellutils.ShellUtils(client, None, shellName)
if shellUtils:
return (shellUtils, credentialId)
except IOException, ioEx:
strException = str(ioEx.getMessage())
errormessages.resolveAndAddToObjectsCollections(strException, shellName, warningsList, errorsList)
if client:
client.close()
# we failed to connect - add the problematic port to failedPorts list
if port:
failedPorts.append(port)
except (UnsupportedEncodingException, UnsupportedCharsetException), ex:
strException = str(ex.getClass().getName())
shouldStop = errormessages.resolveAndAddToObjectsCollections(strException, shellName, warningsList, errorsList)
if client:
client.close()
if shouldStop:
return (None, None)
示例7: __createConnection
# 需要导入模块: from java.util import Properties [as 别名]
# 或者: from java.util.Properties import setProperty [as 别名]
def __createConnection(self):
"create database"
self.__connection = None
try:
logger.info("RegisterJDBC driver: com.mysql.jdbc.Driver")
driver = com.mysql.jdbc.Driver.newInstance()
if driver and driver.acceptsURL(self.__rootJdbcUrl):
props = Properties()
props.setProperty("user", "root")
props.setProperty("password", self.__rootPwd)
logger.info("Create JDBC connection:" + self.__rootJdbcUrl)
self.__connection = driver.connect(self.__rootJdbcUrl, props)
if self.__connection:
logger.info("Create db select prepared statement")
self.__dbstmt = self.__connection.prepareStatement("show databases;")
rs = self.__dbstmt.executeQuery()
self.__databases = []
while (rs.next()):
db = rs.getString(1)
self.__databases.append(db)
except:
self.__connection = None
type, value, traceback = sys.exc_info()
logger.severe("create connection error:" + `value`)
示例8: createClient
# 需要导入模块: from java.util import Properties [as 别名]
# 或者: from java.util.Properties import setProperty [as 别名]
def createClient(framework, ipAddress, namespace, credentialsId):
'''
Framework, string, string, string -> CimClient
@raise ValueError if any parameter is incorrect
@raise ValueError if client fails to be created
'''
properties = Properties()
if ipAddress:
properties.setProperty(cim.ClientProperty.IP_ADDRESS, ipAddress)
else:
raise ValueError("IP Address is None")
if namespace:
properties.setProperty(cim.ClientProperty.NAMESPACE, namespace)
else:
raise ValueError("Namespace is None")
if credentialsId:
properties.setProperty(cim.ClientProperty.CREDENTIALS_ID, credentialsId)
properties.setProperty(SblimClientProperties.HTTP_POOL_SIZE, "0") #disable HTTP pool to support ESXes 4.1
properties.setProperty(SblimClientProperties.USE_MPOST, "false")
try:
client = framework.createClient(properties)
return client
except JException, jex:
msg = jex.getMessage()
logger.error("Failed to create client: %s" % msg)
raise ValueError("Failed to create client")
示例9: save_versions
# 需要导入模块: from java.util import Properties [as 别名]
# 或者: from java.util.Properties import setProperty [as 别名]
def save_versions(self):
print "save versions"
versionsProperties = Properties()
outFile = FileOutputStream(self.versionsFileName)
versionsProperties.setProperty("script", self.app.SCRIPTVERSION)
versionsProperties.setProperty("tools", self.app.TOOLSVERSION)
versionsProperties.store(outFile, None)
outFile.close()
示例10: _buildConnectionProps
# 需要导入模块: from java.util import Properties [as 别名]
# 或者: from java.util.Properties import setProperty [as 别名]
def _buildConnectionProps(instNr, connClient=None):
props = Properties()
logger.debug('Connecting to a SAP instance number:', str(instNr))
props.setProperty(Protocol.SAP_PROTOCOL_ATTRIBUTE_SYSNUMBER, instNr)
if connClient:
logger.debug('Connecting to a SAP system with client: %s' % connClient)
props.setProperty(Protocol.SAP_PROTOCOL_ATTRIBUTE_CLIENT, connClient)
return props
示例11: connect
# 需要导入模块: from java.util import Properties [as 别名]
# 或者: from java.util.Properties import setProperty [as 别名]
def connect(self, framework):
credentialsId = framework.getDestinationAttribute('credentialsId')#user selects the creds in the UI so we already know them
connection_ip = framework.getDestinationAttribute('ip_address')
self._credentialsId = credentialsId
try:
props = Properties()
props.setProperty('ip_address', connection_ip)
except Exception, e:
pass
示例12: DiscoveryMain
# 需要导入模块: from java.util import Properties [as 别名]
# 或者: from java.util.Properties import setProperty [as 别名]
def DiscoveryMain(Framework):
# General variables
OSHVResult = ObjectStateHolderVector()
properties = Properties()
protocol = Framework.getDestinationAttribute('Protocol')
processToPortDict = {} ## {PID:[processName, listeningPort, ipAddress, path, version, status, processCommandline]}
databaseDict = {} ## {instanceName/SID:[dbType, listeningPort, ipAddress, installPath, version, status]}
database_ip_service_endpoints ={} ## {instanceName:[ip_address:port]}
client = None
secondClient = None
isWindows = 'true'
# Attempt to create a client
try:
client = Framework.createClient()
## We have a client
## Get processes running on the box
if(client):
dbconnect_utils.debugPrint(3, '[' + SCRIPT_NAME + ':DiscoveryMain] Got client <%s>' % client.getClientType())
if client.getClientType() == 'wmi':
## Open a second client connection to the DEFAULT namespace for registry access
props = Properties()
props.setProperty(AgentConstants.PROP_WMI_NAMESPACE, 'root\\DEFAULT')
secondClient = Framework.createClient(props)
processToPortDict = dbconnect_agentutils.getProcListByWMI(client, secondClient)
# elif client.getClientType() == 'snmp':
# processToPortDict = dbconnect_agentutils.getProcListBySNMP(client)
else:
Framework.reportWarning('Unable to connect using WMI')
## We have process and port infromation
## Find databases, if any
if processToPortDict != None and len(processToPortDict) > 0:
for pid in processToPortDict.keys():
logger.debug('dddd: ', '[' + SCRIPT_NAME + ':DiscoveryMain] Got process/service/software <%s> listening on port <%s:%s>' % ((processToPortDict[pid])[dbconnect_utils.PROCESSNAME_INDEX], (processToPortDict[pid])[dbconnect_utils.IP_INDEX], (processToPortDict[pid])[dbconnect_utils.PORT_INDEX]))
if Framework.getParameter('discover_oracle').strip().lower() == 'true':
dbconnect_oracle.findDatabases(client, processToPortDict, databaseDict, isWindows, secondClient)
if Framework.getParameter('discover_mssql').strip().lower() == 'true':
dbconnect_mssql.findDatabases(client, processToPortDict, databaseDict, database_ip_service_endpoints, isWindows, secondClient)
if databaseDict != None and len(databaseDict) > 0:
for dbName in databaseDict.keys():
dbconnect_utils.debugPrint('Found <%s> instance <%s> (%s) with listener port <%s:%s> and installed in <%s>' % ((databaseDict[dbName])[dbconnect_utils.DBTYPE_INDEX], dbName, (databaseDict[dbName])[dbconnect_utils.STATUS_INDEX], (databaseDict[dbName])[dbconnect_utils.IP_INDEX], (databaseDict[dbName])[dbconnect_utils.PORT_INDEX], (databaseDict[dbName])[dbconnect_utils.PATH_INDEX]))
OSHVResult.addAll(dbconnect_utils.makeDbOSHs(databaseDict))
else:
Framework.reportWarning('No databases found')
else:
## If we're here, we couldn't find any processes, service, or software
## and we have no data to search for databases
Framework.reportWarning('Unable to get a list or processes, services, or installed software')
else:
dbconnect_utils.debugPrint('Unable to connect using WMI')
except Exception, ex:
exInfo = ex.getMessage()
errormessages.resolveAndReport(exInfo, protocol, Framework)
示例13: mainFunction
# 需要导入模块: from java.util import Properties [as 别名]
# 或者: from java.util.Properties import setProperty [as 别名]
def mainFunction(Framework, OSHVResult, softNameToInstSoftOSH=None):
'''
This function uses registry to provide information
about installed software.
'''
props = Properties()
props.setProperty(AgentConstants.PROP_WMI_NAMESPACE, 'root\\DEFAULT')
wmiClient = None
try:
try:
wmiClient = Framework.createClient(props)
hostOSH = createHostOSH(Framework, wmiClient)
OSHVResult.add(hostOSH)
registryColumns = {'DisplayName': {}, 'InstallLocation': {},
'DisplayVersion': {}, 'Publisher': {}, 'ProductID': {},
'InstallDate': {}}
keyNames = registryColumns.keys()
# These are the Registry sections, where the Software Uninstall information is stored
keyPaths = ['SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall',
'SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall']
for keyPath in keyPaths:
try:
result = getRegistrySubkeys(wmiClient, keyPath, keyNames)
_mergeDictionaries(registryColumns, result)
except JavaException, e:
logger.info('Not a 64bit OS: ' + str(e))
# do the work
_createSoftware(registryColumns['DisplayName'], registryColumns['InstallLocation'],
registryColumns['DisplayVersion'], registryColumns['Publisher'],
registryColumns['ProductID'], registryColumns['InstallDate'],
hostOSH, OSHVResult,
softNameToInstSoftOSH)
try:
props = Properties()
props.setProperty(AgentConstants.PROP_WMI_NAMESPACE, 'root\\cimv2')
client = Framework.createClient(props)
wmiProvider = WmiAgentProvider(client)
hostDiscoverer = WmiHostDiscoverer(wmiProvider)
if hostDiscoverer.isWin2008():
logger.debug('win2008 detected')
discoverWin2008HotFixes(wmiProvider, hostOSH, OSHVResult)
elif hostDiscoverer.isWindows8_2012():
logger.debug('win 8 or win 2012 detected')
discoverWin8_2012HotFixes(wmiProvider, hostOSH, OSHVResult)
else:
logger.debug('Non-win2008/8/2012 detected')
finally:
client.close()
except JavaException, ex:
exInfo = ex.getMessage()
errormessages.resolveAndReport(exInfo, 'WMI', Framework)
示例14: create_default_client
# 需要导入模块: from java.util import Properties [as 别名]
# 或者: from java.util.Properties import setProperty [as 别名]
def create_default_client(framework, cred_id, ip_address):
client = None
properties = Properties()
properties.setProperty("ip_address", ip_address)
try:
client = framework.createClient(cred_id, properties)
except(Exception, JavaException), e:
msg = e.getMessage() if hasattr(e, 'getMessage') else str(e)
raise ConnectionException(msg or 'Connection failed')
示例15: _connectToIamService
# 需要导入模块: from java.util import Properties [as 别名]
# 或者: from java.util.Properties import setProperty [as 别名]
def _connectToIamService(framework, credentialsId):
"""Connection method for the **Identity and Access Management**
@types: Framework, str -> IamClient
"""
from com.hp.ucmdb.discovery.library.clients.cloud.aws import ServiceType
from com.hp.ucmdb.discovery.library.clients.cloud.aws import Client
properties = Properties()
properties.setProperty("credentialsId", credentialsId)
properties.setProperty(Client.AWS_SERVICE_TYPE_PROPERTY, ServiceType.IAM.name()) # @UndefinedVariable
return framework.createClient(properties).getService()