use of com.cloud.hypervisor.ovm3.objects.CloudstackPlugin in project cloudstack by apache.
the class Ovm3HypervisorSupport method masterCheck.
/**
* materCheck
*
* @return
*/
public boolean masterCheck() {
if ("".equals(config.getOvm3PoolVip())) {
LOGGER.debug("No cluster vip, not checking for master");
return false;
}
try {
CloudstackPlugin cSp = new CloudstackPlugin(c);
if (cSp.dom0HasIp(config.getOvm3PoolVip())) {
LOGGER.debug(config.getAgentHostname() + " is a master, already has vip " + config.getOvm3PoolVip());
config.setAgentIsMaster(true);
} else if (cSp.ping(config.getOvm3PoolVip())) {
LOGGER.debug(config.getAgentHostname() + " has a master, someone has vip " + config.getOvm3PoolVip());
config.setAgentHasMaster(true);
} else {
LOGGER.debug(config.getAgentHostname() + " becomes a master, no one has vip " + config.getOvm3PoolVip());
config.setAgentIsMaster(true);
}
} catch (Ovm3ResourceException e) {
LOGGER.debug(config.getAgentHostname() + " can't reach master: " + e.getMessage());
config.setAgentHasMaster(false);
}
return config.getAgentIsMaster();
}
use of com.cloud.hypervisor.ovm3.objects.CloudstackPlugin in project cloudstack by apache.
the class Ovm3HypervisorResource method execute.
@Override
public synchronized StartAnswer execute(StartCommand cmd) {
VirtualMachineTO vmSpec = cmd.getVirtualMachine();
String vmName = vmSpec.getName();
State state = State.Stopped;
Xen xen = new Xen(c);
try {
hypervisorsupport.setVmStateStarting(vmName);
Xen.Vm vm = xen.getVmConfig();
/* max and min ? */
vm.setVmCpus(vmSpec.getCpus());
/* in mb not in bytes */
vm.setVmMemory(vmSpec.getMinRam() / 1024 / 1024);
vm.setVmUuid(UUID.nameUUIDFromBytes(vmSpec.getName().getBytes(Charset.defaultCharset())).toString());
vm.setVmName(vmName);
String domType = guesttypes.getOvm3GuestType(vmSpec.getOs());
if (domType == null || domType.isEmpty()) {
domType = "default";
LOGGER.debug("VM Virt type missing setting to: " + domType);
} else {
LOGGER.debug("VM Virt type set to " + domType + " for " + vmSpec.getOs());
}
vm.setVmDomainType(domType);
if (vmSpec.getBootloader() == BootloaderType.CD) {
LOGGER.warn("CD booting is not supported");
}
/*
* officially CD boot is only supported on HVM, although there is a
* simple way around it..
*/
vmsupport.createVbds(vm, vmSpec);
if (vmSpec.getType() != VirtualMachine.Type.User) {
// double check control network if we run a non user VM
hypervisornetwork.configureNetworking();
vm.setVmExtra(vmSpec.getBootArgs().replace(" ", "%"));
String svmPath = configuration.getAgentOvmRepoPath() + "/" + ovmObject.deDash(vm.getPrimaryPoolUuid()) + "/ISOs";
String svmIso = svmPath + "/" + storagepool.getSystemVMPatchIsoFile().getName();
vm.addIso(svmIso);
}
/* OVS/Network stuff should go here! */
vmsupport.createVifs(vm, vmSpec);
vm.setupVifs();
vm.setVnc("0.0.0.0", vmSpec.getVncPassword());
xen.createVm(ovmObject.deDash(vm.getPrimaryPoolUuid()), vm.getVmUuid());
xen.startVm(ovmObject.deDash(vm.getPrimaryPoolUuid()), vm.getVmUuid());
state = State.Running;
if (vmSpec.getType() != VirtualMachine.Type.User) {
String controlIp = null;
for (NicTO nic : vmSpec.getNics()) {
if (nic.getType() == TrafficType.Control) {
controlIp = nic.getIp();
}
}
/* fix is in cloudstack.py for xend restart timer */
for (int count = 0; count < 60; count++) {
CloudstackPlugin cSp = new CloudstackPlugin(c);
/* skip a beat to make sure we didn't miss start */
if (hypervisorsupport.getVmState(vmName) == null && count > 1) {
String msg = "VM " + vmName + " went missing on " + configuration.getAgentHostname() + ", returning stopped";
LOGGER.debug(msg);
state = State.Stopped;
return new StartAnswer(cmd, msg);
}
/* creative fix? */
try {
Boolean res = cSp.domrCheckSsh(controlIp);
LOGGER.debug("connected to " + controlIp + " on attempt " + count + " result: " + res);
if (res) {
break;
}
} catch (Exception x) {
LOGGER.trace("unable to connect to " + controlIp + " on attempt " + count + " " + x.getMessage(), x);
}
Thread.sleep(5000);
}
}
/*
* Can't remember if HA worked if we were only a pool ?
*/
if (configuration.getAgentInOvm3Pool() && configuration.getAgentInOvm3Cluster()) {
xen.configureVmHa(ovmObject.deDash(vm.getPrimaryPoolUuid()), vm.getVmUuid(), true);
}
/* should be starting no ? */
state = State.Running;
return new StartAnswer(cmd);
} catch (Exception e) {
LOGGER.debug("Start vm " + vmName + " failed", e);
state = State.Stopped;
return new StartAnswer(cmd, e.getMessage());
} finally {
hypervisorsupport.setVmState(vmName, state);
}
}
use of com.cloud.hypervisor.ovm3.objects.CloudstackPlugin in project cloudstack by apache.
the class Ovm3VirtualRoutingResource method executeInVR.
@Override
public ExecutionResult executeInVR(String routerIp, String script, String args, Duration timeout) {
if (!script.contains(domRCloudPath)) {
script = domRCloudPath + "/" + script;
}
String cmd = script + " " + args;
logger.debug("executeInVR via " + agentName + " on " + routerIp + ": " + cmd);
try {
CloudstackPlugin cSp = new CloudstackPlugin(c);
CloudstackPlugin.ReturnCode result;
result = cSp.domrExec(routerIp, cmd);
return new ExecutionResult(result.getRc(), result.getStdOut());
} catch (Exception e) {
logger.error("executeInVR FAILED via " + agentName + " on " + routerIp + ":" + cmd + ", " + e.getMessage(), e);
}
return new ExecutionResult(false, "");
}
use of com.cloud.hypervisor.ovm3.objects.CloudstackPlugin in project cloudstack by apache.
the class Ovm3StorageProcessor method backupSnapshot.
/**
* use the cache, or the normal nfs, also delete the leftovers for us
* also contains object store storage in xenserver.
*/
@Override
public CopyCmdAnswer backupSnapshot(CopyCommand cmd) {
LOGGER.debug("execute backupSnapshot: " + cmd.getClass());
try {
DataTO srcData = cmd.getSrcTO();
DataTO destData = cmd.getDestTO();
SnapshotObjectTO src = (SnapshotObjectTO) srcData;
SnapshotObjectTO dest = (SnapshotObjectTO) destData;
// src.getPath contains the uuid of the snapshot.
String srcFile = getVirtualDiskPath(src.getPath(), src.getDataStore().getUuid());
// destination
String storeUrl = dest.getDataStore().getUrl();
String secPoolUuid = pool.setupSecondaryStorage(storeUrl);
String destDir = config.getAgentSecStoragePath() + "/" + secPoolUuid + "/" + dest.getPath();
String destFile = destDir + "/" + src.getPath();
destFile = destFile.concat(".raw");
// copy
Linux host = new Linux(c);
CloudstackPlugin csp = new CloudstackPlugin(c);
csp.ovsMkdirs(destDir);
LOGGER.debug("CopyFrom: " + srcData.getObjectType() + "," + srcFile + " to " + destData.getObjectType() + "," + destFile);
host.copyFile(srcFile, destFile);
StoragePlugin sp = new StoragePlugin(c);
sp.storagePluginDestroy(secPoolUuid, srcFile);
SnapshotObjectTO newSnap = new SnapshotObjectTO();
// newSnap.setPath(destFile);
// damnit frickin crap, no reference whatsoever... could use parent ?
newSnap.setPath(dest.getPath() + "/" + src.getPath() + ".raw");
newSnap.setParentSnapshotPath(null);
return new CopyCmdAnswer(newSnap);
} catch (Ovm3ResourceException e) {
String msg = "Error backupSnapshot: " + e.getMessage();
LOGGER.info(msg);
return new CopyCmdAnswer(msg);
}
}
use of com.cloud.hypervisor.ovm3.objects.CloudstackPlugin 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;
}
Aggregations