Packages

Create cloud portable Elixir and Phoenix apps. Write once, use everywhere!

Current section

Files

Jump to
nomad lib mix tasks storage storage_delete.ex
Raw

lib/mix/tasks/storage/storage_delete.ex

defmodule Mix.Tasks.Nomad.Storage.Delete do
use Mix.Task
@moduledoc"""
Task for automatically deleting a remote storage on a pre-determined cloud
provider. The storage deletion is done through the cloud provider's API.
Usage:
mix nomad.storage.delete
# Will be prompted for storage name
mix nomad.storage.delete <name>
# Will automaticallu delete the storage
"""
@shortdoc"Create a storage on the chosen cloud provider's storage service."
def run(args) do
case Application.get_env(:nomad, :cloud_provider) do
:aws ->
Application.ensure_all_started(:ex_aws)
Application.ensure_all_started(:httpoison)
:gcl ->
Application.ensure_all_started(:httpoison)
Application.ensure_all_started(:goth)
Application.ensure_all_started(:gcloudex)
end
delete_storage_api_call args
end
defp delete_storage_api_call([name]) do
del name
end
defp delete_storage_api_call([]) do
name = Mix.Shell.IO.prompt("Insert the storage's name: ") |> String.rstrip
del name
end
defp del(name) do
case Nomad.Storage.delete_storage(name) do
:ok -> Mix.Shell.IO.info("The instance has been deleted successfully.")
msg -> Mix.Shell.IO.info("There was a problem deleting the storage: \n#{msg}")
end
end
end