Search in sources :

Example 1 with Role

use of org.ovirt.engine.sdk4.types.Role in project ovirt-engine-sdk-java by oVirt.

the class AddSystemPermission 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 system permissions:
    SystemPermissionsService permissionsService = systemService.permissionsService();
    // Add the "SupeUser" permission to the user with id "123":
    permissionsService.add().permission(permission().role(role().name("SuperUser")).user(user().id("123"))).send();
    // Close the connection to the server:
    connection.close();
}
Also used : SystemService(org.ovirt.engine.sdk4.services.SystemService) SystemPermissionsService(org.ovirt.engine.sdk4.services.SystemPermissionsService) Connection(org.ovirt.engine.sdk4.Connection)

Example 2 with Role

use of org.ovirt.engine.sdk4.types.Role 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();
}
Also used : Vm(org.ovirt.engine.sdk4.types.Vm) Connection(org.ovirt.engine.sdk4.Connection) Permission(org.ovirt.engine.sdk4.types.Permission) Cluster(org.ovirt.engine.sdk4.types.Cluster) VmsService(org.ovirt.engine.sdk4.services.VmsService) Template(org.ovirt.engine.sdk4.types.Template)

Example 3 with Role

use of org.ovirt.engine.sdk4.types.Role in project ovirt-engine-sdk-java by oVirt.

the class ListRoles method main.

public static void main(String[] args) throws Exception {
    // Create the connection to the server:
    Connection connection = connection().url("https://engine41.example.com/ovirt-engine/api").user("admin@internal").password("redhat123").trustStoreFile("truststore.jks").build();
    // Get the reference to the service that manages the roles:
    RolesService rolesService = connection.systemService().rolesService();
    // Retrieve the roles:
    List<Role> roles = rolesService.list().send().roles();
    // For each role print its name and description:
    for (Role role : roles) {
        System.out.printf("%s: %s\n", role.name(), role.description());
    }
    // Close the connection to the server:
    connection.close();
}
Also used : Role(org.ovirt.engine.sdk4.types.Role) RolesService(org.ovirt.engine.sdk4.services.RolesService) Connection(org.ovirt.engine.sdk4.Connection)

Aggregations

Connection (org.ovirt.engine.sdk4.Connection)3 RolesService (org.ovirt.engine.sdk4.services.RolesService)1 SystemPermissionsService (org.ovirt.engine.sdk4.services.SystemPermissionsService)1 SystemService (org.ovirt.engine.sdk4.services.SystemService)1 VmsService (org.ovirt.engine.sdk4.services.VmsService)1 Cluster (org.ovirt.engine.sdk4.types.Cluster)1 Permission (org.ovirt.engine.sdk4.types.Permission)1 Role (org.ovirt.engine.sdk4.types.Role)1 Template (org.ovirt.engine.sdk4.types.Template)1 Vm (org.ovirt.engine.sdk4.types.Vm)1