protected StoragePoolInfo initializeLocalStorage() { String hostIp = getConfiguredProperty("private.ip.address", "127.0.0.1"); String localStoragePath = getConfiguredProperty("local.storage.path", "/mnt"); String lh = hostIp + localStoragePath; String uuid = UUID.nameUUIDFromBytes(lh.getBytes(StringUtils.getPreferredCharset())).toString(); String capacity = getConfiguredProperty("local.storage.capacity", "1000000000"); String available = getConfiguredProperty("local.storage.avail", "10000000"); return new StoragePoolInfo(uuid, hostIp, localStoragePath, localStoragePath, StoragePoolType.Filesystem, Long.parseLong(capacity), Long.parseLong(available)); }
/** * This method creates the StartUp storage command for the local SR. * We will configure 'name-label' and 'description' using {@link #configureStorageNameAndDescription(Connection, SR)}. * Then, we will create the POJO {@link StoragePoolInfo} with SR's information using method {@link #createStoragePoolInfo(Connection, SR)}. */ protected StartupStorageCommand createStartUpStorageCommand(Connection conn, SR sr) throws XenAPIException, XmlRpcException { configureStorageNameAndDescription(conn, sr); StoragePoolInfo storagePoolInfo = createStoragePoolInfo(conn, sr); StartupStorageCommand cmd = new StartupStorageCommand(); cmd.setPoolInfo(storagePoolInfo); cmd.setGuid(_host.getUuid()); cmd.setDataCenter(Long.toString(_dcId)); cmd.setResourceType(Storage.StorageResourceType.STORAGE_POOL); String.format("StartUp command created for local storage [%s] of type [%s] on host [%s]", storagePoolInfo.getUuid(), storagePoolInfo.getPoolType(), _host.getUuid()); return cmd; }
@Override public boolean hostConnect(long hostId, long storagePoolId) { StoragePool storagePool = (StoragePool) dataStoreMgr.getDataStore(storagePoolId, DataStoreRole.Primary); ModifyStoragePoolCommand cmd = new ModifyStoragePoolCommand(true, storagePool); ModifyStoragePoolAnswer answer = sendModifyStoragePoolCommand(cmd, storagePool, hostId); StoragePoolHostVO storagePoolHost = storagePoolHostDao.findByPoolHost(storagePoolId, hostId); if (storagePoolHost != null) { storagePoolHost.setLocalPath(answer.getPoolInfo().getLocalPath().replaceAll("//", "/")); } else { storagePoolHost = new StoragePoolHostVO(storagePoolId, hostId, answer.getPoolInfo().getLocalPath().replaceAll("//", "/")); storagePoolHostDao.persist(storagePoolHost); } StoragePoolVO storagePoolVO = storagePoolDao.findById(storagePoolId); storagePoolVO.setCapacityBytes(answer.getPoolInfo().getCapacityBytes()); storagePoolVO.setUsedBytes(answer.getPoolInfo().getCapacityBytes() - answer.getPoolInfo().getAvailableBytes()); storagePoolDao.update(storagePoolId, storagePoolVO); return true; }
public final void testJson() { StartupStorageCommand sscmd = null; com.cloud.agent.api.StoragePoolInfo pi = new com.cloud.agent.api.StoragePoolInfo("test123", "192.168.0.1", "c:\\", "c:\\", StoragePoolType.Filesystem, 100L, 50L); sscmd = new StartupStorageCommand(); sscmd.setPoolInfo(pi); sscmd.setGuid(pi.getUuid()); sscmd.setDataCenter("foo"); sscmd.setResourceType(Storage.StorageResourceType.STORAGE_POOL); s_logger.debug("StartupStorageCommand fromJson is " + s_gson.toJson(sscmd)); }
String hostAddress = pInfo.getHost(); if (host.getHypervisorType() == Hypervisor.HypervisorType.VMware) { hostAddress = "VMFS datastore: " + pInfo.getHostPath(); StoragePoolVO pool = _storagePoolDao.findPoolByHostPath(host.getDataCenterId(), host.getPodId(), hostAddress, pInfo.getHostPath(), pInfo.getUuid()); if (pool == null && host.getHypervisorType() == HypervisorType.VMware) { if (pInfo.getHostPath().length() > 0) { pool = _storagePoolDao.findPoolByHostPath(host.getDataCenterId(), host.getPodId(), hostAddress, "", pInfo.getUuid()); pool = _storagePoolDao.findPoolByHostPath(host.getDataCenterId(), host.getPodId(), hostAddress, null, pInfo.getUuid()); if (pool != null) { s_logger.debug("Found a storage pool: " + pInfo.getUuid() + ", but with different hostpath " + pInfo.getHostPath() + ", still treat it as the same pool"); params.put("clusterId", host.getClusterId()); params.put("podId", host.getPodId()); params.put("url", pInfo.getPoolType().toString() + "://" + pInfo.getHost() + "/" + pInfo.getHostPath()); params.put("name", name); params.put("localStorage", true); params.put("details", pInfo.getDetails()); params.put("uuid", pInfo.getUuid()); params.put("providerName", provider.getName());
/** * Creates the local storage pool name. * The name will follow the pattern: <hostname>-local-<firstBlockOfUuid> */ protected String createLocalStoragePoolName(Host host, StoragePoolInfo storagePoolInformation) { return String.format("%s-%s-%s", org.apache.commons.lang3.StringUtils.trim(host.getName()), "local", storagePoolInformation.getUuid().split("-")[0]); }
new com.cloud.agent.api.StoragePoolInfo(localStoragePool.getUuid(), cmd.getPrivateIpAddress(), _localStoragePath, _localStoragePath, StoragePoolType.Filesystem, localStoragePool.getCapacity(), localStoragePool.getAvailable()); sscmd.setGuid(pi.getUuid()); sscmd.setDataCenter(_dcId); sscmd.setResourceType(Storage.StorageResourceType.STORAGE_POOL);
@Override public StartupCommand[] initialize() { final List<Object> info = getHostInfo(); final StartupRoutingCommand cmd = new StartupRoutingCommand((Integer)info.get(0), (Long)info.get(1), (Long)info.get(2), (Long)info.get(4), (String)info.get(3), HypervisorType.KVM, RouterPrivateIpStrategy.HostLocal); fillNetworkInformation(cmd); cmd.getHostDetails().putAll(getVersionStrings()); cmd.setCluster(getConfiguredProperty("cluster", "1")); StoragePoolInfo pi = initializeLocalStorage(); StartupStorageCommand sscmd = new StartupStorageCommand(); sscmd.setPoolInfo(pi); sscmd.setGuid(pi.getUuid()); sscmd.setDataCenter((String)_params.get("zone")); sscmd.setResourceType(Storage.StorageResourceType.STORAGE_POOL); return new StartupCommand[] {cmd, sscmd}; }
public DataStore attachHost(DataStore store, HostScope scope, StoragePoolInfo existingInfo) { StoragePoolHostVO poolHost = storagePoolHostDao.findByPoolHost(store.getId(), scope.getScopeId()); if (poolHost == null) { poolHost = new StoragePoolHostVO(store.getId(), scope.getScopeId(), existingInfo.getLocalPath()); storagePoolHostDao.persist(poolHost); } StoragePoolVO pool = this.dataStoreDao.findById(store.getId()); pool.setScope(scope.getScopeType()); pool.setUsedBytes(existingInfo.getCapacityBytes() - existingInfo.getAvailableBytes()); pool.setCapacityBytes(existingInfo.getCapacityBytes()); pool.setStatus(StoragePoolStatus.Up); this.dataStoreDao.update(pool.getId(), pool); this.storageMgr.createCapacityEntry(pool, Capacity.CAPACITY_TYPE_LOCAL_STORAGE, pool.getUsedBytes()); return dataStoreMgr.getDataStore(pool.getId(), DataStoreRole.Primary); }
/** * Instantiate {@link StoragePoolInfo} with SR's information. */ protected StoragePoolInfo createStoragePoolInfo(Connection conn, SR sr) throws XenAPIException, XmlRpcException { long totalCapacity = sr.getPhysicalSize(conn); String srUuid = sr.getUuid(conn); Host host = Host.getByUuid(conn, _host.getUuid()); String address = host.getAddress(conn); long availableCapacity = totalCapacity - sr.getPhysicalUtilisation(conn); String srType = sr.getType(conn).toUpperCase(); return new StoragePoolInfo(srUuid, address, srType, srType, StoragePoolType.valueOf(srType), totalCapacity, availableCapacity); }
poolHost = new StoragePoolHostVO(pool.getId(), hostId, mspAnswer.getPoolInfo().getLocalPath().replaceAll("//", "/")); storagePoolHostDao.persist(poolHost); } else { poolHost.setLocalPath(mspAnswer.getPoolInfo().getLocalPath().replaceAll("//", "/")); poolVO.setUsedBytes(mspAnswer.getPoolInfo().getCapacityBytes() - mspAnswer.getPoolInfo().getAvailableBytes()); poolVO.setCapacityBytes(mspAnswer.getPoolInfo().getCapacityBytes()); primaryStoreDao.update(pool.getId(), poolVO);
public ModifyStoragePoolAnswer(ModifyStoragePoolCommand cmd, long capacityBytes, long availableBytes, Map<String, TemplateProp> tInfo) { super(cmd); result = true; poolInfo = new StoragePoolInfo(null, cmd.getPool().getHost(), cmd.getPool().getPath(), cmd.getLocalPath(), cmd.getPool().getType(), capacityBytes, availableBytes); templateInfo = tInfo; }