use of org.geotoolkit.sml.xml.v100.Connection in project ovirt-engine-sdk-java by oVirt.
the class AddVmNic method main.
public static void main(String[] args) throws Exception {
// Create the connection to the server:
Connection connection = connection().url("https://engine40.example.com/ovirt-engine/api").user("admin@internal").password("redhat123").trustStoreFile("truststore.jks").build();
// Locate the virtual machines service and use it to find the virtual machine:
VmsService vmsService = connection.systemService().vmsService();
Vm vm = vmsService.list().search("name=myvm").send().vms().get(0);
// In order to specify the network that the new interface will be connected to, we need to specify the
// identifier of the virtual network interface profile, so we need to find it:
VnicProfilesService profilesService = connection.systemService().vnicProfilesService();
String profileId = null;
List<VnicProfile> profiles = profilesService.list().send().profiles();
for (VnicProfile profile : profiles) {
if (Objects.equals(profile.name(), "mynetwork")) {
profileId = profile.id();
break;
}
}
// Locate the service that manages the NICs of the virtual machine:
VmNicsService nicsService = vmsService.vmService(vm.id()).nicsService();
// Use the "add" method of the disks service to add the disk:
nicsService.add().nic(nic().name("mynic").description("My network interface card").vnicProfile(vnicProfile().id(profileId))).send();
// Close the connection to the server:
connection.close();
}
use of org.geotoolkit.sml.xml.v100.Connection in project ovirt-engine-sdk-java by oVirt.
the class AddVmWithSysprep method main.
public static void main(String[] args) throws Exception {
// Create the connection to the server:
Connection connection = connection().url("https://engine40.example.com/ovirt-engine/api").user("admin@internal").password("redhat123").trustStoreFile("truststore.jks").build();
// Find the service that manages the collection of virtual machines:
VmsService vmsService = connection.systemService().vmsService();
// Create the virtual machine. Note that no Sysprep stuff is needed here, when creating it, it will be used
// later, when starting it:
Vm vm = vmsService.add().vm(vm().name("myvm").cluster(cluster().name("mycluster")).template(template().name("mytemplate"))).send().vm();
// Find the service that manages the virtual machine:
VmService vmService = vmsService.vmService(vm.id());
// Wait till the virtual machine is down, which indicates that all the disks have been created:
while (vm.status() != VmStatus.DOWN) {
Thread.sleep(5 * 1000);
vm = vmService.get().send().vm();
}
// The content of the Unattend.xml file. Note that this is an incomplete file, make sure to use a complete one,
// maybe reading it from an external file:
String unattendXml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + "<unattend xmlns=\"urn:schemas-microsoft-com:unattend\">\n" + " ...\n" + "</unattend>\n";
// Start the virtual machine enabling Sysprep. Make sure to use a Windows operating system, either in the
// template, or overriding it explicitly here. Without that the Sysprep logic won't be triggered.
vmService.start().useSysprep(true).vm(vm().os(operatingSystem().type("windows_7x64"))).send();
// Close the connection to the server:
connection.close();
}
use of org.geotoolkit.sml.xml.v100.Connection in project ovirt-engine-sdk-java by oVirt.
the class CloneVmFromSnapshot method main.
public static void main(String[] args) throws Exception {
// Create the connection to the server:
Connection connection = connection().url("https://engine40.example.com/ovirt-engine/api").user("admin@internal").password("redhat123").trustStoreFile("truststore.jks").build();
// Get the reference to the root of the tree of services:
SystemService systemService = connection.systemService();
// Find the virtual machine:
VmsService vmsService = systemService.vmsService();
Vm vm = vmsService.list().search("name=myvm").send().vms().get(0);
// Find the service that manages the virtual machine:
VmService vmService = vmsService.vmService(vm.id());
// Find the snapshot. Note that the snapshots collection doesn't support search, so we need to retrieve the
// complete list and the look for the snapshot that has the description that we are looking for.
SnapshotsService snapsService = vmService.snapshotsService();
List<Snapshot> snaps = snapsService.list().send().snapshots();
Snapshot snap = null;
for (Snapshot s : snaps) {
if (Objects.equals(s.description(), "mysnap")) {
snap = s;
break;
}
}
// Create a new virtual machine, cloning it from the snapshot:
Vm clonedVm = vmsService.add().vm(vm().name("myclonedvm").snapshots(snapshot().id(snap.id())).cluster(cluster().name("mycluster"))).send().vm();
// Find the service that manages the cloned virtual machine:
VmService clonedVmService = vmsService.vmService(clonedVm.id());
// Wait till the virtual machine is down, as that means that the creation of the disks has been completed:
for (; ; ) {
Thread.sleep(5 * 1000);
clonedVm = clonedVmService.get().send().vm();
if (clonedVm.status() == VmStatus.DOWN) {
break;
}
}
// Close the connection to the server:
connection.close();
}
use of org.geotoolkit.sml.xml.v100.Connection in project ovirt-engine-sdk-java by oVirt.
the class EnableSerialConsole method main.
public static void main(String[] args) throws Exception {
// Create the connection to the server:
Connection connection = connection().url("https://engine40.example.com/ovirt-engine/api").user("admin@internal").password("redhat123").trustStoreFile("truststore.jks").build();
// Find the virtual machine. Note the use of the `all_content` parameter, it is required in order to obtain
// additional information that isn't retrieved by default, like the configuration of the serial console.
VmsService vmsService = connection.systemService().vmsService();
Vm vm = vmsService.list().search("name=myvm").allContent(true).send().vms().get(0);
// Check if the serial console is enabled, and if it isn't then update the virtual machine to enable it:
if (!vm.console().enabled()) {
VmService vmService = vmsService.vmService(vm.id());
vmService.update().vm(vm().console(console().enabled(true))).send();
}
// Close the connection to the server:
connection.close();
}
use of org.geotoolkit.sml.xml.v100.Connection in project ovirt-engine-sdk-java by oVirt.
the class SearchVms method main.
public static void main(String[] args) throws Exception {
// Create the connection to the server:
Connection connection = connection().url("https://engine40.example.com/ovirt-engine/api").user("admin@internal").password("redhat123").trustStoreFile("truststore.jks").build();
// Get the reference to the "vms" service:
VmsService vmsService = connection.systemService().vmsService();
// Use the "list" method of the "vms" service to search the virtual machines that match a search query:
List<Vm> vms = vmsService.list().search("name=MYVM").caseSensitive(false).send().vms();
// Print the virtual machine names and identifiers:
for (Vm vm : vms) {
System.out.printf("%s: %s", vm.name(), vm.id());
}
// Close the connection to the server:
connection.close();
}
Aggregations