use of com.cloud.hypervisor.ovm3.objects.Connection in project cloudstack by apache.
the class Ovm3StoragePool method addMembers.
/**
* Adding members to a pool, this is seperate from cluster configuration in
* OVM.
*
* @return
* @throws Ovm3ResourceException
*/
private Boolean addMembers() throws Ovm3ResourceException {
List<String> members = new ArrayList<String>();
try {
Connection m = new Connection(config.getOvm3PoolVip(), c.getPort(), c.getUserName(), c.getPassword());
Pool poolPrimary = new Pool(m);
if (poolPrimary.isInAPool()) {
members.addAll(poolPrimary.getPoolMemberList());
if (!poolPrimary.getPoolMemberList().contains(c.getIp()) && c.getIp().equals(config.getOvm3PoolVip())) {
members.add(c.getIp());
}
} else {
LOGGER.warn(c.getIp() + " noticed primary " + config.getOvm3PoolVip() + " is not part of pool");
return false;
}
/* a cluster shares usernames and passwords */
for (String member : members) {
Connection x = new Connection(member, c.getPort(), c.getUserName(), c.getPassword());
Pool poolM = new Pool(x);
if (poolM.isInAPool()) {
poolM.setPoolMemberList(members);
LOGGER.debug("Added " + members + " to pool " + poolM.getPoolId() + " on member " + member);
} else {
LOGGER.warn(member + " unable to be member of a pool it's not in");
return false;
}
}
} catch (Exception e) {
throw new Ovm3ResourceException("Unable to add members: " + e.getMessage(), e);
}
return true;
}
use of com.cloud.hypervisor.ovm3.objects.Connection 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;
}
}
use of com.cloud.hypervisor.ovm3.objects.Connection in project cloudstack by apache.
the class Ovm3HypervisorSupport method setupServer.
/**
* setupServer:
* Add the cloudstack plugin and setup the agent.
* Add the ssh keys to the host.
*
* @param c
* @throws IOException
*/
public Boolean setupServer(String key) throws IOException {
LOGGER.debug("Setup all bits on agent: " + config.getAgentHostname());
/* version dependent patching ? */
try {
com.trilead.ssh2.Connection sshConnection = SSHCmdHelper.acquireAuthorizedConnection(config.getAgentIp(), config.getAgentSshUserName(), config.getAgentSshPassword());
if (sshConnection == null) {
throw new ConfigurationException(String.format("Unable to " + "connect to server(IP=%1$s, username=%2$s, " + "password=%3$s", config.getAgentIp(), config.getAgentSshUserName(), config.getAgentSshPassword()));
}
SCPClient scp = new SCPClient(sshConnection);
String userDataScriptDir = "scripts/vm/hypervisor/ovm3/";
String userDataScriptPath = Script.findScript("", userDataScriptDir);
if (userDataScriptPath == null) {
throw new ConfigurationException("Can not find " + userDataScriptDir);
}
String mkdir = "mkdir -p " + config.getAgentScriptsDir();
if (!SSHCmdHelper.sshExecuteCmd(sshConnection, mkdir)) {
throw new ConfigurationException("Failed " + mkdir + " on " + config.getAgentHostname());
}
for (String script : config.getAgentScripts()) {
script = userDataScriptPath + "/" + script;
scp.put(script, config.getAgentScriptsDir(), "0755");
}
String prepareCmd = String.format(config.getAgentScriptsDir() + "/" + config.getAgentScript() + " --ssl=" + c.getUseSsl() + " " + "--port=" + c.getPort());
if (!SSHCmdHelper.sshExecuteCmd(sshConnection, prepareCmd)) {
throw new ConfigurationException("Failed to insert module on " + config.getAgentHostname());
} else {
/* because of OVM 3.3.1 (might be 2000) */
Thread.sleep(5000);
}
CloudstackPlugin cSp = new CloudstackPlugin(c);
cSp.ovsUploadSshKey(config.getAgentSshKeyFileName(), FileUtils.readFileToString(getSystemVMKeyFile(key)));
cSp.dom0CheckStorageHealthCheck(config.getAgentScriptsDir(), config.getAgentCheckStorageScript(), config.getCsHostGuid(), config.getAgentStorageCheckTimeout(), config.getAgentStorageCheckInterval());
} catch (Exception es) {
LOGGER.error("Unexpected exception ", es);
String msg = "Unable to install module in agent";
throw new CloudRuntimeException(msg);
}
return true;
}
use of com.cloud.hypervisor.ovm3.objects.Connection in project cloudstack by apache.
the class Ovm3HypervisorResource method initialize.
/*
* configure is called before this, does setup of the connection and
* gets the params.
*
* @see com.cloud.resource.ServerResource#initialize()
*/
@Override
public StartupCommand[] initialize() {
LOGGER.debug("Ovm3 resource intializing");
try {
StartupRoutingCommand srCmd = new StartupRoutingCommand();
StartupStorageCommand ssCmd = new StartupStorageCommand();
/* here stuff gets completed, but where should state live ? */
hypervisorsupport.fillHostInfo(srCmd);
hypervisorsupport.vmStateMapClear();
LOGGER.debug("Ovm3 pool " + ssCmd + " " + srCmd);
return new StartupCommand[] { srCmd, ssCmd };
} catch (Exception e) {
LOGGER.debug("Ovm3 resource initializes failed", e);
return new StartupCommand[] {};
}
}
use of com.cloud.hypervisor.ovm3.objects.Connection in project cloudstack by apache.
the class Ovm3HypervisorResource method configure.
/**
* Base configuration of the plugins components.
*/
@Override
public boolean configure(String name, Map<String, Object> params) throws ConfigurationException {
LOGGER.debug("configure " + name + " with params: " + params);
/* check if we're primary or not and if we can connect */
try {
configuration = new Ovm3Configuration(params);
if (!configuration.getIsTest()) {
c = new Connection(configuration.getAgentIp(), configuration.getAgentOvsAgentPort(), configuration.getAgentOvsAgentUser(), configuration.getAgentOvsAgentPassword());
c.setHostName(configuration.getAgentHostname());
}
hypervisorsupport = new Ovm3HypervisorSupport(c, configuration);
if (!configuration.getIsTest()) {
hypervisorsupport.setupServer(configuration.getAgentSshKeyFileName());
}
hypervisorsupport.primaryCheck();
} catch (Exception e) {
throw new CloudRuntimeException("Base checks failed for " + configuration.getAgentHostname(), e);
}
hypervisornetwork = new Ovm3HypervisorNetwork(c, configuration);
hypervisornetwork.configureNetworking();
virtualroutingresource = new Ovm3VirtualRoutingResource(c);
storagepool = new Ovm3StoragePool(c, configuration);
storagepool.prepareForPool();
storageprocessor = new Ovm3StorageProcessor(c, configuration, storagepool);
vmsupport = new Ovm3VmSupport(c, configuration, hypervisorsupport, storageprocessor, storagepool, hypervisornetwork);
vrResource = new VirtualRoutingResource(virtualroutingresource);
if (!vrResource.configure(name, params)) {
throw new ConfigurationException("Unable to configure VirtualRoutingResource");
}
guesttypes = new Ovm3VmGuestTypes();
storageHandler = new StorageSubsystemCommandHandlerBase(storageprocessor);
virtualroutingsupport = new Ovm3VirtualRoutingSupport(c, configuration, virtualroutingresource);
setConfigParams(params);
return true;
}
Aggregations