use of org.ovirt.engine.sdk4.types.Cluster in project ovirt-engine-sdk-java by oVirt.
the class FollowVmLinks 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 service that manages virtual machines:
VmsService vmsService = connection.systemService().vmsService();
// Find the virtual machine:
Vm vm = vmsService.list().search("name=myvm").send().vms().get(0);
// When the server returns a virtual machine it will return links to related objects, like the cluster,
// template and permissions something like this:
//
// <link href="/api/vms/123/permissions" rel="permissions"/>
// ...
// <cluster id="123" href="/api/clusters/123"/>
// <template id="456" href="/api/templates/456"/>
//
// The SDK provides a "followLink" method that can be used to retrieve the complete content of these related
// objects.
Cluster cluster = connection.followLink(vm.cluster());
Template template = connection.followLink(vm.template());
List<Permission> permissions = connection.followLink(vm.permissions());
// Now we can use the details of the cluster, template and permissions:
System.out.printf("cluster: %s\n", cluster.name());
System.out.printf("template: %s\n", template.name());
for (Permission permission : permissions) {
System.out.printf("role: %s\n", permission.role().id());
}
// Close the connection to the server:
connection.close();
}
use of org.ovirt.engine.sdk4.types.Cluster in project ovirt-engine-sdk-java by oVirt.
the class ImportGlanceImage 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 root of the services tree:
SystemService systemService = connection.systemService();
// Find the Glance storage domain that is available for default in any oVirt installation:
StorageDomainsService sdsService = systemService.storageDomainsService();
StorageDomain sd = sdsService.list().search("name=ovirt-image-repository").send().storageDomains().get(0);
// Find the servie that manages the Glance storage domain:
StorageDomainService sdService = sdsService.storageDomainService(sd.id());
// Find the service that manages the images available in that storage domain:
ImagesService imagesService = sdService.imagesService();
// The images service doesn't support search, so in roder to find an image we need to retrieve all of them and
// do the filtering explicitly:
List<Image> images = imagesService.list().send().images();
Image image = null;
for (Image i : images) {
if (Objects.equals(i.name(), "CirrOS 0.3.4 for x86_64")) {
image = i;
break;
}
}
// Find the service that manages the image that we found in the previous step:
ImageService imageService = imagesService.imageService(image.id());
// Import the image:
imageService.import_().importAsTemplate(true).template(template().name("mytemplate")).cluster(cluster().name("mycluster")).storageDomain(storageDomain().name("mydata")).send();
// Close the connection to the server:
connection.close();
}
use of org.ovirt.engine.sdk4.types.Cluster in project ovirt-engine-sdk-java by oVirt.
the class RegisterVm method main.
public static void main(String[] args) throws Exception {
// Create the connection to the server:
Connection connection = connection().url("https://engine/ovirt-engine/api").user("admin@internal").password("redhat123").trustStoreFile("truststore.jks").build();
// Get the reference to the "StorageDomains" service:
StorageDomainsService storageDomainsService = connection.systemService().storageDomainsService();
// Find the storage domain with unregistered VM:
StorageDomain sd = storageDomainsService.list().search("name=mysd").send().storageDomains().get(0);
// Locate the service that manages the storage domain, as that is where the action methods are defined:
StorageDomainService storageDomainService = storageDomainsService.storageDomainService(sd.id());
// Locate the service that manages the VMs in storage domain:
StorageDomainVmsService storageDomainVmsService = storageDomainService.vmsService();
// Find the the unregistered VM we want to register:
List<Vm> unregisteredVms = storageDomainVmsService.list().unregistered(true).send().vm();
Vm vm = null;
for (Vm x : unregisteredVms) {
if ("myvm".equals(x.name())) {
vm = x;
break;
}
}
// Locate the service that manages virtual machine in the storage domain, as that is where the action methods
// are defined:
StorageDomainVmService storageDomainVmService = storageDomainVmsService.vmService(vm.id());
// Register the VM into the system:
storageDomainVmService.register().vm(vm().name("exported_myvm")).cluster(cluster().name("mycluster")).vnicProfileMappings(vnicProfileMapping().sourceNetworkName("mynetwork").sourceNetworkProfileName("mynetwork").targetVnicProfile(vnicProfile().name("mynetwork"))).reassignBadMacs(true).send();
// Close the connection to the server:
connection.close();
}
use of org.ovirt.engine.sdk4.types.Cluster in project ovirt-engine-sdk-java by oVirt.
the class AddIndependentVm 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 "clone" parameter of the "add" method to request that the
// disks of the new virtual machine are independent of the template.
vmsService.add().vm(vm().name("myvm").cluster(cluster().name("mycluster")).template(template().name("mytemplate"))).clone_(true).send();
// Close the connection to the server:
connection.close();
}
use of org.ovirt.engine.sdk4.types.Cluster in project ovirt-engine-sdk-java by oVirt.
the class AddVm 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 "add" method to create a new virtual machine:
vmsService.add().vm(vm().name("myvm").cluster(cluster().name("mycluster")).template(template().name("Blank"))).send();
// Close the connection to the server:
connection.close();
}
Aggregations