private String buildUrl(String path) { UriComponentsBuilder ub = UriComponentsBuilder.newInstance(); ub.scheme(KVMGlobalProperty.AGENT_URL_SCHEME); ub.host(self.getManagementIp()); ub.port(KVMGlobalProperty.AGENT_PORT); if (!"".equals(KVMGlobalProperty.AGENT_URL_ROOT_PATH)) { ub.path(KVMGlobalProperty.AGENT_URL_ROOT_PATH); } ub.path(path); return ub.build().toUriString(); }
private boolean checkMigrateNetworkCidrOfHost(String cidr) { if (NetworkUtils.isIpv4InCidr(self.getManagementIp(), cidr)) { return true; } final String extraIps = HostSystemTags.EXTRA_IPS.getTokenByResourceUuid( self.getUuid(), HostSystemTags.EXTRA_IPS_TOKEN); if (extraIps == null) { logger.error(String.format("Host[uuid:%s] has no IPs in migrate network", self.getUuid())); return false; } final String[] ips = extraIps.split(","); for (String ip: ips) { if (NetworkUtils.isIpv4InCidr(ip, cidr)) { return true; } } return false; }
protected void maintenanceHook(final Completion completion) { FlowChain chain = FlowChainBuilder.newShareFlowChain(); chain.setName(String.format("maintenance-mode-host-%s-ip-%s", self.getUuid(), self.getManagementIp()));
trigger.fail(operr("after connecting, host[name:%s, ip:%s] returns a null os version", vo.getName(), vo.getManagementIp())); return; vo.getClusterUuid(), currentVersion, vo.getName(), vo.getManagementIp(), mineVersion)); return;
private SshResult runShell(String script) { Ssh ssh = new Ssh(); ssh.setHostname(self.getManagementIp()); ssh.setPort(getSelf().getPort()); ssh.setUsername(getSelf().getUsername()); ssh.setPassword(getSelf().getPassword()); ssh.shell(script); return ssh.runAndClose(); }
if (!rsp.isSuccess() || !rsp.isIptablesSucc()) { errCode = operr("unable to connect to kvm host[uuid:%s, ip:%s, url:%s], because %s", self.getUuid(), self.getManagementIp(), connectPath, rsp.getError()); } else { VersionComparator libvirtVersion = new VersionComparator(rsp.getLibvirtVersion()); hostOS, self.getUuid(), self.getName(), self.getManagementIp(), rsp.getLibvirtVersion(), rsp.getQemuVersion())); errCode = operr("unable to connect to kvm host[uuid:%s, ip:%s, url:%s], because %s", self.getUuid(), self.getManagementIp(), connectPath, e.getMessage()); } catch (Throwable t) {
private void continueConnect(final boolean newAdded, final Completion completion) { ErrorCode errCode = connectToAgent(); if (errCode != null) { throw new OperationFailureException(errCode); } FlowChain chain = FlowChainBuilder.newSimpleFlowChain(); chain.setName(String.format("continue-connecting-kvm-host-%s-%s", self.getManagementIp(), self.getUuid())); for (KVMHostConnectExtensionPoint extp : factory.getConnectExtensions()) { KVMHostConnectedContext ctx = new KVMHostConnectedContext(); ctx.setInventory((KVMHostInventory) getSelfInventory()); ctx.setNewAddedHost(newAdded); chain.then(extp.createKvmHostConnectingFlow(ctx)); } chain.done(new FlowDoneHandler(completion) { @Override public void handle(Map data) { if (noStorageAccessible()){ completion.fail(operr("host can not access any primary storage, please check network")); } else { completion.success(); } } }).error(new FlowErrorHandler(completion) { @Override public void handle(ErrorCode errCode, Map data) { completion.fail(err(HostErrors.CONNECTION_ERROR, errCode, "connection error for KVM host[uuid:%s, ip:%s]", self.getUuid(), self.getManagementIp())); } }).start(); }
private void pauseVm(final PauseVmOnHypervisorMsg msg, final NoErrorCompletion completion) { checkStatus(); final VmInstanceInventory vminv = msg.getVmInventory(); PauseVmOnHypervisorReply reply = new PauseVmOnHypervisorReply(); PauseVmCmd cmd = new PauseVmCmd(); cmd.setUuid(vminv.getUuid()); cmd.setTimeout(120); new Http<>(pauseVmPath, cmd, PauseVmResponse.class).call(new ReturnValueCompletion<PauseVmResponse>(msg, completion) { @Override public void success(PauseVmResponse ret) { if (!ret.isSuccess()) { reply.setError(err(HostErrors.FAILED_TO_STOP_VM_ON_HYPERVISOR, "unable to pause vm[uuid:%s, name:%s] on kvm host[uuid:%s, ip:%s], because %s", vminv.getUuid(), vminv.getName(), self.getUuid(), self.getManagementIp(), ret.getError())); logger.warn(reply.getError().getDetails()); } bus.reply(msg, reply); completion.done(); } @Override public void fail(ErrorCode err) { reply.setError(err); bus.reply(msg, reply); completion.done(); } }); }
} catch (KVMException e) { String err = String.format("failed to reboot vm[uuid:%s name:%s] on kvm host[uuid:%s, ip:%s], because %s", vminv.getUuid(), vminv.getName(), self.getUuid(), self.getManagementIp(), e.getMessage()); logger.warn(err, e); throw new OperationFailureException(operr(err));
private void handle(KvmRunShellMsg msg) { SshResult result = runShell(msg.getScript()); KvmRunShellReply reply = new KvmRunShellReply(); if (result.isSshFailure()) { reply.setError(operr("unable to connect to KVM[ip:%s, username:%s, sshPort:%d ] to do DNS check," + " please check if username/password is wrong; %s", self.getManagementIp(), getSelf().getUsername(), getSelf().getPort(), result.getExitErrorMessage())); } else { reply.setStdout(result.getStdout()); reply.setStderr(result.getStderr()); reply.setReturnCode(result.getReturnCode()); } bus.reply(msg, reply); }
protected HostVO(HostVO vo) { this.setClusterUuid(vo.getClusterUuid()); this.setStatus(vo.getStatus()); this.setCreateDate(vo.getCreateDate()); this.setDescription(vo.getDescription()); this.setHypervisorType(vo.getHypervisorType()); this.setLastOpDate(vo.getLastOpDate()); this.setManagementIp(vo.getManagementIp()); this.setName(vo.getName()); this.setState(vo.getState()); this.setUuid(vo.getUuid()); this.setZoneUuid(vo.getZoneUuid()); this.setCapacity(vo.getCapacity()); } }
} catch (KVMException e) { ErrorCode err = operr("failed to stop vm[uuid:%s name:%s] on kvm host[uuid:%s, ip:%s], because %s", vminv.getUuid(), vminv.getName(), self.getUuid(), self.getManagementIp(), e.getMessage()); throw new OperationFailureException(err);
cmd.setBootMode(bootMode == null ? ImageBootMode.Legacy.toString() : bootMode); cmd.setBootDev(toKvmBootDev(spec.getBootOrders())); cmd.setHostManagementIp(self.getManagementIp()); cmd.setConsolePassword(spec.getConsolePassword()); cmd.setUsbRedirect(spec.getUsbRedirect());
} catch (KVMException e) { ErrorCode err = operr("failed to destroy vm[uuid:%s name:%s] on kvm host[uuid:%s, ip:%s], because %s", vminv.getUuid(), vminv.getName(), self.getUuid(), self.getManagementIp(), e.getMessage()); throw new OperationFailureException(err);
protected HostInventory(HostVO vo) { this.setStatus(vo.getStatus().toString()); this.setCreateDate(vo.getCreateDate()); this.setDescription(vo.getDescription()); this.setHypervisorType(vo.getHypervisorType()); this.setLastOpDate(vo.getLastOpDate()); this.setManagementIp(vo.getManagementIp()); this.setName(vo.getName()); this.setState(vo.getState().toString()); this.setUuid(vo.getUuid()); this.setZoneUuid(vo.getZoneUuid()); this.setClusterUuid(vo.getClusterUuid()); if (vo.getCapacity() != null) { this.setTotalCpuCapacity(vo.getCapacity().getTotalCpu()); this.setAvailableCpuCapacity(vo.getCapacity().getAvailableCpu()); this.setTotalMemoryCapacity(vo.getCapacity().getTotalMemory()); this.setAvailableMemoryCapacity(vo.getCapacity().getAvailableMemory()); this.setCpuSockets(vo.getCapacity().getCpuSockets()); this.setCpuNum(vo.getCapacity().getCpuNum()); } }
throw new OperationFailureException(err(SysErrors.NO_CAPABILITY_ERROR, "kvm host[uuid:%s, name:%s, ip:%s] doesn't not support live snapshot. please stop vm[uuid:%s] and try again", self.getUuid(), self.getName(), self.getManagementIp(), msg.getVmUuid() ));