use of com.cloud.dc.ClusterVO in project cloudstack by apache.
the class CiscoNexusVSMElement method validateAndAddVsm.
@Override
@DB
public Pair<Boolean, Long> validateAndAddVsm(final String vsmIp, final String vsmUser, final String vsmPassword, final long clusterId, String clusterName) throws ResourceInUseException {
CiscoNexusVSMDeviceVO vsm = null;
boolean vsmAdded = false;
Long vsmId = 0L;
if (vsmIp != null && vsmUser != null && vsmPassword != null) {
NetconfHelper netconfClient;
try {
netconfClient = new NetconfHelper(vsmIp, vsmUser, vsmPassword);
netconfClient.disconnect();
} catch (CloudRuntimeException e) {
String msg = "Invalid credentials supplied for user " + vsmUser + " for Cisco Nexus 1000v VSM at " + vsmIp;
s_logger.error(msg);
_clusterDao.remove(clusterId);
throw new CloudRuntimeException(msg);
}
// If VSM already exists and is mapped to a cluster, fail this operation.
vsm = _vsmDao.getVSMbyIpaddress(vsmIp);
if (vsm != null) {
List<ClusterVSMMapVO> clusterList = _clusterVSMDao.listByVSMId(vsm.getId());
if (clusterList != null && !clusterList.isEmpty()) {
s_logger.error("Failed to add cluster: specified Nexus VSM is already associated with another cluster");
ResourceInUseException ex = new ResourceInUseException("Failed to add cluster: specified Nexus VSM is already associated with another cluster with specified Id");
// get clusterUuid to report error
ClusterVO cluster = _clusterDao.findById(clusterList.get(0).getClusterId());
ex.addProxyObject(cluster.getUuid());
_clusterDao.remove(clusterId);
throw ex;
}
}
// persist credentials to database if the VSM entry is not already in the db.
vsm = Transaction.execute(new TransactionCallback<CiscoNexusVSMDeviceVO>() {
@Override
public CiscoNexusVSMDeviceVO doInTransaction(TransactionStatus status) {
CiscoNexusVSMDeviceVO vsm = null;
if (_vsmDao.getVSMbyIpaddress(vsmIp) == null) {
vsm = new CiscoNexusVSMDeviceVO(vsmIp, vsmUser, vsmPassword);
_vsmDao.persist(vsm);
}
// Create a mapping between the cluster and the vsm.
vsm = _vsmDao.getVSMbyIpaddress(vsmIp);
if (vsm != null) {
ClusterVSMMapVO connectorObj = new ClusterVSMMapVO(clusterId, vsm.getId());
_clusterVSMDao.persist(connectorObj);
}
return vsm;
}
});
} else {
String msg;
msg = "The global parameter " + Config.VmwareUseNexusVSwitch.toString() + " is set to \"true\". Following mandatory parameters are not specified. ";
if (vsmIp == null) {
msg += "vsmipaddress: Management IP address of Cisco Nexus 1000v dvSwitch. ";
}
if (vsmUser == null) {
msg += "vsmusername: Name of a user account with admin privileges over Cisco Nexus 1000v dvSwitch. ";
}
if (vsmPassword == null) {
if (vsmUser != null) {
msg += "vsmpassword: Password of user account " + vsmUser + ". ";
} else {
msg += "vsmpassword: Password of user account with admin privileges over Cisco Nexus 1000v dvSwitch. ";
}
}
s_logger.error(msg);
// Cleaning up the cluster record as addCluster operation failed because of invalid credentials of Nexus dvSwitch.
_clusterDao.remove(clusterId);
throw new CloudRuntimeException(msg);
}
if (vsm != null) {
vsmAdded = true;
vsmId = vsm.getId();
}
return new Pair<Boolean, Long>(vsmAdded, vsmId);
}
use of com.cloud.dc.ClusterVO in project cloudstack by apache.
the class DiscovererBase method buildConfigParams.
protected HashMap<String, Object> buildConfigParams(HostVO host) {
HashMap<String, Object> params = new HashMap<String, Object>(host.getDetails().size() + 5);
params.putAll(host.getDetails());
params.put("guid", host.getGuid());
params.put("zone", Long.toString(host.getDataCenterId()));
if (host.getPodId() != null) {
params.put("pod", Long.toString(host.getPodId()));
}
if (host.getClusterId() != null) {
params.put("cluster", Long.toString(host.getClusterId()));
String guid = null;
ClusterVO cluster = _clusterDao.findById(host.getClusterId());
if (cluster.getGuid() == null) {
guid = host.getDetail("pool");
} else {
guid = cluster.getGuid();
}
if (guid != null && !guid.isEmpty()) {
params.put("pool", guid);
}
}
params.put("ipaddress", host.getPrivateIpAddress());
params.put("secondary.storage.vm", "false");
params.put("max.template.iso.size", _configDao.getValue(Config.MaxTemplateAndIsoSize.toString()));
params.put("migratewait", _configDao.getValue(Config.MigrateWait.toString()));
params.put(Config.XenServerMaxNics.toString().toLowerCase(), _configDao.getValue(Config.XenServerMaxNics.toString()));
params.put(Config.XenServerHeartBeatInterval.toString().toLowerCase(), _configDao.getValue(Config.XenServerHeartBeatInterval.toString()));
params.put(Config.XenServerHeartBeatTimeout.toString().toLowerCase(), _configDao.getValue(Config.XenServerHeartBeatTimeout.toString()));
params.put("router.aggregation.command.each.timeout", _configDao.getValue(Config.RouterAggregationCommandEachTimeout.toString()));
return params;
}
use of com.cloud.dc.ClusterVO in project cloudstack by apache.
the class AbstractStoragePoolAllocator method filter.
protected boolean filter(ExcludeList avoid, StoragePool pool, DiskProfile dskCh, DeploymentPlan plan) {
if (s_logger.isDebugEnabled()) {
s_logger.debug("Checking if storage pool is suitable, name: " + pool.getName() + " ,poolId: " + pool.getId());
}
if (avoid.shouldAvoid(pool)) {
if (s_logger.isDebugEnabled()) {
s_logger.debug("StoragePool is in avoid set, skipping this pool");
}
return false;
}
Long clusterId = pool.getClusterId();
if (clusterId != null) {
ClusterVO cluster = clusterDao.findById(clusterId);
if (!(cluster.getHypervisorType() == dskCh.getHypervisorType())) {
if (s_logger.isDebugEnabled()) {
s_logger.debug("StoragePool's Cluster does not have required hypervisorType, skipping this pool");
}
return false;
}
} else if (pool.getHypervisor() != null && !pool.getHypervisor().equals(HypervisorType.Any) && !(pool.getHypervisor() == dskCh.getHypervisorType())) {
if (s_logger.isDebugEnabled()) {
s_logger.debug("StoragePool does not have required hypervisorType, skipping this pool");
}
return false;
}
if (!checkDiskProvisioningSupport(dskCh, pool)) {
return false;
}
if (!checkHypervisorCompatibility(dskCh.getHypervisorType(), dskCh.getType(), pool.getPoolType())) {
return false;
}
Volume volume = volumeDao.findById(dskCh.getVolumeId());
if (!storageMgr.storagePoolCompatibleWithVolumePool(pool, volume)) {
return false;
}
if (pool.isManaged() && !storageUtil.managedStoragePoolCanScale(pool, plan.getClusterId(), plan.getHostId())) {
return false;
}
// check capacity
List<Pair<Volume, DiskProfile>> requestVolumeDiskProfilePairs = new ArrayList<>();
requestVolumeDiskProfilePairs.add(new Pair<>(volume, dskCh));
if (dskCh.getHypervisorType() == HypervisorType.VMware) {
// Skip the parent datastore cluster, consider only child storage pools in it
if (pool.getPoolType() == Storage.StoragePoolType.DatastoreCluster && storageMgr.isStoragePoolDatastoreClusterParent(pool)) {
return false;
}
// Skip the storage pool whose parent datastore cluster is not in UP state.
if (pool.getParent() != 0L) {
StoragePoolVO datastoreCluster = storagePoolDao.findById(pool.getParent());
if (datastoreCluster == null || (datastoreCluster != null && datastoreCluster.getStatus() != StoragePoolStatus.Up)) {
return false;
}
}
try {
boolean isStoragePoolStoragepolicyComplaince = storageMgr.isStoragePoolCompliantWithStoragePolicy(requestVolumeDiskProfilePairs, pool);
if (!isStoragePoolStoragepolicyComplaince) {
return false;
}
} catch (StorageUnavailableException e) {
s_logger.warn(String.format("Could not verify storage policy complaince against storage pool %s due to exception %s", pool.getUuid(), e.getMessage()));
return false;
}
}
return storageMgr.storagePoolHasEnoughIops(requestVolumeDiskProfilePairs, pool) && storageMgr.storagePoolHasEnoughSpace(requestVolumeDiskProfilePairs, pool, plan.getClusterId());
}
use of com.cloud.dc.ClusterVO in project cloudstack by apache.
the class HypervServerDiscoverer method processConnect.
@Override
public final void processConnect(final Host agent, final StartupCommand cmd, final boolean forRebalance) throws ConnectionException {
// Limit the commands we can process
if (!(cmd instanceof StartupRoutingCommand)) {
return;
}
StartupRoutingCommand startup = (StartupRoutingCommand) cmd;
// assert
if (startup.getHypervisorType() != HypervisorType.Hyperv) {
s_logger.debug("Not Hyper-V hypervisor, so moving on.");
return;
}
long agentId = agent.getId();
HostVO host = _hostDao.findById(agentId);
// Our Hyper-V machines are not participating in pools, and the pool id
// we provide them is not persisted.
// This means the pool id can vary.
ClusterVO cluster = _clusterDao.findById(host.getClusterId());
if (cluster.getGuid() == null) {
cluster.setGuid(startup.getPool());
_clusterDao.update(cluster.getId(), cluster);
}
if (s_logger.isDebugEnabled()) {
s_logger.debug("Setting up host " + agentId);
}
HostEnvironment env = new HostEnvironment();
SetupCommand setup = new SetupCommand(env);
if (!host.isSetup()) {
setup.setNeedSetup(true);
}
try {
SetupAnswer answer = (SetupAnswer) _agentMgr.send(agentId, setup);
if (answer != null && answer.getResult()) {
host.setSetup(true);
// TODO: clean up magic numbers below
host.setLastPinged((System.currentTimeMillis() >> 10) - 5 * 60);
_hostDao.update(host.getId(), host);
if (answer.needReconnect()) {
throw new ConnectionException(false, "Reinitialize agent after setup.");
}
return;
} else {
String reason = answer.getDetails();
if (reason == null) {
reason = " details were null";
}
s_logger.warn("Unable to setup agent " + agentId + " due to " + reason);
}
// Error handling borrowed from XcpServerDiscoverer, may need to be
// updated.
} catch (AgentUnavailableException e) {
s_logger.warn("Unable to setup agent " + agentId + " because it became unavailable.", e);
} catch (OperationTimedoutException e) {
s_logger.warn("Unable to setup agent " + agentId + " because it timed out", e);
}
throw new ConnectionException(true, "Reinitialize agent after setup.");
}
use of com.cloud.dc.ClusterVO in project cloudstack by apache.
the class Ovm3Discoverer method find.
@Override
public Map<? extends ServerResource, Map<String, String>> find(long dcId, Long podId, Long clusterId, URI url, String username, String password, List<String> hostTags) throws DiscoveryException {
Connection c = null;
CheckUrl(url);
if (clusterId == null) {
String msg = "must specify cluster Id when add host";
LOGGER.info(msg);
throw new DiscoveryException(msg);
}
if (podId == null) {
String msg = "must specify pod Id when add host";
LOGGER.info(msg);
throw new DiscoveryException(msg);
}
ClusterVO cluster = clusterDao.findById(clusterId);
if (cluster == null || (cluster.getHypervisorType() != HypervisorType.Ovm3)) {
String msg = "invalid cluster id or cluster is not for Ovm3 hypervisors";
LOGGER.info(msg);
throw new DiscoveryException(msg);
} else {
LOGGER.debug("cluster: " + cluster);
}
String agentUsername = _params.get("agentusername");
if (agentUsername == null) {
String msg = "Agent user name must be specified";
LOGGER.info(msg);
throw new DiscoveryException(msg);
}
String agentPassword = _params.get("agentpassword");
if (agentPassword == null) {
String msg = "Agent password must be specified";
LOGGER.info(msg);
throw new DiscoveryException(msg);
}
String agentPort = _params.get("agentport");
if (agentPort == null) {
String msg = "Agent port must be specified";
LOGGER.info(msg);
throw new DiscoveryException(msg);
}
try {
String hostname = url.getHost();
InetAddress ia = InetAddress.getByName(hostname);
String hostIp = ia.getHostAddress();
String guid = UUID.nameUUIDFromBytes(hostIp.getBytes("UTF8")).toString();
if (checkIfExisted(guid)) {
String msg = "The host " + hostIp + " has been added before";
LOGGER.info(msg);
throw new DiscoveryException(msg);
}
LOGGER.debug("Ovm3 discover is going to disover host having guid " + guid);
ClusterVO clu = clusterDao.findById(clusterId);
if (clu.getGuid() == null) {
clu.setGuid(UUID.randomUUID().toString());
}
clusterDao.update(clusterId, clu);
Map<String, String> clusterDetails = clusterDetailsDao.findDetails(clusterId);
String ovm3vip = (clusterDetails.get("ovm3vip") == null) ? "" : clusterDetails.get("ovm3vip");
String ovm3pool = (clusterDetails.get("ovm3pool") == null) ? "false" : clusterDetails.get("ovm3pool");
String ovm3cluster = (clusterDetails.get("ovm3cluster") == null) ? "false" : clusterDetails.get("ovm3cluster");
/* should perhaps only make this connect to the agent port ? */
com.trilead.ssh2.Connection sshConnection = new com.trilead.ssh2.Connection(hostIp, 22);
sshConnection.connect(null, 60000, 60000);
sshConnection = SSHCmdHelper.acquireAuthorizedConnection(hostIp, username, password);
if (sshConnection == null) {
String msg = "Cannot Ssh to Ovm3 host(IP=" + hostIp + ", username=" + username + ", password=*******), discovery failed";
LOGGER.warn(msg);
throw new DiscoveryException(msg);
}
Map<String, String> details = new HashMap<String, String>();
Ovm3HypervisorResource ovmResource = new Ovm3HypervisorResource();
details.put("ip", hostIp);
details.put("host", hostname);
details.put("username", username);
details.put("password", password);
details.put("zone", Long.toString(dcId));
details.put("guid", guid);
details.put("pod", Long.toString(podId));
details.put("cluster", Long.toString(clusterId));
details.put("agentusername", agentUsername);
details.put("agentpassword", agentPassword);
details.put("agentport", agentPort.toString());
details.put("ovm3vip", ovm3vip);
details.put("ovm3pool", ovm3pool);
details.put("ovm3cluster", ovm3cluster);
if (publicNetworkDevice != null) {
details.put("public.network.device", publicNetworkDevice);
}
if (privateNetworkDevice != null) {
details.put("private.network.device", privateNetworkDevice);
}
if (guestNetworkDevice != null) {
details.put("guest.network.device", guestNetworkDevice);
}
if (storageNetworkDevice != null) {
details.put("storage.network.device", storageNetworkDevice);
}
Map<String, Object> params = new HashMap<String, Object>();
params.putAll(details);
ovmResource.configure(hostname, params);
ovmResource.start();
c = new Connection(hostIp, Integer.parseInt(agentPort), agentUsername, agentPassword);
/* After resource start, we are able to execute our agent api */
Linux host = new Linux(c);
details.put("agentVersion", host.getAgentVersion());
details.put(HostInfo.HOST_OS_KERNEL_VERSION, host.getHostKernelRelease());
details.put(HostInfo.HOST_OS, host.getHostOs());
details.put(HostInfo.HOST_OS_VERSION, host.getHostOsVersion());
details.put(HostInfo.HYPERVISOR_VERSION, host.getHypervisorVersion());
Map<Ovm3HypervisorResource, Map<String, String>> resources = new HashMap<Ovm3HypervisorResource, Map<String, String>>();
resources.put(ovmResource, details);
return resources;
} catch (UnknownHostException e) {
LOGGER.error("Host name resolve failed exception, Unable to discover Ovm3 host: " + url.getHost(), e);
return null;
} catch (ConfigurationException e) {
LOGGER.error("Configure resource failed, Unable to discover Ovm3 host: " + url.getHost(), e);
return null;
} catch (IOException | Ovm3ResourceException e) {
LOGGER.error("Unable to discover Ovm3 host: " + url.getHost(), e);
return null;
}
}
Aggregations