WARNING - OLD ARCHIVES

This is an archived copy of the Xen.org mailing list, which we have preserved to ensure that existing links to archives are not broken. The live archive, which contains the latest emails, can be found at http://lists.xen.org/
   
 
 
Xen 
 
Home Products Support Community News
 
   
 

xen-api

[Xen-API] [PATCH] Introduce PIF.scan_bios

To: xen-api <xen-api@xxxxxxxxxxxxxxxxxxx>
Subject: [Xen-API] [PATCH] Introduce PIF.scan_bios
From: Rob Hoes <rob.hoes@xxxxxxxxxx>
Date: Mon, 12 Jul 2010 15:54:34 +0100
Delivery-date: Mon, 12 Jul 2010 07:55:00 -0700
Envelope-to: www-data@xxxxxxxxxxxxxxxxxxx
List-help: <mailto:xen-api-request@lists.xensource.com?subject=help>
List-id: Discussion of API issues surrounding Xen <xen-api.lists.xensource.com>
List-post: <mailto:xen-api@lists.xensource.com>
List-subscribe: <http://lists.xensource.com/mailman/listinfo/xen-api>, <mailto:xen-api-request@lists.xensource.com?subject=subscribe>
List-unsubscribe: <http://lists.xensource.com/mailman/listinfo/xen-api>, <mailto:xen-api-request@lists.xensource.com?subject=unsubscribe>
Sender: xen-api-bounces@xxxxxxxxxxxxxxxxxxx
# HG changeset patch
# User Rob Hoes <rob.hoes@xxxxxxxxxx>
Introduce PIF.scan_bios

This function is similar to PIF.scan, but uses biosdevname to determine the 
device names of the network interfaces. The patch also add an extra check to 
the PIF introduce code to ensure that no new PIF is created if one already 
exists with the same device name.

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

diff -r 2d1a8310903b ocaml/idl/api_errors.ml
--- a/ocaml/idl/api_errors.ml
+++ b/ocaml/idl/api_errors.ml
@@ -100,6 +100,7 @@
 let mac_still_exists = "MAC_STILL_EXISTS"
 let mac_does_not_exist = "MAC_DOES_NOT_EXIST"
 let mac_invalid = "MAC_INVALID"
+let duplicate_pif_device_name = "DUPLICATE_PIF_DEVICE_NAME"
 
 let openvswitch_not_active = "OPENVSWITCH_NOT_ACTIVE"
 let transport_pif_not_configured = "TRANSPORT_PIF_NOT_CONFIGURED"
diff -r 2d1a8310903b ocaml/idl/datamodel.ml
--- a/ocaml/idl/datamodel.ml
+++ b/ocaml/idl/datamodel.ml
@@ -421,6 +421,8 @@
     ~doc:"The MAC address specified still exists on this host." ();
   error Api_errors.mac_invalid [ "MAC" ]
     ~doc:"The MAC address specified is not valid." ();
+  error Api_errors.duplicate_pif_device_name [ "device" ]
+    ~doc:"A PIF with this specified device name already exists." ();
 
   error Api_errors.vlan_tag_invalid ["VLAN"]
     ~doc:"You tried to create a VLAN, but the tag you gave was invalid -- it 
must be between 0 and 4094.  The parameter echoes the VLAN tag you gave." ();
@@ -3911,6 +3913,15 @@
   ~allowed_roles:_R_POOL_OP
   ()
 
+let pif_scan_bios = call
+  ~name:"scan_bios"
+  ~doc:"Scan for physical interfaces on a host and create PIF objects to 
represent them. Use BIOS-based device names."
+  ~params:[Ref _host, "host", "The host on which to scan"]
+  ~result:(Set (Ref _pif), "List of newly created PIFs")
+  ~lifecycle:[]
+  ~allowed_roles:_R_POOL_OP
+  ()
+
 let pif_introduce = call
   ~name:"introduce"
   ~doc:"Create a PIF object matching a particular network interface"
@@ -3992,7 +4003,7 @@
       ~gen_events:true
       ~doccomments:[] 
       ~messages_default_allowed_roles:_R_POOL_OP
-      ~messages:[pif_create_VLAN; pif_destroy; pif_reconfigure_ip; pif_scan; 
pif_introduce; pif_forget;
+      ~messages:[pif_create_VLAN; pif_destroy; pif_reconfigure_ip; pif_scan; 
pif_scan_bios; pif_introduce; pif_forget;
                pif_unplug; pif_plug; pif_pool_introduce;
                pif_db_introduce; pif_db_forget
                ] ~contents:
diff -r 2d1a8310903b ocaml/xapi/message_forwarding.ml
--- a/ocaml/xapi/message_forwarding.ml
+++ b/ocaml/xapi/message_forwarding.ml
@@ -2449,6 +2449,11 @@
       info "PIF.scan: host = '%s'" (host_uuid ~__context host);
       let local_fn = Local.PIF.scan ~host in
       do_op_on ~local_fn ~__context ~host (fun session_id rpc -> 
Client.PIF.scan rpc session_id host)
+       
+    let scan_bios ~__context ~host = 
+      info "PIF.scan_bios: host = '%s'" (host_uuid ~__context host);
+      let local_fn = Local.PIF.scan_bios ~host in
+      do_op_on ~local_fn ~__context ~host (fun session_id rpc -> 
Client.PIF.scan_bios rpc session_id host)
 
     let introduce ~__context ~host ~mAC ~device = 
       info "PIF.introduce: host = '%s'; MAC adress = '%s'; device = '%s'" 
(host_uuid ~__context host) mAC device;
diff -r 2d1a8310903b ocaml/xapi/xapi_pif.ml
--- a/ocaml/xapi/xapi_pif.ml
+++ b/ocaml/xapi/xapi_pif.ml
@@ -126,7 +126,8 @@
 let set_difference a b = List.filter (fun x -> not(List.mem x b)) a
 
 type tables = { mac_to_pif_table: (string * API.ref_PIF) list;
-               mac_to_phy_table: (string * string) list }
+               mac_to_phy_table: (string * string) list;
+               mac_to_biosname_table: (string * string) list}
 
 let make_tables ~__context ~host = 
   (* Enumerate known MAC addresses *)
@@ -139,8 +140,12 @@
   let physical_macs = List.map Netdev.get_address physical in
   let mac_to_phy_table = List.combine physical_macs physical in
 
+  let bios_names = List.map Netdev.get_bios_name physical in
+  let mac_to_biosname_table = List.combine physical_macs bios_names in
+
   { mac_to_pif_table = mac_to_pif_table;
-    mac_to_phy_table = mac_to_phy_table }
+    mac_to_phy_table = mac_to_phy_table;
+    mac_to_biosname_table = mac_to_biosname_table}
 
 let is_my_management_pif ~__context ~self = 
   let net = Db.PIF.get_network ~__context ~self in
@@ -183,6 +188,7 @@
 let introduce_internal ?network ?(physical=true) ~t ~__context ~host ~mAC ~mTU 
~device ~vLAN ~vLAN_master_of () = 
   let is_vlan = vLAN >= 0L in
 
+  (* Assert that an interface with the given MAC address exists (ALSO DONE IN 
[introduce]!) *)
   if not(List.mem_assoc mAC t.mac_to_phy_table) && not(is_vlan)
   then raise (Api_errors.Server_error(Api_errors.mac_does_not_exist, [ mAC ]));
 
@@ -256,6 +262,13 @@
 
   let mAC = String.lowercase mAC in (* just a convention *)
   let t = make_tables ~__context ~host in
+  
+  (* Assert that a local PIF with the given device name does not already exist 
*)
+  let existing_pifs = List.map snd t.mac_to_pif_table in
+  List.iter (fun pif -> if Db.PIF.get_device ~__context ~self:pif = device 
then 
+    raise (Api_errors.Server_error(Api_errors.duplicate_pif_device_name, 
[device]))
+  ) existing_pifs;
+  
   (* Make sure the MAC exists *)
   let devices = Netdev.get_by_address mAC in
   match List.filter Netdev.is_physical devices with
@@ -298,6 +311,23 @@
   (* Make sure the right PIF(s) are marked as management PIFs *)
   update_management_flags ~__context ~host
 
+let scan_bios ~__context ~host =       
+       let t = make_tables ~__context ~host in
+       
+       let existing_macs = List.map fst t.mac_to_pif_table in
+       let physical_macs = List.map fst t.mac_to_biosname_table in
+       
+       (* Create PIF records for the new interfaces *)
+       let new_pifs =
+               List.map (fun mac -> 
+                       let device = List.assoc mac t.mac_to_phy_table in
+                       let device' = List.assoc mac t.mac_to_biosname_table in
+                       let mTU = Int64.of_string (Netdev.get_mtu device) in
+                       introduce_internal ~t ~__context ~host ~mAC:mac ~mTU 
~vLAN:(-1L) ~vLAN_master_of:Ref.null ~device:device' ()
+               ) (set_difference physical_macs existing_macs)
+       in
+       new_pifs
+
 (* Dummy MAC used by the VLAN *)
 let vlan_mac = "fe:ff:ff:ff:ff:ff"
 
diff -r 2d1a8310903b ocaml/xapi/xapi_pif.mli
--- a/ocaml/xapi/xapi_pif.mli
+++ b/ocaml/xapi/xapi_pif.mli
@@ -80,6 +80,8 @@
  *  corresponding networks are present and up-to-date. Uses 
{!introduce_internal}. *)
 val scan : __context:Context.t -> host:[ `host ] Ref.t -> unit
 
+val scan_bios : __context:Context.t -> host:[ `host ] Ref.t -> [ `PIF ] Ref.t 
list
+
 (** External facing call to create a new VLAN interface
  * @deprecated since Miami; use [VLAN.create] instead *)
 val create_VLAN :
@@ -130,7 +132,8 @@
 (** Convenient lookup tables for scanning etc *)
 type tables = {
   mac_to_pif_table : (string * API.ref_PIF) list;      (** MAC address to PIF 
reference (all PIFs) *)
-  mac_to_phy_table : (string * string) list;           (** MAC address to 
physical-interface name (all physical interfaces) *)
+  mac_to_phy_table : (string * string) list;           (** MAC address to 
kernel device name (all physical interfaces) *)
+  mac_to_biosname_table: (string * string) list;       (** MAC address to BIOS 
device name (all physical interfaces) *)
 }
 
 (** Construct and return lookup {!tables} with information about the network 
interfaces *)

Attachment: netw-scan-bios
Description: Text document

_______________________________________________
xen-api mailing list
xen-api@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/mailman/listinfo/xen-api
<Prev in Thread] Current Thread [Next in Thread>
  • [Xen-API] [PATCH] Introduce PIF.scan_bios, Rob Hoes <=