Search in sources :

Example 1 with Tag

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

the class ListTags method main.

public static void main(String[] args) throws Exception {
    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 tags:
    TagsService tagsService = connection.systemService().tagsService();
    // Retrieve the tags:
    List<Tag> tags = tagsService.list().send().tags();
    // For each tag print its name and description:
    for (Tag tag : tags) {
        System.out.printf("%s: %s\n", tag.name(), tag.description());
    }
    // Close the connection to the server:
    connection.close();
}
Also used : TagsService(org.ovirt.engine.sdk4.services.TagsService) Connection(org.ovirt.engine.sdk4.Connection) Tag(org.ovirt.engine.sdk4.types.Tag)

Example 2 with Tag

use of org.ovirt.engine.sdk4.types.Tag 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();
}
Also used : Connection(org.ovirt.engine.sdk4.Connection) NetworksService(org.ovirt.engine.sdk4.services.NetworksService)

Example 3 with Tag

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

the class UnassignTagToVm 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();
    // Find the virtual machine:
    Vm vm = vmsService.list().search("name=myvm0").send().vms().get(0);
    // Find the service that manages the vm:
    VmService vmService = vmsService.vmService(vm.id());
    // Locate the service that manages the tags of the vm:
    AssignedTagsService tagsService = vmService.tagsService();
    // Find the tag id:
    String tagId = null;
    for (Tag tag : tagsService.list().send().tags()) {
        if (tag.name().equals("mytag")) {
            tagId = tag.id();
            break;
        }
    }
    // Locate the service that manages the tag:
    AssignedTagService tagService = tagsService.tagService(tagId);
    // Unassign tag from virtual machine:
    tagService.remove().send();
    // Close the connection to the server:
    connection.close();
}
Also used : AssignedTagService(org.ovirt.engine.sdk4.services.AssignedTagService) Vm(org.ovirt.engine.sdk4.types.Vm) VmService(org.ovirt.engine.sdk4.services.VmService) Connection(org.ovirt.engine.sdk4.Connection) VmsService(org.ovirt.engine.sdk4.services.VmsService) Tag(org.ovirt.engine.sdk4.types.Tag) AssignedTagsService(org.ovirt.engine.sdk4.services.AssignedTagsService)

Example 4 with Tag

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

the class AssignTagToVm 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();
    // Find the virtual machine:
    Vm vm = vmsService.list().search("name=myvm0").send().vms().get(0);
    // Find the service that manages the vm:
    VmService vmService = vmsService.vmService(vm.id());
    // Locate the service that manages the tags of the vm:
    AssignedTagsService assignedTagsService = vmService.tagsService();
    // Assign tag to virtual machine:
    assignedTagsService.add().tag(tag().name("mytag")).send();
    // Close the connection to the server:
    connection.close();
}
Also used : Vm(org.ovirt.engine.sdk4.types.Vm) VmService(org.ovirt.engine.sdk4.services.VmService) Connection(org.ovirt.engine.sdk4.Connection) VmsService(org.ovirt.engine.sdk4.services.VmsService) AssignedTagsService(org.ovirt.engine.sdk4.services.AssignedTagsService)

Example 5 with Tag

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

the class RemoveTag 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 tags:
    TagsService tagsService = connection.systemService().tagsService();
    // Find the tag id:
    String tagId = null;
    for (Tag tag : tagsService.list().send().tags()) {
        if (tag.name().equals("mytag")) {
            tagId = tag.id();
            break;
        }
    }
    // Find the service that manages the tag:
    TagService tagService = tagsService.tagService(tagId);
    // Remove the tag:
    tagService.remove().send();
    // Close the connection to the server:
    connection.close();
}
Also used : TagsService(org.ovirt.engine.sdk4.services.TagsService) TagService(org.ovirt.engine.sdk4.services.TagService) Connection(org.ovirt.engine.sdk4.Connection) Tag(org.ovirt.engine.sdk4.types.Tag)

Aggregations

Connection (org.ovirt.engine.sdk4.Connection)7 Tag (org.ovirt.engine.sdk4.types.Tag)4 AssignedTagsService (org.ovirt.engine.sdk4.services.AssignedTagsService)3 TagsService (org.ovirt.engine.sdk4.services.TagsService)3 VmService (org.ovirt.engine.sdk4.services.VmService)3 VmsService (org.ovirt.engine.sdk4.services.VmsService)3 Vm (org.ovirt.engine.sdk4.types.Vm)3 AssignedTagService (org.ovirt.engine.sdk4.services.AssignedTagService)1 NetworksService (org.ovirt.engine.sdk4.services.NetworksService)1 TagService (org.ovirt.engine.sdk4.services.TagService)1