From example of xenserver API, we know, if I want to create Vm, must to create vbd.
In vbd modle, if we want 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 = getallvdirecords ();
Then ....
Modify the function of "makecddrive ":
Private Static vbd makecddrive (Vm, 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 );
}