use of com.cloud.ovm.object.Connection in project cloudstack by apache.
the class OvmResourceBase method setupServer.
protected void setupServer() throws IOException {
com.trilead.ssh2.Connection sshConnection = new com.trilead.ssh2.Connection(_ip, 22);
sshConnection.connect(null, 60000, 60000);
if (!sshConnection.authenticateWithPassword(_username, _password)) {
throw new CloudRuntimeException("Unable to authenticate");
}
SCPClient scp = new SCPClient(sshConnection);
String configScriptName = "scripts/vm/hypervisor/ovm/configureOvm.sh";
String configScriptPath = Script.findScript("", configScriptName);
if (configScriptPath == null) {
throw new CloudRuntimeException("Unable to find " + configScriptName);
}
scp.put(configScriptPath, "/usr/bin/", "0755");
if (!SSHCmdHelper.sshExecuteCmd(sshConnection, "sh /usr/bin/configureOvm.sh preSetup")) {
throw new CloudRuntimeException("Execute configureOvm.sh preSetup failed on " + _ip);
}
File tmp = new File(configScriptPath);
File scriptDir = new File(tmp.getParent());
File[] scripts = scriptDir.listFiles();
for (int i = 0; i < scripts.length; i++) {
File script = scripts[i];
if (script.getName().equals("configureOvm.sh")) {
continue;
}
if (s_logger.isDebugEnabled()) {
s_logger.debug("Copying " + script.getPath() + " to " + s_ovsAgentPath + " on " + _ip + " with permission 0644");
}
scp.put(script.getPath(), s_ovsAgentPath, "0644");
}
sshConnection = SSHCmdHelper.acquireAuthorizedConnection(_ip, _username, _password);
if (sshConnection == null) {
throw new CloudRuntimeException(String.format("Cannot connect to ovm host(IP=%1$s, username=%2$s, password=%3$s", _ip, _username, _password));
}
if (!SSHCmdHelper.sshExecuteCmd(sshConnection, "sh /usr/bin/configureOvm.sh postSetup")) {
throw new CloudRuntimeException("Execute configureOvm.sh postSetup failed on " + _ip);
}
}
use of com.cloud.ovm.object.Connection in project cloudstack by apache.
the class OvmDiscoverer 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 conn = null;
if (!url.getScheme().equals("http")) {
String msg = "urlString is not http so we're not taking care of the discovery for this: " + url;
s_logger.debug(msg);
return null;
}
if (clusterId == null) {
String msg = "must specify cluster Id when add host";
s_logger.debug(msg);
throw new CloudRuntimeException(msg);
}
if (podId == null) {
String msg = "must specify pod Id when add host";
s_logger.debug(msg);
throw new CloudRuntimeException(msg);
}
ClusterVO cluster = _clusterDao.findById(clusterId);
if (cluster == null || (cluster.getHypervisorType() != HypervisorType.Ovm)) {
if (s_logger.isInfoEnabled())
s_logger.info("invalid cluster id or cluster is not for Ovm hypervisors");
return null;
}
String agentUsername = _params.get("agentusername");
if (agentUsername == null) {
throw new CloudRuntimeException("Agent user name must be specified");
}
String agentPassword = _params.get("agentpassword");
if (agentPassword == null) {
throw new CloudRuntimeException("Agent password must be specified");
}
try {
String hostname = url.getHost();
InetAddress ia = InetAddress.getByName(hostname);
String hostIp = ia.getHostAddress();
String guid = UUID.nameUUIDFromBytes(hostIp.getBytes()).toString();
if (checkIfExisted(guid)) {
throw new CloudRuntimeException("The host " + hostIp + " has been added before");
}
s_logger.debug("Ovm 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);
}
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) {
throw new DiscoveryException(String.format("Cannot connect to ovm host(IP=%1$s, username=%2$s, password=%3$s, discover failed", hostIp, username, password));
}
if (!SSHCmdHelper.sshExecuteCmd(sshConnection, "[ -f '/etc/ovs-agent/agent.ini' ]")) {
throw new DiscoveryException("Can not find /etc/ovs-agent/agent.ini " + hostIp);
}
Map<String, String> details = new HashMap<String, String>();
OvmResourceBase ovmResource = new OvmResourceBase();
details.put("ip", hostIp);
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);
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);
}
Map<String, Object> params = new HashMap<String, Object>();
params.putAll(details);
ovmResource.configure("Ovm Server", params);
ovmResource.start();
conn = new Connection(hostIp, "oracle", agentPassword);
/* After resource start, we are able to execute our agent api */
OvmHost.Details d = OvmHost.getDetails(conn);
details.put("agentVersion", d.agentVersion);
details.put(HostInfo.HOST_OS_KERNEL_VERSION, d.dom0KernelVersion);
details.put(HostInfo.HYPERVISOR_VERSION, d.hypervisorVersion);
Map<OvmResourceBase, Map<String, String>> resources = new HashMap<OvmResourceBase, Map<String, String>>();
resources.put(ovmResource, details);
return resources;
} catch (XmlRpcException e) {
s_logger.debug("XmlRpc exception, Unable to discover OVM: " + url, e);
return null;
} catch (UnknownHostException e) {
s_logger.debug("Host name resolve failed exception, Unable to discover OVM: " + url, e);
return null;
} catch (ConfigurationException e) {
s_logger.debug("Configure resource failed, Unable to discover OVM: " + url, e);
return null;
} catch (Exception e) {
s_logger.debug("Unable to discover OVM: " + url, e);
return null;
}
}
use of com.cloud.ovm.object.Connection in project cloudstack by apache.
the class OvmResourceBase method configure.
@Override
public boolean configure(String name, Map<String, Object> params) throws ConfigurationException {
_name = name;
try {
_zoneId = Long.parseLong((String) params.get("zone"));
_podId = Long.parseLong((String) params.get("pod"));
_clusterId = Long.parseLong((String) params.get("cluster"));
_ip = (String) params.get("ip");
_username = (String) params.get("username");
_password = (String) params.get("password");
_guid = (String) params.get("guid");
_privateNetworkName = (String) params.get("private.network.device");
_publicNetworkName = (String) params.get("public.network.device");
_guestNetworkName = (String) params.get("guest.network.device");
_agentUserName = (String) params.get("agentusername");
_agentPassword = (String) params.get("agentpassword");
} catch (Exception e) {
s_logger.debug("Configure " + _name + " failed", e);
throw new ConfigurationException("Configure " + _name + " failed, " + e.toString());
}
if (_podId == null) {
throw new ConfigurationException("Unable to get the pod");
}
if (_ip == null) {
throw new ConfigurationException("Unable to get the host address");
}
if (_username == null) {
throw new ConfigurationException("Unable to get the username");
}
if (_password == null) {
throw new ConfigurationException("Unable to get the password");
}
if (_guid == null) {
throw new ConfigurationException("Unable to get the guid");
}
if (_agentUserName == null) {
throw new ConfigurationException("Unable to get agent user name");
}
if (_agentPassword == null) {
throw new ConfigurationException("Unable to get agent password");
}
try {
setupServer();
} catch (Exception e) {
s_logger.debug("Setup server failed, ip " + _ip, e);
throw new ConfigurationException("Unable to setup server");
}
_conn = new Connection(_ip, _agentUserName, _agentPassword);
try {
OvmHost.registerAsMaster(_conn);
OvmHost.registerAsVmServer(_conn);
_bridges = OvmBridge.getAllBridges(_conn);
} catch (XmlRpcException e) {
s_logger.debug("Get bridges failed", e);
throw new ConfigurationException("Cannot get bridges on host " + _ip + "," + e.getMessage());
}
if (_privateNetworkName != null && !_bridges.contains(_privateNetworkName)) {
throw new ConfigurationException("Cannot find bridge " + _privateNetworkName + " on host " + _ip + ", all bridges are:" + _bridges);
}
if (_publicNetworkName != null && !_bridges.contains(_publicNetworkName)) {
throw new ConfigurationException("Cannot find bridge " + _publicNetworkName + " on host " + _ip + ", all bridges are:" + _bridges);
}
if (_guestNetworkName != null && !_bridges.contains(_guestNetworkName)) {
throw new ConfigurationException("Cannot find bridge " + _guestNetworkName + " on host " + _ip + ", all bridges are:" + _bridges);
}
/* set to false so each time ModifyStoragePoolCommand will re-setup heartbeat*/
s_isHeartBeat = false;
/*
try {
_canBridgeFirewall = canBridgeFirewall();
} catch (XmlRpcException e) {
s_logger.error("Failed to detect whether the host supports security groups.", e);
_canBridgeFirewall = false;
}
*/
_canBridgeFirewall = false;
s_logger.debug(_canBridgeFirewall ? "OVM host supports security groups." : "OVM host doesn't support security groups.");
return true;
}
Aggregations