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

[Xen-API] [PATCH 4 of 8] Tunnelling: error handling


  • To: xen-api@xxxxxxxxxxxxxxxxxxx
  • From: Rob Hoes <rob.hoes@xxxxxxxxxx>
  • Date: Fri, 9 Jul 2010 15:59:50 +0100
  • Delivery-date: Fri, 09 Jul 2010 08:05:39 -0700
  • List-id: Discussion of API issues surrounding Xen <xen-api.lists.xensource.com>

# HG changeset patch
# User Rob Hoes <rob.hoes@xxxxxxxxxx>
# Date 1278673866 -3600
# Node ID 6294016ba6c3817a2423206f4ba76bd607e7d386
# Parent  a7baa421f3d5efc6198dab2849359a4cecf7efd0
Tunnelling: error handling

Raise appropriate exceptions in tunnel.create, VLAN.create, and PIF.plug.

Signed-off-by: Rob Hoes <rob.hoes@xxxxxxxxxx>

diff -r a7baa421f3d5 -r 6294016ba6c3 ocaml/idl/api_errors.ml
--- a/ocaml/idl/api_errors.ml
+++ b/ocaml/idl/api_errors.ml
@@ -101,6 +101,10 @@
 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"
diff -r a7baa421f3d5 -r 6294016ba6c3 ocaml/idl/datamodel.ml
--- a/ocaml/idl/datamodel.ml
+++ b/ocaml/idl/datamodel.ml
@@ -439,6 +439,13 @@
   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 @@
        ~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
diff -r a7baa421f3d5 -r 6294016ba6c3 ocaml/xapi/xapi_pif.ml
--- a/ocaml/xapi/xapi_pif.ml
+++ b/ocaml/xapi/xapi_pif.ml
@@ -308,6 +308,9 @@
   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 @@
   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 =
diff -r a7baa421f3d5 -r 6294016ba6c3 ocaml/xapi/xapi_tunnel.ml
--- a/ocaml/xapi/xapi_tunnel.ml
+++ b/ocaml/xapi/xapi_tunnel.ml
@@ -25,9 +25,15 @@
        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
 ocaml/idl/api_errors.ml   |   4 ++++
 ocaml/idl/datamodel.ml    |   8 ++++++++
 ocaml/xapi/xapi_pif.ml    |  13 ++++++++++++-
 ocaml/xapi/xapi_tunnel.ml |   8 +++++++-
 4 files changed, 31 insertions(+), 2 deletions(-)


Attachment: xen-api.hg-4.patch
Description: Text Data

_______________________________________________
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®.