public ManagedObjectReference findDatastoreByName(String datastoreName) throws Exception { assert (datastoreName != null); List<ManagedObjectReference> datastores = getDatastores(); if (datastores != null) { for (ManagedObjectReference morDatastore : datastores) { DatastoreInfo info = getDatastoreInfo(morDatastore); if (info != null) { if (info.getName().equals(datastoreName)) return morDatastore; } } } return null; }
@Override public ManagedObjectReference findDatastoreByExportPath(String exportPath) throws Exception { if (s_logger.isTraceEnabled()) s_logger.trace("vCenter API trace - findDatastoreByExportPath(). target MOR: " + _mor.getValue() + ", exportPath: " + exportPath); ObjectContent[] ocs = getDatastorePropertiesOnHyperHost(new String[] {"info"}); if (ocs != null && ocs.length > 0) { for (ObjectContent oc : ocs) { DatastoreInfo dsInfo = (DatastoreInfo)oc.getPropSet().get(0).getVal(); if (dsInfo != null && dsInfo instanceof NasDatastoreInfo) { NasDatastoreInfo info = (NasDatastoreInfo)dsInfo; if (info != null) { String vmwareUrl = info.getUrl(); if (vmwareUrl.charAt(vmwareUrl.length() - 1) == '/') vmwareUrl = vmwareUrl.substring(0, vmwareUrl.length() - 1); URI uri = new URI(vmwareUrl); if (uri.getPath().equals("/" + exportPath)) { if (s_logger.isTraceEnabled()) s_logger.trace("vCenter API trace - findDatastoreByExportPath() done(successfully)"); return oc.getObj(); } } } } } if (s_logger.isTraceEnabled()) s_logger.trace("vCenter API trace - findDatastoreByExportPath() done(failed)"); return null; }
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; }
public DatastoreInfo getDatastoreInfo(ManagedObjectReference morDatastore) throws Exception { return (DatastoreInfo)_context.getVimClient().getDynamicProperty(morDatastore, "info"); }
public NasDatastoreInfo getNasDatastoreInfo(ManagedObjectReference morDatastore) throws Exception { DatastoreInfo info = (DatastoreInfo)_context.getVimClient().getDynamicProperty(morDatastore, "info"); if (info instanceof NasDatastoreInfo) return (NasDatastoreInfo)info; return null; }