[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Xen-API] [PATCH] CA-26252: Removed all traces of compat-mode. FIXED



 ocaml/xapi/cli_frontend.ml   |    6 +-
 ocaml/xapi/cli_operations.ml |    2 +-
 ocaml/xapi/cli_printer.ml    |   87 ++++++++++++++--------------
 ocaml/xapi/xapi_cli.ml       |  129 +++++++++++++++++++-----------------------
 ocaml/xe-cli/newcli.ml       |   20 +------
 5 files changed, 106 insertions(+), 138 deletions(-)


# HG changeset patch
# User Mike McClurg <mike.mcclurg@xxxxxxxxxx>
# Date 1286985041 -3600
# Node ID 8ca7127d9f3909ed9459ed49e0cc6dbff3171afd
# Parent  d29070e598d7c64cdddbebf7362aff6188a559ec
CA-26252: Removed all traces of compat-mode. FIXED.

Signed-off-by: Mike McClurg <mike.mcclurg@xxxxxxxxxx>

diff --git a/ocaml/xapi/cli_frontend.ml b/ocaml/xapi/cli_frontend.ml
--- a/ocaml/xapi/cli_frontend.ml
+++ b/ocaml/xapi/cli_frontend.ml
@@ -2592,10 +2592,8 @@
       printer (Cli_printer.PList (make_list vm_cmds))
     end
   
-let cmd_help printer minimal is_compat cmd =
-  if is_compat 
-  then geneva_help printer minimal cmd
-  else rio_help printer minimal cmd
+let cmd_help printer minimal cmd =
+       rio_help printer minimal cmd
 
 
 
diff --git a/ocaml/xapi/cli_operations.ml b/ocaml/xapi/cli_operations.ml
--- a/ocaml/xapi/cli_operations.ml
+++ b/ocaml/xapi/cli_operations.ml
@@ -462,7 +462,7 @@
        end
 
 
-let stdparams = ["server";"password";"port";"username"; "minimal"; "force"; 
"multiple"; "compat"; "all"; "message-priority"]
+let stdparams = ["server";"password";"port";"username"; "minimal"; "force"; 
"multiple"; "all"; "message-priority"]
 
 (* This goes through the list of parameters, extracting any of the form 
map-name-key=value   *)
 (* where map-name is the name of a map in the class. These will be used to set 
the key-value *)
diff --git a/ocaml/xapi/cli_printer.ml b/ocaml/xapi/cli_printer.ml
--- a/ocaml/xapi/cli_printer.ml
+++ b/ocaml/xapi/cli_printer.ml
@@ -36,14 +36,14 @@
   let n = len - String.length s in
   s^(String.make (if n>0 then n else 0) ' ')
 
-let rec multi_line_record is_compat r =
-  let maxlen = 4 + List.fold_left max 0 (List.map (fun (a,b) -> String.length 
a) r) in
-  let indent fs = List.map (fun (f,v)->(pad_string f maxlen,v)) fs in
-  let r =
-    match r with
-       ((k,v)::fs) -> ((if is_compat then k else (pad_rhs k 
maxlen)),v)::(indent fs)
-      | _ -> r in
-  (String.concat "\n" (List.map (fun (f,v)->f^": "^v) r))^"\n"
+let rec multi_line_record r =
+       let maxlen = 4 + List.fold_left max 0 (List.map (fun (a,b) -> 
String.length a) r) in
+       let indent fs = List.map (fun (f,v)->(pad_string f maxlen,v)) fs in
+       let r =
+               match r with
+                               ((k,v)::fs) -> ((pad_rhs k maxlen),v)::(indent 
fs)
+                       | _ -> r in
+       (String.concat "\n" (List.map (fun (f,v)->f^": "^v) r))^"\n"
 
 (* Used to escape commas in --minimal mode *)
 let escape_commas x = 
@@ -53,42 +53,41 @@
                ] in
     Stringext.String.escaped ~rules x
 
-let make_printer is_compat sock minimal =
-  let buffer = ref [] in
+let make_printer sock minimal =
+       let buffer = ref [] in
 
-  let multi_line_xapi_minimal pval =
-    match pval with
-      | (PTable rs) ->
-         if (List.length rs > 0) && (List.length (List.hd rs) > 0) then
-           let names = List.map (fun r -> snd (List.hd r)) rs in
-           let escaped_names = List.map escape_commas names in
-           buffer := (String.concat "," escaped_names) :: !buffer
-      | (PList ss) ->
-         let escaped_ss = List.map escape_commas ss in
-         buffer := (String.concat "," escaped_ss) :: !buffer
-      | _ -> 
-         ()
-  in
-  
-  let multi_line_xapi pval =
-    match pval with
-      | (PTable rs) ->
-         List.iter (fun l -> marshal sock (Command (Print (l ^ "\n")))) 
(List.map (multi_line_record is_compat) rs)
-      | (PList ss) ->
-         List.iter (fun l -> marshal sock (Command (Print (l)))) ss
-      | (PMsg ss) -> 
-         marshal sock (Command (Print ss))
-      | (PStderr ss) ->
-         marshal sock (Command (PrintStderr ss))
-  in
-  
-  let minimal_flush () =
-    marshal sock (Command(Print (String.concat "," (!buffer))))
-  in
-  
-  let flush () = 
-    ()
-  in
+       let multi_line_xapi_minimal pval =
+               match pval with
+                       | (PTable rs) ->
+                               if (List.length rs > 0) && (List.length 
(List.hd rs) > 0) then
+                                       let names = List.map (fun r -> snd 
(List.hd r)) rs in
+                                       let escaped_names = List.map 
escape_commas names in
+                                       buffer := (String.concat "," 
escaped_names) :: !buffer
+                       | (PList ss) ->
+                               let escaped_ss = List.map escape_commas ss in
+                               buffer := (String.concat "," escaped_ss) :: 
!buffer
+                       | _ ->
+                               ()
+       in
 
-  if minimal then (multi_line_xapi_minimal, minimal_flush) else 
(multi_line_xapi, flush)
+       let multi_line_xapi pval =
+               match pval with
+                       | (PTable rs) ->
+                               List.iter (fun l -> marshal sock (Command 
(Print (l ^ "\n")))) (List.map multi_line_record rs)
+                       | (PList ss) ->
+                               List.iter (fun l -> marshal sock (Command 
(Print (l)))) ss
+                       | (PMsg ss) ->
+                               marshal sock (Command (Print ss))
+                       | (PStderr ss) ->
+                               marshal sock (Command (PrintStderr ss))
+       in
 
+       let minimal_flush () =
+               marshal sock (Command(Print (String.concat "," (!buffer))))
+       in
+
+       let flush () =
+               ()
+       in
+
+       if minimal then (multi_line_xapi_minimal, minimal_flush) else 
(multi_line_xapi, flush)
diff --git a/ocaml/xapi/xapi_cli.ml b/ocaml/xapi/xapi_cli.ml
--- a/ocaml/xapi/xapi_cli.ml
+++ b/ocaml/xapi/xapi_cli.ml
@@ -38,43 +38,41 @@
   let towrite = string ^ "\r\n" in
   ignore(Unix.write s towrite 0 (String.length towrite))
 
-let forward args s session is_compat =
-  (* Reject forwarding cli commands if the request came in from a tcp socket *)
-  if not (Context.is_unix_socket s) then raise (Api_errors.Server_error 
(Api_errors.host_is_slave,[Pool_role.get_master_address ()]));
-  let host = Pool_role.get_master_address () in
-  let port = !Xapi_globs.https_port in
-  let st_proc = Xmlrpcclient.get_reusable_stunnel
-    ~write_to_log:Xmlrpcclient.write_to_log host port in
-  finally
-    (fun () ->
-       let ms = st_proc.Stunnel.fd in
-       (* Headers *)
-       let body = String.concat "\r\n" args in
-       let body = 
-        if is_compat then "compat\r\n"^body else body in
-       let body = 
-        match session with None -> body | Some s -> 
("session_id="^(Ref.string_of s)^"\r\n")^body in
-       List.iter (write ms)
-        ["POST /cli HTTP/1.1";"Content-Length: "^(string_of_int (String.length 
body)); ""];
-       ignore_int (Unix.write ms body 0 (String.length body));
-       let (_ : int * int) = unmarshal_protocol ms in  
-       marshal_protocol ms;
-       Unixext.proxy (Unix.dup s) (Unix.dup ms)
-    )
-    (fun () ->
-       if Xmlrpcclient.check_reusable st_proc.Stunnel.fd then begin
-        Stunnel_cache.add st_proc
-       end else begin
-        debug "Disconnecting CLI because it is not reusable";
-        Stunnel.disconnect st_proc
-       end
-    )
+let forward args s session =
+       (* Reject forwarding cli commands if the request came in from a tcp 
socket *)
+       if not (Context.is_unix_socket s) then raise (Api_errors.Server_error 
(Api_errors.host_is_slave,[Pool_role.get_master_address ()]));
+       let host = Pool_role.get_master_address () in
+       let port = !Xapi_globs.https_port in
+       let st_proc = Xmlrpcclient.get_reusable_stunnel
+               ~write_to_log:Xmlrpcclient.write_to_log host port in
+       finally
+               (fun () ->
+                       let ms = st_proc.Stunnel.fd in
+                       (* Headers *)
+                       let body = String.concat "\r\n" args in
+                       let body =
+                               match session with None -> body | Some s -> 
("session_id="^(Ref.string_of s)^"\r\n")^body in
+                       List.iter (write ms)
+                               ["POST /cli HTTP/1.1";"Content-Length: 
"^(string_of_int (String.length body)); ""];
+                       ignore_int (Unix.write ms body 0 (String.length body));
+                       let (_ : int * int) = unmarshal_protocol ms in
+                       marshal_protocol ms;
+                       Unixext.proxy (Unix.dup s) (Unix.dup ms)
+               )
+               (fun () ->
+                       if Xmlrpcclient.check_reusable st_proc.Stunnel.fd then 
begin
+                               Stunnel_cache.add st_proc
+                       end else begin
+                               debug "Disconnecting CLI because it is not 
reusable";
+                               Stunnel.disconnect st_proc
+                       end
+               )
 
 
 (* Check that keys are all present in cmd *)
 let check_required_keys cmd keylist =
   let (_: (string * string) list) = get_params cmd in
-  List.map (get_reqd_param cmd) keylist
+       List.map (get_reqd_param cmd) keylist
 
 let with_session ~local rpc u p session f =  
   let session, logout = 
@@ -94,11 +92,11 @@
     (fun () -> f session)
     (fun () -> do_logout ())
 
-let do_rpcs req s username password minimal is_compat cmd session args =
+let do_rpcs req s username password minimal cmd session args =
   let cmdname = get_cmdname cmd in
   let cspec =
     try
-      Hashtbl.find (if is_compat then cmdtable_geneva else cmdtable) cmdname
+      Hashtbl.find cmdtable cmdname
     with
        Not_found -> raise (Unknown_command cmdname) in
   (* Forward if we're not the master, and if the cspec doesn't contain the key 
'neverforward' *)
@@ -110,10 +108,10 @@
     let generic_rpc = Helpers.get_rpc () in
     let rpc = generic_rpc req s in
     if do_forward
-    then with_session ~local:false rpc username password session (fun sess -> 
forward args s (Some sess) is_compat)
+    then with_session ~local:false rpc username password session (fun sess -> 
forward args s (Some sess))
     else
       begin
-       let (printer,flush) = Cli_printer.make_printer is_compat s minimal in
+       let (printer,flush) = Cli_printer.make_printer s minimal in
        let flush_and_marshall() = flush (); marshal s (Command(Exit 0)) in
        begin
          match cspec.implementation with
@@ -138,13 +136,13 @@
        warn "Uncaught exception: Unix_error '%s' '%s' '%s'" 
(Unix.error_message a) b c;
        raise e
 
-let do_help is_compat cmd minimal s =
-  let (printer,flush)=Cli_printer.make_printer is_compat s minimal in
-  cmd_help printer minimal is_compat cmd;
+let do_help cmd minimal s =
+  let (printer,flush)=Cli_printer.make_printer s minimal in
+  cmd_help printer minimal cmd;
   flush ();
   marshal s (Command (Exit 0))
 
-let exec_command req is_compat cmd s session args =
+let exec_command req cmd s session args =
        let params = get_params cmd in
        let minimal =
                if (List.mem_assoc "minimal" params)
@@ -163,8 +161,8 @@
        else
                debug "xe %s %s" cmd_name (String.concat " " (List.map (fun (k, 
v) -> k ^ "=" ^ v) params));
        if cmd_name = "help"
-       then do_help is_compat cmd minimal s
-       else do_rpcs req s u p minimal is_compat cmd session args
+       then do_help cmd minimal s
+       else do_rpcs req s u p minimal cmd session args
 
 
 let get_line str i =
@@ -190,36 +188,25 @@
     marshal sock (Command (Print msg))) errs;
   marshal sock (Command (Exit 1))
 
-(* If compatability mode is requested, then 'compat' is the first line sent
- * by the thin cli. If we find this, set is_compat true and strip the line
- * from the arguments *)
 let do_handle (req:Http.request) str (s:Unix.file_descr) =
-  let rec get_args n cur =
-    let (next,arg) = get_line str n in
-    let arg = zap_cr arg in
-    match next with 
-       Some i -> get_args i (arg::cur)
-      | None -> (arg::cur)
-  in
-  let args = List.rev (get_args 0 []) in
-  let (session,args) = 
-    try 
-      let line = List.hd args in
-      if String.startswith "session_id=" line
-      then (Some (Ref.of_string (String.sub line 11 (String.length line - 
11))), List.tl args)
-      else (None,args)
-    with _ -> (None,args) in
-  let (is_compat,args) = 
-    try 
-      let is_compat = List.hd args = "compat" in
-      (is_compat, if is_compat then List.tl args else args) 
-    with _ -> (false,args) in
-  let cmd = 
-    if is_compat 
-    then parse_commandline ("xe"::args) 
-    else parse_commandline_2 ("xe"::args) in
-  ignore(exec_command req is_compat cmd s session args)
-    
+       let rec get_args n cur =
+               let (next,arg) = get_line str n in
+               let arg = zap_cr arg in
+               match next with
+                               Some i -> get_args i (arg::cur)
+                       | None -> (arg::cur)
+       in
+       let args = List.rev (get_args 0 []) in
+       let (session,args) =
+               try
+                       let line = List.hd args in
+                       if String.startswith "session_id=" line
+                       then (Some (Ref.of_string (String.sub line 11 
(String.length line - 11))), List.tl args)
+                       else (None,args)
+               with _ -> (None,args) in
+       let cmd = parse_commandline_2 ("xe"::args) in
+       ignore(exec_command req cmd s session args)
+
 let exception_handler s e =
   debug "Xapi_cli.exception_handler: Got exception %s" 
(ExnHelper.string_of_exn e);
   log_backtrace ();
diff --git a/ocaml/xe-cli/newcli.ml b/ocaml/xe-cli/newcli.ml
--- a/ocaml/xe-cli/newcli.ml
+++ b/ocaml/xe-cli/newcli.ml
@@ -22,7 +22,6 @@
 let xapiserver = ref "127.0.0.1"
 let xapiuname = ref "root"
 let xapipword = ref "null"
-let xapicompatmode = ref false
 let xapipasswordfile = ref ""
 let xapicompathost = ref "127.0.0.1"
 let xapiport = ref None
@@ -50,18 +49,8 @@
 exception Usage
 
 let usage () =
-  if !xapicompatmode
-  then
-    begin
-      error "COMPATABILITY MODE\n";
-      error "Usage: %s <cmd> [-h server] [-p port] ([-u username] [-pw 
password] or [-pwf <password file>]) <other arguments>\n" Sys.argv.(0);
-      error "\nA full list of commands can be obtained by running \n\t%s help 
-h <server> -p <port>\n" Sys.argv.(0)
-    end
-  else
-    begin
-      error "Usage: %s <cmd> [-s server] [-p port] ([-u username] [-pw 
password] or [-pwf <password file>]) <other arguments>\n" Sys.argv.(0);
-      error "\nA full list of commands can be obtained by running \n\t%s help 
-s <server> -p <port>\n" Sys.argv.(0)
-    end
+    error "Usage: %s <cmd> [-s server] [-p port] ([-u username] [-pw password] 
or [-pwf <password file>]) <other arguments>\n" Sys.argv.(0);
+    error "\nA full list of commands can be obtained by running \n\t%s help -s 
<server> -p <port>\n" Sys.argv.(0)
 
 let is_localhost ip = ip = "127.0.0.1"
 
@@ -153,9 +142,6 @@
        | "password" -> xapipword := v
        | "passwordfile" -> xapipasswordfile := v
        | "nossl"   -> xeusessl := not(bool_of_string v)
-       | "compat" ->
-           xapicompatmode := (try (bool_of_string v) with _ -> false);
-           reserve_args := (k ^ "=" ^ v) :: !reserve_args
        | "debug" -> xedebug := (try bool_of_string v with _ -> false)
        | "debugonfail" -> xedebugonfail := (try bool_of_string v with _ -> 
false)
        | _ -> raise Not_found);
@@ -170,7 +156,6 @@
     | "-pw" :: pw :: xs -> Some("password", pw, xs)
     | "-pwf" :: pwf :: xs -> Some("passwordfile", pwf, xs)
     | "--nossl" :: xs -> Some("nossl", "true", xs)
-    | "--compat" :: xs -> Some("compat", "true", xs)
     | "--debug" :: xs -> Some("debug", "true", xs)
     | "--debug-on-fail" :: xs -> Some("debugonfail", "true", xs)
     | "-h" :: h :: xs -> Some("server", h, xs)
@@ -475,7 +460,6 @@
         let ic, oc = open_channels () in
         Printf.fprintf oc "POST /cli HTTP/1.0\r\n";
         let args = args @ [("username="^ !xapiuname);("password="^ 
!xapipword)] in
-        let args = if !xapicompatmode then "compat"::args else args in
         let args = String.concat "\n" args in
         Printf.fprintf oc "User-agent: xe-cli/Unix/%d.%d\r\n" major minor;
         Printf.fprintf oc "content-length: %d\r\n\r\n" (String.length args);
_______________________________________________
xen-api mailing list
xen-api@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/mailman/listinfo/xen-api

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.