Hi there
I'm writing a wrapper API around the VCD API, and so far have (eventually, obvious documentation rant etc) figured out how to get the basic listings of Organizations, vApps, VMs and such. I'm now working on instantiating a vApp from a template. This is working, using this code:
InstantiateVAppTemplateParamsType T = new InstantiateVAppTemplateParamsType();
Hi,
Your Vapp might not have been completely created.
Try waiting until the Vapp gets created completely. Then fetch the Vapp again using the getVappByReference/Id methods and do the update.
Regards,
Rajesh Kamal.
Vapp NewVApp = this.VCDVdc.InstantiateVappTemplate(T);
// waiting for the vapp task to complete.
List<Task> tasks = NewVApp.Tasks[0].WaitForTask(0);
// try fetching the vapp again and then do the update.
Hi Rajesh
Thanks for getting back to me, I've been playing with this all morning but still to no avail. I've tried re-fetching the vApp as follows:
InstantiateVAppTemplateParamsType T = new InstantiateVAppTemplateParamsType();
T.AllEULAsAccepted = true;
T.AllEULAsAcceptedSpecified = true;
T.Description = "Auto-created vApp FTW";
T.name = Name;
T.deploy = true;
T.deploySpecified = true;
T.IsSourceDelete = false;
T.IsSourceDeleteSpecified = true;
T.powerOn = false;
T.powerOnSpecified = true;
ReferenceType RT = new ReferenceType();
RT.href = VAppTemplates[0].VCDTemplate.href;
RT.name = VAppTemplates[0].VCDTemplate.name;
RT.type = VAppTemplates[0].VCDTemplate.type;
//RT.VCloudExtension = VAppTemplates[0].VCDTemplate.VCloudExtension;
T.Source = RT;
// Instantiate template
Vapp NewVApp = this.VCDVdc.InstantiateVappTemplate(T);
// Wait for completion, don't really know what I'm doing here so bodge stuff until it works
TaskType TT = NewVApp.Resource.Tasks.Task[0];
ReferenceType R = new ReferenceType() { href = TT.href, name = String.Empty, type = TT.type };
Task Tsk;
do { Tsk = Task.GetTaskByReference(_VCDClient, R); }
while (Tsk.Resource.status == TaskStatusType.running);
// Get the vApp
Vapp V = Vapp.GetVappByReference(_VCDClient, _VCDVdc.GetVappRefByName(Name));
Console.WriteLine("Name: " + V.Resource.name);
But still get the exception that implies I need to reload some dictionary somehow:
System.Collections.Generic.KeyNotFoundException: The given key was not present in the dictionary.
Ah, getting somewhere. If I go all the way back to the Organization level and re-run the getter methods, I find the vApp, but going directly back to the getVAppByReference() method of the Vdc does not seem to re-cache but instead load from dictionary. This now works:
InstantiateVAppTemplateParamsType T = new InstantiateVAppTemplateParamsType();
The rename reckons it works, but it actually doesn't. I suspect this is a different issue though, so I'll start looking at that now.
Thanks for your help.
O.
Hi,
I faced the same issue today (Java SDK). And in my opinion it is definitely a bug. There should be an option to refresh the vDC after creation of a Vapp.
Any chance to get an update?
Hi,
You can refresh your vdc object by just making a Vdc.getVdcByReference() or Vdc.getVdcById() methods.
Ex:
// Create the vapp.
Vapp vapp = vdcObj.InstantiateVappTemplate();
// Refreshing the vdc
vdcObj = Vdc.getVdcByReference(client, vdcObj.getReference()) or Vdc.getVdcById(client, vdcObj.getResource().getId());
Regards,
Rajesh Kamal
Hi Rajesh,
thanks a lot, works. Would be nice, to have a vhc.Refresh(); in future.