Programming and Scripting

Programming and Scripting information

New vSphere5 php sample code released

It was a while back I wrote a PHP manual for programming against VMware Virtual Infrastructure 3 (VI3). Assuming most of you run now-a-days vSphere 5.x I finally got around updating the samples :-)

I am using this code myself for my Raspberry PI analog monitor box for vSphere

You can find my basic explanation in the vSphere 5 PHP guide and the sample files in the download section

 

 

 

 

VMware goes PHP :-) yeah!

PHP, my favorite programming language was never really polulair within VMware, but as more and more solutions are focused on cloud computing, VMware needs to address the needs of service providers who ofter do have a lot of code based on PHP.

To endeavor in this PHP world, VMware’s just release the first public beta of the VMware vCloud SDK for PHP. This SDK allows you to interface to VMware vCloud Director.

http://communities.vmware.com/community/beta/vcloudsdkphp

Unofficial PowerShell SDK for VMware View (part 1)

Welcome to this first part of the ‘unofficial SDK for VMware View”. You might wonder, why “unofficial”? Well, simple, VMware View is one of the few products from VMware that does not have an SDK :-( So if you want to script/program/automate anything against VMware View, you are out of luck. That is, officially you can not.

VMware View uses Microsoft ADAM (Active Directory Application Mode) to store its data. After a day of googling and puzzling, I was finally able to figure out how to do some of these ADAM calls myself using visual basic and powershell. In this part 1, I want to share 2 beginning powershell scripts with you.

Script 1 – Show Desktop Pool Properties

$poolname = "type_here_your_pool_Unique ID name"
$connectionbroker = "type_here_your_IP_of_your_connection_broker"
$userName = "type_your_username"
$userPassword = "type_your_password""

$ldaproot = "LDAP://$connectionbroker/CN=$poolname,OU=Applications,DC=vdi,DC=vmware,DC=int"

$directoryEntry = New-Object System.DirectoryServices.DirectoryEntry($ldapRoot)
$directoryEntry.psbase.Username=$userDn
$directoryEntry.psbase.Password=$userPassword

$directoryEntry.get_Properties()

Script2 – Disable/Enable a desktop pool

$poolname = "type_here_your_pool_Unique ID name"
$connectionbroker = "type_here_your_IP_of_your_connection_broker"
$userName = "type_your_username"
$userPassword = "type_your_password"

$ldaproot = "LDAP://$connectionbroker/CN=$poolname,OU=Applications,DC=vdi,DC=vmware,DC=int"

$directoryEntry = New-Object System.DirectoryServices.DirectoryEntry($ldapRoot)
$directoryEntry.psbase.Username=$userName
$directoryEntry.psbase.Password=$userPassword

# 0 = enabled 1 = disabled
$directoryEntry.InvokeSet("pae-Disabled",0)
$directoryEntry.CommitChanges()

Script 2 can be used to make any changes. If you for instance did not want to change the pool state, but it’s displayname, you can just replace the 2nd last line with:

$directoryEntry.InvokeSet("pae-displayname","type_your_new_display_name")


The next thing I want to find out is how to query which desktops are actively being used and the state of each desktop, but I have not been able to figure this our yet. If anyone would like to help out on this project, please contact me!

VMware is really showing of they are eating their own dog food

All the selfpaced labs this year at VMworld are automatically being provisioned on-demand by a custom build solution based on Lab Manager. Using the open API for labmanager they have build a Cloud like environment for all the attendees. The system does not just provision ‘normal’ virtual machines like windows, but entire virtualized ESX environments, so running ESX inside ESX, with SRM and VC server.

Developers…Developers…Developers…

Yes, I agree with mr Steve Ballmer, developers are important and not just to Microsoft, but also to VMware. That is why VMware is organizing the Technology Exchange Developer Day, one day before VMworld starts on August 31st in San Francisco.

More and more people are developing in-house special programs to manage/monitor their Virtual Environments, if you are one of them, this would be your event to go to! There will be sessions about the vSphere API, VDDK API, VIX API and much more.

I personally will be going as well and happy to talk to anyone about the APIs and how to program using them. If you want to know all sessions, you can check out the schedule here

The VMware Technology Exchange Developer Day

Scriptkiddies: Win a Free trip to VMworld Las Vegas or $5000

Want to go to VMworld Las Vegas for free? or just a nice $5000 cash price? Well start writing some cool Powershell scripts that do awesome things against your VMware Infrastructure :-)

VMware’s Powershell extension for VI3 is really great. It combines the power and ease of PowerShell with the long list of API for VI3. So get creative and make some cool script that you can show off to the entire virtualization community!

To help you get started:
Download the VMware Powershell toolkit
VMworld Europe Power Shell presentation
The VMware Powershell blog
The VMware Powershell Forum

The contest if open until august 30th! To enroll into the competition go to: http://www.vmware.com/landing_pages/toolkit_contest.html

Get full control over your ESXi Server

As you probably know ESX 3i is the embedded version of ESX, mainly run from usb flash disks build-in servers from HP, Dell, IBM and FSC, but you can also install this on your own servers. I really love this version as it is so easy and simple and adds extra (and less) functionality to ESX. The main thing about 3i is that the Red Hat service console has been removed and replaced by a small busybox linux version. To keep this service console tiny, 3i comes with build-in hardware monitoring, something a normal ESX server does not have (wish it did). When connecting to a 3i server with your VC client you can see fan speeds and temperatures in your system and you can of course put alarms on them, in case something breaks.

By default the 3i server gives us no access to this small service console, but there are some down sides to this, as certain things can only be done from the service console :-( and until VMware builds those missing functionalities into the VC interface you still need to get yourself console access. In the beta versions of 3i there was an option in the advanced settings, but this has been removed in the final releases. VMware has published a knowledge base article that describes how to get console access (this is not officially supported by VMware). See the KB Article. In short you just hit Alt-F1 and then type in ‘unsupported’. The article also explain how to disable this Tech Support Mode, in case you want to.

Getting console access

Of course you do not want to be in the server room all the time and your server might not have some kind of remote access facility, so the first thing you probably want to do is enable SSH access to your server. (Thanks to Lee for this information, and again this is not supported by VMware)

  • edit /etc/inetd.conf (using vi)
  • remove the # (remark) sign in front of the SSH line
  • kill and restart the inetd process (or just reboot your server)
  • So why do you need console access?
    There are multiple reasons why you want to have console access. One of the most common reasons is that you might want to change HBA driver options. To get better performance out of your Qlogic or Emulex HBA most people increase their queue depth (see for instance VMware 100.00 io blog post). To find out what options you can set on your drivers you can use the command vmkload_mod:

  • display your loaded drivers: vmkload_mod --list
  • display parameters for your driver: vmkload_mod -s /mod/your_driver
  • Another reason why you definitely still need console access (unfortunately) is if you want to use thin provisioned virtual disks, a new feature in ESX, but for some reason not exposed in the VC interface yet (i think because it is still experimental supported). Any virtual disks created via the normal interface are pre-allocated disks, so a 100GB virtual disk will use 100GB on your VMFS. With thin provisioned disks the actual virtual disk file will start very small and only grow when you will actually need the disk space. Note: this only works for Virtual Disks on iSCSI and FC SAN, not NFS!

    With the vmkfstools command you can create new virtual disks as ‘thin’ disks. After you created the disks, you can then use the normal VC interface to add that disk to your VM.

    Creating a 100GB thin disk:
    vmkfstools -c 100G -d thin /vmfs/volumes/san_vmfs/my_vm/thin_disk.vmdk

    If you already have a pre-allocated disk, you can convert it to a thin disk as well. Well it is not really converting, but creating a new copy as thin disk. After you have done that, you will need to remove the old disk from the VM and add the new converted copy.

    ‘convert’ copy a existing virtual disk to thin format:
    vmkfstools -i /vmfs/volumes/san_vmfs/my_vm/large_disk.vmdk -d thin /vmfs/volumes/san_vmfs/my_vm/new_thin_disk.vmdk

    Well I am sure there are more reasons why you still want to ‘play’ on the service console, as I am born with a commodore 64, I always want a command prompt :-)

    VMware releases new Virtual Disk Development Kit 1.0

    VMware has released this week a new toolkit for virtual disk management that is looking very promising.

    The VDDK provides easy access to virtual disk storage. This enables a wide range of solutions including:

  • Creation of virtual machine disk files to store backup of physical images.
  • Read access to virtual disk to enable off-line centralized scanning of virtual machines for anti-virus.
  • Write access to virtual disk to enable off-line centralized patching of virtual machines.
  • Read access to virtual disk to enable off-line software package analysis of virtual machines.
  • The new API supports managing two kinds of disks; Managed Disks (local virtual diskfiles) and Hosted Disk (virtual disk files on you ESX/VMFS systems). This means the API will allow you to access disks remotely and opens a low of new opportunities for companies making virus scanning software, backup, forensic, etc.

    More on the new API:
    The Virtual Disk API Programming guide
    The Virtual Disk Development Kit Homepage

    Script: List all VM’s in a Cluster

    As a result of the SDK Programming Lab at TSX in Nice, I (Jeremy van Doorn) received a request from someone if it was possible to list all Virtual Machines in a Cluster. With the SDK, this can of course be done, but it might not be obvious to everyone just how …

    I had some free time tonight and wrote a very small script that prints the VM’s in the Cluster that you specify. There is one small issue however -> I only have one ESX host in my environment, so I cannot test if the script actually works with multiple hosts, clusters, etc. If you can, please test the script and let me know what you think …

    You can download the script here. (remember: you need the VI Perl Toolkit be able to run this script)

    We have also created a new project page, where we will store more sample scripts that utilize the VI3 Perl Toolkit.

    Yippie!!

    Well normally i try to keep my posts serieus, but sorry I have to express myself tonight. For months I have been wresteling with the VI3 SDK and was only able to write my own apps using PHP and Perl. Which is great, but does also limit what apps I can write for you guys (and girls?).

    At VMworld I went to the session “vmotion – apples and oranges” or some thing like that where an engineer explained what features can be an issue for vmotion between boxes. So I asked what is the easiest was to find out what CPU features your actual servers support. The answer was disappointing, some story about inserting a floppy of cdrom in your physical server, rebooting????? and the small app will tell you. So they actually do expect you to go to all your servers with a actual physical notepad and write all those bits and bytes down and then later compare them. Yeah right.

    Well I am finding out more and more that the VirtualCenter client is by far not using all the actual functionality of the VI3 product. One of the things the SDK does expose is for every physical server what kind of CPU it has and what features are available. You can even compare if one physical server might have different cpus. So, yes I could write a very easy application in Perl (using the perl toolkit) that shows you all the servers and their cpu features, high light the differences and asking you if you want to set a specific cpu feature mask for a group of selected virtual machines. All automated. Writing that application should take me about one hour. But then all you people need to be able to run that application, meaning you need to have perl installed, add some extra needed modules to perl, download the VI perl toolkit, compile the toolkit and run my small perl app. MMmmmm, far from user friendly. One other option would be to create a Virtual Appliance with linux, all modules installed, and you can just run that. That is easy, but come on, for a simple app, you need to download an entire Virtual Appliance?? mmm. a bit of over kill.

    So I have been troubeling with this delimma and every time I think, let’s just write it in Visual Basic. A simple application environment to write win32 application (sorry C#, java, etc all to complicated for me). But how the freak do you program a soap webservice client in VB???? Well no help from VMware, as there are no VB samples and all VMware engineers are diehard C++ programmers, so forget about them touching a low live like Basic. For months I have been trying to get VB using a proper WSDL to work, with no luck…… (even google let me down)

    til now!!!!!!!!!!!!!!!!!!!!!!!!!

    Yippie, I can not express how happy I am. For 3 nights in a row I have been limiting my sleeping time on trying this challange. But I have done it. I have a working VB application running, where I actually understand the source code and wrote every single line of it myself, I have no slow delay problems (as many other people have using the WSDL file). WOW! Why did no one do this before??

    So soon, on www.run-virtual.com, a new application “VmotionIT”, an application that will check physical server diffenrences and automates setting CPU bit mask on all your virtual machines :-)

    I can finally go to sleep now, with a big smile on my face :-)

    Now I can dream of all the other cool win32 apps I can write:

  • EasyESXSetup – An application that allows you to automate adding ESX servers in your VC environment, configure the right network settings, including enabling vmotion networks, nfs setup profiles, etc.
  • VM_DiskReporter – a win32 service that places and updates actual Virtual Machine disk information into VirtualCenter
  • wmkusage – but then win32 :-)
  • mmmm much to do… need to request a holiday i think :-)

    Sweet dreams.

    powered by Virtacore