Class: Kitchen::Driver::VmpoolStores::VmpoolerStore

Inherits:
BaseStore
  • Object
show all
Defined in:
lib/kitchen/driver/vmpool_stores/vmpooler_store.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ VmpoolerStore

Returns a new instance of VmpoolerStore.

Parameters:

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

Options Hash (opts):

  • :host_url (String)

    The hostname to use in http requests.

  • :user (String) — default: nil

    A username for authentication. Optional only if token is valid.

  • :password (String) — default: nil

    A password for authentication. Optional only if token is valid.

  • :token (String) — default: nil

    A preloaded token to use in requests. Optional only if user and pass are valid.

Raises:


19
20
21
22
23
24
25
26
27
28
29
# File 'lib/kitchen/driver/vmpool_stores/vmpooler_store.rb', line 19

def initialize(opts = {})
  host_url = opts.fetch('host_url')
  user = opts.fetch('user', nil)
  pass = opts.fetch('pass', nil)
  token = opts.fetch('token', nil)
  @tags = opts.fetch('tags', { purpose: 'vmpooler-default' })
  @lifetime = opts.fetch('lifetime', nil)
  @vmpooler_url = URI.join(host_url, '/api/v1/').to_s
  raise Kitchen::Driver::InvalidUrl.new("Bad url: #{vmpooler_url}") unless valid_url?(URI.join(vmpooler_url, 'vm'))
  @token = valid_token?(token) ? token : create_token(user, pass)
end

Instance Attribute Details

#lifetimeObject (readonly)

Returns the value of attribute lifetime


10
11
12
# File 'lib/kitchen/driver/vmpool_stores/vmpooler_store.rb', line 10

def lifetime
  @lifetime
end

#tagsObject (readonly)

Returns the value of attribute tags


10
11
12
# File 'lib/kitchen/driver/vmpool_stores/vmpooler_store.rb', line 10

def tags
  @tags
end

#tokenObject (readonly)

Returns the value of attribute token


10
11
12
# File 'lib/kitchen/driver/vmpool_stores/vmpooler_store.rb', line 10

def token
  @token
end

#vmpooler_urlObject (readonly)

Returns the value of attribute vmpooler_url


10
11
12
# File 'lib/kitchen/driver/vmpool_stores/vmpooler_store.rb', line 10

def vmpooler_url
  @vmpooler_url
end

Instance Method Details

#cleanup(pool_member:, pool_name: nil, reuse_instances: false) {|pool_member, used_status| ... } ⇒ Object

Parameters:

  • pool_member (String)

    the pool member to destroy

Yields:

  • (pool_member, used_status)

38
39
40
41
42
# File 'lib/kitchen/driver/vmpool_stores/vmpooler_store.rb', line 38

def cleanup(pool_member:, pool_name: nil, reuse_instances: false)
  used_status = 'destroyed'
  destroy_pool_member(pool_member)
  yield(pool_member, used_status) if block_given?
end

#take_pool_member(pool_name) ⇒ String

Returns a pool member from the pool.

Parameters:

  • pool_name (String)

    the pool to take from

Returns:

  • (String)

    a pool member from the pool


33
34
35
# File 'lib/kitchen/driver/vmpool_stores/vmpooler_store.rb', line 33

def take_pool_member(pool_name)
  fetch_pool_member(pool_name)
end