Yaniv Bronhaim has uploaded a new change for review.

Change subject: API: Adding mapping between host and action parameters and 
using username field
......................................................................

API: Adding mapping between host and action parameters and using username field

Using username field when specified. When both password and rootPassword
are specified, prefer the rootPassword for backward compatibility.
Using HostMapper for mapping action and host objects to operation's parameters.

Change-Id: Ifc7f6ba85ed6a5a790b3cc0acce3f5d6eb305789
Signed-off-by: Yaniv Bronhaim <ybron...@redhat.com>
---
M 
backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendHostsResource.java
M 
backend/manager/modules/restapi/types/src/main/java/org/ovirt/engine/api/restapi/types/HostMapper.java
2 files changed, 38 insertions(+), 33 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/94/17194/1

diff --git 
a/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendHostsResource.java
 
b/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendHostsResource.java
index 442ed5b..a1b81dd 100644
--- 
a/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendHostsResource.java
+++ 
b/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendHostsResource.java
@@ -16,10 +16,10 @@
 import org.ovirt.engine.api.model.Statistics;
 import org.ovirt.engine.api.resource.HostResource;
 import org.ovirt.engine.api.resource.HostsResource;
-import org.ovirt.engine.api.restapi.model.AuthenticationMethod;
 import org.ovirt.engine.core.common.action.AddVdsActionParameters;
 import org.ovirt.engine.core.common.action.RemoveVdsParameters;
 import org.ovirt.engine.core.common.action.VdcActionType;
+import org.ovirt.engine.core.common.action.VdsOperationActionParameters;
 import org.ovirt.engine.core.common.businessentities.VDS;
 import org.ovirt.engine.core.common.businessentities.VDSGroup;
 import org.ovirt.engine.core.common.businessentities.VdsStatic;
@@ -97,31 +97,8 @@
         if (host.isSetRebootAfterInstallation()) {
             
addParams.setRebootAfterInstallation(host.isRebootAfterInstallation());
         }
-        if (host.isSetSsh()) {
-            if (host.getSsh().isSetUser()) {
-                if (host.getSsh().getUser().isSetPassword()) {
-                    
addParams.setRootPassword(host.getSsh().getUser().getPassword());
-                }
-                // TODO: adding username support.
-                //if (action.getSsh().getUser().isSetUserName()) {
-                //      
addParams.getvds().setSshUsername(action.getSsh().getUser().getUserName());
-                //}
-            }
-            if (host.getSsh().isSetPort()) {
-                
addParams.getvds().setSshPort(host.getSsh().getPort().intValue());
-            }
-            if (host.getSsh().isSetFingerprint()) {
-                
addParams.getvds().setSshKeyFingerprint(host.getSsh().getFingerprint());
-            }
-            if (host.getSsh().isSetAuthenticationMethod()) {
-                AuthenticationMethod m = 
AuthenticationMethod.fromValue(host.getSsh().getAuthenticationMethod());
-                if (m != null) {
-                    addParams.setAuthMethod(
-                            getMapper(AuthenticationMethod.class,
-                                  
org.ovirt.engine.core.common.action.VdsOperationActionParameters.AuthenticationMethod.class).map(m,
 null));
-                }
-            }
-        }
+        addParams = (AddVdsActionParameters) getMapper
+                (Host.class, VdsOperationActionParameters.class).map(host, 
(VdsOperationActionParameters) addParams);
         return performCreate(VdcActionType.AddVds,
                                addParams,
                                new 
QueryIdResolver<Guid>(VdcQueryType.GetVdsByVdsId, IdQueryParameters.class));
diff --git 
a/backend/manager/modules/restapi/types/src/main/java/org/ovirt/engine/api/restapi/types/HostMapper.java
 
b/backend/manager/modules/restapi/types/src/main/java/org/ovirt/engine/api/restapi/types/HostMapper.java
index f7e3ba0..409ea14 100644
--- 
a/backend/manager/modules/restapi/types/src/main/java/org/ovirt/engine/api/restapi/types/HostMapper.java
+++ 
b/backend/manager/modules/restapi/types/src/main/java/org/ovirt/engine/api/restapi/types/HostMapper.java
@@ -101,11 +101,9 @@
     @Mapping(from = SSH.class, to = VdsStatic.class)
     public static VdsStatic map(SSH model, VdsStatic template) {
         VdsStatic entity = template != null ? template : new VdsStatic();
-        /* TODO: add when configured ssh username is enabled
         if (model.isSetUser() && model.getUser().isSetUserName()) {
             entity.setSshUsername(model.getUser().getUserName());
         }
-        */
         if (model.isSetPort() && model.getPort() > 0) {
             entity.setSshPort(model.getPort());
         }
@@ -554,12 +552,14 @@
         if (action.isSetSsh()) {
             if (action.getSsh().isSetUser()) {
                 if (action.getSsh().getUser().isSetPassword()) {
-                    
params.setRootPassword(action.getSsh().getUser().getPassword());
+                    // For backward compatibility giving priority to 
rootPassword field
+                    if (params.getPassword() == null) {
+                        
params.setPassword(action.getSsh().getUser().getPassword());
+                    }
                 }
-                // TODO: uncomment when non-root username support is available
-                //if (action.getSsh().getUser().isSetUserName()) {
-                //      
params.getvds().setSshUsername(action.getSsh().getUser().getUserName());
-                //}
+                if (action.getSsh().getUser().isSetUserName()) {
+                      
params.getvds().setSshUsername(action.getSsh().getUser().getUserName());
+                }
             }
             if (action.getSsh().isSetPort()) {
                 params.getvds().setSshPort(action.getSsh().getPort());
@@ -574,6 +574,34 @@
         return params;
     }
 
+    @Mapping(from = Host.class, to = VdsOperationActionParameters.class)
+    public static VdsOperationActionParameters map(Host host, 
VdsOperationActionParameters params) {
+        params.setPassword(host.getRootPassword());
+        if (host.isSetSsh()) {
+            if (host.getSsh().isSetUser()) {
+                if (host.getSsh().getUser().isSetPassword()) {
+                    // For backward compatibility giving priority to 
rootPassword field
+                    if (params.getPassword() == null) {
+                        
params.setPassword(host.getSsh().getUser().getPassword());
+                    }
+                }
+                if (host.getSsh().getUser().isSetUserName()) {
+                      
params.getvds().setSshUsername(host.getSsh().getUser().getUserName());
+                }
+            }
+            if (host.getSsh().isSetPort()) {
+                params.getvds().setSshPort(host.getSsh().getPort());
+            }
+            if (host.getSsh().isSetFingerprint()) {
+                
params.getvds().setSshKeyFingerprint(host.getSsh().getFingerprint());
+            }
+            if (host.getSsh().isSetAuthenticationMethod()) {
+                
params.setAuthMethod(map(AuthenticationMethod.fromValue(host.getSsh().getAuthenticationMethod()),
 null));
+            }
+        }
+        return params;
+    }
+
     private static Hook createHook(Map.Entry<String, HashMap<String, 
HashMap<String, String>>> keyValuePair,
             Map.Entry<String, HashMap<String, String>> keyValuePair1) {
         String hookName = keyValuePair1.getKey();


-- 
To view, visit http://gerrit.ovirt.org/17194
To unsubscribe, visit http://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ifc7f6ba85ed6a5a790b3cc0acce3f5d6eb305789
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-engine
Gerrit-Branch: master
Gerrit-Owner: Yaniv Bronhaim <ybron...@redhat.com>
_______________________________________________
Engine-patches mailing list
Engine-patches@ovirt.org
http://lists.ovirt.org/mailman/listinfo/engine-patches

Reply via email to