GcpCompute.Instances (GcpCompute v0.2.0)

Copy Markdown View Source

CRUD + lifecycle for Compute Engine instances.

All functions take a GcpCompute.Config and default to its :zone; override per call with zone: "..." in opts. Mutating calls return a GcpCompute.Operation; the *_and_wait helpers poll it to completion for you.

{:ok, instance} =
  GcpCompute.Instances.insert_and_wait(config,
    name: "worker-1",
    machine_type: "e2-micro",
    spot: true
  )

Summary

Functions

Delete an instance. Accepts :zone and :request_id (see insert/3).

Delete an instance and block until the operation is done.

Fetch a single instance by name.

Create an instance. instance is either a keyword spec (built and validated by GcpCompute.Instance.spec/1) or a raw Compute API body map.

Insert an instance and block until it exists, returning the live GcpCompute.Instance.

List instances in a zone (single page).

List one page of instances, surfacing the pagination token.

Start a stopped instance.

Stop a running instance.

Types

spec()

@type spec() :: keyword() | map()

Functions

delete(config, name, opts \\ [])

@spec delete(GcpCompute.Config.t(), String.t(), keyword()) ::
  {:ok, GcpCompute.Operation.t()} | {:error, GcpCompute.Error.t()}

Delete an instance. Accepts :zone and :request_id (see insert/3).

delete_and_wait(config, name, opts \\ [])

@spec delete_and_wait(GcpCompute.Config.t(), String.t(), keyword()) ::
  {:ok, GcpCompute.Operation.t()} | {:error, GcpCompute.Error.t()}

Delete an instance and block until the operation is done.

get(config, name, opts \\ [])

@spec get(GcpCompute.Config.t(), String.t(), keyword()) ::
  {:ok, GcpCompute.Instance.t()} | {:error, GcpCompute.Error.t()}

Fetch a single instance by name.

insert(config, instance, opts \\ [])

@spec insert(GcpCompute.Config.t(), spec(), keyword()) ::
  {:ok, GcpCompute.Operation.t()} | {:error, GcpCompute.Error.t()}

Create an instance. instance is either a keyword spec (built and validated by GcpCompute.Instance.spec/1) or a raw Compute API body map.

Options

  • :zone — override the config's default zone.
  • :request_id — idempotency token (requestId); safe to retry.

insert_and_wait(config, instance, opts \\ [])

@spec insert_and_wait(GcpCompute.Config.t(), spec(), keyword()) ::
  {:ok, GcpCompute.Instance.t()} | {:error, GcpCompute.Error.t()}

Insert an instance and block until it exists, returning the live GcpCompute.Instance.

Accepts every insert/3 option plus :timeout (ms) for the operation poll.

list(config, opts \\ [])

@spec list(
  GcpCompute.Config.t(),
  keyword()
) :: {:ok, [GcpCompute.Instance.t()]} | {:error, GcpCompute.Error.t()}

List instances in a zone (single page).

Returns just the items; callers that need to paginate should use list_page/2, which also surfaces the nextPageToken.

Options

  • :zone, :filter, :maxResults, :pageToken, :orderBy — passed through to the Compute API.

list_page(config, opts \\ [])

@spec list_page(
  GcpCompute.Config.t(),
  keyword()
) ::
  {:ok, %{items: [GcpCompute.Instance.t()], next_page_token: String.t() | nil}}
  | {:error, GcpCompute.Error.t()}

List one page of instances, surfacing the pagination token.

Same options as list/2. Returns {:ok, %{items: [Instance.t()], next_page_token: String.t() | nil}}; next_page_token is nil on the last (or only) page — pass it back as :pageToken to fetch the next page.

start(config, name, opts \\ [])

@spec start(GcpCompute.Config.t(), String.t(), keyword()) ::
  {:ok, GcpCompute.Operation.t()} | {:error, GcpCompute.Error.t()}

Start a stopped instance.

stop(config, name, opts \\ [])

@spec stop(GcpCompute.Config.t(), String.t(), keyword()) ::
  {:ok, GcpCompute.Operation.t()} | {:error, GcpCompute.Error.t()}

Stop a running instance.