Class: CFCM::Monkey::HardMonkey

Inherits:
Object
  • Object
show all
Defined in:
lib/cfcm/monkey.rb

Instance Method Summary collapse

Constructor Details

#initialize(iaas, config_file, input_file, probability, frequency, dry_run = false) ⇒ HardMonkey

Returns a new instance of HardMonkey.



63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/cfcm/monkey.rb', line 63

def initialize(iaas, config_file, input_file, probability, frequency, dry_run = false)
  
  @probability = probability
  @frequency = frequency
  @dry_run = dry_run
  
  # Parse the config file
  @config = YAML.load_file(config_file)
  
  # Parse the input file
  input_fd = File.open(input_file, "rb")
  @input = input_fd.read.split
  
  # Build the IaaS interface
  @iaas_interface = nil          
  case iaas.downcase
  when "vsphere"
    @iaas_interface = CFCM::IAAS::Vsphere.new(@config["host"], @config["user"], @config["password"], @config)
  else
    puts "Unknown IaaS -- #{iaas}"
  end
end

Instance Method Details

#show_helpObject



59
60
61
# File 'lib/cfcm/monkey.rb', line 59

def show_help
  puts "Description coming soon"
end

#startObject



86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# File 'lib/cfcm/monkey.rb', line 86

def start
  # Start the Eventmachine loop, similar to above and shut down VMs at random
  EventMachine.run do
    EventMachine.add_periodic_timer(@frequency) do
      # Determine if we should unleash the monkey
      if (Random.rand(100) + 1) <= @probability
        vm = @input.sample
        puts "Sending Power Off to #{vm}"
        if @dry_run
          puts "Power Off not sent -- runing in dry run mode"
        else
          @iaas_interface.power_off_vm(vm)
        end
      end
    end
  end
end