Examples of VirtualMachineTO


Examples of com.cloud.agent.api.to.VirtualMachineTO

        String vncAddr = "";
        String vncPassword = "mySuperSecretPassword";

        LibvirtComputingResource lcr = new LibvirtComputingResource();
        VirtualMachineTO to = new VirtualMachineTO(id, name, VirtualMachine.Type.User, cpus, minSpeed, maxSpeed, minRam, maxRam, BootloaderType.HVM, os, false, false, vncPassword);
        to.setVncAddr(vncAddr);
        to.setUuid("b0f0a72d-7efb-3cad-a8ff-70ebf30b3af9");

        LibvirtVMDef vm = lcr.createVMFromSpec(to);
        vm.setHvsType(_hyperVisorType);

        String vmStr = "<domain type='" + _hyperVisorType + "'>\n";
View Full Code Here

Examples of com.cloud.agent.api.to.VirtualMachineTO

    @Override
    public StartAnswer execute(StartCommand cmd) {
        StartAnswer answer = super.execute(cmd);

        VirtualMachineTO vmSpec = cmd.getVirtualMachine();
        if (vmSpec.getType() == VirtualMachine.Type.ConsoleProxy) {
            Connection conn = getConnection();
            String publicIp = null;
            for (NicTO nic : vmSpec.getNics()) {
                if (nic.getType() == TrafficType.Guest) {
                    publicIp = nic.getIp();
                }
            }
            callHostPlugin(conn, "vmops", "setDNATRule", "ip", publicIp, "port", "8443", "add", "true");
View Full Code Here

Examples of com.cloud.agent.api.to.VirtualMachineTO

        Host srcHost = mock(Host.class);
        Host destHost = mock(Host.class);
        when(srcHost.getClusterId()).thenReturn(1L);
        when(destHost.getClusterId()).thenReturn(1L);
        Map<VolumeInfo, DataStore> volumeMap = new HashMap<VolumeInfo, DataStore>();
        VirtualMachineTO to = mock(VirtualMachineTO.class);
        when(to.getId()).thenReturn(6L);
        VMInstanceVO instance = mock(VMInstanceVO.class);
        when(instanceDao.findById(6L)).thenReturn(instance);

        MockContext<CommandResult> context = new MockContext<CommandResult>(null, null, volumeMap);
        AsyncCallbackDispatcher<VmwareStorageMotionStrategyTest, CopyCommandResult> caller = AsyncCallbackDispatcher.create(this);
View Full Code Here

Examples of com.cloud.agent.api.to.VirtualMachineTO

        Host srcHost = mock(Host.class);
        Host destHost = mock(Host.class);
        when(srcHost.getClusterId()).thenReturn(1L);
        when(destHost.getClusterId()).thenReturn(1L);
        Map<VolumeInfo, DataStore> volumeMap = new HashMap<VolumeInfo, DataStore>();
        VirtualMachineTO to = mock(VirtualMachineTO.class);
        when(to.getId()).thenReturn(6L);
        VMInstanceVO instance = mock(VMInstanceVO.class);
        when(instanceDao.findById(6L)).thenReturn(instance);

        MockContext<CommandResult> context = new MockContext<CommandResult>(null, null, volumeMap);
        AsyncCallbackDispatcher<VmwareStorageMotionStrategyTest, CopyCommandResult> caller = AsyncCallbackDispatcher.create(this);
View Full Code Here

Examples of com.cloud.agent.api.to.VirtualMachineTO

        Host srcHost = mock(Host.class);
        Host destHost = mock(Host.class);
        when(srcHost.getClusterId()).thenReturn(1L);
        when(destHost.getClusterId()).thenReturn(2L);
        Map<VolumeInfo, DataStore> volumeMap = new HashMap<VolumeInfo, DataStore>();
        VirtualMachineTO to = mock(VirtualMachineTO.class);
        when(to.getId()).thenReturn(6L);
        VMInstanceVO instance = mock(VMInstanceVO.class);
        when(instanceDao.findById(6L)).thenReturn(instance);

        MockContext<CommandResult> context = new MockContext<CommandResult>(null, null, volumeMap);
        AsyncCallbackDispatcher<VmwareStorageMotionStrategyTest, CopyCommandResult> caller = AsyncCallbackDispatcher.create(this);
View Full Code Here

Examples of com.cloud.agent.api.to.VirtualMachineTO

        Host srcHost = mock(Host.class);
        Host destHost = mock(Host.class);
        when(srcHost.getClusterId()).thenReturn(1L);
        when(destHost.getClusterId()).thenReturn(2L);
        Map<VolumeInfo, DataStore> volumeMap = new HashMap<VolumeInfo, DataStore>();
        VirtualMachineTO to = mock(VirtualMachineTO.class);
        when(to.getId()).thenReturn(6L);
        VMInstanceVO instance = mock(VMInstanceVO.class);
        when(instanceDao.findById(6L)).thenReturn(instance);

        MockContext<CommandResult> context = new MockContext<CommandResult>(null, null, volumeMap);
        AsyncCallbackDispatcher<VmwareStorageMotionStrategyTest, CopyCommandResult> caller = AsyncCallbackDispatcher.create(this);
View Full Code Here

Examples of com.cloud.agent.api.to.VirtualMachineTO

    return HypervisorType.BareMetal;
  }

  @Override
  public <T extends VirtualMachine> VirtualMachineTO implement(VirtualMachineProfile<T> vm) {
    VirtualMachineTO to = toVirtualMachineTO(vm);

    VMInstanceVO vo = _vmDao.findById(vm.getId());
        if (vo.getLastHostId() == null) {
            to.setBootArgs(BaremetalManager.DO_PXE);
        }
       
        Map<String, String> details = new HashMap<String, String>();
        details.put("template", vm.getTemplate().getUrl());
        to.setDetails(details);
       
    // Determine the VM's OS description
    GuestOSVO guestOS = _guestOsDao.findById(vm.getVirtualMachine().getGuestOSId());
    to.setOs(guestOS.getDisplayName());

    return to;
  }
View Full Code Here

Examples of com.cloud.agent.api.to.VirtualMachineTO

    return success ? new StopAnswer(cmd, "Success", 0, true) : new StopAnswer(cmd, "IPMI power off failed", false);
  }

  protected StartAnswer execute(StartCommand cmd) {
    VirtualMachineTO vm = cmd.getVirtualMachine();
    State state = State.Stopped;

    try {
      changeVmState(vm.getName(), State.Starting);

      OutputInterpreter.AllLinesParser interpreter = new OutputInterpreter.AllLinesParser();
      if (!doScript(_getStatusCommand, interpreter)) {
        return new StartAnswer(cmd, "Cannot get current power status of " + _name);
      }

      if (isPowerOn(interpreter.getLines())) {
        if (!doScript(_rebootCommand)) {
          return new StartAnswer(cmd, "IPMI reboot failed");
        }
      } else {
        if (!doScript(_powerOnCommand)) {
          return new StartAnswer(cmd, "IPMI power on failed");
        }
      }

      if (_isEchoScAgent) {
          SecurityGroupHttpClient hc = new SecurityGroupHttpClient();
          boolean echoRet = hc.echo(vm.getNics()[0].getIp(), TimeUnit.MINUTES.toMillis(30), TimeUnit.MINUTES.toMillis(1));
          if (!echoRet) {
              return new StartAnswer(cmd, String.format("Call security group agent on vm[%s] timeout", vm.getNics()[0].getIp()));
          }
      }

      s_logger.debug("Start bare metal vm " + vm.getName() + "successfully");
      state = State.Running;
      _vmName = vm.getName();
      return new StartAnswer(cmd);
    } finally {
      if (state != State.Stopped) {
        changeVmState(vm.getName(), state);
      } else {
        removeVmState(vm.getName());
      }
    }
  }
View Full Code Here

Examples of com.cloud.agent.api.to.VirtualMachineTO

  }

  @Override
  public <T extends VirtualMachine> VirtualMachineTO implement(
      VirtualMachineProfile<T> vm) {
    VirtualMachineTO to = toVirtualMachineTO(vm);

    // Determine the VM's OS description
    GuestOSVO guestOS = _guestOsDao.findById(vm.getVirtualMachine().getGuestOSId());
    to.setOs(guestOS.getDisplayName());

    return to;
  }
View Full Code Here

Examples of com.cloud.agent.api.to.VirtualMachineTO

        if (s_logger.isInfoEnabled()) {
            s_logger.info("Executing resource MigrateWithStorageCommand: " + _gson.toJson(cmd));
        }

        VirtualMachineTO vmTo = cmd.getVirtualMachine();
        final String vmName = vmTo.getName();

        State state = null;
        synchronized (_vms) {
            state = _vms.get(vmName);
            _vms.put(vmName, State.Stopping);
        }

        VmwareHypervisorHost srcHyperHost = null;
        VmwareHypervisorHost tgtHyperHost = null;
        VirtualMachineMO vmMo = null;

        ManagedObjectReference morDsAtTarget = null;
        ManagedObjectReference morDsAtSource = null;
        ManagedObjectReference morDc = null;
        ManagedObjectReference morDcOfTargetHost = null;
        ManagedObjectReference morTgtHost = new ManagedObjectReference();
        VirtualMachineRelocateSpec relocateSpec = new VirtualMachineRelocateSpec();
        List<VirtualMachineRelocateSpecDiskLocator> diskLocators = new ArrayList<VirtualMachineRelocateSpecDiskLocator>();
        VirtualMachineRelocateSpecDiskLocator diskLocator = null;

        boolean isFirstDs = true;
        String tgtDsName = "";
        String tgtDsNfsHost;
        String tgtDsNfsPath;
        int tgtDsNfsPort;
        VolumeTO volume;
        StorageFilerTO filerTo;
        Set<String> mountedDatastoresAtSource = new HashSet<String>();
        List<VolumeObjectTO> volumeToList =  new ArrayList<VolumeObjectTO>();
        Map<Long, Integer> volumeDeviceKey = new HashMap<Long, Integer>();

        Map<VolumeTO, StorageFilerTO> volToFiler = cmd.getVolumeToFiler();
        String tgtHost = cmd.getTargetHost();
        String tgtHostMorInfo = tgtHost.split("@")[0];
        morTgtHost.setType(tgtHostMorInfo.split(":")[0]);
        morTgtHost.setValue(tgtHostMorInfo.split(":")[1]);

        try {
            srcHyperHost = getHyperHost(getServiceContext());
            tgtHyperHost = new HostMO(getServiceContext(), morTgtHost);
            morDc = srcHyperHost.getHyperHostDatacenter();
            morDcOfTargetHost = tgtHyperHost.getHyperHostDatacenter();
            if (!morDc.getValue().equalsIgnoreCase(morDcOfTargetHost.getValue())) {
                String msg = "Source host & target host are in different datacentesr";
                throw new CloudRuntimeException(msg);
            }
            VmwareManager mgr = tgtHyperHost.getContext().getStockObject(VmwareManager.CONTEXT_STOCK_NAME);

            // find VM through datacenter (VM is not at the target host yet)
            vmMo = srcHyperHost.findVmOnPeerHyperHost(vmName);
            if (vmMo == null) {
                String msg = "VM " + vmName + " does not exist in VMware datacenter " + morDc.getValue();
                s_logger.error(msg);
                throw new Exception(msg);
            }

            // Get details of each target datastore & attach to source host.
            for (Entry<VolumeTO, StorageFilerTO> entry : volToFiler.entrySet()) {
                volume = entry.getKey();
                filerTo = entry.getValue();

                volume.getPoolUuid().replace("-", "");
                tgtDsName = filerTo.getUuid().replace("-", "");
                tgtDsNfsHost = filerTo.getHost();
                tgtDsNfsPath = filerTo.getPath();
                tgtDsNfsPort = filerTo.getPort();

                s_logger.debug("Preparing spec for volume : " + volume.getName());
                morDsAtTarget = HypervisorHostHelper.findDatastoreWithBackwardsCompatibility(tgtHyperHost, filerTo.getUuid());
                if (morDsAtTarget == null) {
                    String msg = "Unable to find the mounted datastore with uuid " + morDsAtTarget + " to execute MigrateWithStorageCommand";
                    s_logger.error(msg);
                    throw new Exception(msg);
                }
                morDsAtSource = HypervisorHostHelper.findDatastoreWithBackwardsCompatibility(srcHyperHost, filerTo.getUuid());
                if (morDsAtSource == null) {
                    morDsAtSource = srcHyperHost.mountDatastore(false, tgtDsNfsHost, tgtDsNfsPort, tgtDsNfsPath, tgtDsName);
                    if (morDsAtSource == null) {
                        throw new Exception("Unable to mount datastore " + tgtDsNfsHost + ":/" + tgtDsNfsPath + " on " + _hostName);
                    }
                    mountedDatastoresAtSource.add(tgtDsName);
                    s_logger.debug("Mounted datastore " + tgtDsNfsHost + ":/" + tgtDsNfsPath + " on " + _hostName);
                }

                if (isFirstDs) {
                    relocateSpec.setDatastore(morDsAtSource);
                    isFirstDs = false;
                }
                VmwareStorageLayoutHelper.getVmwareDatastorePathFromVmdkFileName(
                        new DatastoreMO(srcHyperHost.getContext(), morDsAtSource),
                        vmName,
                        volume.getPath() + ".vmdk");
                diskLocator = new VirtualMachineRelocateSpecDiskLocator();
                diskLocator.setDatastore(morDsAtSource);
                int diskId = getVirtualDiskInfo(vmMo, volume.getPath() + ".vmdk");
                diskLocator.setDiskId(diskId);

                diskLocators.add(diskLocator);
                volumeDeviceKey.put(volume.getId(), diskId);

            }
            relocateSpec.getDisk().addAll(diskLocators);

            // Prepare network at target before migration
            NicTO[] nics = vmTo.getNics();
            for (NicTO nic : nics) {
                // prepare network on the host
                prepareNetworkFromNicInfo(new HostMO(getServiceContext(), morTgtHost), nic, false, vmTo.getType());
            }

            // Ensure secondary storage mounted on target host
            String secStoreUrl = mgr.getSecondaryStorageStoreUrl(Long.parseLong(_dcId));
            if(secStoreUrl == null) {
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.