Class: GeneralClass

Inherits:
Object
  • Object
show all
Defined in:
lib/miq_utilities/general.rb

Overview

Wrapper class to interact with linux machines via ssh

Instance Method Summary collapse

Constructor Details

#initialize(name) ⇒ GeneralClass

Returns a new instance of GeneralClass.



13
14
15
# File 'lib/miq_utilities/general.rb', line 13

def initialize(name)
  @logger = LoggingClass.new(name)
end

Instance Method Details

#process_tags(category, category_description, single_value, tag, tag_description) ⇒ Object

process tags



26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/miq_utilities/general.rb', line 26

def process_tags(category, category_description, single_value, tag, tag_description)
  # Convert to lower case and replace all non-word characters with underscores
  category_name = category.to_s.downcase.gsub(/\W/, '_')
  tag_name = tag.to_s.downcase.gsub(/\W|:/, '_')
  @logger.log(level: 'info', message: "Converted category name:<#{category_name}> Converted tag name: <#{tag_name}>")
  # if the category exists else create it
  unless $evm.execute('category_exists?', category_name)
    @logger.log(level: 'info', message: "Category <#{category_name}> doesn't exist, creating category")
    $evm.execute('category_create', name: category_name, single_value: single_value, description: category_description.to_s)
  end
  # if the tag exists else create it
  @logger.log(level: 'info', message: "Adding new tag <#{tag_name}> description <#{tag_description}> in Category <#{category_name}>") unless $evm.execute('tag_exists?', category_name, tag_name)
  $evm.execute('tag_create', category_name, name: tag_name, description: tag_description.to_s) unless $evm.execute('tag_exists?', category_name, tag_name)
end

#retry_method(retry_time = 1.minute) ⇒ Object

basic retry logic



18
19
20
21
22
23
# File 'lib/miq_utilities/general.rb', line 18

def retry_method(retry_time = 1.minute)
  @logger.log(level: 'info', message: "Sleeping for #{retry_time} seconds")
  $evm.root['ae_result'] = 'retry'
  $evm.root['ae_retry_interval'] = retry_time
  exit(MIQ_OK)
end

#update_vm_custom_attributes(key, value, vm) ⇒ Object



41
42
43
44
# File 'lib/miq_utilities/general.rb', line 41

def update_vm_custom_attributes(key, value, vm)
  @logger.log(level: 'debug', message: "#{key} #{value}")
  vm.custom_set(key, value)
end