이것은 내가 처리 한 방법입니다. 코드가 조금 복잡해 보일 수도 있지만 요점은 다음과 같습니다.
이 호스트의 모든 볼륨을 검색하여 NFS 파일 시스템이 내장 된 볼륨을 찾습니다. 이 볼륨 각각에 대해 볼륨 이름 = 데이터 저장소 이름 조건으로 Datastore 목록을 반복합니다. 일치하는 항목을 찾으면 DatastoreInfo 개체에서 NASDatastoreInfo 개체를 가져 와서 원격 NFS 서버 IP 및 내보내기 디렉터리를 확인합니다.
이 호스트의 모든 볼륨에 대해 HostFileSystemVolume.type == 'NFS'를 확인한 다음 해당 볼륨의 원격 NFS 서버 IP 및 내보내기 디렉토리를 확인하십시오.
코드는 이미 '호스트'
HostDatastoreSystem hds = host.getHostDatastoreSystem();
HostDatastoreBrowser hdb = host.getDatastoreBrowser();
Datastore[] allDS = hdb.getDatastores();
HostConfigInfo hostConfigInfo = host.getConfig();
HostFileSystemVolumeInfo hostFSVolumeInfo = hostConfigInfo.getFileSystemVolume();
HostFileSystemMountInfo[] hostFSMountInfo= hostFSVolumeInfo.getMountInfo();
for (HostFileSystemMountInfo hfsmi : hostFSMountInfo) {
HostFileSystemVolume hfsv = hfsmi.getVolume();
if (hfsv.getType().equalsIgnoreCase("nfs")){
String dsName = hfsv.getName();
for(Datastore ds: allDS) {
DatastoreInfo di = ds.getInfo();
if (di.getName().equals(dsName)){
HostNasVolume nas = ((NasDatastoreInfo)di).getNas();
if (nas.getRemoteHost().equals(nfsServer) & nas.getRemotePath().equals(datastorePathOnNfsServer)) {
try {
} catch (HostConfigFault e) {
logger.error("ERROR : unmountNfsDatastore : Could not remove Datastore named: " + ds.getName() + " on " + "host: " + hostname , e);
ret = 1;
return ret;
} catch (ResourceInUse e) {
logger.error("ERROR : unmountNfsDatastore : Could not remove Datastore named: " + ds.getName() + " on " + "host: " + hostname , e);
ret = 1;
return ret;
} catch (NotFound e) {
logger.error("ERROR : unmountNfsDatastore : Could not remove Datastore named: " + ds.getName() + " on " + "host: " + hostname , e);
ret = 1;
return ret;
} catch (RuntimeFault e) {
logger.error("ERROR : unmountNfsDatastore : Could not remove Datastore named: " + ds.getName() + " on " + "host: " + hostname , e);
ret = 1;
return ret;
} catch (RemoteException e) {
logger.error("ERROR : unmountNfsDatastore : Could not remove Datastore named: " + ds.getName() + " on " + "host: " + hostname , e);
ret = 1;
return ret;
}
return 0;
}
}
}
}
}
logger.error("ERROR : unmountNfsDatastore : Could not find Datastore exported by " + nfsServer + " on " + "host: " + hostname);
ret = 0;
return ret;
hds.removeDatastore(ds);
라는 VCENTER에 서비스 인스턴스 '시'와 HostSystem 개체가 있습니다