ovirt - engine - sdk - java 4.0.0 학습 기록

4633 단어 ovirtsdk자바
import org.ovirt.engine.sdk4.Connection;
import org.ovirt.engine.sdk4.services.ClustersService;
import org.ovirt.engine.sdk4.services.ClustersService.ListResponse;
import org.ovirt.engine.sdk4.services.DataCentersService;
import org.ovirt.engine.sdk4.services.HostsService;
import org.ovirt.engine.sdk4.services.VmsService;
import org.ovirt.engine.sdk4.types.Cluster;
import org.ovirt.engine.sdk4.types.DataCenter;
import org.ovirt.engine.sdk4.types.Host;
import org.ovirt.engine.sdk4.types.Vm;

import static org.ovirt.engine.sdk4.ConnectionBuilder.connection;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class Test {
    private static final String URL = "https://svcloud.casvip.com:443/ovirt-engine/api";
    private static final String USERNAME = "admin@internal";
    private static final String PASSWORD = "Admin123***";

    public static void main(String[] args) {
        // 1.        
        Connection connection = connection()
                .url(URL)
                .user(USERNAME)
                .password(PASSWORD)
                .build();
        
        // 2.       
        DataCentersService dataCentersSevice = connection.systemService().dataCentersService();
        List dataCenters = dataCentersSevice.list().send().dataCenters();
        Map dataCenterMap = new HashMap();
        System.out.println("    :");
        for(DataCenter dt : dataCenters) {
            System.out.println("\t   - " + dt.name());
            System.out.println("\t\tID - " + dt.id());
            System.out.println("\t\tClusters - " + dt.clusters().size());
            dataCenterMap.put(dt.id(), dt.name());
        }
        
        // 3.     
        ClustersService clustersService = connection.systemService().clustersService();
        List clusters = clustersService.list().send().clusters();
        Map clusterMap = new HashMap();
        System.out.println("  :");
        for(Cluster clu : clusters) {
            if(clu.id() != null) {
                System.out.println("\t   - " + clu.name());
                System.out.println("\t\tID - " + clu.id());
                System.out.println("\t\tData Center - " + clu.dataCenter());
                clusterMap.put(clu.id(), clu.name());
            }
        }
        
        // 4.    
        HostsService hostsService = connection.systemService().hostsService();
        List hosts = hostsService.list().send().hosts();
        Map hostMap = new HashMap();
        System.out.println("  :");
        for(Host host : hosts) {
            System.out.println("\t   - " + host.name());
            System.out.println("\t\tID - " + host.id());
            System.out.println("\t\tIP - " + host.address());
            System.out.println("\t\tCluster - " + clusterMap.get(host.cluster().id()));
            System.out.println("\t\tData Center - " + host.cluster().dataCenter());
            hostMap.put(host.id(), host.name());
        }
        
        // 5.      
        VmsService vmsService = connection.systemService().vmsService();
        List vms = vmsService.list().send().vms();
        System.out.println("   :");
        for(Vm vm : vms) {
            System.out.println("\t   - " + vm.name());
            System.out.println("\t\t   - " + vm.description());
            if(vm.host() != null) {
                System.out.println("\t\t   - " + hostMap.get(vm.host().id()));
            }
            System.out.println("\t\tIP - " + vm.display().address());
            System.out.println("\t\tFQDN - " + vm.fqdn());
            System.out.println("\t\tCluster - " + clusterMap.get(vm.cluster().id()));
            System.out.println("\t\tMemory - " + vm.memory());
            System.out.println("\t\tOS - " + vm.os().type());
            System.out.println("\t\tCPU - " + vm.cpu().architecture());
            System.out.println("\t\tCPU Level - " + vm.cpu().level());
            System.out.println("\t\t     - " + vm.display().type().value());
            System.out.println("\t\tStauts - " + vm.status().value());
            System.out.println("\t\t     - " + vm.creationTime());
            System.out.println("\t\t   - " + vm.comment());
        }

    }

}

좋은 웹페이지 즐겨찾기