zakird / pyad

Python Active Directory Tools | *Not actively maintained*
http://zakird.github.io/pyad/
176 stars 72 forks source link

Could not rename a computer name #27

Open eric-lich opened 10 years ago

eric-lich commented 10 years ago

Code: computer = adcomputer.ADComputer.from_cn('WS-490')

computer.rename('WS-4900')

Traceback (most recent call last): File "C:\Users\Administrator\Desktop\utility\test.py", line 25, in computer.rename('WS-4900') File "C:\Python27\lib\site-packages\pyad\adobject.py", line 419, in rename parent = self.parent_container File "C:\Python27\lib\site-packages\pyad\adobject.py", line 517, in __get_parent_container q.adjust_pyad_type() File "C:\Python27\lib\site-packages\pyad\adobject.py", line 512, in adjust_pyad_type raise Exception("Unkown type. Adjustment not possible.") Exception: Unkown type. Adjustment not possible.

zakird commented 10 years ago

Hrm. Is the computer in an OU or what's its actual DN?

zakird commented 10 years ago

things that would also be helpful would be:

print ADObject.from_dn(computer.parent_container_path, options = computer._make_options()).type

eric-lich commented 10 years ago

This computer DN is: CN=WS-490,CN=Computers,DC=dc2k8,DC=wingra,DC=com. And return type is "container"

zakird commented 10 years ago

"In a default installation of an Active Directory domain, user accounts, computer accounts, and groups are put in CN=objectclass containers instead of being put in a more desirable organizational unit class container. Similarly, user accounts, computer accounts, and groups that were created by using earlier-version APIs are put in the CN=Users and CN=computers containers."

zakird commented 10 years ago

This is fixable easily enough, will post a patch in a minute to test.

zakird commented 10 years ago

Can you try installing 0.5.12 from github and try again?

eric-lich commented 10 years ago

ok

eric-lich commented 10 years ago

After upgraded, Computer name renamed, but show some error:

File "C:\Python27\lib\site-packages\pyad\adobject.py", line 442, in rename self.__set_gc_adsi_obj() File "C:\Python27\lib\site-packages\pyad\adobject.py", line 215, in __set_gc_adsi_obj self._gc_adsi_obj = self.adsi_provider.GetObject('', path) File "", line 2, in GetObject pywintypes.com_error: (-2147352567, 'Exception occurred.', (0, u'Active Directory', u'There is no such object on the server.\r\n', None, 0, -2147016656), None)

zakird commented 10 years ago

Does the computer actually get renamed?

eric-lich commented 10 years ago

Yes, renamed.

zakird commented 10 years ago

Is the GC on a different server than the DC to which you're connected?

zakird commented 10 years ago

What it looks like is that this isn't propagating to the global catalog quickly enough and when pyad attempts to get the new object, it fails because the GC still thinks it's named the old thing. There isn't a ton you can do here other than try to allow some time to for it to propagate. There's a small sleep in the code base that should help this along, but isn't high enough in this particularly environment.

Not a great solution other than sleep and try again.

eric-lich commented 10 years ago

My test env is Windows server 2008R2 Enterprise, Only one machine(as Domain server).

eric-lich commented 10 years ago

I try to delay the time(in rename method: time.sleep) to 10s, error is the same one.

Kipjr commented 7 years ago

Is there a solution to this problem? It also happens with the function move.