Packages

Spawn and manage Google Compute Engine instances over the REST API, with pluggable auth, telemetry, and an ergonomic instance builder.

Current section

Files

Jump to
gcp_compute lib gcp_compute disk.ex
Raw

lib/gcp_compute/disk.ex

defmodule GcpCompute.Disk do
@moduledoc "Parsed `disks` entry of an instance."
alias GcpCompute.Util
@type t :: %__MODULE__{
device_name: String.t() | nil,
boot: boolean() | nil,
auto_delete: boolean() | nil,
source: String.t() | nil,
size_gb: integer() | nil,
type: String.t() | nil,
raw: map()
}
defstruct [:device_name, :boot, :auto_delete, :source, :size_gb, :type, raw: %{}]
@doc "Parse a list of decoded JSON `disks` (nil-safe)."
@spec list(list() | nil) :: [t()]
def list(nil), do: []
def list(disks) when is_list(disks), do: Enum.map(disks, &from_json/1)
@doc "Parse one decoded JSON disk map."
@spec from_json(map()) :: t()
def from_json(map) when is_map(map) do
%__MODULE__{
device_name: map["deviceName"],
boot: map["boot"],
auto_delete: map["autoDelete"],
source: Util.short_name(map["source"]),
size_gb: Util.to_integer(map["diskSizeGb"]),
type: Util.short_name(map["type"]),
raw: map
}
end
end