Also, there is no option to set
Hostname for the VM.
Code:
/*********************Begin Customize VM*********************/
// Generate the random password, using whatever mechanism you
// prefer:
String password = "cJql3P9XLQG4drCYVG/6Q/";
// You need to know the name of the template, the cluster and
// the VM you are going to create:
String templateName = "rhel2_temp";
String clusterName = "testCluster";
String vmName = "myvm";
// Prepare the data to create the VM from the template:
org.ovirt.engine.sdk.entities.Template templateData = new Template();
templateData.setName(templateName);
org.ovirt.engine.sdk.entities.Cluster clusterData = new Cluster();
clusterData.setName(clusterName);
org.ovirt.engine.sdk.entities.VM vmDataForCreate = new VM();
vmDataForCreate.setName(vmName);
vmDataForCreate.setCluster(clusterData);
vmDataForCreate.setTemplate(templateData);
// Send the request to create the VM to the server:
api.getVMs().add(vmDataForCreate);
String state;
// White till the VM is down (it will be locked for a while):
for (;;) {
state = api.getVMs().get(vmName).getStatus().getState();
if ("down".equals(state)) {
break;
}
Thread.sleep(1000);
}
System.out.println("System Status:"+state);
// Populate parameters for the action to start the VM with cloud-init:
org.ovirt.engine.sdk.entities.User userData = new User();
userData.setUserName("root");
userData.setPassword(password);
Users usersData = new Users();
usersData.getUsers().add(userData);
CloudInit cloudData = new CloudInit();
cloudData.setUsers(usersData);
Initialization initData = new Initialization();
initData.setCloudInit(cloudData);
VM vmDataForStart = new VM();
vmDataForStart.setInitialization(initData);
Action actionData = new Action();
actionData.setVm(vmDataForStart);
// Send the request to start the VM to the server:
api.getVMs().get(vmName).start(actionData);
System.out.println("After : "+api.getVMs().get(vmName).getStatus());
/*********************End Customize VM*********************/
Thanks & Regards,