Search in sources :

Example 1 with NetworkUsage

use of org.ovirt.engine.api.model.NetworkUsage in project ovirt-engine by oVirt.

the class V3NetworkInAdapter method adapt.

@Override
public Network adapt(V3Network from) {
    Network to = new Network();
    if (from.isSetLinks()) {
        to.getLinks().addAll(adaptIn(from.getLinks()));
    }
    if (from.isSetActions()) {
        to.setActions(adaptIn(from.getActions()));
    }
    if (from.isSetCluster()) {
        to.setCluster(adaptIn(from.getCluster()));
    }
    if (from.isSetComment()) {
        to.setComment(from.getComment());
    }
    if (from.isSetDataCenter()) {
        to.setDataCenter(adaptIn(from.getDataCenter()));
    }
    if (from.isSetDescription()) {
        to.setDescription(from.getDescription());
    }
    if (from.isSetDisplay()) {
        to.setDisplay(from.isDisplay());
    }
    if (from.isSetId()) {
        to.setId(from.getId());
    }
    if (from.isSetHref()) {
        to.setHref(from.getHref());
    }
    if (from.isSetIp()) {
        to.setIp(adaptIn(from.getIp()));
    }
    if (from.isSetLabels()) {
        to.setNetworkLabels(new NetworkLabels());
        to.getNetworkLabels().getNetworkLabels().addAll(adaptIn(from.getLabels().getLabels()));
    }
    if (from.isSetMtu()) {
        to.setMtu(from.getMtu());
    }
    if (from.isSetName()) {
        to.setName(from.getName());
    }
    if (from.isSetProfileRequired()) {
        to.setProfileRequired(from.isProfileRequired());
    }
    if (from.isSetQos()) {
        to.setQos(adaptIn(from.getQos()));
    }
    if (from.isSetRequired()) {
        to.setRequired(from.isRequired());
    }
    if (from.isSetStatus() && from.getStatus().isSetState()) {
        to.setStatus(NetworkStatus.fromValue(from.getStatus().getState()));
    }
    if (from.isSetStp()) {
        to.setStp(from.isStp());
    }
    if (from.isSetUsages()) {
        Network.UsagesList toUsages = to.getUsages();
        if (toUsages == null) {
            toUsages = new Network.UsagesList();
            to.setUsages(toUsages);
        }
        List<NetworkUsage> toList = toUsages.getUsages();
        from.getUsages().getUsages().forEach(usage -> toList.add(NetworkUsage.fromValue(usage)));
    }
    if (from.isSetVlan()) {
        to.setVlan(adaptIn(from.getVlan()));
    }
    return to;
}
Also used : NetworkLabels(org.ovirt.engine.api.model.NetworkLabels) Network(org.ovirt.engine.api.model.Network) V3Network(org.ovirt.engine.api.v3.types.V3Network) NetworkUsage(org.ovirt.engine.api.model.NetworkUsage)

Example 2 with NetworkUsage

use of org.ovirt.engine.api.model.NetworkUsage in project ovirt-engine by oVirt.

the class NetworkMapper method map.

@Mapping(from = Network.class, to = org.ovirt.engine.core.common.businessentities.network.Network.class)
public static org.ovirt.engine.core.common.businessentities.network.Network map(Network model, org.ovirt.engine.core.common.businessentities.network.Network template) {
    org.ovirt.engine.core.common.businessentities.network.Network entity = template != null ? template : new org.ovirt.engine.core.common.businessentities.network.Network();
    entity.setCluster(template != null && template.getCluster() != null ? template.getCluster() : new NetworkCluster());
    if (model.isSetId()) {
        entity.setId(GuidUtils.asGuid(model.getId()));
    }
    if (model.isSetName()) {
        entity.setName(model.getName());
    }
    if (model.isSetDescription()) {
        entity.setDescription(model.getDescription());
    }
    if (model.isSetComment()) {
        entity.setComment(model.getComment());
    }
    if (model.isSetDataCenter() && model.getDataCenter().isSetId()) {
        entity.setDataCenterId(GuidUtils.asGuid(model.getDataCenter().getId()));
    }
    if (model.isSetIp()) {
        if (model.getIp().isSetAddress()) {
            entity.setAddr(model.getIp().getAddress());
        }
        if (model.getIp().isSetNetmask()) {
            entity.setSubnet(model.getIp().getNetmask());
        }
        if (model.getIp().isSetGateway()) {
            entity.setGateway(model.getIp().getGateway());
        }
    }
    if (model.isSetVlan()) {
        entity.setVlanId(model.getVlan().getId());
    }
    if (model.isSetStp()) {
        entity.setStp(model.isStp());
    }
    if (model.isSetDisplay()) {
        // for backward compatibility use display tag or usage tag
        entity.getCluster().setDisplay(model.isDisplay());
    }
    if (model.isSetUsages()) {
        List<NetworkUsage> networkUsages = new ArrayList<>();
        for (NetworkUsage usage : model.getUsages().getUsages()) {
            networkUsages.add(usage);
        }
        entity.getCluster().setDisplay(networkUsages.contains(NetworkUsage.DISPLAY));
        entity.getCluster().setMigration(networkUsages.contains(NetworkUsage.MIGRATION));
        entity.getCluster().setManagement(networkUsages.contains(NetworkUsage.MANAGEMENT));
        entity.getCluster().setGluster(networkUsages.contains(NetworkUsage.GLUSTER));
        entity.getCluster().setDefaultRoute(networkUsages.contains(NetworkUsage.DEFAULT_ROUTE));
        entity.setVmNetwork(networkUsages.contains(NetworkUsage.VM));
    }
    if (model.isSetMtu()) {
        entity.setMtu(model.getMtu());
    }
    if (model.isSetRequired()) {
        entity.getCluster().setRequired(model.isRequired());
    }
    if (model.isSetQos()) {
        entity.setQosId(Guid.createGuidFromString(model.getQos().getId()));
    }
    if (model.isSetDnsResolverConfiguration()) {
        entity.setDnsResolverConfiguration(DnsResolverConfigurationMapper.map(entity.getDnsResolverConfiguration(), model.getDnsResolverConfiguration()));
    }
    if (model.isSetExternalProvider() && model.getExternalProvider().isSetId()) {
        ProviderNetwork providerNetwork = new ProviderNetwork();
        providerNetwork.setProviderId(GuidUtils.asGuid(model.getExternalProvider().getId()));
        if (model.isSetExternalProviderPhysicalNetwork() && model.getExternalProviderPhysicalNetwork().isSetId()) {
            providerNetwork.setPhysicalNetworkId(GuidUtils.asGuid(model.getExternalProviderPhysicalNetwork().getId()));
        }
        entity.setProvidedBy(providerNetwork);
    }
    return entity;
}
Also used : NetworkUsage(org.ovirt.engine.api.model.NetworkUsage) ArrayList(java.util.ArrayList) NetworkCluster(org.ovirt.engine.core.common.businessentities.network.NetworkCluster) ProviderNetwork(org.ovirt.engine.core.common.businessentities.network.ProviderNetwork)

Aggregations

NetworkUsage (org.ovirt.engine.api.model.NetworkUsage)2 ArrayList (java.util.ArrayList)1 Network (org.ovirt.engine.api.model.Network)1 NetworkLabels (org.ovirt.engine.api.model.NetworkLabels)1 V3Network (org.ovirt.engine.api.v3.types.V3Network)1 NetworkCluster (org.ovirt.engine.core.common.businessentities.network.NetworkCluster)1 ProviderNetwork (org.ovirt.engine.core.common.businessentities.network.ProviderNetwork)1