Class: CFCM::CLI::Command

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

Instance Method Summary collapse

Instance Method Details

#hard(probability = 10, frequency = 10) ⇒ Object



68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/cfcm/cli.rb', line 68

def hard(probability = 10, frequency = 10)
  if (!options[:iaas] || !options[:input] || !options[:config])
    CFCM::Monkey::HardMonkey.new.show_help
  else
    if options[:probability]
      if options[:probability] < 1 || options[:probability] > 100
        puts "Probability must be between 1 and 100"
        return
      else
        probability = options[:probability]
      end
    end
    if options[:frequency]
      frequency = options[:frequency]
    end
    dry_run = false
    if (options[:dry_run])
      dry_run = true
    end
              
    puts "Awakening the monkey on your #{options[:iaas]} infrastructure with a #{probability}% chance of chaos every #{frequency} second#{frequency > 1? "s" : ""}"
    monkey = CFCM::Monkey::HardMonkey.new(options[:iaas], options[:config], options[:input], probability, frequency, dry_run)
    monkey.start
  end
end

#soft(username, password, app, target = "http://api.cloudfoundry.com", min = 1, max = 5, probability = 10, frequency = 10) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/cfcm/cli.rb', line 20

def soft(username, password, app, target = "http://api.cloudfoundry.com", min = 1, max = 5, probability = 10, frequency = 10)
  
  if options[:target]
    target = options[:target]
  end
  if options[:min]
    min = options[:min]
  end
  if options[:max]
    max = options[:max]
  end
  if options[:probability]
    if options[:probability] < 1 || options[:probability] > 100
      puts "Probability must be between 1 and 100"
      return
    else
      probability = options[:probability]
    end
  end
  if options[:frequency]
    frequency = options[:frequency]
  end
  
  require 'cfcm/cf'
  session = CFCM::CF::Session.new(target, username, password)
  if session.is_logged_in 
    if !session.app_exists(app)
      puts "Application not found"
      return
    end
  else
    puts "Could not log in"
    return
  end
  
  puts "Awakening the monkey on #{app} with a #{probability}% chance of chaos every #{frequency} second#{frequency > 1? "s" : ""}"
  monkey = CFCM::Monkey::SoftMonkey.new(session, app, probability, min, max, frequency)
  monkey.start
end

#versionObject



9
10
11
12
# File 'lib/cfcm/cli.rb', line 9

def version
  require 'cfcm/version'
  puts CFCM::VERSION
end