Class: Kitchen::Driver::VmpoolStores::FileBaseStore

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

Direct Known Subclasses

FileStore, GitlabBaseStore

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from BaseStore

#initialize

Constructor Details

This class inherits a constructor from Kitchen::Driver::VmpoolStores::BaseStore

Instance Attribute Details

#pool_data(refresh = false) ⇒ Object (readonly)

Returns the value of attribute pool_data


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

def pool_data
  @pool_data
end

#pool_fileObject (readonly)

Returns the value of attribute pool_file


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

def pool_file
  @pool_file
end

Instance Method Details

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

Parameters:

  • pool_member (String)

    a VM instance

  • pool_name (String)

    a VM pool

  • reuse_instances (Boolean)

    whether or not to mark used VM instances as unused

Yields:

  • (pool_member, used_status)

25
26
27
28
29
30
31
32
33
34
35
# File 'lib/kitchen/driver/vmpool_stores/file_base_store.rb', line 25

def cleanup(pool_member:, pool_name:, reuse_instances:)
  used_status = 'garbage'
  if reuse_instances
    mark_unused(pool_member, pool_name)
    used_status = 'unused'
  else
    used_hosts(pool_name).delete(pool_member)
    add_to_garbage(pool_member, pool_name)
  end
  yield(pool_member, used_status) if block_given?
end

#createObject


47
48
49
50
# File 'lib/kitchen/driver/vmpool_stores/file_base_store.rb', line 47

def create
  write_content(base_content)
  read
end

#readObject


52
53
54
# File 'lib/kitchen/driver/vmpool_stores/file_base_store.rb', line 52

def read
  read_content
end

#rereadObject


56
57
58
# File 'lib/kitchen/driver/vmpool_stores/file_base_store.rb', line 56

def reread
  pool_data(true)
end

#saveObject


60
61
62
63
# File 'lib/kitchen/driver/vmpool_stores/file_base_store.rb', line 60

def save
  write_content
  read
end

#take_pool_member(pool_name) ⇒ String

mark them used so nobody else can use it

Returns:

  • (String)
    • a random host from the list of systems

Raises:


15
16
17
18
19
20
# File 'lib/kitchen/driver/vmpool_stores/file_base_store.rb', line 15

def take_pool_member(pool_name)
  member = pool_hosts(pool_name).sample
  raise Kitchen::Driver::PoolMemberNotFound.new("No pool members exist for #{pool_name}, please create some pool members") unless member
  mark_used(member, pool_name)
  member
end

#update(content = nil) ⇒ Object


42
43
44
45
# File 'lib/kitchen/driver/vmpool_stores/file_base_store.rb', line 42

def update(content = nil)
  write_content(content)
  read
end