Fix mapping of lists in ONE Records, import both VM and VM_POOL

subrecords
This commit is contained in:
Timothée Floure 2021-03-05 16:09:04 +01:00
parent ae52442bd6
commit 053d5a3320
Signed by: tfloure
GPG key ID: 4502C902C00A1E12
2 changed files with 12 additions and 2 deletions

View file

@ -63,6 +63,9 @@ defmodule RecycledCloud.OpenNebula.Schema do
data
end
defp transform_value({k, l}) when is_list(l) do
{k, Enum.map(l, fn v -> map_record(v) end)}
end
defp transform_value({k, v}), do: {k, map_record(v)}
# Here be dragons! See moduledoc.

View file

@ -19,8 +19,15 @@ defmodule RecycledCloud.OpenNebula.Schema.Records do
def get_model_for(object), do: Map.get(@models, object)
for {name, record} <- Record.extract_all(from: Schema.get_hrl_for("vm")) do
extract = fn name, acc -> Record.extract_all(from: Schema.get_hrl_for(name)) ++ acc end
sources = ["vm", "vm_pool"]
|> Enum.reduce([], extract)
|> Enum.sort_by(fn {name, _} -> name end)
|> Enum.dedup_by(fn {name, _} -> name end)
#IO.inspect sources |> Enum.dedup_by(fn {, _} -> name end)
for {name, record} <- sources do
Record.defrecord name, record
end
Record.defrecord :VM_POOL, Record.extract(:VM_POOL, from: Schema.get_hrl_for("vm_pool"))
end