|   | 
      | 
  
  
      | 
      | 
  
 
     | 
    | 
  
  
     | 
    | 
  
  
    |   | 
      | 
  
  
    | 
         
xen-api
[Xen-API] [PATCH 3 of 8] Tunnelling: creation and destruction of	tunnels
 
# HG changeset patch
# User Rob Hoes <rob.hoes@xxxxxxxxxx>
# Date 1278671988 -3600
# Node ID a7baa421f3d5efc6198dab2849359a4cecf7efd0
# Parent  2c476bb5574a9e4c53960dd759d03578c20a31ea
Tunnelling: creation and destruction of tunnels
Signed-off-by: Rob Hoes <rob.hoes@xxxxxxxxxx>
diff -r 2c476bb5574a -r a7baa421f3d5 ocaml/xapi/xapi_tunnel.ml
--- a/ocaml/xapi/xapi_tunnel.ml
+++ b/ocaml/xapi/xapi_tunnel.ml
@@ -14,11 +14,36 @@
 module D = Debug.Debugger(struct let name="xapi" end) 
 open D
 
+let choose_tunnel_device_name ~__context ~host = 
+       let pifs = List.filter (fun self -> Db.PIF.get_host ~__context ~self = 
host) (Db.PIF.get_all ~__context) in
+       let devices = List.map (fun self -> Db.PIF.get_device ~__context ~self) 
pifs in
+       let rec choose n = 
+               let name = Printf.sprintf "tunnel%d" n in
+               if List.mem name devices
+               then choose (n + 1)
+               else name in
+       choose 0
+
 let create ~__context ~transport_PIF ~network =
-       debug "CREATE TUNNEL";
-       Ref.make ()
+       let tunnel = Ref.make () in
+       let access_PIF = Ref.make () in
+       let host = Db.PIF.get_host ~__context ~self:transport_PIF in
+       let device = choose_tunnel_device_name ~__context ~host in
+       let device_name = device in
+       let mAC = Xapi_vif_helpers.gen_mac (0, Uuid.to_string (Uuid.make_uuid 
())) in
+       Db.PIF.create ~__context ~ref:access_PIF ~uuid:(Uuid.to_string 
(Uuid.make_uuid ()))
+               ~device ~device_name ~network ~host ~mAC ~mTU:(-1L) ~vLAN:(-1L) 
~metrics:Ref.null
+               ~physical:false ~currently_attached:false 
+               ~ip_configuration_mode:`None ~iP:"" ~netmask:"" ~gateway:"" 
~dNS:"" ~bond_slave_of:Ref.null 
+               ~vLAN_master_of:Ref.null ~management:false ~other_config:[] 
~disallow_unplug:false;
+       Db.Tunnel.create ~__context ~ref:tunnel ~uuid:(Uuid.to_string 
(Uuid.make_uuid ()))
+               ~access_PIF ~transport_PIF ~status:["active", "false"] 
~other_config:[];
+       Xapi_pif.plug ~__context ~self:access_PIF;
+       tunnel
        
 let destroy ~__context ~self =
-       debug "DESTROY TUNNEL";
-       ()
+       let pif = Db.Tunnel.get_access_PIF ~__context ~self in
+       Xapi_pif.unplug ~__context ~self:pif;
+       Db.PIF.destroy ~__context ~self:pif;
+       Db.Tunnel.destroy ~__context ~self
 
diff -r 2c476bb5574a -r a7baa421f3d5 ocaml/xapi/xapi_vif_helpers.mli
--- a/ocaml/xapi/xapi_vif_helpers.mli
+++ b/ocaml/xapi/xapi_vif_helpers.mli
@@ -64,4 +64,7 @@
   __context:Context.t ->
   vm:[ `VM ] Ref.t ->
   preserve_mac_address:bool -> [ `VIF ] Ref.t -> API.ref_VIF
-  
+
+(** Generate a MAC address *)  
+val gen_mac : int * string -> string
+
 ocaml/xapi/xapi_tunnel.ml       |  33 +++++++++++++++++++++++++++++----
 ocaml/xapi/xapi_vif_helpers.mli |   5 ++++-
 2 files changed, 33 insertions(+), 5 deletions(-)
 
xen-api.hg-3.patch 
Description: Text Data 
_______________________________________________
xen-api mailing list
xen-api@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/mailman/listinfo/xen-api
 
 |   
 
 | 
    | 
  
  
    |   | 
    |