Notifiying Users in vCAC via ‘Recent Events’

During long running provisionings you may want to inform the user about the states you are currently processing. In my previous blog post I showed how to add a text to the ‘CurrentTask’. But maybe you want to give the user a little bit more information where the status field does not provide enough space. Especially in case of a provisioning failure you may want to give a more detailed explanation that just telling that the machine will be destroyed. With a few lines of PowerShell and the vCAC management context once more to the rescue you can achieve this easily:

# $m is the MgmtContext (repository)
PS > $m.GetType();

IsPublic IsSerial Name                                     BaseType
-------- -------- ----                                     --------
True     False    ManagementModelEntities                  DynamicOps.Repository.RepositoryServiceContext

# Create a new user log object
PS > $ul = New-Object DynamicOps.ManagementModel.UserLog;
PS > $ul.Type = [DynamicOps.ManagementModel.UserLogSeverity]::Info;
PS > $ul.Timestamp = [datetime]::Now;
PS > $ul.UserName = 'SHAREDOP\vcacservice';
PS > $ul.Message = "Hello, world!";
PS > $m.AddToUserLogs($ul);
PS > $m.SaveChanges();

Descriptor                        Headers                                                  StatusCode Error
----------                        -------                                                  ---------- -----
System.Data.Services.Client.En... {[DataServiceVersion, 1.0;], [...                               201
PS > $ul

UserLogId         : 1418
UserName          : SHAREDOP\vcacservice
Timestamp         : 11/3/2013 8:36:32 PM
Type              : 0
Message           : Hello, world!
ProvisioningGroup :

PS > $m.Detach($ul);

In case you wonder: yes, you can set the datetime to a future date and you can also delete log entries you no longer need. For exameple when you have maintainance on a vCenter cluster you could write a log entry to all affected users who have machines on that resource. Later on when normal service operation has been resumed you delete the old log entry and insert a new one with an updated message.

PS > $m.UserLogs |? UserLogId -eq 1234;

UserLogId         : 1234
UserName          : SHAREDOP\someEndUser
Timestamp         : 10/19/2013 11:27:06 AM
Type              : 0
Message           : Machine DUB100139: Memory Change, it is now [0] MB
ProvisioningGroup :

PS > $m.DeleteObject($ul)
PS > $m.SaveChanges()

Descriptor                        Headers                                                  StatusCode Error
----------                        -------                                                  ---------- -----
System.Data.Services.Client.En... {[DataServiceVersion, 1.0;], [...                               204


  1. […] Another side effect of this approach is the fact, that you might run into a situation where the request fails as you might not find enough space to place a machine. From a usability standpoint this is changing the behaviour of vCAC as the user does not get an error message while submitting the request (but only afterwards). You can work around this by writing a message into the user log as described in Notifiying Users in vCAC via ‘Recent Events’. […]

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: