use of com.cloud.hypervisor.ovm3.objects.Ovm3ResourceException in project cloudstack by apache.
the class Ovm3StoragePool method setupSecondaryStorage.
/**
* The secondary storage mountpoint is a uuid based on the host combined
* with the path.
*
* @param url
* @return
* @throws Ovm3ResourceException
*/
public String setupSecondaryStorage(String url) throws Ovm3ResourceException {
URI uri = URI.create(url);
if (uri.getHost() == null) {
throw new Ovm3ResourceException("Secondary storage host can not be empty!");
}
String uuid = ovmObject.newUuid(uri.getHost() + ":" + uri.getPath());
LOGGER.info("Secondary storage with uuid: " + uuid);
return setupNfsStorage(uri, uuid);
}
use of com.cloud.hypervisor.ovm3.objects.Ovm3ResourceException in project cloudstack by apache.
the class Ovm3VmSupport method plugNunplugNic.
/**
* Implements the unplug and plug feature for Nics, the boolan decides
* to either plug (true) or unplug (false)
*
* @param nic
* @param vmName
* @param plug
* @return
*/
private Answer plugNunplugNic(NicTO nic, String vmName, Boolean plug) {
try {
Xen xen = new Xen(c);
Xen.Vm vm = xen.getVmConfig(vmName);
/* check running */
if (vm == null) {
return new Answer(null, false, "Unable to execute command due to missing VM");
}
// setup the NIC in the VM config.
if (plug) {
createVif(vm, nic);
vm.setupVifs();
} else {
deleteVif(vm, nic);
}
// execute the change
xen.configureVm(ovmObject.deDash(vm.getPrimaryPoolUuid()), vm.getVmUuid());
} catch (Ovm3ResourceException e) {
String msg = "Unable to execute command due to " + e.toString();
LOGGER.debug(msg);
return new Answer(null, false, msg);
}
return new Answer(null, true, "success");
}
use of com.cloud.hypervisor.ovm3.objects.Ovm3ResourceException in project cloudstack by apache.
the class Ovm3VmSupport method createVif.
/* should add bitrates and latency... */
private Boolean createVif(Xen.Vm vm, NicTO nic) throws Ovm3ResourceException {
try {
String net = network.getNetwork(nic);
if (net != null) {
LOGGER.debug("Adding vif " + nic.getDeviceId() + " " + nic.getMac() + " " + net + " to " + vm.getVmName());
vm.addVif(nic.getDeviceId(), net, nic.getMac());
} else {
LOGGER.debug("Unable to add vif " + nic.getDeviceId() + " no network for " + vm.getVmName());
return false;
}
} catch (Exception e) {
String msg = "Unable to add vif " + nic.getType() + " for " + vm.getVmName() + " " + e.getMessage();
LOGGER.debug(msg);
throw new Ovm3ResourceException(msg);
}
return true;
}
use of com.cloud.hypervisor.ovm3.objects.Ovm3ResourceException in project cloudstack by apache.
the class Ovm3HypervisorSupport method getAllVmStates.
/**
* getAllVmStates: Get the state of all the VMs
*
* @return
* @throws Ovm3ResourceException
*/
private Map<String, State> getAllVmStates(Map<String, State> vmStateMap) throws Ovm3ResourceException {
Map<String, Xen.Vm> vms = getAllVms();
final Map<String, State> states = new HashMap<String, State>();
for (final Map.Entry<String, Xen.Vm> entry : vms.entrySet()) {
Xen.Vm vm = entry.getValue();
State ns = State.Running;
String as = vm.getVmState();
if (vm.isControlDomain() || as == null) {
continue;
}
/* need a more exact match! */
if (as.contains("r")) {
ns = State.Running;
/* The domain is blocked, and not running or runnable. */
} else if (as.contains("b")) {
ns = State.Running;
/* The domain has been paused */
} else if (as.contains("p")) {
ns = State.Running;
/* The guest has requested to be shutdown, still migrating... */
} else if (as.contains("s")) {
if (vmStateMap.get(vm.getVmName()) == State.Migrating) {
ns = State.Migrating;
} else {
ns = State.Stopped;
}
/* The domain has crashed */
} else if (as.contains("c")) {
ns = State.Error;
/*
* The domain is in process of dying (if we see this twice we
* have a problem ?)
*/
} else if (as.contains("d")) {
ns = State.Stopping;
} else {
ns = State.Unknown;
}
LOGGER.trace("state " + ns + " for " + vm.getVmName() + " based on " + as);
states.put(vm.getVmName(), ns);
}
return states;
}
use of com.cloud.hypervisor.ovm3.objects.Ovm3ResourceException in project cloudstack by apache.
the class Ovm3HypervisorSupport method execute.
/* Check if the host is in ready state for CS */
public ReadyAnswer execute(ReadyCommand cmd) {
try {
Linux host = new Linux(c);
Pool pool = new Pool(c);
/* only interesting when doing cluster */
if (!host.getIsMaster() && config.getAgentInOvm3Cluster()) {
if (pool.getPoolMasterVip().equalsIgnoreCase(c.getIp())) {
/* check pool state here */
return new ReadyAnswer(cmd);
} else {
LOGGER.debug("Master IP changes to " + pool.getPoolMasterVip() + ", it should be " + c.getIp());
return new ReadyAnswer(cmd, "I am not the master server");
}
} else if (host.getIsMaster()) {
LOGGER.debug("Master, not clustered " + config.getAgentHostname());
return new ReadyAnswer(cmd);
} else {
LOGGER.debug("No master, not clustered " + config.getAgentHostname());
return new ReadyAnswer(cmd);
}
} catch (CloudRuntimeException | Ovm3ResourceException e) {
LOGGER.debug("XML RPC Exception" + e.getMessage(), e);
throw new CloudRuntimeException("XML RPC Exception" + e.getMessage(), e);
}
}
Aggregations