From Example of XenServer API, We Know, if i want to create VM ,must to create VBD.
in VBD modle , if we want to to CreateVM from ISO,then,VDI is must to achieve.
for example :
in "TestBase.java", we create a function :
protected static VDI getAllVDIRecords() throws Exception
{
Mapall_vdi = VDI.getAllRecords(connection);
for(Map.Entry e : all_vdi.entrySet()){
if(e.getKey().getUuid(connection).equals("2bfa10aa-24fb-4942-9f18-776ac5a04ce0")){ // this is uuid is my file one of SR
return e.getKey();
}
}
throw new Exception("No Windows templates found!");
}
in “CreateVM.java” create a sentence :
VDI vdi = getAllVDIRecords();
then ....
modify the function of "makeCDDrive" :
private static VBD makeCDDrive(VM vm,VDI vdi) throws Exception
{
VBD.Record vbdrecord = new VBD.Record();
vbdrecord.VM = vm;
vbdrecord.VDI = vdi; //we definde from getAllVDIRecords function of TestBase.java
// vbdrecord.VDI = null;
vbdrecord.userdevice = "1";
vbdrecord.mode = Types.VbdMode.RO;
vbdrecord.type = Types.VbdType.CD;
vbdrecord.empty = false; //this is important,only “false”,we can upload the iso
return VBD.create(connection, vbdrecord);
}