1
0
mirror of https://github.com/dkmstr/openuds.git synced 2024-12-22 13:34:04 +03:00

done ad machine removal

This commit is contained in:
Adolfo Gómez 2013-02-15 10:30:21 +00:00
parent 140be8fc27
commit 77a363e350
3 changed files with 29 additions and 12 deletions

View File

@ -36,6 +36,8 @@ import logging
logger = logging.getLogger(__name__)
MAX_SEQ = 1000000000000000
class UniqueIDGenerator(object):
def __init__(self, typeName, owner, baseName = 'uds'):
@ -45,10 +47,10 @@ class UniqueIDGenerator(object):
def setBaseName(self, newBaseName):
self._baseName = newBaseName
def __filter(self, rangeStart):
return dbUniqueId.objects.filter( basename = self._baseName, seq__gte=rangeStart )
def __filter(self, rangeStart, rangeEnd=MAX_SEQ):
return dbUniqueId.objects.filter( basename = self._baseName, seq__gte=rangeStart, seq__lte=rangeEnd )
def get(self, rangeStart=0, rangeEnd=1000000000):
def get(self, rangeStart=0, rangeEnd=MAX_SEQ):
'''
Tries to generate a new unique id in the range provided. This unique id
is global to "unique ids' database
@ -56,7 +58,7 @@ class UniqueIDGenerator(object):
# First look for a name in the range defined
try:
dbUniqueId.objects.lock()
flt = self.__filter(rangeStart)
flt = self.__filter(rangeStart, rangeEnd)
try:
item = flt.filter(assigned=False)[0]
dbUniqueId.objects.filter(id=item.id).update( owner = self._owner, assigned = True )
@ -69,7 +71,7 @@ class UniqueIDGenerator(object):
seq = rangeStart
logger.debug('Found seq {0}'.format(seq))
if seq > rangeEnd:
return None # No ids free in range
return -1 # No ids free in range
dbUniqueId.objects.create( owner = self._owner, basename = self._baseName, seq = seq, assigned = True)
return seq
except Exception:

View File

@ -180,7 +180,7 @@ class ServiceCacheUpdater(Job):
logger.error(str(e))
# TODO: When alerts are ready, notify this
except:
logger.exception()
logger.exception('Exception')
@transaction.autocommit
def growL2Cache(self, ds, cacheL1, cacheL2, assigned):

View File

@ -40,13 +40,15 @@ class WinDomainOsManager(WindowsOsManager):
super(WinDomainOsManager, self).__init__(environment, values)
if values != None:
if values['domain'] == '':
raise osmanagers.OSManager.ValidationException(_('Must provide a domain!!!'))
raise osmanagers.OSManager.ValidationException(_('Must provide a domain!'))
if values['domain'].find('.') == -1:
raise osmanagers.OSManager.ValidationException(_('Must provide domain in FQDN'))
if values['account'] == '':
raise osmanagers.OSManager.ValidationException(_('Must provide an account to add machines to domain!!!'))
raise osmanagers.OSManager.ValidationException(_('Must provide an account to add machines to domain!'))
if values['account'].find('\\') != -1:
raise osmanagers.OSManager.ValidationException(_('DOM\\USER form is not allowed!'))
if values['password'] == '':
raise osmanagers.OSManager.ValidationException(_('Must provide a password for the account!!!'))
raise osmanagers.OSManager.ValidationException(_('Must provide a password for the account!'))
self._domain = values['domain']
self._ou = values['ou']
self._account = values['account']
@ -85,6 +87,7 @@ class WinDomainOsManager(WindowsOsManager):
for server in servers:
_str = ''
try:
uri = "%s://%s:%d" % ('ldap', str(server.target)[:-1], server.port)
logger.debug('URI: {0}'.format(uri))
@ -95,7 +98,11 @@ class WinDomainOsManager(WindowsOsManager):
l.network_timeout = l.timeout = 5
l.protocol_version = ldap.VERSION3
l.simple_bind_s(who = self._account+'@'+self._domain, cred = self._password)
account = self._account
if account.find('@') is False:
account += '@' + self._domain
l.simple_bind_s(who = account, cred = self._password)
return l
except ldap.LDAPError as e:
@ -111,14 +118,22 @@ class WinDomainOsManager(WindowsOsManager):
super(WinDomainOsManager,self).release(service)
try:
ldap = self.__connectLdap()
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 as e:
log.doLog(service, log.WARN, "Could not remove machine from domain (invalid credentials for {0})".format(self._account), log.OSMANAGER);
# TODO: remove machine from active directory os, under ou or default location if not specified
#_filter = '(&(objectClass=computer)(sAMAccountName=%s$))' % service.friendly_name
try:
# res = l.search_ext_s(base = self._ou, scope = ldap.SCOPE_SUBTREE,
# filterstr = _filter)[0]
l.delete('cn={0},{1}'.format(service.friendly_name, self._ou))
except:
logger.exception('Not found: ')
def check(self):
try: