Java 类com.vmware.vim25.mo.HostDatastoreSystem 实例源码

项目:WBSAirback    文件:HypervisorManagerVMware.java   
public boolean existsNFSStore(String name, String host, String address, String path) throws Exception {
    if(address == null || path == null || address.isEmpty() || path.isEmpty()) {
        return false;
    }
    ServiceInstance si = new ServiceInstance(new URL(this._url), this._user, this._password, true);
    if(host == null || host.isEmpty()) {
        si.getServerConnection().logout();
        throw new Exception("invalid host name");
    }
    try {
        HostSystem _host = (HostSystem) new InventoryNavigator(si.getRootFolder()).searchManagedEntity("HostSystem", host);
        if(_host == null) {
            si.getServerConnection().logout();
            throw new Exception("host system not found");
        }

        HostDatastoreSystem _hds = _host.getHostDatastoreSystem();
        for(Datastore _ds : _hds.getDatastores()) {
            DatastoreInfo _info = _ds.getInfo();
            if(_info instanceof NasDatastoreInfo) {
                NasDatastoreInfo _nasinfo = (NasDatastoreInfo) _info;
                if(name.equalsIgnoreCase(_nasinfo.getNas().getName())) {
                    return true;
                } else if(address.equalsIgnoreCase(_nasinfo.getNas().getRemoteHost()) &&
                        path.equalsIgnoreCase(_nasinfo.getNas().getRemotePath())) {
                    return true;
                }
            }
        }
    } catch(Exception _ex) {
    } finally {
        si.getServerConnection().logout();
    }
    return false;
}