Raise appropriate exceptions in tunnel.create, VLAN.create, and PIF.plug.
Signed-off-by: Rob Hoes <rob.hoes@citrix.com>
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"
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" ();
~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
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
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 =
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