cfcm 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +1 -0
- data/Gemfile +2 -1
- data/Gemfile.lock +8 -0
- data/README.md +14 -1
- data/lib/cfcm/cli.rb +33 -5
- data/lib/cfcm/iaas/iaas.rb +20 -0
- data/lib/cfcm/iaas/vsphere.rb +24 -0
- data/lib/cfcm/monkey.rb +47 -1
- data/lib/cfcm/version.rb +1 -1
- metadata +4 -2
data/.gitignore
CHANGED
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
GEM
|
2
2
|
specs:
|
3
3
|
addressable (2.2.6)
|
4
|
+
builder (3.0.0)
|
4
5
|
cfoundry (0.3.23)
|
5
6
|
multi_json (~> 1.3.6)
|
6
7
|
rest-client (~> 1.6.1)
|
@@ -14,8 +15,13 @@ GEM
|
|
14
15
|
mime-types (1.19)
|
15
16
|
mothership (0.0.14)
|
16
17
|
multi_json (1.3.6)
|
18
|
+
nokogiri (1.5.5)
|
17
19
|
rake (0.9.2.2)
|
18
20
|
rb-readline (0.4.2)
|
21
|
+
rbvmomi (1.5.1)
|
22
|
+
builder
|
23
|
+
nokogiri (>= 1.4.1)
|
24
|
+
trollop
|
19
25
|
rest-client (1.6.7)
|
20
26
|
mime-types (>= 1.16)
|
21
27
|
rspec (1.3.2)
|
@@ -25,6 +31,7 @@ GEM
|
|
25
31
|
simplecov-html (~> 0.5.3)
|
26
32
|
simplecov-html (0.5.3)
|
27
33
|
terminal-table (1.4.5)
|
34
|
+
trollop (2.0)
|
28
35
|
uuidtools (2.1.3)
|
29
36
|
vmc (0.4.0.beta.36)
|
30
37
|
addressable (~> 2.2.6)
|
@@ -56,4 +63,5 @@ PLATFORMS
|
|
56
63
|
|
57
64
|
DEPENDENCIES
|
58
65
|
eventmachine (= 0.12.10)
|
66
|
+
rbvmomi (= 1.5.1)
|
59
67
|
vmc (= 0.4.0.beta.36)
|
data/README.md
CHANGED
@@ -1,4 +1,17 @@
|
|
1
1
|
cloudfoundry-chaos-monkey
|
2
2
|
=========================
|
3
3
|
|
4
|
-
Chaos Monkey style service for Cloud Foundry
|
4
|
+
Chaos Monkey style service for Cloud Foundry
|
5
|
+
|
6
|
+
Using Cloud Foundry Chaos Monkey
|
7
|
+
--------------------------------
|
8
|
+
|
9
|
+
First off, grab the Cloud Foundry Chaos Monkey gem
|
10
|
+
|
11
|
+
`gem install cfcm`
|
12
|
+
|
13
|
+
and then unleash the monkey! In this example, we'll use CFCM on an application named `myapp`, keeping between 2 and 5 instances. We want CFCM to have a 30% chance of adding or removing an instance every 10 seconds. Adding and removeing instances is known as "soft mode", that is, this is equvilant to doing "vmc instane [app] -1". There is a "hard mode" planned that is a bit more chaotic.
|
14
|
+
|
15
|
+
`cfcm soft [email] [password] myapp --min 2 --max 5 -p 30 -f 10`
|
16
|
+
|
17
|
+
It's as easy as that!
|
data/lib/cfcm/cli.rb
CHANGED
@@ -6,11 +6,11 @@ module CFCM
|
|
6
6
|
class Command < Thor
|
7
7
|
|
8
8
|
desc "soft USERNAME PASSWORD APP", "Removes/Adds instances via VMC APIs"
|
9
|
-
method_option :target, :aliases => ["--target", "-t"], :type => :string, :desc => "Cloud Foundry API Target URL"
|
10
|
-
method_option :min, :alias => ["--min"], :type => :numeric, :desc => "Minimum number of instances"
|
11
|
-
method_option :max, :alias => ["--max"], :type => :numeric, :desc => "Maximum number of instances"
|
12
|
-
method_option :probability, :aliases => ["--probability", "-p"], :type => :numeric, :desc => "[1-100] Probablity for the Chaos Monkey to add/remove an instance"
|
13
|
-
method_option :frequency, :aliases => ["--frequency", "-f"], :type => :numeric, :desc => "Number of
|
9
|
+
method_option :target, :aliases => ["--target", "-t"], :type => :string, :desc => "Cloud Foundry API Target URL (Default: http://api.cloudfoundry.com)"
|
10
|
+
method_option :min, :alias => ["--min"], :type => :numeric, :desc => "Minimum number of instances (Default: 1)"
|
11
|
+
method_option :max, :alias => ["--max"], :type => :numeric, :desc => "Maximum number of instances (Default: 5)"
|
12
|
+
method_option :probability, :aliases => ["--probability", "-p"], :type => :numeric, :desc => "[1-100] Probablity for the Chaos Monkey to add/remove an instance (Default: 10)"
|
13
|
+
method_option :frequency, :aliases => ["--frequency", "-f"], :type => :numeric, :desc => "Number of seconds between attempts to add/remove an instance (Default: 10)"
|
14
14
|
def soft(username, password, app, target = "http://api.cloudfoundry.com", min = 1, max = 5, probability = 10, frequency = 10)
|
15
15
|
|
16
16
|
if options[:target]
|
@@ -50,6 +50,34 @@ module CFCM
|
|
50
50
|
monkey = CFCM::Monkey::SoftMonkey.new(session, app, probability, min, max, frequency)
|
51
51
|
monkey.start
|
52
52
|
end
|
53
|
+
|
54
|
+
|
55
|
+
desc "hard", "Removes/Adds DEAs through IaaS commands"
|
56
|
+
method_option :iaas, :alias => ["--iaas"], :type => :string, :desc => "IaaS to communicate with [VSPHERE]"
|
57
|
+
method_option :input, :aliases => ["--input", "-i"], :type => :string, :desc => "Path to file listing valid DEAs (See Documentation)"
|
58
|
+
method_option :config, :aliases => ["--config", "-c"], :type => :string, :desc => "Path to IaaS config YML file (See Documentation)"
|
59
|
+
method_option :probability, :aliases => ["--probability", "-p"], :type => :numeric, :desc => "[1-100] Probablity for the Chaos Monkey to add/remove an instance (Default: 10)"
|
60
|
+
method_option :frequency, :aliases => ["--frequency", "-f"], :type => :numeric, :desc => "Number of seconds between attempts to add/remove an instance (Default: 10)"
|
61
|
+
def hard(probability = 10, frequency = 10)
|
62
|
+
if (!options[:iaas] || !options[:input] || !options[:config])
|
63
|
+
CFCM::Monkey::HardMonkey.new.show_help
|
64
|
+
else
|
65
|
+
if options[:probability]
|
66
|
+
if options[:probability] < 1 || options[:probability] > 100
|
67
|
+
puts "Probability must be between 1 and 100"
|
68
|
+
return
|
69
|
+
else
|
70
|
+
probability = options[:probability]
|
71
|
+
end
|
72
|
+
end
|
73
|
+
if options[:frequency]
|
74
|
+
frequency = options[:frequency]
|
75
|
+
end
|
76
|
+
|
77
|
+
monkey = CFCM::Monkey::HardMonkey.new(options[:iaas], options[:config], options[:input], probability, frequency)
|
78
|
+
monkey.start
|
79
|
+
end
|
80
|
+
end
|
53
81
|
end
|
54
82
|
end
|
55
83
|
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'rbvmomi'
|
2
|
+
|
3
|
+
module CFCM
|
4
|
+
module IAAS
|
5
|
+
class IaaS
|
6
|
+
|
7
|
+
def initalize(host, user, password, config)
|
8
|
+
@host = host
|
9
|
+
@user = user
|
10
|
+
@password = password
|
11
|
+
@config = config
|
12
|
+
end
|
13
|
+
|
14
|
+
def power_off_vm(vm)
|
15
|
+
puts "Not Implemented"
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'rbvmomi'
|
2
|
+
|
3
|
+
module CFCM
|
4
|
+
module IAAS
|
5
|
+
class Vsphere
|
6
|
+
|
7
|
+
def initialize(host, user, password, config)
|
8
|
+
@host = host
|
9
|
+
@user = user
|
10
|
+
@password = password
|
11
|
+
@config = config
|
12
|
+
end
|
13
|
+
|
14
|
+
def power_off_vm(vm_name)
|
15
|
+
opts = {:host=>@host, :user=>@user, :password=>@password, :insecure=>true}
|
16
|
+
vim = RbVmomi::VIM.connect opts
|
17
|
+
dc = vim.serviceInstance.content.rootFolder.traverse(config["datacenter"], RbVmomi::VIM::Datacenter) or abort "datacenter not found"
|
18
|
+
vm = dc.vmFolder.traverse(vm_name, VIM::VirtualMachine) or abort "VM not found"
|
19
|
+
vm.PowerOffVM_Task.wait_for_completion
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
data/lib/cfcm/monkey.rb
CHANGED
@@ -1,4 +1,7 @@
|
|
1
|
-
require
|
1
|
+
require 'eventmachine'
|
2
|
+
require 'yaml'
|
3
|
+
require 'cfcm/iaas/iaas'
|
4
|
+
require 'cfcm/iaas/vsphere'
|
2
5
|
|
3
6
|
module CFCM
|
4
7
|
module Monkey
|
@@ -50,5 +53,48 @@ module CFCM
|
|
50
53
|
end
|
51
54
|
end
|
52
55
|
end
|
56
|
+
|
57
|
+
|
58
|
+
class HardMonkey
|
59
|
+
def show_help
|
60
|
+
puts "Description coming soon"
|
61
|
+
end
|
62
|
+
|
63
|
+
def initialize(iaas, config_file, input_file, probability, frequency)
|
64
|
+
|
65
|
+
@probability = probability
|
66
|
+
@frequency = frequency
|
67
|
+
|
68
|
+
# Parse the config file
|
69
|
+
@config = YAML.load_file(config_file)
|
70
|
+
|
71
|
+
# Parse the input file
|
72
|
+
input_fd = File.open(input_file, "rb")
|
73
|
+
@input = input_fd.read.split
|
74
|
+
|
75
|
+
# Build the IaaS interface
|
76
|
+
@iaas_interface = nil
|
77
|
+
case iaas.downcase
|
78
|
+
when "vsphere"
|
79
|
+
@iaas_interface = CFCM::IAAS::Vsphere.new(@config["host"], @config["user"], @config["password"], @config)
|
80
|
+
else
|
81
|
+
puts "Unknown IaaS -- #{iaas}"
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
def start
|
86
|
+
# Start the Eventmachine loop, similar to above and shut down VMs at random
|
87
|
+
EventMachine.run do
|
88
|
+
EventMachine.add_periodic_timer(@frequency) do
|
89
|
+
# Determine if we should unleash the monkey
|
90
|
+
if (Random.rand(100) + 1) <= @probability
|
91
|
+
vm = @input.sample
|
92
|
+
puts "Sending Power Off to #{vm}"
|
93
|
+
@iaas_interface.power_off_vm(vm)
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
53
99
|
end
|
54
100
|
end
|
data/lib/cfcm/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cfcm
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-09-05 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: thor
|
@@ -60,6 +60,8 @@ files:
|
|
60
60
|
- cfcm.gemspec
|
61
61
|
- lib/cfcm/cf.rb
|
62
62
|
- lib/cfcm/cli.rb
|
63
|
+
- lib/cfcm/iaas/iaas.rb
|
64
|
+
- lib/cfcm/iaas/vsphere.rb
|
63
65
|
- lib/cfcm/monkey.rb
|
64
66
|
- lib/cfcm/version.rb
|
65
67
|
homepage: https://github.com/BrianMMcClain/cloudfoundry-chaos-monkey
|