VMware {code} Community
tos2k
Expert
Expert

vSphere 4 custom tasks

Hi.

Minor question, probably to akutz or VMware Smiley Wink

Creating custom tasks for VI3 in VC was working stable and fine. It still works for vCenter vSphere 4, but the tasks show "XXX ... label not found...."

I have no clue what additional label has to be defined and where. Please help.

No info in docs, release notes or changes either, unfortunately.

Tos2k

0 Kudos
8 Replies
tos2k
Expert
Expert

Common VMware...

What about change management??

Cant be that difficult to post the changes and though the adjustments to do to existing code....

Thx, Tos2k

0 Kudos
jbctech
Contributor
Contributor

Hi Tos2k,

I had the same issue and VMware informed me that you have to use ResourceInfo blocks in VI4. This happens during your plugin registration - for Java, mine looks something like this:

String yourTask = "com.yourcompany.yourproduct.yourTask";

ExtensionResourceInfo eri1 = new ExtensionResourceInfo();

eri1.setLocale("en");

eri1.setModule("task");

KeyValue key1 = new KeyValue();

key1.setKey(yourTask + ".label");

key1.setValue("Your Task Label");

KeyValue key2 = new KeyValue();

key2.setKey(yourTask + ".summary");

key2.setValue("Your Task description summary");

eri1.setData(new KeyValue[] { key1, key2 });

Then just make sure you attach it to your Extension object by doing:

Extension plugin = new Extension();

...

plugin.setResourceList(new ExtensionResourceInfo[] );

I also had to reboot the vCenter server for the change to take effect. You may get away with just restarting the web services, but I'm not sure...

tos2k
Expert
Expert

Hi!

Thx for your reply! Its not that easy, it does not work for me yet. What you write applies to the code I am using, and was using for VI3 too.

Cant you please a complete code snippet, from creating the extension until creating a task that ist visible in the task list!?

What my code does is to define the extension. The possible tasks to each extension is defined on the extensions tasklist property. Do you use that, or do you use the Extension "directly"?

Tos2k

0 Kudos
jbctech
Contributor
Contributor

Correct - you follow the same basic registration as you did with VI3. The difference is you add that block that I specified above and attach it to the Extension. Once you do this, re-register your plugin and stop/start the VMware services (or reboot), it should display the correct strings.

Then, in your plugin code, you do something like this to setup the task (where YOUR_PACKAGE_NAME is the key you used to register, and YOUR_TASK_ID is the "com.netapp.yourcompany.yourTask" from above):

ExtensionManager extMgr = si.getExtensionManager();

Extension myExt = null;

try {

myExt = extMgr.findExtension(YOUR_PACKAGE_NAME);

}

catch (RemoteException e) {

// handle

}

ArrayList<ExtensionTaskTypeInfo> taskId = new ArrayList<ExtensionTaskTypeInfo>();

ExtensionTaskTypeInfo tmp = new ExtensionTaskTypeInfo();

tmp.setTaskID(YOUR_TASK_ID);

taskId.add(tmp);

myExt.setTaskList(taskId.toArray(new ExtensionTaskTypeInfo[http:// taskId.size() |http:// taskId.size() ])); // stupid auto formats should be <bracket> taskId.size() <bracket>

try {

extMgr.updateExtension(myExt);

}

catch (NotFound e) {

// handle

}

catch (RuntimeException e) {

// handle

}

catch (RemoteException e) {

// handle

}

I follow the basic registration as Example 3 in this doc: - the ONLY real difference is I add the ExtensionResourceInfo blocks for my tasks, attach that to the Extension and use the above method to setup the task.

tos2k
Expert
Expert

Thanks for your help. I found out of that. Anyway, its a shame that VMware was not able to post the necessary info on that.

For VI3, the taskID was displayed in the task list, from VI4 this has been changed to a key/value pair defined on the Extension itself.

Even if the sample code for .Net seems to be a little more complex than for Java:

                string myPackage = "com.sample.stuff.Test Bla";
                string yourTask = myPackage + ".taskZero";
                string yourTask0 = myPackage + ".taskOne";
                Extension myExt = new Extension();
                try
                {
                    _service.UnregisterExtension(_service.RetrieveServiceContent(ServiceInstance).extensionManager, myPackage);
                }
                catch { }
                ExtensionTaskTypeInfo tmp = new ExtensionTaskTypeInfo();
                tmp.taskID = yourTask;

                ExtensionTaskTypeInfo tmp0 = new ExtensionTaskTypeInfo();
                tmp0.taskID = yourTask0;
                
                myExt.taskList = new ExtensionTaskTypeInfo[] { tmp, tmp0 };

                ExtensionResourceInfo eri1 = new ExtensionResourceInfo();
                eri1.locale = "en";
                eri1.module = "task";
                KeyValue key1 = new KeyValue();
                key1.key = yourTask + ".label";
                key1.value = "Your Task Label";
                KeyValue key2 = new KeyValue();
                key2.key = yourTask + ".summary";
                key2.value = "Your Task description summary";
                KeyValue key3 = new KeyValue();
                key3.key = yourTask0 + ".label";
                key3.value = "Another Task Label";
                KeyValue key4 = new KeyValue();
                key4.key = yourTask0 + ".summary";
                key4.value = "Another Task description summary";
                eri1.data = new KeyValue[] { key1, key2, key3, key4 };
                myExt.resourceList = new ExtensionResourceInfo[]{ eri1 };

                myExt.description = new Description();
                myExt.description.label = "Your Label";
                myExt.description.summary = "Your summary";

                myExt.key = myPackage;
                myExt.version = "1.0.0";

                ExtensionClientInfo eci = new ExtensionClientInfo();
                eci.company = "Here we go";
                eci.description = new Description();
                eci.description.label = "Come on";
                eci.description.summary = "Your Summ";
                eci.type = "win32";
                eci.version = "1.0.0";
                eci.url = "http://www.mydigitallife.info/";
                myExt.client = new ExtensionClientInfo[] { eci };

                myExt.lastHeartbeatTime = DateTime.Now;
               _service.RegisterExtension(_service.RetrieveServiceContent(ServiceInstance).extensionManager, myExt);

               ManagedObjectReference dc1 = new ManagedObjectReference();
               dc1.type = "Datacenter";
               dc1.Value = "datacenter-2";

               _service.CreateTask(_service.RetrieveServiceContent(ServiceInstance).taskManager, dc1,
    yourTask, "ITSME", true, null);
               _service.CreateTask(_service.RetrieveServiceContent(ServiceInstance).taskManager, dc1,
    yourTask0, "ITSYOU", true, null);

Tos2k

0 Kudos
tos2k
Expert
Expert

Changes from VI3 to VI4 documented in this thread Smiley Wink

0 Kudos
kienchuoi
Contributor
Contributor

Hi,

I was looking for a way to customize the vCenter task and thanks to your answer, I could make it work.

I would also like to know if it is possible to custom the message of one task in case that task ended with error. e.g. if I do VimPortType#setTaskState(taskRef, TaskInfoState.error, message, fault).

Until now I got only error message associated to the pre-defined MethodFault.

Thanks for any help.

0 Kudos
vcs-vmware
Contributor
Contributor

Hi Kienchuoi,

Were you able to set description of the task on the fly? I did see a function called  - SetTaskDescription, but couldn't get it to work.

Did you try it out?

If it succeeded, could you please share your code? I am trying it out in parallel. If it works, i will post the answer on the forum.

thanks

0 Kudos