Friday, April 10, 2009

Grab LDAP uidNumber from VBScript

I had a need to grab a user's uidNumber from a Sun LDAP server on a Windows machine using VBScript. After fiddling around, here's the function:

Function getLDAPUserUIDNumber(username)
Dim conn
Dim rs
Dim uidNumber
Dim strSearch

strSearch = "(uid=" & username & ")"

Set conn = CreateObject("ADODB.Connection")
conn.Provider = "ADSDSOObject"
conn.Open "ADs Provider", "cn=Directory Manager", "xxxxx"

Set rs = conn.Execute( _
";" _
& strSearch & ";uidNumber;subtree")

While Not rs.EOF
uidNumber = rs.Fields("uidNumber").Value
rs.MoveNext
Wend

conn.Close

getLDAPUserUIDNumber = uidNumber
End Function

Wednesday, April 1, 2009

Manually moving Virtual Center from one data store to another

If Virtual Center is up and running, moving VM's from one storage location to another (with or without vmotion) is fairly straight forward. What if it's Virtual Center you want to move between stores? This applied to us today as our VCenter VM was on local storage and we needed to move it to shared storage. Why? So it can be HA'd and vmotion'd in the future. By the way, this article assumes you have access to the service console so this won't work on ESXi.

First, take the Virtual Center VM down and ssh to the service console of the ESX host.

For reference in our environment:
VM Name: gsbvcenter
Source Data Store: gsbhesx06-localStore0
Destination Data Store: vm_vol17
ESX host: gsbhesx06

Step 1 - Move the vm's disk to the new data store:
mkdir vmfs/volumes/vm_vol17/gsbvcenter/gsbvcenter.vmdk
vmkfstools -i /vmfs/volumes/gsbhesx06-localStore0/gsbvcenter/gsbvcenter.vmdk /vmfs/volumes/vm_vol17/gsbvcenter/gsbvcenter.vmdk

Step 2 - Relocate all the other vm related files to the new storage location (cp command works).

Step 3 – Find the UUID's of the data store volumes:

[root@gsbhesx06 volumes]# ls -l /vmfs/volumes
total 9216
drwxrwxrwt 1 root root 1120 Apr 1 06:30 47b9e964-f71a7fb8-7f02-001d09677bf6
drwxrwxrwt 1 root root 980 Apr 1 06:44 47b9ee61-9d49a8b5-f812-001d09677bf6
drwxrwxrwt 1 root root 980 Apr 1 11:01 47c72a83-4613e78e-49bd-001d09677bf6
drwxrwxrwt 1 root root 980 Apr 1 06:29 47cf26a2-9041b567-6fc1-001d09677bf6
drwxrwxrwt 1 root root 980 Apr 1 06:44 48333fb2-9cfcd611-2241-001d09677bf6
drwxr-xr-t 1 root root 2240 Apr 1 06:07 4963cc67-9a2121e0-17a0-001ec9ad3118
drwxrwxrwt 1 root root 1680 Apr 1 06:24 49652475-6b20d5dd-c389-001ec9ad3118
drwxrwxrwt 1 root root 2800 Mar 13 03:51 49652718-816b40f4-f300-001ec9ad3118
drwxrwxrwt 1 root root 2100 Apr 1 13:03 49acc4b9-3e289c76-d32d-001ec9ad317c
lrwxr-xr-x 1 root root 35 Apr 1 14:07 gsbhesx06-localStore0 -> 47b9e964-f71a7fb8-7f02-001d09677bf6
lrwxr-xr-x 1 root root 35 Apr 1 14:07 vm-gsbhav0v -> 48333fb2-9cfcd611-2241-001d09677bf6
lrwxr-xr-x 1 root root 35 Apr 1 14:07 vm-gsblgh1 -> 47cf26a2-9041b567-6fc1-001d09677bf6
lrwxr-xr-x 1 root root 35 Apr 1 14:07 vm-gsblnxam01 -> 47c72a83-4613e78e-49bd-001d09677bf6
lrwxr-xr-x 1 root root 35 Apr 1 14:07 vm-gsbrdb01 -> 47b9ee61-9d49a8b5-f812-001d09677bf6
lrwxr-xr-x 1 root root 35 Apr 1 14:07 vm_vol14 -> 49652475-6b20d5dd-c389-001ec9ad3118
lrwxr-xr-x 1 root root 35 Apr 1 14:07 vm_vol15 -> 49652718-816b40f4-f300-001ec9ad3118
lrwxr-xr-x 1 root root 35 Apr 1 14:07 vm_vol16 -> 4963cc67-9a2121e0-17a0-001ec9ad3118
lrwxr-xr-x 1 root root 35 Apr 1 14:07 vm_vol17 -> 49acc4b9-3e289c76-d32d-001ec9ad317c

Take note of the symlinks from that.

Step 4 – Modify the new vmx configuration to point to the new data store. Edit (using vi) the vmx file (gsbvcenter.vmx in our case) and look for the following:

sched.swap.derivedName = "/vmfs/volumes/49acc4b9-3e289c76-d32d-001ec9ad317c/gsbvcenter/gsbvcenter-b00a2b32.vswp"

And change the UUID in there to reflect the UUID of the new volume you just moved the files to. Save and exit.

Step 5 – Unregister and register the VM's

vmware-cmd –l

Verify the VM is in fact registered on that host.

Unregister that VM from the host:
vmware-cmd –s unregister /vmfs/volumes/47b9e964-f71a7fb8-7f02-001d09677bf6/gsbvcenter/gsbvcenter.vmx

Register the new one (new UUID path):
vmware-cmd –s register /vmfs/volumes/49acc4b9-3e289c76-d32d-001ec9ad317c /gsbvcenter/gsbvcenter.vmx

vmware-cmd –l to verify the change has been made

Step 5 – Power on the VM and answer the question

http to the ESX host and login locally.
Power on the VM
Answer "keep" to the question regarding the machine file locations

I know there's a way to power on and answer the question from the command line; we didn't figure it out completely. At this point you should be able to connect to the VC server from the client and do whatever you want. We then vmotion'd the VM to another host.