pyad icon indicating copy to clipboard operation
pyad copied to clipboard

Could not rename a computer name

Open eric-lich opened this issue 11 years ago • 15 comments

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.

eric-lich avatar Aug 07 '14 02:08 eric-lich

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

zakird avatar Aug 07 '14 03:08 zakird

things that would also be helpful would be:

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

zakird avatar Aug 07 '14 03:08 zakird

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

eric-lich avatar Aug 07 '14 03:08 eric-lich

"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 avatar Aug 07 '14 03:08 zakird

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

zakird avatar Aug 07 '14 03:08 zakird

Can you try installing 0.5.12 from github and try again?

zakird avatar Aug 07 '14 03:08 zakird

ok

eric-lich avatar Aug 07 '14 03:08 eric-lich

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 "<COMObject ADsNameSpaces>", 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)

eric-lich avatar Aug 07 '14 03:08 eric-lich

Does the computer actually get renamed?

zakird avatar Aug 07 '14 03:08 zakird

Yes, renamed.

eric-lich avatar Aug 07 '14 03:08 eric-lich

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

zakird avatar Aug 07 '14 03:08 zakird

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.

zakird avatar Aug 07 '14 03:08 zakird

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

eric-lich avatar Aug 07 '14 03:08 eric-lich

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

eric-lich avatar Aug 07 '14 03:08 eric-lich

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

Kipjr avatar Oct 19 '17 00:10 Kipjr