Shahar Havivi has uploaded a new change for review. Change subject: vmINit Rest ......................................................................
vmINit Rest Change-Id: I41030e2b0bff2a96583f2107fc1dd897bec54fe6 Signed-off-by: Shahar Havivi <shav...@redhat.com> --- D backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/action/CloudInitParameters.java M backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendVmResource.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/main/java/org/ovirt/engine/api/restapi/types/VmMapper.java 4 files changed, 54 insertions(+), 161 deletions(-) git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/46/21846/1 diff --git a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/action/CloudInitParameters.java b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/action/CloudInitParameters.java deleted file mode 100644 index eb182a6..0000000 --- a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/action/CloudInitParameters.java +++ /dev/null @@ -1,121 +0,0 @@ -package org.ovirt.engine.core.common.action; - -import java.io.Serializable; -import java.util.List; -import java.util.Map; - -import org.ovirt.engine.core.common.businessentities.network.VdsNetworkInterface; - -public class CloudInitParameters implements Serializable { - private static final long serialVersionUID = -139795494679460456L; - - private String hostname; - private String authorizedKeys; - private Boolean regenerateKeys; - - private List<String> dnsServers; - private List<String> dnsSearch; - private Map<String, VdsNetworkInterface> interfaces; - private List<String> startOnBoot; - - private String timeZone; - private String rootPassword; - - private Map<String, Attachment> attachments; - - public static class Attachment implements Serializable { - public static enum AttachmentType { - BASE64, - PLAINTEXT, - } - AttachmentType type; - String content; - - public void setAttachmentType(AttachmentType type) { - this.type = type; - } - public AttachmentType getAttachmentType() { - return type; - } - - public void setContent(String content) { - this.content = content; - } - public String getContent() { - return content; - } - } - - public CloudInitParameters() { - } - - public void setHostname(String hostname) { - this.hostname = hostname; - } - public String getHostname() { - return hostname; - } - - public void setAuthorizedKeys(String authorizedKeys) { - this.authorizedKeys = authorizedKeys; - } - public String getAuthorizedKeys() { - return authorizedKeys; - } - - public void setRegenerateKeys(Boolean regenerateKeys) { - this.regenerateKeys = regenerateKeys; - } - public Boolean getRegenerateKeys() { - return regenerateKeys; - } - - public void setDnsServers(List<String> dnsServers) { - this.dnsServers = dnsServers; - } - public List<String> getDnsServers() { - return dnsServers; - } - - public void setDnsSearch(List<String> dnsSearch) { - this.dnsSearch = dnsSearch; - } - public List<String> getDnsSearch() { - return dnsSearch; - } - - public void setInterfaces(Map<String, VdsNetworkInterface> interfaces) { - this.interfaces = interfaces; - } - public Map<String, VdsNetworkInterface> getInterfaces() { - return interfaces; - } - - public void setStartOnBoot(List<String> startOnBoot) { - this.startOnBoot = startOnBoot; - } - public List<String> getStartOnBoot() { - return startOnBoot; - } - - public void setTimeZone(String timeZone) { - this.timeZone = timeZone; - } - public String getTimeZone() { - return timeZone; - } - - public void setRootPassword(String password) { - this.rootPassword = password; - } - public String getRootPassword() { - return rootPassword; - } - - public void setAttachments(Map<String, Attachment> attachments) { - this.attachments = attachments; - } - public Map<String, Attachment> getAttachments() { - return attachments; - } -} diff --git a/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendVmResource.java b/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendVmResource.java index c0219ef..9192cba 100644 --- a/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendVmResource.java +++ b/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendVmResource.java @@ -42,7 +42,6 @@ import org.ovirt.engine.api.restapi.types.VmMapper; import org.ovirt.engine.core.common.VdcObjectType; import org.ovirt.engine.core.common.action.ChangeVMClusterParameters; -import org.ovirt.engine.core.common.action.CloudInitParameters; import org.ovirt.engine.core.common.action.MigrateVmParameters; import org.ovirt.engine.core.common.action.MigrateVmToServerParameters; import org.ovirt.engine.core.common.action.MoveVmParameters; @@ -60,6 +59,7 @@ import org.ovirt.engine.core.common.businessentities.InitializationType; import org.ovirt.engine.core.common.businessentities.VDS; import org.ovirt.engine.core.common.businessentities.VDSGroup; +import org.ovirt.engine.core.common.businessentities.VmInit; import org.ovirt.engine.core.common.businessentities.VmStatic; import org.ovirt.engine.core.common.interfaces.SearchType; import org.ovirt.engine.core.common.queries.GetPermissionsForObjectParameters; @@ -253,8 +253,8 @@ } } params.setInitializationType(InitializationType.CloudInit); - ((RunVmOnceParams) params).setCloudInitParameters( - getMapper(CloudInit.class, CloudInitParameters.class) + ((RunVmOnceParams) params).setVmInit( + getMapper(CloudInit.class, VmInit.class) .map(cloudInit, null)); } } else { 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 bc837b5..845a853 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 @@ -12,6 +12,7 @@ import org.ovirt.engine.api.model.Option; import org.ovirt.engine.api.model.Options; import org.ovirt.engine.api.restapi.utils.GuidUtils; +import org.ovirt.engine.core.common.businessentities.VmInitInterface; import org.ovirt.engine.core.common.businessentities.network.Bond; import org.ovirt.engine.core.common.businessentities.network.InterfaceStatus; import org.ovirt.engine.core.common.businessentities.network.NetworkBootProtocol; @@ -75,7 +76,7 @@ } } if(model.isSetBootProtocol()){ - NetworkBootProtocol networkBootProtocol = map(BootProtocol.fromValue(model.getBootProtocol()), null); + NetworkBootProtocol networkBootProtocol = map(BootProtocol.fromValue(model.getBootProtocol()), NetworkBootProtocol.NONE); if(networkBootProtocol != null){ entity.setBootProtocol(networkBootProtocol); } @@ -214,4 +215,21 @@ } return null; } + + @Mapping(from = BootProtocol.class, to = VmInitInterface.BootProtocol.class) + public static VmInitInterface.BootProtocol map(BootProtocol bootProtocol, VmInitInterface.BootProtocol template) { + if(bootProtocol!=null){ + switch (bootProtocol) { + case DHCP: + return VmInitInterface.BootProtocol.DHCP; + case STATIC: + return VmInitInterface.BootProtocol.STATIC; + case NONE: + return VmInitInterface.BootProtocol.NONE; + default: + return null; + } + } + return null; + } } diff --git a/backend/manager/modules/restapi/types/src/main/java/org/ovirt/engine/api/restapi/types/VmMapper.java b/backend/manager/modules/restapi/types/src/main/java/org/ovirt/engine/api/restapi/types/VmMapper.java index 054a97b..d512da2 100644 --- a/backend/manager/modules/restapi/types/src/main/java/org/ovirt/engine/api/restapi/types/VmMapper.java +++ b/backend/manager/modules/restapi/types/src/main/java/org/ovirt/engine/api/restapi/types/VmMapper.java @@ -3,7 +3,6 @@ import static org.ovirt.engine.core.compat.Guid.createGuidFromString; import java.util.ArrayList; -import java.util.HashMap; import java.util.LinkedHashSet; import java.util.List; import java.util.Map; @@ -55,8 +54,6 @@ import org.ovirt.engine.api.restapi.utils.CustomPropertiesParser; import org.ovirt.engine.api.restapi.utils.GuidUtils; import org.ovirt.engine.api.restapi.utils.UsbMapperUtils; -import org.ovirt.engine.core.common.action.CloudInitParameters; -import org.ovirt.engine.core.common.action.CloudInitParameters.Attachment; import org.ovirt.engine.core.common.action.RunVmOnceParams; import org.ovirt.engine.core.common.businessentities.BootSequence; import org.ovirt.engine.core.common.businessentities.MigrationSupport; @@ -64,11 +61,12 @@ import org.ovirt.engine.core.common.businessentities.UsbPolicy; import org.ovirt.engine.core.common.businessentities.VDSGroup; import org.ovirt.engine.core.common.businessentities.VMStatus; +import org.ovirt.engine.core.common.businessentities.VmInit; +import org.ovirt.engine.core.common.businessentities.VmInitFile; +import org.ovirt.engine.core.common.businessentities.VmInitInterface; import org.ovirt.engine.core.common.businessentities.VmPayload; import org.ovirt.engine.core.common.businessentities.VmStatic; import org.ovirt.engine.core.common.businessentities.VmTemplate; -import org.ovirt.engine.core.common.businessentities.network.NetworkBootProtocol; -import org.ovirt.engine.core.common.businessentities.network.VdsNetworkInterface; import org.ovirt.engine.core.common.osinfo.OsRepository; import org.ovirt.engine.core.common.utils.SimpleDependecyInjector; import org.ovirt.engine.core.common.utils.VmDeviceType; @@ -913,27 +911,27 @@ return entity; } - @Mapping(from = Attachment.AttachmentType.class, to = PayloadEncoding.class) - public static PayloadEncoding map(Attachment.AttachmentType attachmentType, PayloadEncoding template) { - switch (attachmentType) { + @Mapping(from = VmInitFile.FileType.class, to = PayloadEncoding.class) + public static PayloadEncoding map(VmInitFile.FileType fileType, PayloadEncoding template) { + switch (fileType) { case BASE64: return PayloadEncoding.BASE64; case PLAINTEXT: return PayloadEncoding.PLAINTEXT; default: return null; } } - @Mapping(from = PayloadEncoding.class, to = Attachment.AttachmentType.class) - public static Attachment.AttachmentType map(PayloadEncoding attachmentType, Attachment.AttachmentType template) { + @Mapping(from = PayloadEncoding.class, to = VmInitFile.FileType.class) + public static VmInitFile.FileType map(PayloadEncoding attachmentType, VmInitFile.FileType template) { switch (attachmentType) { - case BASE64: return Attachment.AttachmentType.BASE64; - case PLAINTEXT: return Attachment.AttachmentType.PLAINTEXT; + case BASE64: return VmInitFile.FileType.BASE64; + case PLAINTEXT: return VmInitFile.FileType.PLAINTEXT; default: return null; } } - @Mapping(from = CloudInit.class, to = CloudInitParameters.class) - public static CloudInitParameters map(CloudInit model, CloudInitParameters template) { - CloudInitParameters entity = template != null ? template : new CloudInitParameters(); + @Mapping(from = CloudInit.class, to = VmInit.class) + public static VmInit map(CloudInit model, VmInit template) { + VmInit entity = template != null ? template : new VmInit(); if (model.isSetHost() && model.getHost().isSetAddress()) { entity.setHostname(model.getHost().getAddress()); @@ -958,32 +956,28 @@ if (model.isSetNetwork()) { if (model.getNetwork().isSetNics()) { - Map<String, VdsNetworkInterface> interfaces = new HashMap<>(); + List<VmInitInterface> interfaces = new ArrayList<VmInitInterface>(); + entity.setInterfaces(interfaces); for (NIC iface : model.getNetwork().getNics().getNics()) { - VdsNetworkInterface vdsNetworkInterface = new VdsNetworkInterface(); + VmInitInterface vmInitInterface = new VmInitInterface(); + interfaces.add(vmInitInterface); if (iface.isSetBootProtocol()) { - NetworkBootProtocol protocol = HostNicMapper.map(BootProtocol.fromValue(iface.getBootProtocol()), null); - vdsNetworkInterface.setBootProtocol(protocol); - if (protocol != NetworkBootProtocol.DHCP && iface.isSetNetwork() && iface.getNetwork().isSetIp()) { + VmInitInterface.BootProtocol protocol = HostNicMapper.map(BootProtocol.fromValue(iface.getBootProtocol()), vmInitInterface.getBootProtocol()); + vmInitInterface.setBootProtocol(protocol); + if (protocol != VmInitInterface.BootProtocol.DHCP && iface.isSetNetwork() && iface.getNetwork().isSetIp()) { if (iface.getNetwork().getIp().isSetAddress()) { - vdsNetworkInterface.setAddress(iface.getNetwork().getIp().getAddress()); + vmInitInterface.setIp(iface.getNetwork().getIp().getAddress()); } if (iface.getNetwork().getIp().isSetNetmask()) { - vdsNetworkInterface.setSubnet(iface.getNetwork().getIp().getNetmask()); + vmInitInterface.setNetmask(iface.getNetwork().getIp().getNetmask()); } if (iface.getNetwork().getIp().isSetGateway()) { - vdsNetworkInterface.setGateway(iface.getNetwork().getIp().getGateway()); + vmInitInterface.setGateway(iface.getNetwork().getIp().getGateway()); } } - } - - interfaces.put(iface.getName(), vdsNetworkInterface); - - if (iface.isSetOnBoot() && iface.isOnBoot()) { - if (entity.getStartOnBoot() == null) { - entity.setStartOnBoot(new ArrayList<String>()); + if (iface.isSetOnBoot() && iface.isOnBoot()) { + vmInitInterface.setStartOnBoot(true); } - entity.getStartOnBoot().add(iface.getName()); } } @@ -1032,12 +1026,14 @@ if (model.isSetFiles() && model.getFiles().isSetFiles() && !model.getFiles().getFiles().isEmpty()) { - entity.setAttachments(new HashMap<String, Attachment>()); + List<VmInitFile> files = new ArrayList<VmInitFile>(); + entity.setFiels(files); for (File file : model.getFiles().getFiles()) { - Attachment attachment = new Attachment(); - attachment.setAttachmentType(map(PayloadEncoding.fromValue(file.getType()), null)); - attachment.setContent(file.getContent()); - entity.getAttachments().put(file.getName(), attachment); + VmInitFile vmInitFile = new VmInitFile(); + files.add(vmInitFile); + vmInitFile.setFileType(map(PayloadEncoding.fromValue(file.getType()), null)); + vmInitFile.setContent(file.getContent()); + vmInitFile.setPath(file.getName()); } } -- To view, visit http://gerrit.ovirt.org/21846 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I41030e2b0bff2a96583f2107fc1dd897bec54fe6 Gerrit-PatchSet: 1 Gerrit-Project: ovirt-engine Gerrit-Branch: master Gerrit-Owner: Shahar Havivi <shav...@redhat.com> _______________________________________________ Engine-patches mailing list Engine-patches@ovirt.org http://lists.ovirt.org/mailman/listinfo/engine-patches