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 Comment »