Having trouble doing this, likely because I don't understand quite what I'm doing. From the UI, you can associate a profile with a cluster. Then, you can right-click on a host within the cluster and do "Apply Profile". Works great, and requires no extra inputs. From the perl SDK, it's not so easy.
From the docs, it looks like it's two steps: (a) ExecuteHostProfile followed by (b) ApplyHostConfig_Task.
So, my code looks like this. First I look up the profile, by name:
die unless defined $profile;
then I apply it like so:
my $res = $profile->ExecuteHostProfile(host => $host);
my $taskRef = $hostProfileManager->ApplyHostConfig_Task(host => $host, configSpec => $res->configSpec);
Using the 4.x API, this fails with "Cannot apply the host configuration". If I take the contents of $res->requireInput (which contains two items) and feed it back into ExecuteHostProfile as a "deferredParam", the resulting configuration doesn't seem to change... I continually get the same two items back in $res->requireInput, regardless how many times I feed them back tino ExecuteHostProfile.
If I use the 5.x API in order to get access to the "userInput" parameter in the ApplyHostConfig_Task call, and pass the same $res->requireInput via that parameter like so:
my $taskRef = $hostProfileManager->ApplyHostConfig_Task(host => $hostObject, configSpec => $res->configSpec, userInput => $res->requireInput);
I get this instead:
Can't call method "serialize" on unblessed reference at .../vsphere-sdk-5.0/lib/VMware/share/VMware/VICommon.pm line 2435.
Can anybody shed some light on how this is supposed to work, and what I might be doing wrong?
In case anybody else runs into this, it appears to be a known issue (i.e. the code presented in the original post isn't wrong; there's a bug in VMware).
johnklassa,
were you able to overcome the issue? same issue is seen when i run ApplyHostConfig_Task and GenerateConfigTaskList.
Thanks
Nope, no resolution... Still waiting on VMware engineering to come up with a fix.
Have you reported this to VMware? apart from posting it in forum?
Thanks
Yes. I have an "official" case open, and it's being worked...
This issue is with vSphere SDK for Perl only right? because from PowerCLI and vSphere Client, i am able apply the profile. do we have any workaround? ( on i think of using powerCLI to apply the profile)
Thanks
I don't know where all the problem occurs, as I haven't tried anything but perl. So, I'm not aware if there is (or isn't) a workaround. VMware suggested I use Java, but the software environment in which I need this functionality isn't well suited to it.
Are you checking the 'status' property of your ProfileExecuteResult. The configSpec will only be valid if it's 'success'. You're probably getting 'needInput' as the status.
--Just saw you hit that, let me look into a bit more.
Ok, I found the problem.
In the WSDL, KeyAnyValue's property 'value' is defined as xsd:anyType, but is not defined as an array. Similarly, the KeyAnyValue class in the Perl toolkit has the same configuration.
The host profile is spitting out KeyAnyValue with value => array in several places. The first I found was in the SNMP Agent setting (community for example). The next I found was in the NetworkProfile nicNames. If you edit these in the HostProfile by blanking them out, they won't populate in the SOAP data as an array. However, that's probably not the right fix for this.
You may have this problem with the other SDK kits as well, depends on how they handle anyType as an array (which isn't specified as an array in the VIM WSDL).
As for why this doesn't occur in PowerCLI, could be how they handle that serialization vs Perl's toolkit. I'll leave it upto someone who knows SOAP/WSDL better than I to debate on the proper syntax for xsd:anyType with no minOccurs/maxOccurs values. ![]()
Ok, I mucked around with this for a bit.
I think there two issues here:
1. VIM25Stub.pm defines KeyAnyValue->value as a single value. As a very unsupported workaround, the KeyAnyValue definition in VIM25Stub.pm was changed to:
I used a simple Login Banner + Advanced Configuration Option enabled HostProfile with these changes successfully.
I've attached the script I used with the simple profile setting. To run it, you'll need to CPAN install 'Sub::Override'. It's a source module IIRC, so you can copy and paste it into a module file in your path if CPAN isn't an option.
> profiletest.pl --username=administrator --password=****** --server=172.16.254.50 --host=vlab5-esx-03.vlab5.local --profile=VLAB5-P2
I don't check the task status in the script, I did validations visually in the vCenter Client UI.
I'm not sure it will be of much use, particularly with the modification to the VIM25Stub.pm file. Since it's going to require some more robust determination of the xsi:type in the serialization functions in the toolkit, it will need some testing before being production worthy.
Also, just to feed some information. I did manage to get one of my hosts in a state where I get general errors anytime I try to apply a HostProfile (even a simple one). I can't seem to recover it, and it was the result of a applying a very complex HostProfile with some input answers. It's possible this xsi:type issue caused the problem, but I feel the HostProfile system shouldn't be that easily laid out. It may be a related bug.
Does anyone know if this bug ever got resolved? I am trying to do the same thing (roughly) and am getting the same serialize error.
T.
