class Kitchen::Driver::VmpoolStores::FileBaseStore

Attributes

pool_data[R]
pool_file[R]

Public Instance Methods

cleanup(pool_member:, pool_name:, reuse_instances:) { |pool_member, used_status| ... } click to toggle source

@param pool_member [String] a VM instance @param pool_name [String] a VM pool @param reuse_instances [Boolean] whether or not to mark used VM instances as unused

# 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
create() click to toggle source
# File lib/kitchen/driver/vmpool_stores/file_base_store.rb, line 47
def create
  write_content(base_content)
  read
end
read() click to toggle source
# File lib/kitchen/driver/vmpool_stores/file_base_store.rb, line 52
def read
  read_content
end
reread() click to toggle source
# File lib/kitchen/driver/vmpool_stores/file_base_store.rb, line 56
def reread
  pool_data(true)
end
save() click to toggle source
# File lib/kitchen/driver/vmpool_stores/file_base_store.rb, line 60
def save
  write_content
  read
end
take_pool_member(pool_name) click to toggle source

@return [String] - a random host from the list of systems mark them used so nobody else can use it

# 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) click to toggle source
# File lib/kitchen/driver/vmpool_stores/file_base_store.rb, line 42
def update(content = nil)
  write_content(content)
  read
end

Private Instance Methods

add_to_garbage(pool_member, pool_name) click to toggle source

@param pool_member [String] @return Array - list of instances in the garbage

# File lib/kitchen/driver/vmpool_stores/file_base_store.rb, line 69
def add_to_garbage(pool_member, pool_name)
  return if garbage_hosts(pool_name).include?(pool_member)
  garbage_hosts(pool_name) << pool_member
  save
  garbage_hosts(pool_name)
end
garbage_hosts(pool_name) click to toggle source
# File lib/kitchen/driver/vmpool_stores/file_base_store.rb, line 117
def garbage_hosts(pool_name)
  pool(pool_name)['garbage_collection'] ||= []
end
mark_unused(name, pool_name) click to toggle source

@param name [String] - the hostname to mark not used @return Array - list of unused instances

# File lib/kitchen/driver/vmpool_stores/file_base_store.rb, line 89
def mark_unused(name, pool_name)
  used_hosts(pool_name).delete(name)
  pool_hosts(pool_name) << name unless pool_hosts(pool_name).include?(name)
  save
  pool_hosts(pool_name)
end
mark_used(name, pool_name) click to toggle source

@param name [String] - the hostname to mark used @return Array - list of used instances

# File lib/kitchen/driver/vmpool_stores/file_base_store.rb, line 78
def mark_used(name, pool_name)
  # ideally the member should not already be in this array
  # but just in case we will protect against that
  pool_hosts(pool_name).delete(name)
  used_hosts(pool_name) << name unless used_hosts(pool_name).include?(name)
  save
  used_hosts(pool_name)
end
pool(name) click to toggle source

@return [Hash] - a pool hash by the given pool_name from the config

# File lib/kitchen/driver/vmpool_stores/file_base_store.rb, line 102
def pool(name)
  raise ArgumentError.new("Pool #{name} does not exist") unless pool_exists?(name)
  pool_data[name]
end
pool_exists?(name) click to toggle source

@return [Boolean] - true if the pool exists

# File lib/kitchen/driver/vmpool_stores/file_base_store.rb, line 108
def pool_exists?(name)
  pool_names.include?(name)
end
pool_hosts(pool_name) click to toggle source

@return Array - a list of host names in the pool

# File lib/kitchen/driver/vmpool_stores/file_base_store.rb, line 113
def pool_hosts(pool_name)
  pool(pool_name)['pool_instances'] ||= []
end
pool_names() click to toggle source

@return Array - a list of pool names

# File lib/kitchen/driver/vmpool_stores/file_base_store.rb, line 97
def pool_names
  pool_data.keys
end
read_content() click to toggle source
# File lib/kitchen/driver/vmpool_stores/file_base_store.rb, line 126
def read_content
  raise NotImplementedError
end
used_hosts(pool_name) click to toggle source

@return Array - a list of used host names in the pool

# File lib/kitchen/driver/vmpool_stores/file_base_store.rb, line 122
def used_hosts(pool_name)
  pool(pool_name)['used_instances'] ||= []
end
write_content(content = pool_data) click to toggle source
# File lib/kitchen/driver/vmpool_stores/file_base_store.rb, line 130
def write_content(content = pool_data)
  raise NotImplementedError
end