From d3407fae886662947c75cc38421a32a75ff8da88 Mon Sep 17 00:00:00 2001 From: Hentioe Date: Thu, 29 Oct 2020 10:48:53 +0800 Subject: Add some APIs to create resources --- .../model/network_interfaces/create_or_update.ex | 41 ++++++++++++++ .../model/virtual_machines/create_or_update.ex | 64 ++++++++++++++++++++++ lib/azure_ex/request.ex | 4 +- 3 files changed, 107 insertions(+), 2 deletions(-) create mode 100644 lib/azure_ex/model/network_interfaces/create_or_update.ex create mode 100644 lib/azure_ex/model/virtual_machines/create_or_update.ex (limited to 'lib/azure_ex') diff --git a/lib/azure_ex/model/network_interfaces/create_or_update.ex b/lib/azure_ex/model/network_interfaces/create_or_update.ex new file mode 100644 index 0000000..bff597c --- /dev/null +++ b/lib/azure_ex/model/network_interfaces/create_or_update.ex @@ -0,0 +1,41 @@ +defmodule AzureEx.Model.NetworkInterfaces.CreateOrUpdate do + @moduledoc false + + use TypedStruct + + alias __MODULE__.{Properties} + + typedstruct module: Subnet do + @derive Jason.Encoder + + field :id, String.t() + end + + typedstruct module: NetworkInterfaceIPConfiguration.Properties do + @derive Jason.Encoder + + field :subnet, Subnet.t() + end + + typedstruct module: NetworkInterfaceIPConfiguration do + @derive Jason.Encoder + + field :name, String.t() + field :properties, NetworkInterfaceIPConfiguration.Properties.t() + end + + typedstruct module: Properties do + @derive Jason.Encoder + + field :ipConfigurations, [NetworkInterfaceIPConfiguration.t()] + end + + typedstruct do + @derive Jason.Encoder + + field :id, String.t() + + field :location, String.t() + field :properties, Properties.t(), default: %Properties{} + end +end diff --git a/lib/azure_ex/model/virtual_machines/create_or_update.ex b/lib/azure_ex/model/virtual_machines/create_or_update.ex new file mode 100644 index 0000000..e719c0d --- /dev/null +++ b/lib/azure_ex/model/virtual_machines/create_or_update.ex @@ -0,0 +1,64 @@ +defmodule AzureEx.Model.VirtualMachines.CreateOrUpdate do + @moduledoc false + + use TypedStruct + + alias __MODULE__.{Properties, NetworkInterfaceReference, StorageProfile} + + typedstruct module: HardwareProfile do + @derive Jason.Encoder + + field :vmSize, String.t() + end + + typedstruct module: ImageReference do + @derive Jason.Encoder + + field :offer, String.t() + field :publisher, String.t() + field :sku, String.t() + field :version, String.t() + end + + typedstruct module: StorageProfile do + @derive Jason.Encoder + + field :imageReference, ImageReference.t() + end + + typedstruct module: NetworkInterfaceReference do + @derive Jason.Encoder + + field :id, String.t() + end + + typedstruct module: NetworkProfile do + @derive Jason.Encoder + + field :networkInterfaces, [NetworkInterfaceReference.t()] + end + + typedstruct module: OSProfile do + @derive Jason.Encoder + + field :adminPassword, String.t() + field :adminUsername, String.t() + field :computerName, String.t() + end + + typedstruct module: Properties do + @derive Jason.Encoder + + field :hardwareProfile, HardwareProfile.t() + field :networkProfile, NetworkProfile.t() + field :storageProfile, StorageProfile.t() + field :osProfile, OSProfile.t() + end + + typedstruct do + @derive Jason.Encoder + + field :location, String.t() + field :properties, Properties.t(), default: %Properties{} + end +end diff --git a/lib/azure_ex/request.ex b/lib/azure_ex/request.ex index c33cd51..88763f3 100644 --- a/lib/azure_ex/request.ex +++ b/lib/azure_ex/request.ex @@ -12,8 +12,8 @@ defmodule AzureEx.Request do @type httpoison_result :: {:ok, HTTPoison.Response.t()} | {:error, HTTPoison.Error.t()} @spec call(binary, method, data) :: {:ok, result} | {:error, error} - def call(endpoint, method, body \\ %{}) do - method |> send(endpoint, body) |> handle_response() + def call(endpoint, method, data \\ %{}) do + method |> send(endpoint, data) |> handle_response() end @spec handle_response({:ok, HTTPoison.Response.t()}) :: {:ok, result} | {:error, error} -- cgit v1.2.3