oVirt虚拟机控制台连接流程分析

1. VmListModel.java
private void connectToConsoles() {
  final VmConsoles consoles=consolesFactory.getVmConsolesForVm(vm);
  ...
  consoles.connect();
}

2. VmConsoles.java
void connect() throws ConsoleConnectException;

3. VmConsolesImpl.java
    public void connect() throws ConsoleConnectException {
        if (!canConnectToConsole()) {
            throw new ConsoleConnectException(connectErrorMessage());
        }

        getConsoleModel(getSelectedProcotol().getBackingClass()).getConnectCommand().execute();
    }

4. ConsoleModel.java
    @Override
    public void executeCommand(UICommand command) {
        super.executeCommand(command);

        if (command == getConnectCommand()) {
            connect();
        }
    }

    protected abstract void connect();

5. SpiceConsoleModel.java
    @Override
    protected void connect() {
        if (getEntity() != null) {
            getLogger().debug("Connecting to Spice console..."); //$NON-NLS-1$

            // Don't connect if there VM is not running on any host.
            if (getEntity().getRunOnVds() == null) {
                return;
            }

            // If it is not windows or SPICE guest agent is not installed, make sure the WAN options are disabled.
            if (!AsyncDataProvider.getInstance().isWindowsOsType(getEntity().getVmOsId()) || !getEntity().getHasSpiceDriver()) {
                getspice().getOptions().setWanOptionsEnabled(false);
            }

            UICommand invokeConsoleCommand = new UICommand("invokeConsoleCommand", new BaseCommandTarget() { //$NON-NLS-1$
                @Override
                public void executeCommand(UICommand uiCommand) {
                    invokeConsole();
                }
            });
            executeCommandWithConsoleSafenessWarning(invokeConsoleCommand);
        }
    }

6. SpiceConsoleModel.java
public void invokeConsole() {
  Frontend.getInstance().runAction(VdcActionType.VmLogon, new VmOperationParameterBase(getEntity().getId()),  //先登录到虚拟机里面判断用户名和密码是否正确

  spiceConsoleModel.executeQuery(getEntity());

  ((SpiceConsoleModel) model).invokeClient(null);

public void invokeClient(final List<RepoImage> repoImages) {
  try {
       getspice().setOptions(configuredOptions);
       if (getspice() instanceof HasForeignMenuData) {
           setForeignMenuData((HasForeignMenuData) getspice());
       }
       getspice().invokeClient();  //如果上面判断成功了,就会执行到这里,这里就是初始化console.vv文件里面的内容
   } catch (RuntimeException ex) {
       getLogger().error("Exception on Spice connect", ex); //$NON-NLS-1$
  }

}

7. ConsoleClient.java
public interface ConsoleClient {
    ConsoleOptions getOptions();
    void setOptions(ConsoleOptions options);
    void invokeClient();  //根据使用的协议类型来进行跳转
}

8. 如果我们用的是原生spice协议,则 SpiceNativeImpl.java
public class SpiceNativeImpl extends AbstractSpice implements ISpiceNative {

    @Override
    public void invokeClient() {
        AsyncQuery callback = new AsyncQuery(this, new INewAsyncCallback() {
            @Override
            public void onSuccess(Object model, Object returnValue) { // todo avoid code duplication with vnc
                StringBuilder configBuilder = new StringBuilder((String) ((VdcQueryReturnValue) returnValue).getReturnValue());
                writeHYPERSysSection(configBuilder, getOptions());
                ConsoleModel.makeConsoleConfigRequest("console.vv", //$NON-NLS-1$
                        "application/x-virt-viewer; charset=UTF-8", //$NON-NLS-1$
                        configBuilder.toString());
            }
        });

        Frontend.getInstance().runQuery(
                VdcQueryType.GetConsoleDescriptorFile,
                new ConsoleOptionsParams(getOptions()), callback);
    }
}

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值