Search in sources :

Example 6 with VMInstanceVO

use of com.cloud.vm.VMInstanceVO in project cloudstack by apache.

the class NuageVspEntityBuilder method buildVmDhcpOption.

/** Build VspDhcpVMOption to put on the VM interface */
public VspDhcpVMOption buildVmDhcpOption(NicVO userNic, boolean defaultHasDns, boolean networkHasDns) {
    VMInstanceVO userVm = _vmInstanceDao.findById(userNic.getInstanceId());
    VspDhcpVMOption.Builder vspDhcpVMOptionBuilder = new VspDhcpVMOption.Builder().nicUuid(userNic.getUuid()).defaultHasDns(defaultHasDns).hostname(userVm.getHostName()).networkHasDns(networkHasDns).isDefaultInterface(userNic.isDefaultNic()).domainRouter(VirtualMachine.Type.DomainRouter.equals(userNic.getVmType()));
    return vspDhcpVMOptionBuilder.build();
}
Also used : VMInstanceVO(com.cloud.vm.VMInstanceVO) VspDhcpVMOption(net.nuage.vsp.acs.client.api.model.VspDhcpVMOption)

Example 7 with VMInstanceVO

use of com.cloud.vm.VMInstanceVO in project cloudstack by apache.

the class NuageVspGuestNetworkGuru method updateDhcpOptionsForExistingVms.

private void updateDhcpOptionsForExistingVms(Network network, HostVO nuageVspHost, VspNetwork vspNetwork, boolean networkHasDns, Map<Long, Boolean> networkHasDnsCache) throws InsufficientVirtualNetworkCapacityException {
    // Update dhcp options if a VR is added when we are not initiating the network
    if (s_logger.isDebugEnabled()) {
        s_logger.debug(String.format("DomainRouter is added to an existing network: %s in state: %s", network.getName(), network.getState()));
    }
    List<NicVO> userNics = _nicDao.listByNetworkId(network.getId());
    LinkedListMultimap<Long, VspDhcpVMOption> dhcpOptionsPerDomain = LinkedListMultimap.create();
    for (NicVO userNic : userNics) {
        if (userNic.getVmType() == VirtualMachine.Type.DomainRouter) {
            continue;
        }
        VMInstanceVO userVm = _vmInstanceDao.findById(userNic.getInstanceId());
        boolean defaultHasDns = getDefaultHasDns(networkHasDnsCache, userNic);
        VspDhcpVMOption dhcpOption = _nuageVspEntityBuilder.buildVmDhcpOption(userNic, defaultHasDns, networkHasDns);
        dhcpOptionsPerDomain.put(userVm.getDomainId(), dhcpOption);
    }
    for (Long domainId : dhcpOptionsPerDomain.keySet()) {
        VspDomain vspDomain = _nuageVspEntityBuilder.buildVspDomain(_domainDao.findById(domainId));
        VspNetwork vspNetworkForDomain = new VspNetwork.Builder().fromObject(vspNetwork).domain(vspDomain).build();
        List<VspDhcpVMOption> dhcpOptions = dhcpOptionsPerDomain.get(domainId);
        UpdateDhcpOptionVspCommand cmd = new UpdateDhcpOptionVspCommand(dhcpOptions, vspNetworkForDomain);
        Answer answer = _agentMgr.easySend(nuageVspHost.getId(), cmd);
        if (answer == null || !answer.getResult()) {
            s_logger.error("UpdateDhcpOptionVspCommand failed at \"reserve\" for network " + vspNetwork.getName() + " under domain " + vspNetwork.getVspDomain().getName());
            if ((null != answer) && (null != answer.getDetails())) {
                s_logger.error(answer.getDetails());
            }
            throw new InsufficientVirtualNetworkCapacityException("Failed to reserve VM in Nuage VSP.", Network.class, network.getId());
        }
    }
}
Also used : VspDomain(net.nuage.vsp.acs.client.api.model.VspDomain) VMInstanceVO(com.cloud.vm.VMInstanceVO) UpdateDhcpOptionVspCommand(com.cloud.agent.api.guru.UpdateDhcpOptionVspCommand) Answer(com.cloud.agent.api.Answer) InsufficientVirtualNetworkCapacityException(com.cloud.exception.InsufficientVirtualNetworkCapacityException) VspNetwork(net.nuage.vsp.acs.client.api.model.VspNetwork) NicVO(com.cloud.vm.NicVO) VspDhcpVMOption(net.nuage.vsp.acs.client.api.model.VspDhcpVMOption)

Example 8 with VMInstanceVO

use of com.cloud.vm.VMInstanceVO in project cloudstack by apache.

the class ApiResponseHelper method createSnapshotResponse.

@Override
public SnapshotResponse createSnapshotResponse(Snapshot snapshot) {
    SnapshotResponse snapshotResponse = new SnapshotResponse();
    snapshotResponse.setId(snapshot.getUuid());
    populateOwner(snapshotResponse, snapshot);
    VolumeVO volume = findVolumeById(snapshot.getVolumeId());
    String snapshotTypeStr = snapshot.getRecurringType().name();
    snapshotResponse.setSnapshotType(snapshotTypeStr);
    if (volume != null) {
        snapshotResponse.setVolumeId(volume.getUuid());
        snapshotResponse.setVolumeName(volume.getName());
        snapshotResponse.setVolumeType(volume.getVolumeType().name());
        DataCenter zone = ApiDBUtils.findZoneById(volume.getDataCenterId());
        if (zone != null) {
            snapshotResponse.setZoneId(zone.getUuid());
        }
        if (volume.getVolumeType() == Volume.Type.ROOT) {
            //TODO combine lines and 489 into a join in the volume dao
            VMInstanceVO instance = ApiDBUtils.findVMInstanceById(volume.getInstanceId());
            if (instance != null) {
                GuestOS guestOs = ApiDBUtils.findGuestOSById(instance.getGuestOSId());
                if (guestOs != null) {
                    snapshotResponse.setOsTypeId(guestOs.getUuid());
                    snapshotResponse.setOsDisplayName(guestOs.getDisplayName());
                }
            }
        }
    }
    snapshotResponse.setCreated(snapshot.getCreated());
    snapshotResponse.setName(snapshot.getName());
    snapshotResponse.setIntervalType(ApiDBUtils.getSnapshotIntervalTypes(snapshot.getId()));
    snapshotResponse.setState(snapshot.getState());
    snapshotResponse.setLocationType(ApiDBUtils.getSnapshotLocationType(snapshot.getId()));
    SnapshotInfo snapshotInfo = null;
    if (snapshot instanceof SnapshotInfo) {
        snapshotInfo = (SnapshotInfo) snapshot;
    } else {
        DataStoreRole dataStoreRole = getDataStoreRole(snapshot, _snapshotStoreDao, _dataStoreMgr);
        snapshotInfo = snapshotfactory.getSnapshot(snapshot.getId(), dataStoreRole);
    }
    if (snapshotInfo == null) {
        s_logger.debug("Unable to find info for image store snapshot with uuid " + snapshot.getUuid());
        snapshotResponse.setRevertable(false);
    } else {
        snapshotResponse.setRevertable(snapshotInfo.isRevertable());
        snapshotResponse.setPhysicaSize(snapshotInfo.getPhysicalSize());
    }
    // set tag information
    List<? extends ResourceTag> tags = ApiDBUtils.listByResourceTypeAndId(ResourceObjectType.Snapshot, snapshot.getId());
    List<ResourceTagResponse> tagResponses = new ArrayList<ResourceTagResponse>();
    for (ResourceTag tag : tags) {
        ResourceTagResponse tagResponse = createResourceTagResponse(tag, true);
        CollectionUtils.addIgnoreNull(tagResponses, tagResponse);
    }
    snapshotResponse.setTags(tagResponses);
    snapshotResponse.setObjectName("snapshot");
    return snapshotResponse;
}
Also used : ArrayList(java.util.ArrayList) VMInstanceVO(com.cloud.vm.VMInstanceVO) DataStoreRole(com.cloud.storage.DataStoreRole) SnapshotInfo(org.apache.cloudstack.engine.subsystem.api.storage.SnapshotInfo) DataCenter(com.cloud.dc.DataCenter) ResourceTag(com.cloud.server.ResourceTag) VolumeVO(com.cloud.storage.VolumeVO) SnapshotResponse(org.apache.cloudstack.api.response.SnapshotResponse) VMSnapshotResponse(org.apache.cloudstack.api.response.VMSnapshotResponse) ResourceTagResponse(org.apache.cloudstack.api.response.ResourceTagResponse) GuestOS(com.cloud.storage.GuestOS)

Example 9 with VMInstanceVO

use of com.cloud.vm.VMInstanceVO in project cloudstack by apache.

the class UserConcentratedAllocator method calcHostAllocatedCpuMemoryCapacity.

/**
     *
     * @param hostId
     *            Host id to calculate against
     * @param capacityType
     *            CapacityVO.CAPACITY_TYPE_MEMORY or
     *            CapacityVO.CAPACITY_TYPE_CPU
     * @return
     */
private long calcHostAllocatedCpuMemoryCapacity(long hostId, short capacityType) {
    assert (capacityType == Capacity.CAPACITY_TYPE_MEMORY || capacityType == Capacity.CAPACITY_TYPE_CPU) : "Invalid capacity type passed in calcHostAllocatedCpuCapacity()";
    // List<VMInstanceVO> vms = _vmInstanceDao.listByLastHostId(hostId);
    List<VMInstanceVO> vms = null;
    long usedCapacity = 0;
    if (vms != null) {
        for (VMInstanceVO vm : vms) {
            if (skipCalculation(vm)) {
                continue;
            }
            ServiceOffering so = null;
            if (vm.getType() == VirtualMachine.Type.User) {
                UserVmVO userVm = _vmDao.findById(vm.getId());
                if (userVm == null) {
                    continue;
                }
            }
            so = _offeringDao.findById(vm.getId(), vm.getServiceOfferingId());
            if (capacityType == Capacity.CAPACITY_TYPE_MEMORY) {
                usedCapacity += so.getRamSize() * 1024L * 1024L;
                if (s_logger.isDebugEnabled()) {
                    s_logger.debug("Counting memory capacity used by vm: " + vm.getId() + ", size: " + so.getRamSize() + "MB, host: " + hostId + ", currently counted: " + usedCapacity + " Bytes");
                }
            } else if (capacityType == Capacity.CAPACITY_TYPE_CPU) {
                usedCapacity += so.getCpu() * so.getSpeed();
                if (s_logger.isDebugEnabled()) {
                    s_logger.debug("Counting cpu capacity used by vm: " + vm.getId() + ", cpu: " + so.getCpu() + ", speed: " + so.getSpeed() + ", currently counted: " + usedCapacity + " Bytes");
                }
            }
        }
    }
    return usedCapacity;
}
Also used : UserVmVO(com.cloud.vm.UserVmVO) ServiceOffering(com.cloud.offering.ServiceOffering) VMInstanceVO(com.cloud.vm.VMInstanceVO)

Example 10 with VMInstanceVO

use of com.cloud.vm.VMInstanceVO in project cloudstack by apache.

the class HypervStorageMotionStrategy method copyAsync.

@Override
public void copyAsync(Map<VolumeInfo, DataStore> volumeMap, VirtualMachineTO vmTo, Host srcHost, Host destHost, AsyncCompletionCallback<CopyCommandResult> callback) {
    Answer answer = null;
    String errMsg = null;
    try {
        VMInstanceVO instance = instanceDao.findById(vmTo.getId());
        if (instance != null) {
            answer = migrateVmWithVolumes(instance, vmTo, srcHost, destHost, volumeMap);
        } else {
            throw new CloudRuntimeException("Unsupported operation requested for moving data.");
        }
    } catch (Exception e) {
        s_logger.error("copy failed", e);
        errMsg = e.toString();
    }
    CopyCommandResult result = new CopyCommandResult(null, answer);
    result.setResult(errMsg);
    callback.complete(result);
}
Also used : Answer(com.cloud.agent.api.Answer) MigrateWithStorageAnswer(com.cloud.agent.api.MigrateWithStorageAnswer) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) VMInstanceVO(com.cloud.vm.VMInstanceVO) CopyCommandResult(org.apache.cloudstack.engine.subsystem.api.storage.CopyCommandResult) AgentUnavailableException(com.cloud.exception.AgentUnavailableException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) OperationTimedoutException(com.cloud.exception.OperationTimedoutException)

Aggregations

VMInstanceVO (com.cloud.vm.VMInstanceVO)131 ArrayList (java.util.ArrayList)40 HostVO (com.cloud.host.HostVO)34 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)30 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)28 Account (com.cloud.user.Account)28 VolumeVO (com.cloud.storage.VolumeVO)24 Test (org.junit.Test)24 HostPodVO (com.cloud.dc.HostPodVO)15 HashMap (java.util.HashMap)14 NetworkVO (com.cloud.network.dao.NetworkVO)13 User (com.cloud.user.User)13 NicVO (com.cloud.vm.NicVO)13 VmWorkJobVO (org.apache.cloudstack.framework.jobs.impl.VmWorkJobVO)13 PhysicalNetworkVO (com.cloud.network.dao.PhysicalNetworkVO)12 StoragePoolVO (org.apache.cloudstack.storage.datastore.db.StoragePoolVO)12 ActionEvent (com.cloud.event.ActionEvent)11 Random (java.util.Random)11 Answer (com.cloud.agent.api.Answer)10 ConcurrentOperationException (com.cloud.exception.ConcurrentOperationException)10