diff --git a/ocaml/idl/datamodel_errors.ml b/ocaml/idl/datamodel_errors.ml index fed2f830db1..5105df678ea 100644 --- a/ocaml/idl/datamodel_errors.ml +++ b/ocaml/idl/datamodel_errors.ml @@ -2010,6 +2010,9 @@ let _ = error Api_errors.too_many_groups [] ~doc:"VM can only belong to one group." () ; + error Api_errors.host_driver_no_hardware ["driver variant"] + ~doc:"No hardware present for this host driver variant" () ; + message (fst Api_messages.ha_pool_overcommitted) ~doc: diff --git a/ocaml/xapi-consts/api_errors.ml b/ocaml/xapi-consts/api_errors.ml index 54bdd6f6660..8d31f1e7dd0 100644 --- a/ocaml/xapi-consts/api_errors.ml +++ b/ocaml/xapi-consts/api_errors.ml @@ -1403,3 +1403,5 @@ let telemetry_next_collection_too_late = let illegal_in_fips_mode = add_error "ILLEGAL_IN_FIPS_MODE" let too_many_groups = add_error "TOO_MANY_GROUPS" + +let host_driver_no_hardware = add_error "HOST_DRIVER_NO_HARDWARE" diff --git a/ocaml/xapi/xapi_host_driver.ml b/ocaml/xapi/xapi_host_driver.ml index be66e3093f0..a4061a7f9f0 100644 --- a/ocaml/xapi/xapi_host_driver.ml +++ b/ocaml/xapi/xapi_host_driver.ml @@ -21,6 +21,9 @@ module Tool = Xapi_host_driver_tool let invalid_value field value = raise Api_errors.(Server_error (invalid_value, [field; value])) +let no_hardware driver_variant = + raise Api_errors.(Server_error (host_driver_no_hardware, [driver_variant])) + module Variant = struct let create ~__context ~name ~version ~driver ~hw_present ~priority ~dev_status = @@ -68,6 +71,8 @@ module Variant = struct let drv = Db.Driver_variant.get_driver ~__context ~self in let d = Db.Host_driver.get_record ~__context ~self:drv in let v = Db.Driver_variant.get_record ~__context ~self in + if v.API.driver_variant_hardware_present = false then + no_hardware (Ref.string_of self) ; let stdout = Tool.call ["select"; d.API.host_driver_name; v.API.driver_variant_name] in @@ -133,6 +138,8 @@ let select ~__context ~self ~variant = D.debug "%s selecting driver %s variant %s" __FUNCTION__ drv var ; let d = Db.Host_driver.get_record ~__context ~self in let v = Db.Driver_variant.get_record ~__context ~self:variant in + if v.API.driver_variant_hardware_present = false then + no_hardware (Ref.string_of variant) ; let stdout = Tool.call ["select"; d.API.host_driver_name; v.API.driver_variant_name] in