Vijava 学习笔记之 VCenter连接

无情 阅读:792 2021-03-31 22:38:42 评论:0
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; 
    } 
}
<pre name="code" class="html">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(); 
        } 
 
 
    } 
} 


 
 
 
 

相关结果截图:


声明

1.本站遵循行业规范,任何转载的稿件都会明确标注作者和来源;2.本站的原创文章,请转载时务必注明文章作者和来源,不尊重原创的行为我们将追究责任;3.作者投稿可能会经我们编辑修改或补充。

关注我们

一个IT知识分享的公众号