Module: Hyperb::Funcs

Includes:
Utils
Included in:
API
Defined in:
lib/hyperb/funcs/funcs.rb

Overview

funcs api wrapper

Instance Method Summary collapse

Methods included from Utils

#camelize, #check_arguments, #downcase_symbolize, #prepare_json, #underscore

Instance Method Details

#call_func(params = {}) ⇒ Object

call a func

Parameters:

  • params (Hash) (defaults to: {})

    A customizable set of params.

  • params (defaults to: {})

    :name [String] the function name.

  • params (defaults to: {})

    :uuid [String] function uuid.

  • params (defaults to: {})

    :sync [Boolean] block until function reply

Raises:

See Also:



122
123
124
125
126
127
# File 'lib/hyperb/funcs/funcs.rb', line 122

def call_func(params = {})
  raise ArgumentError, 'Invalid arguments.' unless check_arguments(params, 'name', 'uuid')
  path = "call/#{params[:name]}/#{params[:uuid]}"
  path.concat('/sync') if params.key?(:sync) && params[:sync]
  Hyperb::FuncCallRequest.new(self, path, {}, 'post').perform
end

#create_func(params = {}) ⇒ Object

create a func

to run the function (e.g. s1,s2, s3, s4, m1, m2, m3, l1, l2, l3)

object in the form of: “ExposedPorts”: { “<port>/<tcp|udp>: {}” }

Parameters:

  • params (Hash) (defaults to: {})

    A customizable set of params.

  • params (defaults to: {})

    :name [String] the function name.

  • params (defaults to: {})

    :container_size [String] the size of containers

  • params (defaults to: {})

    :timeout [String] default is 300 seconds, maximum is 86400 seconds.

  • params (defaults to: {})

    :uuid [String] The uuid of function.

  • params (defaults to: {})

    :config [Hash] func configurations

  • params (defaults to: {})

    config :tty [Boolean] attach streams to a tty

  • params (defaults to: {})

    config :exposed_ports [Hash] an object mapping ports to an empty

  • params (defaults to: {})

    config :env [Array] list of env vars, “VAR=VALUE”

  • params (defaults to: {})

    config :cmd [Array|String] list of env vars, “VAR=VALUE”

  • params (defaults to: {})

    config :image [String] image to run

  • params (defaults to: {})

    config :entrypoint [String] entrypoint

  • params (defaults to: {})

    config :working_dir [String] working directory

  • params (defaults to: {})

    config :labels [Hash] labels

  • params (defaults to: {})

    :host_config [Hash] func host configurations

  • params (defaults to: {})

    host_config :links [Array] list of links

  • params (defaults to: {})

    host_config :port_bindings [Hash]

  • params (defaults to: {})

    host_config :publish_all_ports [Boolean]

  • params (defaults to: {})

    host_config :volumes_from [Array]

  • params (defaults to: {})

    host_config :network_mode [String]

Raises:

See Also:



80
81
82
83
84
85
86
87
88
# File 'lib/hyperb/funcs/funcs.rb', line 80

def create_func(params = {})
  raise ArgumentError, 'Invalid arguments.' unless check_arguments(params, 'name')
  path = '/funcs/create'

  body = {}
  body.merge!(prepare_json(params))

  Hyperb::Request.new(self, path, {}, 'post', body).perform
end

#funcsHyperb::Func

list funcs

Returns:

Raises:

See Also:



17
18
19
20
21
22
# File 'lib/hyperb/funcs/funcs.rb', line 17

def funcs
  path = '/funcs'
  query = {}
  response = JSON.parse(Hyperb::Request.new(self, path, query, 'get').perform)
  response.map { |func| Hyperb::Func.new(func) }
end

#remove_func(params = {}) ⇒ Object

remove a func

Parameters:

  • params (Hash) (defaults to: {})

    A customizable set of params.

  • params (defaults to: {})

    :name [String] the function name.

Raises:

See Also:



103
104
105
106
107
# File 'lib/hyperb/funcs/funcs.rb', line 103

def remove_func(params = {})
  raise ArgumentError, 'Invalid arguments.' unless check_arguments(params, 'name')
  path = '/funcs/' + params[:name]
  Hyperb::Request.new(self, path, {}, 'delete').perform
end

#status_func(params = {}) ⇒ Hash

func status

Parameters:

  • params (Hash) (defaults to: {})

    A customizable set of params.

  • params (defaults to: {})

    :name [String] the function name.

  • params (defaults to: {})

    :uuid [String] the function uuid.

Returns:

  • (Hash)

    Array of Funcs.

Raises:

See Also:



37
38
39
40
41
# File 'lib/hyperb/funcs/funcs.rb', line 37

def status_func(params = {})
  raise ArgumentError, 'Invalid arguments.' unless check_arguments(params, 'name', 'uuid')
  path = "status/#{params[:name]}/#{params[:uuid]}"
  JSON.parse(Hyperb::FuncCallRequest.new(self, path, {}, 'get').perform)
end