Skip to content

Commit c7a1249

Browse files
committed
Add PIF.set_property
We'll add some constraints to this in the next patches. Signed-off-by: Rob Hoes <[email protected]>
1 parent c46faf6 commit c7a1249

File tree

4 files changed

+37
-2
lines changed

4 files changed

+37
-2
lines changed

ocaml/idl/datamodel.ml

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4674,14 +4674,26 @@ let pif_db_forget = call
46744674
~allowed_roles:_R_POOL_OP
46754675
()
46764676

4677+
let pif_set_property = call
4678+
~name:"set_property"
4679+
~doc:"Set the value of a property of the PIF"
4680+
~params:[
4681+
Ref _pif, "self", "The PIF";
4682+
String, "name", "The property name";
4683+
String, "value", "The property value";
4684+
]
4685+
~lifecycle:[Published, rel_augusta, ""]
4686+
~allowed_roles:_R_POOL_OP
4687+
()
4688+
46774689
let pif =
46784690
create_obj ~in_db:true ~in_product_since:rel_rio ~in_oss_since:oss_since_303 ~internal_deprecated_since:None ~persist:PersistEverything ~gen_constructor_destructor:false ~name:_pif ~descr:"A physical network interface (note separate VLANs are represented as several PIFs)"
46794691
~gen_events:true
46804692
~doccomments:[]
46814693
~messages_default_allowed_roles:_R_POOL_OP
46824694
~messages:[pif_create_VLAN; pif_destroy; pif_reconfigure_ip; pif_reconfigure_ipv6; pif_set_primary_address_type; pif_scan; pif_introduce; pif_forget;
46834695
pif_unplug; pif_plug; pif_pool_introduce;
4684-
pif_db_introduce; pif_db_forget
4696+
pif_db_introduce; pif_db_forget; pif_set_property
46854697
] ~contents:
46864698
[ uid _pif;
46874699
(* qualifier changed RW -> StaticRO in Miami *)

ocaml/xapi/message_forwarding.ml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2902,6 +2902,12 @@ module Forward = functor(Local: Custom_actions.CUSTOM_ACTIONS) -> struct
29022902
do_op_on ~local_fn ~__context ~host:(Db.PIF.get_host ~__context ~self)
29032903
(fun session_id rpc -> Client.PIF.set_primary_address_type rpc session_id self primary_address_type)
29042904

2905+
let set_property ~__context ~self ~name ~value =
2906+
info "PIF.set_property: PIF = '%s'; name = '%s'; value = '%s'" (pif_uuid ~__context self) name value;
2907+
let host = Db.PIF.get_host ~__context ~self in
2908+
let local_fn = Local.PIF.set_property ~self ~name ~value in
2909+
do_op_on ~local_fn ~__context ~host (fun session_id rpc -> Client.PIF.set_property rpc session_id self name value)
2910+
29052911
let scan ~__context ~host =
29062912
info "PIF.scan: host = '%s'" (host_uuid ~__context host);
29072913
let local_fn = Local.PIF.scan ~host in

ocaml/xapi/xapi_pif.ml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -649,6 +649,15 @@ let set_primary_address_type ~__context ~self ~primary_address_type =
649649
Db.PIF.set_primary_address_type ~__context ~self ~value:primary_address_type;
650650
Monitor_dbcalls.clear_cache_for_pif ~pif_name:(Db.PIF.get_device ~__context ~self)
651651

652+
let set_property ~__context ~self ~name ~value =
653+
(* Remove the existing property with this name, then add the new value. *)
654+
let properties = List.filter
655+
(fun (property_name, _) -> property_name <> name)
656+
(Db.PIF.get_properties ~__context ~self)
657+
in
658+
let properties = (name, value) :: properties in
659+
Db.PIF.set_properties ~__context ~self ~value:properties
660+
652661
let rec unplug ~__context ~self =
653662
assert_pif_is_managed ~__context ~self;
654663
assert_no_protection_enabled ~__context ~self;

ocaml/xapi/xapi_pif.mli

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,15 @@ val set_primary_address_type :
127127
__context:Context.t ->
128128
self:API.ref_PIF ->
129129
primary_address_type:[`IPv4 | `IPv6 ] -> unit
130-
130+
131+
(** Set a property on a PIF *)
132+
val set_property :
133+
__context:Context.t ->
134+
self:API.ref_PIF ->
135+
name:string ->
136+
value:string ->
137+
unit
138+
131139
(** Attempt to bring down the PIF: disconnect the underlying network interface from
132140
* its bridge and disable the interface. *)
133141
val unplug : __context:Context.t -> self:API.ref_PIF -> unit

0 commit comments

Comments
 (0)