Xenserver 5.5 Api Cheat Sheet

ADVERTISEMENT

XenServer 5.5 API Cheat Sheet
The code snippets below does not include error handling and asynchronous API calls.
Logging into Xenserver
Connection connection =
new Connection(new
URL(" + xenserverHostname));
Session.loginWithPassword( connection,
xenserverUsername, xenserverPassword,
xenserverApiversion);
//
default is null
try
{
// xenserver api goes here
}
finally
{
Session.logout(connection);
}
Identify the machine to clone
// namelabelToClone = "CentOS_5.3"
// find a halted real virtual machine that match the specified name label.
Set<VM> refVMs = VM.getByNameLabel(connection, namelabelToClone);
if
(refVMs.size() == 1) {
VM vm = refVMs.iterator().next();
VM.Record record = vm.getRecord(connection);
if
(!record.isATemplate &&
!record.isControlDomain &&
record.powerState == Types.VmPowerState.HALTED) {
return
vm;
}
}
Clone a new machine
// clone machine by name lable
VM newVM = vm.createClone(getConnection(), namelabel);
newVM.setNameDescription(
getConnection(),
"Cloned " + namelabelToClone + " at " +
new
Date().toString());

ADVERTISEMENT

00 votes

Related Articles

Related forms

Related Categories

Parent category: Education
Go
Page of 4