Search in sources :

Example 11 with VmNetworkInterface

use of org.ovirt.engine.core.common.businessentities.network.VmNetworkInterface in project ovirt-engine by oVirt.

the class OvfManagerTest method initInterfaces.

private static void initInterfaces(VM vm) {
    List<VmNetworkInterface> ifaces = new ArrayList<>();
    RandomUtils rnd = RandomUtils.instance();
    for (int i = 0; i < rnd.nextInt(2, 10); i++) {
        VmNetworkInterface vmInterface = new VmNetworkInterface();
        vmInterface.setStatistics(new VmNetworkStatistics());
        vmInterface.setId(Guid.newGuid());
        vmInterface.setVmId(vm.getId());
        vmInterface.setName(generateRandomName());
        vmInterface.setVnicProfileName(generateRandomName());
        vmInterface.setNetworkName(generateRandomName());
        vmInterface.setLinked(rnd.nextBoolean());
        vmInterface.setSpeed(rnd.nextInt(1000));
        vmInterface.setType(rnd.nextInt(10));
        vmInterface.setMacAddress(rnd.nextMacAddress());
        ifaces.add(vmInterface);
    }
    vm.setInterfaces(ifaces);
}
Also used : RandomUtils(org.ovirt.engine.core.utils.RandomUtils) VmNetworkInterface(org.ovirt.engine.core.common.businessentities.network.VmNetworkInterface) VmNetworkStatistics(org.ovirt.engine.core.common.businessentities.network.VmNetworkStatistics) ArrayList(java.util.ArrayList)

Example 12 with VmNetworkInterface

use of org.ovirt.engine.core.common.businessentities.network.VmNetworkInterface in project ovirt-engine by oVirt.

the class VmValidatorTest method mockVnic.

private VmNetworkInterface mockVnic(boolean passthrough, boolean migratable, boolean plugged) {
    VmNetworkInterface vnic = mock(VmNetworkInterface.class);
    when(vnic.isPassthrough()).thenReturn(passthrough);
    when(vnic.isPlugged()).thenReturn(plugged);
    Guid vnicProfileId = Guid.newGuid();
    when(vnic.getVnicProfileId()).thenReturn(vnicProfileId);
    VnicProfile profile = mock(VnicProfile.class);
    when(vnicProfileDao.get(vnicProfileId)).thenReturn(profile);
    when(profile.isMigratable()).thenReturn(migratable);
    return vnic;
}
Also used : VmNetworkInterface(org.ovirt.engine.core.common.businessentities.network.VmNetworkInterface) VnicProfile(org.ovirt.engine.core.common.businessentities.network.VnicProfile) Guid(org.ovirt.engine.core.compat.Guid)

Example 13 with VmNetworkInterface

use of org.ovirt.engine.core.common.businessentities.network.VmNetworkInterface in project ovirt-engine by oVirt.

the class BackendTemplateNicResourceTest method setUpNicExpectations.

private VmNetworkInterface setUpNicExpectations() {
    VmNetworkInterface nic = mock(VmNetworkInterface.class);
    when(nic.getId()).thenReturn(NIC_ID);
    when(nic.getType()).thenReturn(0);
    return nic;
}
Also used : VmNetworkInterface(org.ovirt.engine.core.common.businessentities.network.VmNetworkInterface)

Example 14 with VmNetworkInterface

use of org.ovirt.engine.core.common.businessentities.network.VmNetworkInterface in project ovirt-engine by oVirt.

the class VdsBrokerObjectsBuilder method buildInterfaceStatisticsData.

public static List<VmNetworkInterface> buildInterfaceStatisticsData(Map<String, Object> struct) {
    // ------------- vm network statistics -----------------------
    if (!struct.containsKey(VdsProperties.VM_NETWORK)) {
        return null;
    }
    Map networkStruct = (Map) struct.get(VdsProperties.VM_NETWORK);
    List<VmNetworkInterface> interfaceStatistics = new ArrayList<>();
    for (Object tempNic : networkStruct.values()) {
        Map nic = (Map) tempNic;
        VmNetworkInterface stats = new VmNetworkInterface();
        if (nic.containsKey(VdsProperties.VM_INTERFACE_NAME)) {
            stats.setName((String) ((nic.get(VdsProperties.VM_INTERFACE_NAME) instanceof String) ? nic.get(VdsProperties.VM_INTERFACE_NAME) : null));
        }
        extractInterfaceStatistics(nic, stats);
        stats.setMacAddress((String) ((nic.get(VdsProperties.MAC_ADDR) instanceof String) ? nic.get(VdsProperties.MAC_ADDR) : null));
        interfaceStatistics.add(stats);
    }
    return interfaceStatistics;
}
Also used : VmNetworkInterface(org.ovirt.engine.core.common.businessentities.network.VmNetworkInterface) ArrayList(java.util.ArrayList) Map(java.util.Map) HashMap(java.util.HashMap)

Example 15 with VmNetworkInterface

use of org.ovirt.engine.core.common.businessentities.network.VmNetworkInterface in project ovirt-engine by oVirt.

the class VdsBrokerObjectsBuilder method buildVmStaticDataFromExternalProvider.

private static VmStatic buildVmStaticDataFromExternalProvider(Map<String, Object> struct) {
    if (!struct.containsKey(VdsProperties.vm_guid) || !struct.containsKey(VdsProperties.vm_name) || !struct.containsKey(VdsProperties.mem_size_mb) || !struct.containsKey(VdsProperties.num_of_cpus)) {
        return null;
    }
    VmStatic vmStatic = new VmStatic();
    vmStatic.setId(Guid.createGuidFromString((String) struct.get(VdsProperties.vm_guid)));
    vmStatic.setName((String) struct.get(VdsProperties.vm_name));
    vmStatic.setMemSizeMb(parseIntVdsProperty(struct.get(VdsProperties.mem_size_mb)));
    vmStatic.setNumOfSockets(parseIntVdsProperty(struct.get(VdsProperties.num_of_cpus)));
    vmStatic.setCustomCpuName((String) struct.get(VdsProperties.cpu_model));
    vmStatic.setCustomEmulatedMachine((String) struct.get(VdsProperties.emulatedMachine));
    addGraphicsDeviceFromExternalProvider(vmStatic, struct);
    if (struct.containsKey(VdsProperties.vm_disks)) {
        for (Object disk : (Object[]) struct.get(VdsProperties.vm_disks)) {
            Map<String, Object> diskMap = (Map<String, Object>) disk;
            if (VdsProperties.Disk.equals(diskMap.get(VdsProperties.type))) {
                DiskImage image = buildDiskImageFromExternalProvider(diskMap, vmStatic.getId());
                vmStatic.getImages().add(image);
            }
        }
    }
    if (struct.containsKey(VdsProperties.NETWORKS)) {
        int idx = 0;
        for (Object networkMap : (Object[]) struct.get(VdsProperties.NETWORKS)) {
            VmNetworkInterface nic = buildNetworkInterfaceFromExternalProvider((Map<String, Object>) networkMap);
            nic.setName(String.format("nic%d", ++idx));
            nic.setVmName(vmStatic.getName());
            nic.setVmId(vmStatic.getId());
            vmStatic.getInterfaces().add(nic);
        }
    }
    return vmStatic;
}
Also used : VmNetworkInterface(org.ovirt.engine.core.common.businessentities.network.VmNetworkInterface) VmStatic(org.ovirt.engine.core.common.businessentities.VmStatic) Map(java.util.Map) HashMap(java.util.HashMap) DiskImage(org.ovirt.engine.core.common.businessentities.storage.DiskImage)

Aggregations

VmNetworkInterface (org.ovirt.engine.core.common.businessentities.network.VmNetworkInterface)115 Test (org.junit.Test)27 ArrayList (java.util.ArrayList)25 Guid (org.ovirt.engine.core.compat.Guid)19 VM (org.ovirt.engine.core.common.businessentities.VM)16 HashMap (java.util.HashMap)11 List (java.util.List)9 Map (java.util.Map)9 DiskImage (org.ovirt.engine.core.common.businessentities.storage.DiskImage)6 PairQueryable (org.ovirt.engine.core.common.utils.PairQueryable)6 MapVnicsContext (org.ovirt.engine.core.bll.exportimport.vnics.MapVnicsContext)5 VmDevice (org.ovirt.engine.core.common.businessentities.VmDevice)5 HostNicVfsConfig (org.ovirt.engine.core.common.businessentities.network.HostNicVfsConfig)5 VmNetworkStatistics (org.ovirt.engine.core.common.businessentities.network.VmNetworkStatistics)5 Nic (org.ovirt.engine.api.model.Nic)4 VnicProfileHelper (org.ovirt.engine.core.bll.network.vm.VnicProfileHelper)4 VmTemplate (org.ovirt.engine.core.common.businessentities.VmTemplate)4 Network (org.ovirt.engine.core.common.businessentities.network.Network)4 IdQueryParameters (org.ovirt.engine.core.common.queries.IdQueryParameters)4 Collection (java.util.Collection)3