]> xenbits.xensource.com Git - xcp/xen-api.git/commitdiff
Tunnelling: error handling
authorRob Hoes <rob.hoes@citrix.com>
Wed, 14 Jul 2010 15:43:27 +0000 (16:43 +0100)
committerRob Hoes <rob.hoes@citrix.com>
Wed, 14 Jul 2010 15:43:27 +0000 (16:43 +0100)
Raise appropriate exceptions in tunnel.create, VLAN.create, and PIF.plug.

Signed-off-by: Rob Hoes <rob.hoes@citrix.com>
ocaml/idl/api_errors.ml
ocaml/idl/datamodel.ml
ocaml/xapi/xapi_pif.ml
ocaml/xapi/xapi_tunnel.ml

index e7684251e36df199c7a7297a5061bc4d6b4e0976..ffae0083eecff58c21e8da89d12bacb6daa983d5 100644 (file)
@@ -101,6 +101,10 @@ let mac_still_exists = "MAC_STILL_EXISTS"
 let mac_does_not_exist = "MAC_DOES_NOT_EXIST"
 let mac_invalid = "MAC_INVALID"
 
+let openvswitch_not_active = "OPENVSWITCH_NOT_ACTIVE"
+let transport_pif_not_configured = "TRANSPORT_PIF_NOT_CONFIGURED"
+let is_tunnel_access_pif = "IS_TUNNEL_ACCESS_PIF"
+
 let vlan_tag_invalid = "VLAN_TAG_INVALID"
 let vm_bad_power_state = "VM_BAD_POWER_STATE"
 let vm_is_template = "VM_IS_TEMPLATE"
index 46fade1acfe58caed97d88b4d7858d55a4b800a8..fe03c75a717f045f95a2f6ffb84b9a6293758bd8 100644 (file)
@@ -439,6 +439,13 @@ let _ =
   error Api_errors.pif_device_not_found []
     ~doc:"The specified device was not found." ();
 
+  error Api_errors.openvswitch_not_active []
+    ~doc:"This operation needs the OpenVSwitch networking backend to be enabled." ();
+  error Api_errors.transport_pif_not_configured ["PIF"]
+    ~doc:"The tunnel transport PIF has no IP configuration set." ();
+  error Api_errors.is_tunnel_access_pif ["PIF"]
+    ~doc:"You tried to create a VLAN or tunnel on top of a tunnel access PIF - use the underlying transport PIF instead." ();
+
   (* VM specific errors *)
   error Api_errors.vm_is_protected [ "vm" ]
     ~doc:"This operation cannot be performed because the specified VM is protected by xHA" ();
@@ -4111,6 +4118,7 @@ let tunnel_create = call
        ~result:(Ref _tunnel, "The reference of the created tunnel object")
        ~lifecycle:[]
        ~allowed_roles:_R_POOL_OP
+       ~errs:[Api_errors.openvswitch_not_active; Api_errors.transport_pif_not_configured; Api_errors.is_tunnel_access_pif]
        ()
 
 let tunnel_destroy = call
index bcfd86ea78b23105bbebd61219e72c33e4514307..a15970f77c6dc2baaae7535c748d78b9931d9e94 100644 (file)
@@ -308,6 +308,9 @@ let vLAN_create ~__context ~tagged_PIF ~tag ~network =
   if List.mem (device, tag) other_keys
   then raise (Api_errors.Server_error (Api_errors.pif_vlan_exists, [device]));
 
+  if Db.PIF.get_tunnel_access_PIF_of ~__context ~self:tagged_PIF <> [] then
+    raise (Api_errors.Server_error (Api_errors.is_tunnel_access_pif, [Ref.string_of tagged_PIF]));
+               
   (* Copy the MTU from the base PIF *)
   let mTU = Db.PIF.get_MTU ~__context ~self:tagged_PIF in
 
@@ -420,9 +423,17 @@ let unplug ~__context ~self =
   then abort_if_network_attached_to_protected_vms ~__context ~self;
   Nm.bring_pif_down ~__context self
 
-let plug ~__context ~self =
+let rec plug ~__context ~self =
   let network = Db.PIF.get_network ~__context ~self in
   let host = Db.PIF.get_host ~__context ~self in
+  let tunnel = Db.PIF.get_tunnel_access_PIF_of ~__context ~self in
+  if tunnel <> [] then
+    let tunnel = List.hd tunnel in
+    let transport_PIF = Db.Tunnel.get_transport_PIF ~__context ~self:tunnel in
+    if Db.PIF.get_ip_configuration_mode ~__context ~self:transport_PIF = `None then
+      raise (Api_errors.Server_error (Api_errors.transport_pif_not_configured, [Ref.string_of transport_PIF]))
+    else
+         plug ~__context ~self:transport_PIF;    
   Xapi_network.attach ~__context ~network ~host
    
 let calculate_pifs_required_at_start_of_day ~__context =
index f557bcf8a2dec10201500e30d61b3f5315a9beaf..de796683846272ca9ca1ceb76ab5b7363cdccec8 100644 (file)
@@ -25,9 +25,15 @@ let choose_tunnel_device_name ~__context ~host =
        choose 0
 
 let create ~__context ~transport_PIF ~network =
+       let pool = Helpers.get_pool ~__context in
+       let host = Db.PIF.get_host ~__context ~self:transport_PIF in
+       Xapi_pif.assert_no_other_local_pifs ~__context ~host ~network;
+       if Netdev.network.Netdev.kind <> Netdev.Vswitch then
+               raise (Api_errors.Server_error (Api_errors.openvswitch_not_active, []));
+       if Db.PIF.get_tunnel_access_PIF_of ~__context ~self:transport_PIF <> [] then
+               raise (Api_errors.Server_error (Api_errors.is_tunnel_access_pif, [Ref.string_of transport_PIF]));
        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