Moti Asayag has uploaded a new change for review. Change subject: restapi: Add setupnetworks api ......................................................................
restapi: Add setupnetworks api The patch adds the host level setupnetworks api which allows to manage network configuration via network attachments. Change-Id: If3f6004956a6b0f17ef5242eb5021429949f65fe Signed-off-by: Moti Asayag <masa...@redhat.com> --- M backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/resource/HostResource.java M backend/manager/modules/restapi/interface/definition/src/main/resources/api.xsd M backend/manager/modules/restapi/interface/definition/src/main/resources/rsdl_metadata.yaml M backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendHostResource.java M backend/manager/modules/restapi/types/src/main/java/org/ovirt/engine/api/restapi/types/HostNicMapper.java M backend/manager/modules/restapi/types/src/test/java/org/ovirt/engine/api/restapi/types/HostNicMapperTest.java 6 files changed, 223 insertions(+), 5 deletions(-) git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/79/35379/1 diff --git a/backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/resource/HostResource.java b/backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/resource/HostResource.java index fc3ac55..3e85aa5 100644 --- a/backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/resource/HostResource.java +++ b/backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/resource/HostResource.java @@ -16,6 +16,7 @@ package org.ovirt.engine.api.resource; +import javax.ws.rs.Consumes; import javax.ws.rs.POST; import javax.ws.rs.Path; import javax.ws.rs.PathParam; @@ -29,8 +30,8 @@ @Produces({ApiMediaType.APPLICATION_XML, ApiMediaType.APPLICATION_JSON, ApiMediaType.APPLICATION_X_YAML}) public interface HostResource extends UpdatableResource<Host>, MeasurableResource { - @Path("{action: (approve|install|fence|activate|deactivate|commitnetconfig|iscsidiscover|iscsilogin|forceselectspm)}/{oid}") - public ActionResource getActionSubresource(@PathParam("action")String action, @PathParam("oid")String oid); + @Path("{action: (approve|install|fence|activate|deactivate|commitnetconfig|iscsidiscover|iscsilogin|forceselectspm|setupnetworks)}/{oid}") + public ActionResource getActionSubresource(@PathParam("action") String action, @PathParam("oid") String oid); @POST @Actionable @@ -97,4 +98,10 @@ @Path("permissions") public AssignedPermissionsResource getPermissionsResource(); + + @POST + @Consumes({ ApiMediaType.APPLICATION_XML, ApiMediaType.APPLICATION_JSON, ApiMediaType.APPLICATION_X_YAML }) + @Actionable + @Path("setupnetworks") + public Response setupNetworks(Action action); } diff --git a/backend/manager/modules/restapi/interface/definition/src/main/resources/api.xsd b/backend/manager/modules/restapi/interface/definition/src/main/resources/api.xsd index 77f2024..454e98d 100644 --- a/backend/manager/modules/restapi/interface/definition/src/main/resources/api.xsd +++ b/backend/manager/modules/restapi/interface/definition/src/main/resources/api.xsd @@ -173,6 +173,10 @@ <xs:element ref="template" minOccurs="0" maxOccurs="1"/> <!-- For Setup Networks --> <xs:element ref="host_nics" minOccurs="0" maxOccurs="1"/> + <xs:element ref="network_attachments" minOccurs="0" maxOccurs="1"/> + <xs:element name="removed_network_attachments" type="NetworkAttachments" minOccurs="0" maxOccurs="1"/> + <xs:element name="bonds" type="HostNics" minOccurs="0" maxOccurs="1"/> + <xs:element name="removed_bonds" type="HostNics" minOccurs="0" maxOccurs="1"/> <xs:element name="check_connectivity" type="xs:boolean" minOccurs="0"/> <xs:element name="connectivity_timeout" type="xs:int" minOccurs="0"/> <!-- A VM can be started paused --> diff --git a/backend/manager/modules/restapi/interface/definition/src/main/resources/rsdl_metadata.yaml b/backend/manager/modules/restapi/interface/definition/src/main/resources/rsdl_metadata.yaml index fe09f21..5d135bc 100644 --- a/backend/manager/modules/restapi/interface/definition/src/main/resources/rsdl_metadata.yaml +++ b/backend/manager/modules/restapi/interface/definition/src/main/resources/rsdl_metadata.yaml @@ -3081,6 +3081,7 @@ action.checkConnectivity: xs:boolean action.connectivityTimeout: xs:int action.force: xs:boolean + deprecated: true description: initiate the command to setup networks for the network interface card of the specified host urlparams: {} headers: @@ -3168,8 +3169,57 @@ async: {context: matrix, type: 'xs:boolean', value: true|false, required: false} headers: Correlation-Id: {value: 'any string', required: false} - - +- name: /hosts/{host:id}/setupnetworks|rel=setupnetworks + description: initiate the command to setup networks for the specified host + request: + body: + parameterType: Action + signatures: + - mandatoryArguments: {} + optionalArguments: { + action.network_attachments.network_attachment--COLLECTION: { + network_attachment.id: 'xs:string', + network_attachment.network.id: 'xs:string', + network_attachment.host_nic.name|id: 'xs:string', + network_attachment.ip_configuration.ipv4s.boot_protocol: 'xs:string', + network_attachment.ip_configuration.ipv4s.ipv4--COLLECTION: { + ipv4.address: 'xs:string', + ipv4.netmask: 'xs:string', + ipv4.gateway: 'xs:string' + }, + network_attachment.properties.property--COLLECTION: { + property.name: 'xs:string', + property.value: 'xs:string' + }, + network_attachment.override_configuration: 'xs:boolean' + }, + action.removed_network_attachments.network_attachment--COLLECTION: { + network_attachment.id: 'xs:string' + }, + action.bonds.host_nic--COLLECTION: { + host_nic.name|id: 'xs:string', + host_nic.bonding.options.option--COLLECTION: { + option.name: 'xs:string', + option.value: 'xs:string', + option.type: 'xs:string' + }, + bonding.slaves.host_nic--COLLECTION: { + host_nic.name|id: 'xs:string' + } + }, + action.removed_bonds.host_nic--COLLECTION: { + host_nic.name|id: 'xs:string' + }, + action.checkConnectivity: 'xs:boolean', + action.connectivityTimeout: 'xs:int', + action.async: 'xs:boolean', + action.grace_period.expiry: 'xs:long' + } + description: initiate the command to setup networks for the specified host + urlparams: {} + headers: + Content-Type: {value: application/xml|json, required: true} + Correlation-Id: {value: 'any string', required: false} - name: /hosts/{host:id}/nics/{nic:id}/networkattachments|rel=get description: get the list of network attachments of the network interface request: diff --git a/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendHostResource.java b/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendHostResource.java index 06bcddc..6d64647 100644 --- a/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendHostResource.java +++ b/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendHostResource.java @@ -3,6 +3,7 @@ import static org.ovirt.engine.api.restapi.resource.BackendHostsResource.SUB_COLLECTIONS; import java.util.List; +import java.util.Map; import javax.ws.rs.Path; import javax.ws.rs.core.Response; @@ -14,6 +15,7 @@ import org.ovirt.engine.api.model.Fault; import org.ovirt.engine.api.model.FenceType; import org.ovirt.engine.api.model.Host; +import org.ovirt.engine.api.model.HostNIC; import org.ovirt.engine.api.model.IscsiDetails; import org.ovirt.engine.api.model.LogicalUnit; import org.ovirt.engine.api.model.PowerManagement; @@ -28,12 +30,14 @@ import org.ovirt.engine.api.resource.NetworkAttachmentsResource; import org.ovirt.engine.api.resource.StatisticsResource; import org.ovirt.engine.api.restapi.model.AuthenticationMethod; +import org.ovirt.engine.api.restapi.types.Mapper; import org.ovirt.engine.core.common.VdcObjectType; import org.ovirt.engine.core.common.action.ApproveVdsParameters; import org.ovirt.engine.core.common.action.ChangeVDSClusterParameters; import org.ovirt.engine.core.common.action.FenceVdsActionParameters; import org.ovirt.engine.core.common.action.FenceVdsManualyParameters; import org.ovirt.engine.core.common.action.ForceSelectSPMParameters; +import org.ovirt.engine.core.common.action.HostSetupNetworksParameters; import org.ovirt.engine.core.common.action.MaintenanceNumberOfVdssParameters; import org.ovirt.engine.core.common.action.StorageServerConnectionParametersBase; import org.ovirt.engine.core.common.action.UpdateVdsActionParameters; @@ -41,6 +45,8 @@ import org.ovirt.engine.core.common.action.VdcActionType; import org.ovirt.engine.core.common.action.VdsActionParameters; import org.ovirt.engine.core.common.action.VdsOperationActionParameters; +import org.ovirt.engine.core.common.businessentities.BusinessEntityMap; +import org.ovirt.engine.core.common.businessentities.Entities; import org.ovirt.engine.core.common.businessentities.FenceActionType; import org.ovirt.engine.core.common.businessentities.FenceStatusReturnValue; import org.ovirt.engine.core.common.businessentities.StorageServerConnections; @@ -48,6 +54,8 @@ import org.ovirt.engine.core.common.businessentities.VDSGroup; import org.ovirt.engine.core.common.businessentities.VDSType; import org.ovirt.engine.core.common.businessentities.VdsStatic; +import org.ovirt.engine.core.common.businessentities.network.Bond; +import org.ovirt.engine.core.common.businessentities.network.NetworkAttachment; import org.ovirt.engine.core.common.queries.DiscoverSendTargetsQueryParameters; import org.ovirt.engine.core.common.queries.GetPermissionsForObjectParameters; import org.ovirt.engine.core.common.queries.IdQueryParameters; @@ -163,6 +171,96 @@ action); } + @Override + public Response setupNetworks(Action action) { + HostSetupNetworksParameters parameters = toParameters(action); + return performAction(VdcActionType.HostSetupNetworks, parameters, action); + } + + private HostSetupNetworksParameters toParameters(Action action) { + HostSetupNetworksParameters parameters = new HostSetupNetworksParameters(guid); + Map<Guid, NetworkAttachment> attachmentsById = getBackendNetworkAttachments(); + + if (action.isSetNetworkAttachments()) { + for (org.ovirt.engine.api.model.NetworkAttachment model : action.getNetworkAttachments() + .getNetworkAttachments()) { + NetworkAttachment attachment = mapNetworkAttachment(attachmentsById, model); + parameters.getNetworkAttachments().add(attachment); + } + } + + if (action.isSetRemovedNetworkAttachments()) { + for (org.ovirt.engine.api.model.NetworkAttachment model : action.getRemovedNetworkAttachments() + .getNetworkAttachments()) { + NetworkAttachment attachment = mapNetworkAttachment(attachmentsById, model); + parameters.getRemovedNetworkAttachments().add(attachment); + } + } + + BusinessEntityMap<Bond> bonds = getBackendHostBonds(); + if (action.isSetBonds()) { + for (HostNIC bond : action.getBonds().getHostNics()) { + parameters.getBonds().add(mapBonds(bonds, bond)); + } + } + + if (action.isSetRemovedBonds()) { + for (HostNIC bond : action.getRemovedBonds().getHostNics()) { + parameters.getRemovedBonds().add(mapBonds(bonds, bond)); + } + } + + parameters.setRollbackOnFailure(action.isSetCheckConnectivity() ? action.isCheckConnectivity() : false); + if (action.isSetConnectivityTimeout()) { + parameters.setConectivityTimeout(action.getConnectivityTimeout()); + } + + return parameters; + } + + public Map<Guid, NetworkAttachment> getBackendNetworkAttachments() { + List<NetworkAttachment> backendAttachments = + getBackendCollection(NetworkAttachment.class, + VdcQueryType.GetNetworkAttachmentsByHostId, + new IdQueryParameters(guid)); + return Entities.businessEntitiesById(backendAttachments); + } + + public BusinessEntityMap<Bond> getBackendHostBonds() { + List<Bond> backendBonds = + getBackendCollection(Bond.class, VdcQueryType.GetHostBondsByHostId, new IdQueryParameters(guid)); + return new BusinessEntityMap<Bond>(backendBonds); + } + + public NetworkAttachment mapNetworkAttachment(Map<Guid, NetworkAttachment> attachmentsById, + org.ovirt.engine.api.model.NetworkAttachment model) { + Mapper<org.ovirt.engine.api.model.NetworkAttachment, NetworkAttachment> networkAttachmentMapper = + getMapper(org.ovirt.engine.api.model.NetworkAttachment.class, NetworkAttachment.class); + NetworkAttachment attachment; + if (model.isSetId()) { + Guid attachmentId = asGuid(model.getId()); + attachment = networkAttachmentMapper.map(model, attachmentsById.get(attachmentId)); + } else { + attachment = networkAttachmentMapper.map(model, null); + } + + return attachment; + } + + public Bond mapBonds(BusinessEntityMap<Bond> bonds, HostNIC model) { + Mapper<HostNIC, Bond> hostNicMapper = getMapper(HostNIC.class, Bond.class); + Bond bond; + if (model.isSetId()) { + Guid nicId = asGuid(model.getId()); + bond = hostNicMapper.map(model, bonds.get(nicId)); + } else { + Bond tempalte = model.isSetName() ? bonds.get(model.getName()) : null; + bond = hostNicMapper.map(model, tempalte); + } + + return bond; + } + private Host setCluster(Host host, Cluster cluster) { if (cluster.isSetId()) { host.setCluster(cluster); diff --git a/backend/manager/modules/restapi/types/src/main/java/org/ovirt/engine/api/restapi/types/HostNicMapper.java b/backend/manager/modules/restapi/types/src/main/java/org/ovirt/engine/api/restapi/types/HostNicMapper.java index f321acb..aa6e3ea 100644 --- a/backend/manager/modules/restapi/types/src/main/java/org/ovirt/engine/api/restapi/types/HostNicMapper.java +++ b/backend/manager/modules/restapi/types/src/main/java/org/ovirt/engine/api/restapi/types/HostNicMapper.java @@ -11,8 +11,8 @@ import org.ovirt.engine.api.model.NicStatus; import org.ovirt.engine.api.model.Option; import org.ovirt.engine.api.model.Options; -import org.ovirt.engine.api.restapi.utils.CustomPropertiesParser; import org.ovirt.engine.api.model.VLAN; +import org.ovirt.engine.api.restapi.utils.CustomPropertiesParser; import org.ovirt.engine.api.restapi.utils.GuidUtils; import org.ovirt.engine.core.common.businessentities.network.Bond; import org.ovirt.engine.core.common.businessentities.network.InterfaceStatus; @@ -91,6 +91,40 @@ return entity; } + @Mapping(from = HostNIC.class, to = Bond.class) + public static Bond map(HostNIC model, Bond template) { + Bond entity = template == null ? new Bond() : template; + + if (model.isSetId()) { + entity.setId(GuidUtils.asGuid(model.getId())); + } + + if (model.isSetName()) { + entity.setName(model.getName()); + } + + if (model.isSetBonding()) { + entity.setBonded(true); + if (model.getBonding().isSetSlaves()) { + for (HostNIC slave : model.getBonding().getSlaves().getSlaves()) { + if (slave.isSetName()) { + entity.getSlaves().add(slave.getName()); + } + } + } + + if (model.getBonding().isSetOptions()) { + StringBuffer buf = new StringBuffer(); + for (Option opt : model.getBonding().getOptions().getOptions()) { + buf.append(opt.getName() + "=" + opt.getValue() + " "); + } + entity.setBondOptions(buf.toString().substring(0, buf.length() - 1)); + } + } + + return entity; + } + @Mapping(from = VdsNetworkInterface.class, to = HostNIC.class) public static HostNIC map(VdsNetworkInterface entity, HostNIC template) { HostNIC model = template != null ? template : new HostNIC(); diff --git a/backend/manager/modules/restapi/types/src/test/java/org/ovirt/engine/api/restapi/types/HostNicMapperTest.java b/backend/manager/modules/restapi/types/src/test/java/org/ovirt/engine/api/restapi/types/HostNicMapperTest.java index c3528a1..3149e20 100644 --- a/backend/manager/modules/restapi/types/src/test/java/org/ovirt/engine/api/restapi/types/HostNicMapperTest.java +++ b/backend/manager/modules/restapi/types/src/test/java/org/ovirt/engine/api/restapi/types/HostNicMapperTest.java @@ -1,9 +1,14 @@ package org.ovirt.engine.api.restapi.types; import org.junit.Test; +import org.ovirt.engine.api.model.Bonding; import org.ovirt.engine.api.model.HostNIC; +import org.ovirt.engine.api.model.Slaves; import org.ovirt.engine.api.restapi.utils.CustomPropertiesParser; +import org.ovirt.engine.core.common.businessentities.network.Bond; import org.ovirt.engine.core.common.businessentities.network.VdsNetworkInterface; +import org.ovirt.engine.core.compat.Guid; +import org.ovirt.engine.core.utils.RandomUtils; public class HostNicMapperTest extends AbstractInvertibleMappingTest<HostNIC, VdsNetworkInterface, VdsNetworkInterface> { @@ -62,4 +67,24 @@ model = HostNicMapper.map(entity, null); assertEquals(entity.getNetworkImplementationDetails().isInSync(), !model.isCustomConfiguration()); } + + @Test + public void testBondMapping() { + HostNIC model = new HostNIC(); + model.setId(Guid.newGuid().toString()); + model.setName(RandomUtils.instance().nextString(10)); + model.setBonding(new Bonding()); + model.getBonding().setSlaves(new Slaves()); + HostNIC slaveA = new HostNIC(); + slaveA.setName(RandomUtils.instance().nextString(10)); + model.getBonding().getSlaves().getSlaves().add(slaveA); + Bond entity = HostNicMapper.map(model, null); + assertNotNull(entity); + assertEquals(model.getId(), entity.getId().toString()); + assertEquals(model.getName(), entity.getName()); + assertEquals(model.getBonding().getSlaves().getSlaves().size(), entity.getSlaves().size()); + for (HostNIC slave : model.getBonding().getSlaves().getSlaves()) { + assertTrue(entity.getSlaves().contains(slave.getName())); + } + } } -- To view, visit http://gerrit.ovirt.org/35379 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: If3f6004956a6b0f17ef5242eb5021429949f65fe Gerrit-PatchSet: 1 Gerrit-Project: ovirt-engine Gerrit-Branch: master Gerrit-Owner: Moti Asayag <masa...@redhat.com> _______________________________________________ Engine-patches mailing list Engine-patches@ovirt.org http://lists.ovirt.org/mailman/listinfo/engine-patches