2
0
mirror of https://github.com/xcat2/confluent.git synced 2025-07-05 20:35:38 +00:00

Phase 2 of Windows compatibility

More work to try to enable confluent to be frozen by
pyinstaller
This commit is contained in:
Jarrod Johnson
2015-07-31 17:07:40 -04:00
parent b48cd8b685
commit 29417d935c
29 changed files with 140 additions and 86 deletions

View File

@ -1,2 +0,0 @@
from pkgutil import extend_path
__path__ = extend_path(__path__, __name__)

View File

@ -30,7 +30,10 @@ from confluent import main
#p = cProfile.Profile(time.clock)
#p.enable()
#try:
main.run()
if __name__ == '__main__':
import multiprocessing
multiprocessing.freeze_support()
main.run()
#except:
# pass
#p.disable()

View File

@ -0,0 +1,41 @@
#!/usr/bin/env python
# vim: tabstop=4 shiftwidth=4 softtabstop=4
# Copyright 2014 IBM Corporation
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import sys
import os
path = os.path.dirname(os.path.realpath(__file__))
path = os.path.realpath(os.path.join(path, '..', 'lib', 'python'))
print(path)
if path.startswith('/opt'):
# if installed into system path, do not muck with things
sys.path.append(path)
import confluentd.main
#import cProfile
#import time
#p = cProfile.Profile(time.clock)
#p.enable()
#try:
import multiprocessing
if __name__ == '__main__':
multiprocessing.freeze_support()
confluentd.main.run()
#except:
# pass
#p.disable()
#p.print_stats(sort='cumulative')
#p.print_stats(sort='time')

View File

@ -1,2 +0,0 @@
from pkgutil import extend_path
__path__ = extend_path(__path__, __name__)

View File

@ -30,9 +30,9 @@
__author__ = 'jjohnson2'
import confluent.exceptions as exc
import confluent.lookuptools as lookuptools
import confluent.core
import confluentd.exceptions as exc
import confluentd.lookuptools as lookuptools
import confluentd.core
def decode_alert(varbinds, configmanager):
"""Decode an SNMP alert for a server
@ -53,7 +53,7 @@ def decode_alert(varbinds, configmanager):
if node is None:
raise exc.InvalidArgumentException(
'Unable to find a node with specified manager')
return confluent.core.handle_path(
return confluentd.core.handle_path(
'/nodes/{0}/events/hardware/decode'.format(node), 'update',
configmanager, varbinds, autostrip=False)

View File

@ -19,7 +19,7 @@
# the PBKDF2 transform is skipped unless a user has been idle for sufficient
# time
import confluent.config.configmanager as configmanager
import confluentd.config.configmanager as configmanager
import eventlet
import eventlet.tpool
import Crypto.Protocol.KDF as KDF

View File

@ -64,10 +64,10 @@ from Crypto.Hash import SHA256
import anydbm as dbm
import ast
import base64
import confluent.config.attributes as allattributes
import confluent.log
import confluent.util
import confluent.exceptions as exc
import confluentd.config.attributes as allattributes
import confluentd.log
import confluentd.util
import confluentd.exceptions as exc
import copy
import cPickle
import errno
@ -276,11 +276,11 @@ def _generate_new_id():
# generate a random id outside the usual ranges used for normal users in
# /etc/passwd. Leave an equivalent amount of space near the end disused,
# just in case
uid = str(confluent.util.securerandomnumber(65537, 4294901759))
uid = str(confluentd.util.securerandomnumber(65537, 4294901759))
if 'idmap' not in _cfgstore['main']:
return uid
while uid in _cfgstore['main']['idmap']:
uid = str(confluent.util.securerandomnumber(65537, 4294901759))
uid = str(confluentd.util.securerandomnumber(65537, 4294901759))
return uid
@ -415,7 +415,11 @@ def hook_new_configmanagers(callback):
class ConfigManager(object):
_cfgdir = "/etc/confluent/cfg/"
if os.name == 'nt':
_cfgdir = os.path.join(
os.getenv('SystemDrive'), '\\ProgramData', 'confluent', 'cfg')
else:
_cfgdir = "/etc/confluent/cfg"
_cfgwriter = None
_writepending = False
_syncrunning = False
@ -1009,7 +1013,7 @@ class ConfigManager(object):
except Exception:
global tracelog
if tracelog is None:
tracelog = confluent.log.Logger('trace')
tracelog = confluentd.log.Logger('trace')
tracelog.log(traceback.format_exc(), ltype=log.DataTypes.event,
event=log.Events.stacktrace)
@ -1207,15 +1211,15 @@ class ConfigManager(object):
global _cfgstore
_cfgstore = {}
rootpath = cls._cfgdir
_load_dict_from_dbm(['globals'], rootpath + "/globals")
_load_dict_from_dbm(['globals'], os.path.join(rootpath, "globals"))
for confarea in _config_areas:
_load_dict_from_dbm(['main', confarea], rootpath + "/" + confarea)
_load_dict_from_dbm(['main', confarea], os.path.join(rootpath, confarea))
try:
for tenant in os.listdir(rootpath + '/tenants/'):
for tenant in os.listdir(os.path.join(rootpath, 'tenants')):
for confarea in _config_areas:
_load_dict_from_dbm(
['main', tenant, confarea],
"%s/%s/%s" % (rootpath, tenant, confarea))
os.path.join(rootpath, tenant, confarea))
except OSError:
pass
@ -1246,7 +1250,7 @@ class ConfigManager(object):
dirtyglobals = copy.deepcopy(_cfgstore['dirtyglobals'])
del _cfgstore['dirtyglobals']
_mkpath(cls._cfgdir)
globalf = dbm.open(cls._cfgdir + "/globals", 'c', 384) # 0600
globalf = dbm.open(os.path.join(cls._cfgdir, "globals"), 'c', 384) # 0600
try:
for globalkey in dirtyglobals:
if globalkey in _cfgstore['globals']:
@ -1267,11 +1271,11 @@ class ConfigManager(object):
pathname = cls._cfgdir
currdict = _cfgstore['main']
else:
pathname = cls._cfgdir + '/tenants/' + tenant + '/'
pathname = os.path.join(cls._cfgdir, 'tenants', tenant)
currdict = _cfgstore['tenant'][tenant]
for category in dkdict.iterkeys():
_mkpath(pathname)
dbf = dbm.open(pathname + category, 'c', 384) # 0600
dbf = dbm.open(os.path.join(pathname, category), 'c', 384) # 0600
try:
for ck in dkdict[category]:
if ck not in currdict[category]:
@ -1325,7 +1329,8 @@ def dump_db_to_directory(location, password, redact=None):
cfgfile.write(ConfigManager(tenant=None)._dump_to_json(redact=redact))
cfgfile.write('\n')
try:
for tenant in os.listdir(ConfigManager._cfgdir + '/tenants/'):
for tenant in os.listdir(
os.path.join(ConfigManager._cfgdir, '/tenants/')):
with open(os.path.join(location, tenant + '.json'), 'w') as cfgfile:
cfgfile.write(ConfigManager(tenant=tenant)._dump_to_json(
redact=redact))

View File

@ -21,12 +21,12 @@
#we track nodes that are actively being logged, watched, or have attached
#there should be no more than one handler per node
import collections
import confluent.config.configmanager as configmodule
import confluent.exceptions as exc
import confluent.interface.console as conapi
import confluent.log as log
import confluent.core as plugin
import confluent.util as util
import confluentd.config.configmanager as configmodule
import confluentd.exceptions as exc
import confluentd.interface.console as conapi
import confluentd.log as log
import confluentd.core as plugin
import confluentd.util as util
import eventlet
import eventlet.event
import random

View File

@ -33,14 +33,14 @@
# functions. Console is special and just get's passed through
# see API.txt
import confluent.alerts as alerts
import confluent.config.attributes as attrscheme
import confluent.interface.console as console
import confluent.exceptions as exc
import confluent.messages as msg
import confluent.noderange as noderange
import confluentd.alerts as alerts
import confluentd.config.attributes as attrscheme
import confluentd.interface.console as console
import confluentd.exceptions as exc
import confluentd.messages as msg
import confluentd.noderange as noderange
try:
import confluent.shellmodule as shellmodule
import confluentd.shellmodule as shellmodule
except ImportError:
pass
import itertools

View File

@ -18,15 +18,15 @@
# It additionally manages httprequest console sessions
import base64
import Cookie
import confluent.auth as auth
import confluent.config.attributes as attribs
import confluent.consoleserver as consoleserver
import confluent.exceptions as exc
import confluent.log as log
import confluent.messages
import confluent.core as pluginapi
import confluent.tlvdata as tlvdata
import confluent.util as util
import confluentd.auth as auth
import confluentd.config.attributes as attribs
import confluentd.consoleserver as consoleserver
import confluentd.exceptions as exc
import confluentd.log as log
import confluentd.messages
import confluentd.core as pluginapi
import confluent.tlvdata
import confluentd.util as util
import copy
import eventlet
import json
@ -36,6 +36,7 @@ import time
import urlparse
import eventlet.wsgi
#scgi = eventlet.import_patched('flup.server.scgi')
tlvdata = confluent.tlvdata
auditlog = None
@ -61,44 +62,44 @@ class RobustCookie(Cookie.SimpleCookie):
def group_creation_resources():
yield confluent.messages.Attributes(
yield confluentd.messages.Attributes(
kv={'name': None}, desc="Name of the group").html() + '<br>'
yield confluent.messages.ListAttributes(kv={'nodes': []},
yield confluentd.messages.ListAttributes(kv={'nodes': []},
desc='Nodes to add to the group'
).html() + '<br>\n'
for attr in sorted(attribs.node.iterkeys()):
if attr == 'groups':
continue
if attr.startswith("secret."):
yield confluent.messages.CryptedAttributes(
yield confluentd.messages.CryptedAttributes(
kv={attr: None},
desc=attribs.node[attr]['description']).html() + '<br>\n'
elif ('type' in attribs.node[attr] and
list == attribs.node[attr]['type']):
yield confluent.messages.ListAttributes(
yield confluentd.messages.ListAttributes(
kv={attr: []},
desc=attribs.node[attr]['description']).html() + '<br>\n'
else:
yield confluent.messages.Attributes(
yield confluentd.messages.Attributes(
kv={attr: None},
desc=attribs.node[attr]['description']).html() + '<br>\n'
def node_creation_resources():
yield confluent.messages.Attributes(
yield confluentd.messages.Attributes(
kv={'name': None}, desc="Name of the node").html() + '<br>'
for attr in sorted(attribs.node.iterkeys()):
if attr.startswith("secret."):
yield confluent.messages.CryptedAttributes(
yield confluentd.messages.CryptedAttributes(
kv={attr: None},
desc=attribs.node[attr]['description']).html() + '<br>\n'
elif ('type' in attribs.node[attr] and
list == attribs.node[attr]['type']):
yield confluent.messages.ListAttributes(
yield confluentd.messages.ListAttributes(
kv={attr: []},
desc=attribs.node[attr]['description']).html() + '<br>\n'
else:
yield confluent.messages.Attributes(
yield confluentd.messages.Attributes(
kv={attr: None},
desc=attribs.node[attr]['description']).html() + '<br>\n'
@ -120,11 +121,11 @@ def user_creation_resources():
}
for attr in sorted(credential.iterkeys()):
if attr == "password":
yield confluent.messages.CryptedAttributes(
yield confluentd.messages.CryptedAttributes(
kv={attr: None},
desc=credential[attr]['description']).html() + '<br>\n'
else:
yield confluent.messages.Attributes(
yield confluentd.messages.Attributes(
kv={attr: None},
desc=credential[attr]['description']).html() + '<br>\n'
@ -465,7 +466,7 @@ def _assemble_html(responses, resource, querydict, url, extension):
extension)
pendingrsp = []
for rsp in responses:
if isinstance(rsp, confluent.messages.LinkRelation):
if isinstance(rsp, confluentd.messages.LinkRelation):
yield rsp.html(extension) + "<br>"
else:
pendingrsp.append(rsp)
@ -511,7 +512,7 @@ def _assemble_json(responses, resource, url, extension):
links['collection'] = {"href": "./" + extension}
rspdata = {}
for rsp in responses:
if isinstance(rsp, confluent.messages.LinkRelation):
if isinstance(rsp, confluentd.messages.LinkRelation):
haldata = rsp.raw()
for hk in haldata.iterkeys():
if 'href' in haldata[hk]:

View File

@ -60,7 +60,7 @@
# or other fields)
import collections
import confluent.config.configmanager
import confluentd.config.configmanager
import eventlet
import json
import os
@ -128,9 +128,14 @@ class Logger(object):
# we are just a copy of the same object
return
self.initialized = True
self.filepath = confluent.config.configmanager.get_global("logdirectory")
self.filepath = confluentd.config.configmanager.get_global("logdirectory")
if self.filepath is None:
self.filepath = "/var/log/confluent/"
if os.name == 'nt':
self.filepath = os.path.join(
os.getenv('SystemDrive'), '\\ProgramData', 'confluent',
'logs')
else:
self.filepath = "/var/log/confluent/"
self.isconsole = console
if console:
self.filepath += "consoles/"

View File

@ -25,7 +25,7 @@
# service should have a null tenant and a tenant entry that correlates)
__author__ = 'jjohnson2'
import confluent.config.configmanager as configmanager
import confluentd.config.configmanager as configmanager
import itertools
import socket

View File

@ -26,14 +26,14 @@
# It also will optionally snoop SLP DA requests
import atexit
import confluent.auth as auth
import confluent.config.configmanager as configmanager
import confluent.consoleserver as consoleserver
import confluent.core as confluentcore
import confluent.httpapi as httpapi
import confluent.log as log
import confluentd.auth as auth
import confluentd.config.configmanager as configmanager
import confluentd.consoleserver as consoleserver
import confluentd.core as confluentcore
import confluentd.httpapi as httpapi
import confluentd.log as log
try:
import confluent.sockapi as sockapi
import confluentd.sockapi as sockapi
except ImportError:
#On platforms without pwd, give up on the sockapi in general and be http
#only for now
@ -139,6 +139,9 @@ def _initsecurity(config):
def run():
if 'fcntl' in locals():
_checkpidfile()
if os.name == 'nt':
configfile = os.path.join(os.getenv('SystemDrive'), '\\ProgramData',
'confluent', 'cfg', 'service.cfg')
configfile = "/etc/confluent/service.cfg"
config = ConfigParser.ConfigParser()
config.read(configfile)

View File

@ -18,7 +18,7 @@
# This module implements client/server messages emitted from plugins.
# Things are defined here to 'encourage' developers to coordinate information
# format. This is also how different data formats are supported
import confluent.exceptions as exc
import confluentd.exceptions as exc
import json
valid_health_values = set([

View File

@ -12,9 +12,9 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import confluent.exceptions as exc
import confluent.messages as msg
import confluent.config.attributes as allattributes
import confluentd.exceptions as exc
import confluentd.messages as msg
import confluentd.config.attributes as allattributes
def retrieve(nodes, element, configmanager, inputdata):

View File

@ -14,9 +14,9 @@
# limitations under the License.
import atexit
import confluent.exceptions as exc
import confluent.interface.console as conapi
import confluent.messages as msg
import confluentd.exceptions as exc
import confluentd.interface.console as conapi
import confluentd.messages as msg
import eventlet
import eventlet.event
import eventlet.green.threading as threading

View File

@ -22,7 +22,7 @@
# only by the process owner and such an owner would be able to read a file
# anyway. Regardless, it is advisable to 'unset'
import confluent.interface.console as conapi
import confluentd.interface.console as conapi
import eventlet
import eventlet.green.select as select
import eventlet.green.subprocess as subprocess

View File

@ -32,13 +32,13 @@ import eventlet.green.socket as socket
import eventlet.green.ssl as ssl
import eventlet
import confluent.auth as auth
import confluentd.auth as auth
import confluent.tlvdata as tlvdata
import confluent.consoleserver as consoleserver
import confluent.config.configmanager as configmanager
import confluent.exceptions as exc
import confluent.log as log
import confluent.core as pluginapi
import confluentd.consoleserver as consoleserver
import confluentd.config.configmanager as configmanager
import confluentd.exceptions as exc
import confluentd.log as log
import confluentd.core as pluginapi
tracelog = None