VirtualMachine.getHostId
Code IndexAdd Codota to your IDE (free)

Best code snippets using com.cloud.vm.VirtualMachine.getHostId(Showing top 15 results out of 315)

origin: apache/cloudstack

private Long getHostId(VolumeInfo volumeInfo) {
  VirtualMachine virtualMachine = volumeInfo.getAttachedVM();
  if (virtualMachine == null) {
    return null;
  }
  Long hostId = virtualMachine.getHostId();
  if (hostId == null) {
    hostId = virtualMachine.getLastHostId();
  }
  return hostId;
}
origin: apache/cloudstack

@Override
public Pair<String, Integer> getVncPort(final VirtualMachine vm) {
  if (vm.getHostId() == null) {
    s_logger.warn("VM " + vm.getHostName() + " does not have host, return -1 for its VNC port");
    return new Pair<String, Integer>(null, -1);
  }
  if (s_logger.isTraceEnabled()) {
    s_logger.trace("Trying to retrieve VNC port from agent about VM " + vm.getHostName());
  }
  final GetVncPortAnswer answer = (GetVncPortAnswer)_agentMgr.easySend(vm.getHostId(), new GetVncPortCommand(vm.getId(), vm.getInstanceName()));
  if (answer != null && answer.getResult()) {
    return new Pair<String, Integer>(answer.getAddress(), answer.getPort());
  }
  return new Pair<String, Integer>(null, -1);
}
origin: apache/cloudstack

@Override
public VirtualMachineTO implement(VirtualMachineProfile vm) {
  VirtualMachineTO to = toVirtualMachineTO(vm);
  // Determine the VM's OS description
  GuestOSVO guestOS = _guestOsDao.findByIdIncludingRemoved(vm.getVirtualMachine().getGuestOSId());
  to.setOs(guestOS.getDisplayName());
  HostVO host = _hostDao.findById(vm.getVirtualMachine().getHostId());
  GuestOSHypervisorVO guestOsMapping = null;
  if (host != null) {
    guestOsMapping = _guestOsHypervisorDao.findByOsIdAndHypervisor(guestOS.getId(), getHypervisorType().toString(), host.getHypervisorVersion());
  }
  if (guestOsMapping == null || host == null) {
    to.setPlatformEmulator("Other");
  } else {
    to.setPlatformEmulator(guestOsMapping.getGuestOsName());
  }
  return to;
}
origin: apache/cloudstack

@Override
public boolean release(final Network network, final NicProfile nic,
    final VirtualMachineProfile vm,
    final ReservationContext context) throws ConcurrentOperationException,
    ResourceUnavailableException {
  if (!canHandle(network, Service.Connectivity)) {
    return false;
  }
  if (nic.getBroadcastType() != Networks.BroadcastDomainType.Vswitch) {
    return false;
  }
  if (nic.getTrafficType() != Networks.TrafficType.Guest) {
    return false;
  }
  final HostVO host = _hostDao.findById(vm.getVirtualMachine().getHostId());
  _ovsTunnelMgr.checkAndRemoveHostFromTunnelNetwork(network, host);
  return true;
}
origin: apache/cloudstack

  @Override
  public boolean isVmAlive(VirtualMachine vm, Host host) throws UnknownVM {
    CheckVirtualMachineCommand cmd = new CheckVirtualMachineCommand(vm.getInstanceName());
    try {
      CheckVirtualMachineAnswer answer = (CheckVirtualMachineAnswer)_agentMgr.send(vm.getHostId(), cmd);
      if (!answer.getResult()) {
        s_logger.debug("Unable to get vm state on " + vm.toString());
        throw new UnknownVM();
      }

      s_logger.debug("Agent responded with state " + answer.getState().toString());
      return answer.getState() == PowerState.PowerOn;
    } catch (AgentUnavailableException e) {
      s_logger.debug("Unable to reach the agent for " + vm.toString() + ": " + e.getMessage());
      throw new UnknownVM();
    } catch (OperationTimedoutException e) {
      s_logger.debug("Operation timed out for " + vm.toString() + ": " + e.getMessage());
      throw new UnknownVM();
    }
  }
}
origin: apache/cloudstack

@Override
public SystemVmInstanceResponse createSystemVmInstanceResponse(VirtualMachine vm) {
  SystemVmInstanceResponse vmResponse = new SystemVmInstanceResponse();
  vmResponse.setId(vm.getUuid());
  vmResponse.setSystemVmType(vm.getType().toString().toLowerCase());
  vmResponse.setName(vm.getHostName());
  if (vm.getHostId() != null) {
    Host host = ApiDBUtils.findHostById(vm.getHostId());
    if (host != null) {
      vmResponse.setHostId(host.getUuid());
    }
  }
  if (vm.getState() != null) {
    vmResponse.setState(vm.getState().toString());
  }
  if (vm.getType() == Type.DomainRouter) {
    VirtualRouter router = (VirtualRouter)vm;
    if (router.getRole() != null) {
      vmResponse.setRole(router.getRole().toString());
    }
  }
  vmResponse.setObjectName("systemvminstance");
  return vmResponse;
}
origin: apache/cloudstack

@Override
public void releaseVlan(Network nw, VirtualMachineProfile vm) {
  List<BaremetalRctVO> vos = rctDao.listAll();
  if (vos.isEmpty()) {
    throw new CloudRuntimeException("no rack configuration found, please call addBaremetalRct to add one");
  }
  BaremetalRctVO vo = vos.get(0);
  BaremetalRct rct = gson.fromJson(vo.getRct(), BaremetalRct.class);
  HostVO host = hostDao.findById(vm.getVirtualMachine().getHostId());
  RackPair rp = findRack(rct, host.getPrivateMacAddress());
  assert rp != null : String.format("where is my rack???");
  int vlan = Integer.parseInt(Networks.BroadcastDomainType.getValue(nw.getBroadcastUri()));
  BaremetalVlanStruct struct = new BaremetalVlanStruct();
  struct.setHostMac(rp.host.getMac());
  struct.setPort(rp.host.getPort());
  struct.setSwitchIp(rp.rack.getL2Switch().getIp());
  struct.setSwitchPassword(rp.rack.getL2Switch().getPassword());
  struct.setSwitchType(rp.rack.getL2Switch().getType());
  struct.setSwitchUsername(rp.rack.getL2Switch().getUsername());
  struct.setVlan(vlan);
  BaremetalSwitchBackend backend = getSwitchBackend(rp.rack.getL2Switch().getType());
  backend.removePortFromVlan(struct);
}
origin: apache/cloudstack

@Override
public EndPoint select(DataObject srcData, DataObject destData, StorageAction action) {
  s_logger.error("IR24 select BACKUPSNAPSHOT from primary to secondary " + srcData.getId() + " dest=" + destData.getId());
  if (action == StorageAction.BACKUPSNAPSHOT && srcData.getDataStore().getRole() == DataStoreRole.Primary) {
    SnapshotInfo srcSnapshot = (SnapshotInfo)srcData;
    VolumeInfo volumeInfo = srcSnapshot.getBaseVolume();
    VirtualMachine vm = volumeInfo.getAttachedVM();
    if (srcSnapshot.getHypervisorType() == Hypervisor.HypervisorType.KVM) {
      if (vm != null && vm.getState() == VirtualMachine.State.Running) {
        return getEndPointFromHostId(vm.getHostId());
      }
    }
    if (srcSnapshot.getHypervisorType() == Hypervisor.HypervisorType.VMware) {
      if (vm != null) {
        Long hostId = vm.getHostId() != null ? vm.getHostId() : vm.getLastHostId();
        if (hostId != null) {
          return getEndPointFromHostId(hostId);
        }
      }
    }
  }
  return select(srcData, destData);
}
origin: apache/cloudstack

@Override
public void finalizeStop(VirtualMachineProfile profile, Answer answer) {
  VirtualMachine vm = profile.getVirtualMachine();
  // release elastic IP here
  IPAddressVO ip = _ipAddressDao.findByAssociatedVmId(profile.getId());
  if (ip != null && ip.getSystem()) {
    CallContext ctx = CallContext.current();
    try {
      long networkId = ip.getAssociatedWithNetworkId();
      Network guestNetwork = _networkDao.findById(networkId);
      NetworkOffering offering = _entityMgr.findById(NetworkOffering.class, guestNetwork.getNetworkOfferingId());
      assert (offering.getAssociatePublicIP() == true) : "User VM should not have system owned public IP associated with it when offering configured not to associate public IP.";
      _rulesMgr.disableStaticNat(ip.getId(), ctx.getCallingAccount(), ctx.getCallingUserId(), true);
    } catch (Exception ex) {
      s_logger.warn("Failed to disable static nat and release system ip " + ip + " as a part of vm " + profile.getVirtualMachine() + " stop due to exception ", ex);
    }
  }
  List<NicVO> nics = _nicDao.listByVmId(vm.getId());
  for (NicVO nic : nics) {
    NetworkVO network = _networkDao.findById(nic.getNetworkId());
    if (network.getTrafficType() == TrafficType.Guest) {
      if (nic.getBroadcastUri() != null && nic.getBroadcastUri().getScheme().equals("pvlan")) {
        NicProfile nicProfile = new NicProfile(nic, network, nic.getBroadcastUri(), nic.getIsolationUri(), 0, false, "pvlan-nic");
        setupVmForPvlan(false, vm.getHostId(), nicProfile);
      }
    }
  }
}
origin: apache/cloudstack

private void handleAuthRequest(HttpServletRequest req, HttpServletResponse resp, long vmId) {
  // TODO authentication channel between console proxy VM and management server needs to be secured,
  // the data is now being sent through private network, but this is apparently not enough
  VirtualMachine vm = _vmMgr.findById(vmId);
  if (vm == null) {
    s_logger.warn("VM " + vmId + " does not exist, sending failed response for authentication request from console proxy");
    sendResponse(resp, "failed");
    return;
  }
  if (vm.getHostId() == null) {
    s_logger.warn("VM " + vmId + " lost host info, failed response for authentication request from console proxy");
    sendResponse(resp, "failed");
    return;
  }
  HostVO host = _ms.getHostBy(vm.getHostId());
  if (host == null) {
    s_logger.warn("VM " + vmId + "'s host does not exist, sending failed response for authentication request from console proxy");
    sendResponse(resp, "failed");
    return;
  }
  String sid = req.getParameter("sid");
  if (sid == null || !sid.equals(vm.getVncPassword())) {
    s_logger.warn("sid " + sid + " in url does not match stored sid.");
    sendResponse(resp, "failed");
    return;
  }
  sendResponse(resp, "success");
}
origin: apache/cloudstack

@Override
public boolean postStateTransitionEvent(StateMachine2.Transition<State, Event> transition, VirtualMachine vo, boolean status, Object opaque) {
 State newState = transition.getToState();
 State oldState = transition.getCurrentState();
 if (newState != State.Starting && newState != State.Error && newState != State.Expunging) {
  return true;
 }
 if (vo.getHypervisorType() != HypervisorType.BareMetal) {
  return true;
 }
 HostVO host = _hostDao.findById(vo.getHostId());
 if (host == null) {
  s_logger.debug("Skip oldState " + oldState + " to " + "newState " + newState + " transimtion");
  return true;
 }
 _hostDao.loadDetails(host);
 if (newState == State.Starting) {
  host.setDetail("vmName", vo.getInstanceName());
  s_logger.debug("Add vmName " + host.getDetail("vmName") + " to host " + host.getId() + " details");
 } else {
  if (host.getDetail("vmName") != null && host.getDetail("vmName").equalsIgnoreCase(vo.getInstanceName())) {
   s_logger.debug("Remove vmName " + host.getDetail("vmName") + " from host " + host.getId() + " details");
   host.getDetails().remove("vmName");
  }
 }
 _hostDao.saveDetails(host);
 return true;
}
origin: apache/cloudstack

Long hostId;
if (host == null) {
  hostId = (profile.getVirtualMachine().getHostId() == null ? profile.getVirtualMachine().getLastHostId(): profile.getVirtualMachine().getHostId());
} else {
  hostId = host.getId();
origin: apache/cloudstack

HostVO host = hostDao.findById(vm.getVirtualMachine().getHostId());
GuestOSHypervisorVO guestOsMapping = null;
if (host != null) {
origin: apache/cloudstack

protected Long destroyVM(final HaWorkVO work) {
  final VirtualMachine vm = _itMgr.findById(work.getInstanceId());
  s_logger.info("Destroying " + vm.toString());
  try {
    if (vm.getState() != State.Destroyed) {
      s_logger.info("VM is no longer in Destroyed state " + vm.toString());
      return null;
    }
    if (vm.getHostId() != null) {
      _itMgr.destroy(vm.getUuid(), false);
      s_logger.info("Successfully destroy " + vm);
      return null;
    } else {
      if (s_logger.isDebugEnabled()) {
        s_logger.debug(vm + " has already been stopped");
      }
      return null;
    }
  } catch (final AgentUnavailableException e) {
    s_logger.debug("Agnet is not available" + e.getMessage());
  } catch (OperationTimedoutException e) {
    s_logger.debug("operation timed out: " + e.getMessage());
  } catch (ConcurrentOperationException e) {
    s_logger.debug("concurrent operation: " + e.getMessage());
  }
  return (System.currentTimeMillis() >> 10) + _stopRetryInterval;
}
origin: apache/cloudstack

@Override
public VirtualMachineTO implement(VirtualMachineProfile vm) {
  VirtualMachineTO to = toVirtualMachineTO(vm);
  // Determine the VM's OS description
  GuestOSVO guestOS = _guestOsDao.findByIdIncludingRemoved(vm.getVirtualMachine().getGuestOSId());
  to.setOs(guestOS.getDisplayName());
  HostVO host = _hostDao.findById(vm.getVirtualMachine().getHostId());
  GuestOSHypervisorVO guestOsMapping = null;
  if (host != null) {
    guestOsMapping = _guestOsHypervisorDao.findByOsIdAndHypervisor(guestOS.getId(), getHypervisorType().toString(), host.getHypervisorVersion());
  }
  if (guestOsMapping == null || host == null) {
    to.setPlatformEmulator("Other");
  } else {
    to.setPlatformEmulator(guestOsMapping.getGuestOsName());
  }
  return to;
}
com.cloud.vmVirtualMachinegetHostId

Popular methods of VirtualMachine

  • getId
  • getGuestOSId
    returns the guest OS ID
  • getInstanceName
  • getState
  • getHostName
  • getAccountId
  • getDataCenterId
  • getLastHostId
  • getType
  • getUuid
  • getHypervisorType
  • getServiceOfferingId
  • getHypervisorType,
  • getServiceOfferingId,
  • getDomainId,
  • getTemplateId,
  • getPodIdToDeployIn,
  • getPrivateIpAddress,
  • isDisplay,
  • getCreated,
  • getUpdated

Popular classes and methods

  • setContentView (Activity)
  • getResourceAsStream (ClassLoader)
    Returns a stream for the resource with the specified name. See #getResource(String) for a descriptio
  • requestLocationUpdates (LocationManager)
  • Permission (java.security)
    Abstract class for representing access to a system resource. All permissions have a name (whose inte
  • TimeZone (java.util)
    TimeZone represents a time zone, primarily used for configuring a Calendar or java.text.SimpleDateF
  • TreeMap (java.util)
    A map whose entries are sorted by their keys. All optional operations such as #put and #remove are s
  • Executor (java.util.concurrent)
    An object that executes submitted Runnable tasks. This interface provides a way of decoupling task s
  • Pattern (java.util.regex)
    Emulation of the Pattern class, uses RegExp as internal implementation.
  • Servlet (javax.servlet)
    Defines methods that all servlets must implement.A servlet is a small Java program that runs within
  • Options (org.apache.commons.cli)
    Main entry-point into the library. Options represents a collection of Option objects, which describ

For IntelliJ IDEA and
Android Studio

  • Codota IntelliJ IDEA pluginCodota Android Studio pluginCode IndexSign in
  • EnterpriseFAQAboutContact Us
  • Terms of usePrivacy policyCodeboxFind Usages
Add Codota to your IDE (free)