use of org.openmuc.j60870.Connection in project ovirt-engine-sdk-java by oVirt.
the class AttachNfsDataStorageDomain 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 service that manages the storage domains, and use it to search for the storage domain:
StorageDomainsService sdsService = connection.systemService().storageDomainsService();
StorageDomain sd = sdsService.list().search("name=mydata").send().storageDomains().get(0);
// Locate the service that manages the data centers and use it to search for the data center:
DataCentersService dcsService = connection.systemService().dataCentersService();
DataCenter dc = dcsService.list().search("name=mydc").send().dataCenters().get(0);
// Locate the service that manages the data center where we want to attach the storage domain:
DataCenterService dcService = dcsService.dataCenterService(dc.id());
// Locate the service that manages the storage domains that are attached to the data center:
AttachedStorageDomainsService attachedSdsService = dcService.storageDomainsService();
// Use the "add" method of the service that manages the attached storage domains to attach it:
attachedSdsService.add().storageDomain(storageDomain().id(sd.id())).send();
// Wait till the storage domain is active:
AttachedStorageDomainService attachedSdService = attachedSdsService.storageDomainService(sd.id());
for (; ; ) {
Thread.sleep(5 * 1000);
sd = attachedSdService.get().send().storageDomain();
if (sd.status() == StorageDomainStatus.ACTIVE) {
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 ChangeVmCd 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 service that manages the virtual machines:
VmsService vmsService = connection.systemService().vmsService();
// Find the virtual machine:
Vm vm = vmsService.list().search("name=myvm").send().vms().get(0);
// Locate the service that manages the virtual machine:
VmService vmService = vmsService.vmService(vm.id());
// Locate the service that manages the CDROM devices of the virtual machine:
VmCdromsService cdromsService = vmService.cdromsService();
// Get the first CDROM:
Cdrom cdrom = cdromsService.list().send().cdroms().get(0);
// Locate the service that manages the CDROM device found in the previous step:
VmCdromService cdromService = cdromsService.cdromService(cdrom.id());
// Change the CDROM disk of the virtual machine to 'my_iso_file.iso'. By default the below operation changes
// permanently the disk that will be visible to the virtual machine after the next boot, but it doesn't have
// any effect on the currently running virtual machine. If you want to change the disk that is visible to the
// current running virtual machine, change the value of the 'current' parameter to 'true'.
cdromService.update().cdrom(cdrom().file(file().id("my_iso_file.iso"))).current(false).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 AddLogicalNetwork 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 "networks" service:
NetworksService networksService = connection.systemService().networksService();
// Use the "add" method to create new VM logical network in data center called "mydatacenter", with VLAN tag
// 100 and MTU 1500.
networksService.add().network(network().name("mynetwork").description("My logical network").dataCenter(dataCenter().name("mydatacenter")).vlan(vlan().id(100)).usages(Arrays.asList(NetworkUsage.DISPLAY)).mtu(1500)).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 AddMacPool 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 the MAC address pools:
MacPoolsService poolsService = connection.systemService().macPoolsService();
// Add a new MAC address pool:
MacPool pool = poolsService.add().pool(macPool().name("mymacpool").ranges(range().from("02:00:00:00:00:00").to("02:00:00:01:00:00"))).send().pool();
// Find the service that manages clusters, as we need it in order to find the cluster where we wnt to set the
// MAC address pool:
ClustersService clustersService = connection.systemService().clustersService();
// Find the cluster:
Cluster cluster = clustersService.list().search("name=mycluster").send().clusters().get(0);
// Find the service that manages the cluster, as we need it in order to do the update:
ClusterService clusterService = clustersService.clusterService(cluster.id());
// Update the service so that it uses the new MAC pool:
clusterService.update().cluster(cluster().macPool(macPool().id(pool.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 AddUserPublicSshKey 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();
// Get the reference to the service that manages the users:
UsersService usersService = systemService.usersService();
// Find the user:
User user = usersService.list().search("name=myuser").send().users().get(0);
// Get the reference to the service that manages the user that we found in the previous step:
UserService userService = usersService.userService(user.id());
// Get a reference to the service that manages the public SSH keys of the user:
SshPublicKeysService keysService = userService.sshPublicKeysService();
// Add a new SSH public key:
keysService.add().key(sshPublicKey().content("ssh-rsa AAA...mu9 myuser@example.com")).send();
// Note that the above operation will fail because the example SSH public key is not valid, make sure to use a
// valid key.
// Close the connection to the server:
connection.close();
}
Aggregations