Vijava 学习笔记之 VCenter连接

package com.vmware.util;

/**
 * Created by vixuan-008 on 2015/4/8.
 * ClientSesion 类:连接VCent服务器(URL、用户名和密码)
 */
public class ClientSesion implements java.io.Serializable {
    private String host;//vcent url
    private String username;//vcent 用户名
    private String password;//vcent 密码
    // set 和  get
    public String getHost() {
        return host;
    }

    public void setHost(String host) {
        this.host = host;
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }
    //默认构造函数
    public ClientSesion(){
        super();
    }
    //构造函数
    public ClientSesion(String host, String username, String password) {
        super();
        this.host = host;
        this.username = username;
        this.password = password;
    }
}
package com.vmware.client;

import com.vmware.util.ClientSesion;
import com.vmware.vim25.AboutInfo;
import com.vmware.vim25.mo.*;

import java.net.URL;

/**
 * Created by vixuan-008 on 2015/4/8.
 * 测试类
 */
public class Client {
    public static void main(String[] args){

        try{
            ClientSesion session=new ClientSesion("172.16.1.20","root","vmware");
            URL url = new URL("https", session.getHost(), "/sdk");
            ServiceInstance si = new ServiceInstance(url, session.getUsername(), session.getPassword(), true);

            Folder rootFolder = si.getRootFolder();
            //VCenter vc = new VCenter();
            AboutInfo ai = si.getAboutInfo();
            System.out.println("名称"+ai.getFullName());
            System.out.println("版本:"+ai.getVersion());
//            System.out.println(ai.apiType);
//            si.currentTime();
       }catch(Exception e){
            e.printStackTrace();
        }


    }
}


 
  
 
  

相关结果截图:


你可能感兴趣的:(Vmware,Vsphere,Vijava开发笔记,Vsphere,虚拟化,开发实战)