Search in sources :

Example 16 with Pair

use of org.ovirt.engine.core.common.utils.Pair in project ovirt-engine by oVirt.

the class HostModel method getFenceAgentModelList.

public List<FenceAgentModel> getFenceAgentModelList(VDS vds) {
    List<FenceAgentModel> agents = new ArrayList<>();
    // Keep a list of examined agents to prevent duplicate management IPs from showing up in the UI.
    Set<Pair<String, String>> examinedAgents = new HashSet<>();
    for (FenceAgent agent : vds.getFenceAgents()) {
        FenceAgentModel model = new FenceAgentModel();
        model.setHost(this);
        // Set primary PM parameters.
        model.getManagementIp().setEntity(agent.getIp());
        model.getPmUserName().setEntity(agent.getUser());
        model.getPmPassword().setEntity(agent.getPassword());
        model.getPmType().setSelectedItem(agent.getType());
        if (agent.getPort() != null) {
            model.getPmPort().setEntity(agent.getPort());
        }
        model.getPmEncryptOptions().setEntity(agent.getEncryptOptions());
        model.setPmOptionsMap(PowerManagementUtils.pmOptionsStringToMap(agent.getOptions()));
        model.setOrder(agent.getOrder());
        if (!examinedAgents.contains(new Pair<>(model.getManagementIp().getEntity(), model.getPmType().getSelectedItem()))) {
            boolean added = false;
            for (FenceAgentModel concurrentModel : agents) {
                if (model.getOrder().getEntity() != null && model.getOrder().getEntity().equals(concurrentModel.getOrder().getEntity())) {
                    concurrentModel.getConcurrentList().add(model);
                    added = true;
                    break;
                }
            }
            if (!added) {
                agents.add(model);
            }
        }
        examinedAgents.add(new Pair<>(model.getManagementIp().getEntity(), model.getPmType().getSelectedItem()));
    }
    return agents;
}
Also used : ArrayList(java.util.ArrayList) FenceAgent(org.ovirt.engine.core.common.businessentities.pm.FenceAgent) Pair(org.ovirt.engine.core.common.utils.Pair) HashSet(java.util.HashSet)

Example 17 with Pair

use of org.ovirt.engine.core.common.utils.Pair in project ovirt-engine by oVirt.

the class HSMGetStorageDomainInfoVDSCommand method buildStorageStaticFromStruct.

private static Pair<StorageDomainStatic, Guid> buildStorageStaticFromStruct(Map<String, Object> struct) {
    Pair<StorageDomainStatic, Guid> returnValue = new Pair<>();
    StorageDomainStatic sdStatic = new StorageDomainStatic();
    if (struct.containsKey("name")) {
        sdStatic.setStorageName(struct.get("name").toString());
    }
    if (struct.containsKey("type")) {
        sdStatic.setStorageType(EnumUtils.valueOf(StorageType.class, struct.get("type").toString(), true));
    }
    if (struct.containsKey("class")) {
        String domainType = struct.get("class").toString();
        if ("backup".equalsIgnoreCase(domainType)) {
            sdStatic.setStorageDomainType(StorageDomainType.ImportExport);
        } else {
            sdStatic.setStorageDomainType(EnumUtils.valueOf(StorageDomainType.class, domainType, true));
        }
    }
    if (struct.containsKey("version")) {
        sdStatic.setStorageFormat(StorageFormatType.forValue(struct.get("version").toString()));
    }
    if (sdStatic.getStorageType() != StorageType.UNKNOWN) {
        if (sdStatic.getStorageType().isFileDomain() && struct.containsKey("remotePath")) {
            String path = struct.get("remotePath").toString();
            List<StorageServerConnections> connections = DbFacade.getInstance().getStorageServerConnectionDao().getAllForStorage(path);
            if (connections.isEmpty()) {
                sdStatic.setConnection(new StorageServerConnections());
                sdStatic.getConnection().setConnection(path);
                sdStatic.getConnection().setStorageType(sdStatic.getStorageType());
            } else {
                sdStatic.setStorage(connections.get(0).getId());
                sdStatic.setConnection(connections.get(0));
            }
        } else if (sdStatic.getStorageType() != StorageType.NFS) {
            if (struct.containsKey("vguuid")) {
                sdStatic.setStorage(struct.get("vguuid").toString());
            }
            if (struct.containsKey("metadataDevice")) {
                sdStatic.setFirstMetadataDevice(Objects.toString(struct.get("metadataDevice")));
            }
            if (struct.containsKey("vgMetadataDevice")) {
                sdStatic.setVgMetadataDevice(Objects.toString(struct.get("vgMetadataDevice")));
            }
        }
    }
    if (struct.containsKey("state")) {
        sdStatic.setSanState(EnumUtils.valueOf(SANState.class, struct.get("state").toString().toUpperCase(), false));
    }
    returnValue.setFirst(sdStatic);
    Object[] poolUUIDs = (Object[]) struct.get("pool");
    if (poolUUIDs.length != 0) {
        returnValue.setSecond(Guid.createGuidFromString(poolUUIDs[0].toString()));
    }
    return returnValue;
}
Also used : StorageDomainStatic(org.ovirt.engine.core.common.businessentities.StorageDomainStatic) StorageDomainType(org.ovirt.engine.core.common.businessentities.StorageDomainType) StorageType(org.ovirt.engine.core.common.businessentities.storage.StorageType) StorageServerConnections(org.ovirt.engine.core.common.businessentities.StorageServerConnections) SANState(org.ovirt.engine.core.common.businessentities.SANState) Guid(org.ovirt.engine.core.compat.Guid) Pair(org.ovirt.engine.core.common.utils.Pair)

Example 18 with Pair

use of org.ovirt.engine.core.common.utils.Pair in project ovirt-engine by oVirt.

the class CloudInitHandlerMetadataProtocolTest method startOnBootFalse.

@SuppressWarnings("unchecked")
private static Pair startOnBootFalse() {
    VmInit vmInit = new VmInit();
    VmInitNetwork underTest = new VmInitNetwork();
    underTest.setStartOnBoot(false);
    vmInit.setNetworks(Collections.singletonList(underTest));
    return new Pair(vmInit, new IllegalArgumentException("Malformed input", new IllegalArgumentException("'Start on boot' must be true")));
}
Also used : VmInit(org.ovirt.engine.core.common.businessentities.VmInit) VmInitNetwork(org.ovirt.engine.core.common.businessentities.VmInitNetwork) Pair(org.ovirt.engine.core.common.utils.Pair)

Example 19 with Pair

use of org.ovirt.engine.core.common.utils.Pair in project ovirt-engine by oVirt.

the class CloudInitHandlerMetadataProtocolTest method staticIPv4.

/**
 * ENI after fix 1464043:
 * payload:
 * "network-interfaces" : "iface eth0 inet static\n  address 192.168.122.180\n  netmask 255.255.255.0\n  gateway 192.168.122.1\n"
 *
 * cloud-init-output.log: ok
 *
 * virt-cat img:/etc/sysconfig/network-scripts/ifcfg-eth0:
 * BOOTPROTO=static
 * DEVICE=eth0
 * IPADDR=192.168.122.182
 * NETMASK=255.255.255.0
 * ONBOOT=yes
 * TYPE=Ethernet
 * USERCTL=no
 *
 * ----------------------------------------------------------
 */
private static Pair<VmInit, String> staticIPv4() {
    final VmInitNetwork underTest = new VmInitNetwork();
    underTest.setName(IFACE_NAME);
    underTest.setBootProtocol(Ipv4BootProtocol.STATIC_IP);
    underTest.setIp(IPV4_ADDRESS);
    underTest.setNetmask(IPV4_NETMASK);
    underTest.setGateway(IPV4_GATEWAY);
    underTest.setStartOnBoot(true);
    VmInit vmInit = new VmInit();
    vmInit.setNetworks(Collections.singletonList(underTest));
    String expectedOutput = "{\n" + "  \"links\": [\n" + "    {\n" + "      \"id\": \"iface name\",\n" + "      \"type\": \"vif\",\n" + "      \"name\": \"iface name\"\n" + "    }\n" + "  ],\n" + "  \"networks\": [\n" + "    {\n" + "      \"id\": \"iface name\",\n" + "      \"type\": \"ipv4\",\n" + "      \"link\": \"iface name\",\n" + "      \"ip_address\": \"ipv4 address\",\n" + "      \"netmask\": \"ipv4 netmask\",\n" + "      \"gateway\": \"ipv4 gateway\"\n" + "    }\n" + "  ]\n" + "}";
    return new Pair<>(vmInit, expectedOutput);
}
Also used : VmInit(org.ovirt.engine.core.common.businessentities.VmInit) VmInitNetwork(org.ovirt.engine.core.common.businessentities.VmInitNetwork) Pair(org.ovirt.engine.core.common.utils.Pair)

Example 20 with Pair

use of org.ovirt.engine.core.common.utils.Pair in project ovirt-engine by oVirt.

the class CloudInitHandlerMetadataProtocolTest method staticIPv6AddressOnly.

/**
 * payload:
 * {"links":[{"name":"eth0","id":"eth0","type":"vif"}],"networks":[{"link":"eth0","id":"eth0","ip_address":"2001:cdba::3257:9652","type":"ipv6"}]}
 *
 * cloud-init-output.log: ok
 * but cannot login to machine (because i dont have ipv6 configured on my local machine?)
 *
 * virt-cat img:/etc/sysconfig/network-scripts/ifcfg-eth0
 * BOOTPROTO=static
 * DEVICE=eth0
 * IPV6ADDR=2001:cdba::3257:9652
 * IPV6INIT=yes
 * ONBOOT=yes
 * TYPE=Ethernet
 * USERCTL=no
 */
private static Pair<VmInit, String> staticIPv6AddressOnly() {
    final VmInitNetwork underTest = new VmInitNetwork();
    underTest.setName(IFACE_NAME);
    underTest.setIpv6BootProtocol(Ipv6BootProtocol.STATIC_IP);
    underTest.setIpv6Address(IPV6_ADDRESS);
    underTest.setStartOnBoot(true);
    VmInit vmInit = new VmInit();
    vmInit.setNetworks(Collections.singletonList(underTest));
    String expectedOutput = "{\n" + "  \"links\": [\n" + "    {\n" + "      \"id\": \"iface name\",\n" + "      \"type\": \"vif\",\n" + "      \"name\": \"iface name\"\n" + "    }\n" + "  ],\n" + "  \"networks\": [\n" + "    {\n" + "      \"id\": \"iface name\",\n" + "      \"type\": \"ipv6\",\n" + "      \"link\": \"iface name\",\n" + "      \"ip_address\": \"ipv6 address\"\n" + "    }\n" + "  ]\n" + "}";
    return new Pair<>(vmInit, expectedOutput);
}
Also used : VmInit(org.ovirt.engine.core.common.businessentities.VmInit) VmInitNetwork(org.ovirt.engine.core.common.businessentities.VmInitNetwork) Pair(org.ovirt.engine.core.common.utils.Pair)

Aggregations

Pair (org.ovirt.engine.core.common.utils.Pair)147 ArrayList (java.util.ArrayList)61 Guid (org.ovirt.engine.core.compat.Guid)61 HashMap (java.util.HashMap)30 VDS (org.ovirt.engine.core.common.businessentities.VDS)26 VDSReturnValue (org.ovirt.engine.core.common.vdscommands.VDSReturnValue)25 Test (org.junit.Test)24 StorageDomainStatic (org.ovirt.engine.core.common.businessentities.StorageDomainStatic)19 List (java.util.List)16 StorageDomain (org.ovirt.engine.core.common.businessentities.StorageDomain)16 Map (java.util.Map)13 EngineLock (org.ovirt.engine.core.utils.lock.EngineLock)13 StoragePool (org.ovirt.engine.core.common.businessentities.StoragePool)12 VM (org.ovirt.engine.core.common.businessentities.VM)12 HashSet (java.util.HashSet)10 VmInit (org.ovirt.engine.core.common.businessentities.VmInit)10 VmInitNetwork (org.ovirt.engine.core.common.businessentities.VmInitNetwork)10 EngineException (org.ovirt.engine.core.common.errors.EngineException)9 Callable (java.util.concurrent.Callable)8 VmDevice (org.ovirt.engine.core.common.businessentities.VmDevice)8