All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.ovirt.engine.sdk.Example Maven / Gradle / Ivy

There is a newer version: 3.6.10.0
Show newest version
//
// Copyright (c) 2012 Red Hat, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//           http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//

package org.ovirt.engine.sdk;

import java.io.IOException;
import java.util.List;
import java.util.UUID;

import org.apache.http.client.ClientProtocolException;
import org.ovirt.engine.sdk.decorators.VM;
import org.ovirt.engine.sdk.decorators.VMDisk;
import org.ovirt.engine.sdk.decorators.VMStatistic;
import org.ovirt.engine.sdk.entities.Action;
import org.ovirt.engine.sdk.entities.ApiSummary;
import org.ovirt.engine.sdk.entities.ProductInfo;
import org.ovirt.engine.sdk.exceptions.ServerException;
import org.ovirt.engine.sdk.exceptions.UnsecuredConnectionAttemptError;

public class Example {
    private static final String URL = "http://localhost:8080/api";

    @SuppressWarnings("unused")
    public static void main(String[] args) throws ClientProtocolException, ServerException,
            UnsecuredConnectionAttemptError, IOException {
        // Api api = new Api(URL, "admin@internal", "123456");
        Api api =
                new Api(URL,
                        "admin@internal",
                        "123456",
                        null,
                        null,
                        null,
                        null,
                        null,
                        null,
                        null,
                        true,
                        null);

        ApiSummary sum = api.getSummary();

        ProductInfo pi = api.getProductInfo();

        // #1
        List vms = api.getVMs().list();

        List vms2 = api.getVMs().list("name=test", null, null);

        // #2
        VM vm = api.getVMs().get("test2");

        List vmDisks = vm.getDisks().list(1);
        List vmDisks2 = vm.getDisks().list();

        VMDisk disk = vm.getDisks().get(UUID.fromString("076f9734-0500-45df-b1a7-4ff77778fce4"));

        Action act = disk.deactivate(new Action());

        // #3
        vm.setDescription("java_sdk_test");
        VM newVM = vm.update();

        // #4
        Action res = vm.start(new Action() {
            {
                setVm(new org.ovirt.engine.sdk.entities.VM());
            }
        });

        // #5
        List vmstatistics = vm.getStatistics().list();

        // #6
        VMStatistic vmstatistic = vm.getStatistics().get(UUID.fromString("5a89a1d2-32be-33f7-a0d1-f8b5bc974ff6"));

        // #7
        vm.delete();
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy