本文整理汇总了Python中uds.core.util.log.doLog函数的典型用法代码示例。如果您正苦于以下问题:Python doLog函数的具体用法?Python doLog怎么用?Python doLog使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了doLog函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: readyReceived
def readyReceived(self, userService, data):
# No group to add
if self._group == '':
return
if not '.' in self._domain:
logger.info('Adding to a group for a non FQDN domain is not supported')
return
try:
l = self.__connectLdap()
except dns.resolver.NXDOMAIN: # No domain found, log it and pass
logger.warn('Could not find _ldap._tcp.' + self._domain)
log.doLog(service, log.WARN, "Could not remove machine from domain (_ldap._tcp.{0} not found)".format(self._domain), log.OSMANAGER)
except ldap.LDAPError:
logger.exception('Ldap Exception caught')
log.doLog(service, log.WARN, "Could not remove machine from domain (invalid credentials for {0})".format(self._account), log.OSMANAGER)
try:
machine = self.__getMachine(l, userService.friendly_name)
group = self.__getGroup(l)
l.modify_s(group, ((ldap.MOD_ADD, 'member', machine),))
except ldap.ALREADY_EXISTS:
# Already added this machine to this group, pass
pass
except Exception:
logger.error('Got exception trying to add machine to group')
示例2: checkAndUpdateState
def checkAndUpdateState(userService, userServiceInstance, state):
"""
Checks the value returned from invocation to publish or checkPublishingState, updating the servicePoolPub database object
Return True if it has to continue checking, False if finished
"""
try:
if State.isFinished(state):
checkLater = False
userServiceInstance.finish()
userService.updateData(userServiceInstance)
userService.setState(State.USABLE) # Wi will only migrate fully functional services
elif State.isErrored(state):
checkLater = False
userService.updateData(userServiceInstance)
userService.setState(State.ERROR)
else:
checkLater = True # The task is running
userService.updateData(userServiceInstance)
userService.save()
if checkLater:
ClusterMigrationTask.checkLater(userService, userServiceInstance)
except Exception as e:
logger.exception('Migrating service')
log.doLog(userService, log.ERROR, 'Exception: {0}'.format(e), log.INTERNAL)
userService.setState(State.ERROR)
userService.save()
示例3: loggedOut
def loggedOut(self, userService, userName=None, save=True):
'''
This method:
- Add log in event to stats
- Sets service in use
- Invokes userLoggedIn for user service instance
'''
uniqueId = userService.unique_id
userService.setInUse(False)
si = userService.getInstance()
si.userLoggedOut(userName)
userService.updateData(si)
serviceIp = si.getIp()
fullUserName = 'unknown'
if userService.user is not None:
fullUserName = userService.user.manager.name + '\\' + userService.user.name
knownUserIP = userService.src_ip + ':' + userService.src_hostname
knownUserIP = knownUserIP if knownUserIP != ':' else 'unknown'
addEvent(userService.deployed_service, ET_LOGOUT, fld1=userName, fld2=knownUserIP, fld3=serviceIp, fld4=fullUserName)
log.doLog(userService, log.INFO, "User {0} has logged out", log.OSMANAGER)
log.useLog('logout', uniqueId, serviceIp, userName, knownUserIP, fullUserName)
if save:
userService.save()
示例4: sernotify
def sernotify(request, idUserService, notification):
try:
if notification == 'hostname':
hostname = request.GET.get('hostname', None)[:64] # Cuts host name to 64 chars
ip = request.ip
if GlobalConfig.HONOR_CLIENT_IP_NOTIFY.getBool(True) is True:
ip = request.GET.get('ip', ip)
if ip is not None and hostname is not None:
us = UserService.objects.get(uuid=idUserService)
us.setConnectionSource(ip, hostname)
else:
return HttpResponse('Invalid request!', 'text/plain')
elif notification == "log":
message = request.GET.get('message', None)
level = request.GET.get('level', None)
if message is not None and level is not None:
us = UserService.objects.get(uuid=idUserService)
log.doLog(us, level, message, log.TRANSPORT)
else:
return HttpResponse('Invalid request!', 'text/plain')
except Exception as e:
logger.exception("Exception")
return errors.errorView(request, e)
return HttpResponse('ok', content_type='text/plain')
示例5: deleteItem
def deleteItem(self, parent, item): # This is also used by CachedService, so we use "userServices" directly and is valid for both
service = None
try:
service = parent.userServices.get(uuid=processUuid(item))
except Exception:
logger.exception('deleteItem')
self.invalidItemException()
if service.user:
logStr = 'Deleted assigned service {} to user {} by {}'.format(service.friendly_name, service.user.pretty_name, self._user.pretty_name)
else:
logStr = 'Deleted cached service {} by {}'.format(service.friendly_name, self._user.pretty_name)
if service.state in (State.USABLE, State.REMOVING):
service.remove()
elif service.state == State.PREPARING:
service.cancel()
elif service.state == State.REMOVABLE:
self.invalidItemException(_('Item already being removed'))
else:
self.invalidItemException(_('Item is not removable'))
log.doLog(parent, log.INFO, logStr, log.ADMIN)
return self.success()
示例6: growL1Cache
def growL1Cache(self, sp, cacheL1, cacheL2, assigned):
'''
This method tries to enlarge L1 cache.
If for some reason the number of deployed services (Counting all, ACTIVE
and PREPARING, assigned, L1 and L2) is over max allowed service deployments,
this method will not grow the L1 cache
'''
logger.debug("Growing L1 cache creating a new service for {0}".format(sp))
# First, we try to assign from L2 cache
if cacheL2 > 0:
valid = None
with transaction.atomic():
for n in sp.cachedUserServices().select_for_update().filter(UserServiceManager.getCacheStateFilter(services.UserDeployment.L2_CACHE)).order_by('creation_date'):
if n.needsOsManager():
if State.isUsable(n.state) is False or State.isUsable(n.os_state):
valid = n
break
else:
valid = n
break
if valid is not None:
valid.moveToLevel(services.UserDeployment.L1_CACHE)
return
try:
UserServiceManager.manager().createCacheFor(sp.activePublication(), services.UserDeployment.L1_CACHE)
except MaxServicesReachedException as e:
log.doLog(sp, log.ERROR, 'Max number of services reached for this service', log.INTERNAL)
logger.error(str(e))
except:
logger.exception('Exception')
示例7: loggedIn
def loggedIn(self, userService, userName=None):
"""
This method:
- Add log in event to stats
- Sets service in use
- Invokes userLoggedIn for user service instance
"""
uniqueId = userService.unique_id
userService.setInUse(True)
si = userService.getInstance()
si.userLoggedIn(userName)
userService.updateData(si)
serviceIp = si.getIp()
fullUserName = 'unknown'
if userService.user is not None:
fullUserName = userService.user.manager.name + '\\' + userService.user.name
knownUserIP = userService.src_ip + ':' + userService.src_hostname
knownUserIP = knownUserIP if knownUserIP != ':' else 'unknown'
if userName is None:
userName = 'unknown'
addEvent(userService.deployed_service, ET_LOGIN, fld1=userName, fld2=knownUserIP, fld3=serviceIp, fld4=fullUserName)
log.doLog(userService, log.INFO, "User {0} has logged in".format(userName), log.OSMANAGER)
log.useLog('login', uniqueId, serviceIp, userName, knownUserIP, fullUserName, userService.friendly_name, userService.deployed_service.name)
counter = int(userService.getProperty('loginsCounter', '0')) + 1
userService.setProperty('loginsCounter', six.text_type(counter))
示例8: release
def release(self, service):
'''
service is a db user service object
'''
super(WinDomainOsManager, self).release(service)
if not '.' in self._domain:
logger.info('Releasing from a not FQDN domain is not supported')
return
try:
l = self.__connectLdap()
except dns.resolver.NXDOMAIN: # No domain found, log it and pass
logger.warn('Could not find _ldap._tcp.' + self._domain)
log.doLog(service, log.WARN, "Could not remove machine from domain (_ldap._tcp.{0} not found)".format(self._domain), log.OSMANAGER)
except ldap.LDAPError:
logger.exception('Ldap Exception caught')
log.doLog(service, log.WARN, "Could not remove machine from domain (invalid credentials for {0})".format(self._account), log.OSMANAGER)
try:
res = self.__getMachine(l, service.friendly_name)
if res is None:
raise Exception('Machine {} not found on AD (permissions?)'.format(service.friendly_name))
l.delete_s(res) # Remove by DN, SYNC
except IndexError:
logger.error('Error deleting {} from BASE {}'.format(service.friendly_name, ou))
except Exception:
logger.exception('Deleting from AD: ')
示例9: saveItem
def saveItem(self, parent, item):
# If already exists
uuid = processUuid(item) if item is not None else None
try:
calendar = Calendar.objects.get(uuid=processUuid(self._params['calendarId']))
access = self._params['access'].upper()
if access not in ('ALLOW', 'DENY'):
raise Exception()
except Exception:
self.invalidRequestException(_('Invalid parameters on request'))
priority = int(self._params['priority'])
if uuid is not None:
calAccess = parent.calendarAccess.get(uuid=uuid)
calAccess.calendar = calendar
calAccess.service_pool = parent
calAccess.access = access
calAccess.priority = priority
calAccess.save()
else:
parent.calendarAccess.create(calendar=calendar, access=access, priority=priority)
log.doLog(parent, log.INFO, "Added access calendar {}/{} by {}".format(calendar.name, access, self._user.pretty_name), log.ADMIN)
return self.success()
示例10: cancel
def cancel(self, servicePoolPub): # pylint: disable=no-self-use
'''
Invoked to cancel a publication.
Double invokation (i.e. invokation over a "cancelling" item) will lead to a "forced" cancellation (unclean)
:param servicePoolPub: Service pool publication (db object for a publication)
'''
servicePoolPub = DeployedServicePublication.objects.get(pk=servicePoolPub.id)
if servicePoolPub.state not in State.PUBLISH_STATES:
if servicePoolPub.state == State.CANCELING: # Double cancel
logger.info('Double cancel invoked for a publication')
log.doLog(servicePoolPub.deployed_service, log.WARN, 'Forced cancel on publication, you must check uncleaned resources manually', log.ADMIN)
servicePoolPub.setState(State.CANCELED)
servicePoolPub.save()
return
else:
raise PublishException(_('Can\'t cancel non running publication'))
if servicePoolPub.state == State.LAUNCHING:
servicePoolPub.state = State.CANCELED
servicePoolPub.save()
return servicePoolPub
try:
pubInstance = servicePoolPub.getInstance()
state = pubInstance.cancel()
servicePoolPub.setState(State.CANCELING)
PublicationFinishChecker.checkAndUpdateState(servicePoolPub, pubInstance, state)
return servicePoolPub
except Exception, e:
raise PublishException(str(e))
示例11: checkAndUpdateState
def checkAndUpdateState(userService, userServiceInstance, state):
"""
Checks the value returned from invocation to publish or checkPublishingState, updating the servicePoolPub database object
Return True if it has to continue checking, False if finished
"""
try:
# Fills up basic data
userService.unique_id = userServiceInstance.getUniqueId() # Updates uniqueId
userService.friendly_name = userServiceInstance.getName() # And name, both methods can modify serviceInstance, so we save it later
userService.save(update_fields=['unique_id', 'friendly_name'])
updater = {
State.PREPARING: UpdateFromPreparing,
State.REMOVING: UpdateFromRemoving,
State.CANCELING: UpdateFromCanceling
}.get(userService.state, UpdateFromOther)
logger.debug('Updating from {} with updater {} and state {}'.format(State.toString(userService.state), updater, state))
updater(userService, userServiceInstance).run(state)
except Exception as e:
logger.exception('Checking service state')
log.doLog(userService, log.ERROR, 'Exception: {0}'.format(e), log.INTERNAL)
userService.setState(State.ERROR)
userService.save(update_fields=['data'])
示例12: run
def run(self):
logger.debug('Checking user service finished {0}'.format(self._svrId))
uService = None
try:
uService = UserService.objects.get(pk=self._svrId)
if uService.state != self._state:
logger.debug('Task overrided by another task (state of item changed)')
# This item is no longer valid, returning will not check it again (no checkLater called)
return
ci = uService.getInstance()
logger.debug("uService instance class: {0}".format(ci.__class__))
state = ci.checkState()
UserServiceOpChecker.checkAndUpdateState(uService, ci, state)
except UserService.DoesNotExist as e:
logger.error('User service not found (erased from database?) {0} : {1}'.format(e.__class__, e))
except Exception as e:
# Exception caught, mark service as errored
logger.exception("Error {0}, {1} :".format(e.__class__, e))
if uService is not None:
log.doLog(uService, log.ERROR, 'Exception: {0}'.format(e), log.INTERNAL)
try:
uService.setState(State.ERROR)
uService.save(update_fields=['data', 'state', 'state_date'])
except Exception:
logger.error('Can\'t update state of uService object')
示例13: genPassword
def genPassword(self, service):
import random
import string
randomPass = service.recoverValue('winOsRandomPass')
if randomPass is None:
randomPass = ''.join(random.choice(string.ascii_letters + string.digits) for _ in range(16))
service.storeValue('winOsRandomPass', randomPass)
log.doLog(service, log.INFO, "Password set to \"{}\"".format(randomPass), log.OSMANAGER)
return randomPass
示例14: deleteItem
def deleteItem(self, parent: MetaPool, item: str):
member = parent.members.get(uuid=processUuid(self._args[0]))
logStr = "Removed meta pool member {} by {}".format(member.pool.name, self._user.pretty_name)
member.delete()
log.doLog(parent, log.INFO, logStr, log.ADMIN)
return self.success()
示例15: checkAndUpdateState
def checkAndUpdateState(userService, userServiceInstance, state):
'''
Checks the value returned from invocation to publish or checkPublishingState, updating the servicePoolPub database object
Return True if it has to continue checking, False if finished
'''
try:
prevState = userService.state
userService.unique_id = userServiceInstance.getUniqueId() # Updates uniqueId
userService.friendly_name = userServiceInstance.getName() # And name, both methods can modify serviceInstance, so we save it later
if State.isFinished(state):
checkLater = False
userServiceInstance.finish()
if State.isPreparing(prevState):
if userServiceInstance.service().publicationType is None or userService.publication == userService.deployed_service.activePublication():
userService.setState(State.USABLE)
# and make this usable if os manager says that it is usable, else it pass to configuring state
if userServiceInstance.osmanager() is not None and userService.os_state == State.PREPARING: # If state is already "Usable", do not recheck it
stateOs = userServiceInstance.osmanager().checkState(userService)
# If state is finish, we need to notify the userService again that os has finished
if State.isFinished(stateOs):
state = userServiceInstance.notifyReadyFromOsManager('')
userService.updateData(userServiceInstance)
else:
stateOs = State.FINISHED
if State.isRuning(stateOs):
userService.setOsState(State.PREPARING)
else:
userService.setOsState(State.USABLE)
else:
# We ignore OsManager info and if userService don't belong to "current" publication, mark it as removable
userService.setState(State.REMOVABLE)
elif State.isRemoving(prevState):
if userServiceInstance.osmanager() is not None:
userServiceInstance.osmanager().release(userService)
userService.setState(State.REMOVED)
else:
# Canceled,
logger.debug("Canceled us {2}: {0}, {1}".format(prevState, State.toString(state), State.toString(userService)))
userService.setState(State.CANCELED)
userServiceInstance.osmanager().release(userService)
userService.updateData(userServiceInstance)
elif State.isErrored(state):
checkLater = False
userService.updateData(userServiceInstance)
userService.setState(State.ERROR)
else:
checkLater = True # The task is running
userService.updateData(userServiceInstance)
userService.save()
if checkLater:
UserServiceOpChecker.checkLater(userService, userServiceInstance)
except Exception as e:
logger.exception('Checking service state')
log.doLog(userService, log.ERROR, 'Exception: {0}'.format(e), log.INTERNAL)
userService.setState(State.ERROR)
userService.save()