use of org.openmuc.j60870.Connection in project ovirt-engine-sdk-java by oVirt.
the class UpdateDataCenter 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 data centers service:
DataCentersService dcsService = connection.systemService().dataCentersService();
// Retrieve the description of the data center:
DataCenter dc = dcsService.list().search("name=mydc").send().dataCenters().get(0);
// In order to update the data center we need a reference to the service that manages it, then we can call the
// "update" method passing the update:
DataCenterService dcService = dcsService.dataCenterService(dc.id());
dc = dcService.update().dataCenter(dataCenter().description("Updated description")).send().dataCenter();
// Print the description of the result of the update:
System.out.printf("%s: %s", dc.name(), dc.description());
// Close the connection to the server:
connection.close();
}
use of org.openmuc.j60870.Connection in project ovirt-engine-sdk-java by oVirt.
the class UpdateQuotaLimits 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 reference to the root of the tree of services:
SystemService systemService = connection.systemService();
// Find the data center and the service that manages it:
DataCentersService dcsService = systemService.dataCentersService();
DataCenter dc = dcsService.list().search("name=mydc").send().dataCenters().get(0);
DataCenterService dcService = dcsService.dataCenterService(dc.id());
// Find the storage domain and the service that manages it:
StorageDomainsService sdsService = systemService.storageDomainsService();
StorageDomain sd = sdsService.list().search("name=mydata").send().storageDomains().get(0);
StorageDomainService sdService = sdsService.storageDomainService(sd.id());
// Find the quota and the service that manages it. Note that the service that manages the quota doesn't support
// search, so we need to retrieve all the quotas and filter explicitly. If the quota doesn't exist, create it.
QuotasService quotasService = dcService.quotasService();
List<Quota> quotas = quotasService.list().send().quotas();
Quota quota = null;
for (Quota q : quotas) {
if (Objects.equals(q.id(), "myquota")) {
quota = q;
break;
}
}
if (quota == null) {
quota = quotasService.add().quota(quota().name("myquota").description("My quota").clusterHardLimitPct(20).clusterSoftLimitPct(80).storageHardLimitPct(20).storageSoftLimitPct(80)).send().quota();
}
QuotaService quotaService = quotasService.quotaService(quota.id());
// Find the quota limits for the storage domain that we are interested on:
QuotaStorageLimitsService limitsService = quotaService.quotaStorageLimitsService();
List<QuotaStorageLimit> limits = limitsService.list().send().limits();
QuotaStorageLimit limit = null;
for (QuotaStorageLimit l : limits) {
if (Objects.equals(l.id(), sd.id())) {
limit = l;
break;
}
}
// If that limit exists we will delete it:
if (limit != null) {
QuotaStorageLimitService limitService = limitsService.limitService(limit.id());
limitService.remove();
}
// Create the limit again with the desired values, in this example it will be 100 GiB:
limitsService.add().limit(quotaStorageLimit().name("mydatalimit").description("My storage domain limit").limit(100).storageDomain(storageDomain().id(sd.id()))).send();
// Close the connection to the server:
connection.close();
}
use of org.openmuc.j60870.Connection in project ovirt-engine-sdk-java by oVirt.
the class AddVmDisk 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);
// Locate the service that manages the disk attachments of the virtual machine:
DiskAttachmentsService diskAttachmentsService = vmsService.vmService(vm.id()).diskAttachmentsService();
// Use the `add` method of the disk attachments service to add the disk. Note that the size of the disk,
// the `provionedSize` attribute, is specified in bytes, so to create a disk of 10 GiB the value should
// be 10 * 2^30.
DiskAttachment diskAttachment = diskAttachmentsService.add().attachment(diskAttachment().disk(disk().name("mydisk").description("My disk").format(DiskFormat.COW).provisionedSize(BigInteger.valueOf(10).multiply(BigInteger.valueOf(2).pow(30))).storageDomains(storageDomain().name("mydata"))).interface_(DiskInterface.VIRTIO).bootable(false).active(true)).send().attachment();
// Wait till the disk is OK:
DisksService disksService = connection.systemService().disksService();
DiskService diskService = disksService.diskService(diskAttachment.disk().id());
for (; ; ) {
Thread.sleep(5 * 1000);
Disk disk = diskService.get().send().disk();
if (disk.status() == DiskStatus.OK) {
break;
}
}
// Close the connection to the server:
connection.close();
}
use of org.openmuc.j60870.Connection in project ovirt-engine-sdk-java by oVirt.
the class AddHost 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 hosts service:
HostsService hostsService = connection.systemService().hostsService();
// Add the host:
Host host = hostsService.add().host(host().name("myhost").description("My host").address("node40.example.com").rootPassword("redhat123").cluster(cluster().name("mycluster"))).send().host();
// Wait till the host is up:
HostService hostService = hostsService.hostService(host.id());
for (; ; ) {
Thread.sleep(5 * 1000);
host = hostService.get().send().host();
if (host.status() == HostStatus.UP) {
break;
}
}
// Close the connection to the server:
connection.close();
}
use of org.openmuc.j60870.Connection in project ovirt-engine-sdk-java by oVirt.
the class AddLunDiskToVm 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("123456").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);
// Locate the service that manages the disk attachments of the virtual machine:
DiskAttachmentsService diskAttachmentsService = vmsService.vmService(vm.id()).diskAttachmentsService();
// Use the "add" method of the disk attachments service to add the LUN disk.
diskAttachmentsService.add().attachment(diskAttachment().disk(disk().name("myiscsidisk").lunStorage(hostStorage().type(StorageType.ISCSI).logicalUnits(logicalUnit().address("192.168.200.3").port(3260).target("iqn.2014-07.org.ovirt:storage").id("36001405e793bf9c57a840f58c9a8a220").username("username").password("password")))).interface_(DiskInterface.VIRTIO).bootable(false).active(true)).send().attachment();
// Close the connection to the server:
connection.close();
}
Aggregations