cfcm 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,18 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ coverage
6
+ InstalledFiles
7
+ lib/bundler/man
8
+ pkg
9
+ rdoc
10
+ spec/reports
11
+ test/tmp
12
+ test/version_tmp
13
+ tmp
14
+
15
+ # YARD artifacts
16
+ .yardoc
17
+ _yardoc
18
+ doc/
data/Gemfile ADDED
@@ -0,0 +1 @@
1
+ gem 'vmc', "0.4.0.beta.36"
data/Gemfile.lock ADDED
@@ -0,0 +1,57 @@
1
+ GEM
2
+ specs:
3
+ addressable (2.2.6)
4
+ cfoundry (0.3.23)
5
+ multi_json (~> 1.3.6)
6
+ rest-client (~> 1.6.1)
7
+ rubyzip (~> 0.9.5)
8
+ crack (0.3.1)
9
+ interact (0.4.7)
10
+ json_pure (1.6.7)
11
+ manifests-vmc-plugin (0.4.3)
12
+ cfoundry (~> 0.3.9)
13
+ mime-types (1.19)
14
+ mothership (0.0.14)
15
+ multi_json (1.3.6)
16
+ rake (0.9.2.2)
17
+ rb-readline (0.4.2)
18
+ rest-client (1.6.7)
19
+ mime-types (>= 1.16)
20
+ rspec (1.3.2)
21
+ rubyzip (0.9.9)
22
+ simplecov (0.6.4)
23
+ multi_json (~> 1.0)
24
+ simplecov-html (~> 0.5.3)
25
+ simplecov-html (0.5.3)
26
+ terminal-table (1.4.5)
27
+ uuidtools (2.1.3)
28
+ vmc (0.4.0.beta.36)
29
+ addressable (~> 2.2.6)
30
+ cfoundry (~> 0.3.23)
31
+ interact (~> 0.4.0)
32
+ interact (~> 0.4.7)
33
+ json_pure (>= 1.5.1, < 1.7.0)
34
+ json_pure (~> 1.6.5)
35
+ manifests-vmc-plugin (~> 0.4.3)
36
+ mothership (~> 0.0.14)
37
+ multi_json (~> 1.3.6)
38
+ rake
39
+ rake
40
+ rb-readline (~> 0.4.2)
41
+ rest-client (>= 1.6.1, < 1.7.0)
42
+ rspec
43
+ rspec (~> 1.3.0)
44
+ rubyzip (~> 0.9.4)
45
+ simplecov
46
+ terminal-table (~> 1.4.2)
47
+ uuidtools (~> 2.1.0)
48
+ webmock (~> 1.5.0)
49
+ webmock (1.5.0)
50
+ addressable (>= 2.2.2)
51
+ crack (>= 0.1.7)
52
+
53
+ PLATFORMS
54
+ ruby
55
+
56
+ DEPENDENCIES
57
+ vmc (= 0.4.0.beta.36)
data/README.md ADDED
@@ -0,0 +1,4 @@
1
+ cloudfoundry-chaos-monkey
2
+ =========================
3
+
4
+ Chaos Monkey style service for Cloud Foundry
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
data/bin/cfcm ADDED
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+ $:.push File.dirname(__FILE__) + '/../lib'
3
+
4
+ require "rubygems"
5
+ require "cfcm/cli"
6
+
7
+ CFCM::CLI::Command.start
data/cfcm.gemspec ADDED
@@ -0,0 +1,20 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/cfcm/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["Brian McClain"]
6
+ gem.email = ["brianmmcclain@gmail.com"]
7
+ gem.description = %q{Cloud Foundry Chaos Monkey}
8
+ gem.summary = gem.summary
9
+ gem.homepage = "https://github.com/BrianMMcClain/cloudfoundry-chaos-monkey"
10
+
11
+ gem.files = `git ls-files`.split($\)
12
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
13
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
14
+ gem.name = "cfcm"
15
+ gem.require_paths = ["lib"]
16
+ gem.version = CFCM::VERSION
17
+
18
+ gem.add_dependency "thor"
19
+ gem.add_dependency "vmc"
20
+ end
data/lib/cfcm/cf.rb ADDED
@@ -0,0 +1,62 @@
1
+ require 'vmc'
2
+
3
+ module CFCM
4
+ module CF
5
+ class Session
6
+ def initialize(target, username, password)
7
+ begin
8
+ @client = VMC::Client.new(target)
9
+ @client.login(username, password)
10
+ rescue
11
+ puts "Could not login!"
12
+ #TODO: Handle error
13
+ return
14
+ end
15
+ end
16
+
17
+ def get_app(app_name)
18
+ if !@client
19
+ puts "Must be loged in"
20
+ #TODO: Handle error
21
+ return
22
+ end
23
+
24
+ @client.apps.each do |app|
25
+ if app[:name] == app_name
26
+ return app
27
+ end
28
+ end
29
+
30
+ puts "Application Not Found"
31
+ #TODO: Handle error
32
+ return nil
33
+ end
34
+
35
+ def remaining_memory
36
+ if !@client
37
+ puts "Must be loged in"
38
+ #TODO: Handle error
39
+ return
40
+ end
41
+
42
+ info = @client.info
43
+ return info[:limits][:memory] - info[:usage][:memory]
44
+ end
45
+
46
+ def max_instance_growth(app_name)
47
+ if !@client
48
+ puts "Must be loged in"
49
+ #TODO: Handle error
50
+ return
51
+ end
52
+
53
+ remaining_memory = self.remaining_memory
54
+ app = self.get_app(app_name)
55
+ app_memory = app[:resources][:memory]
56
+
57
+ max_new_instances = (remaining_memory / app_memory).floor
58
+ return max_new_instances
59
+ end
60
+ end
61
+ end
62
+ end
data/lib/cfcm/cli.rb ADDED
@@ -0,0 +1,28 @@
1
+ require "thor"
2
+
3
+ module CFCM
4
+ module CLI
5
+ class Command < Thor
6
+
7
+ desc "soft USERNAME PASSWORD APP", "Removes/Adds instances via VMC APIs"
8
+ method_option :target, :alias => ["--target"], :type => :string, :desc => "Cloud Foundry API Target URL"
9
+ method_option :min, :alias => ["--min"], :type => :numeric, :desc => "Minimum number of instances"
10
+ method_option :max, :alias => ["--max"], :type => :numeric, :desc => "Maximum number of instances"
11
+ def soft(username, password, app, target = "http://api.cloudfoundry.com", min = 1, max = 5)
12
+
13
+ if options[:target]
14
+ target = options[:target]
15
+ end
16
+ if options[:min]
17
+ min = options[:min]
18
+ end
19
+ if options[:max]
20
+ min = options[:max]
21
+ end
22
+
23
+ require 'cfcm/cf'
24
+ session = CFCM::CF::Session.new(target, username, password)
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,3 @@
1
+ module CFCM
2
+ VERSION = "0.0.1"
3
+ end
metadata ADDED
@@ -0,0 +1,89 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: cfcm
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Brian McClain
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-08-31 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: thor
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: vmc
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ description: Cloud Foundry Chaos Monkey
47
+ email:
48
+ - brianmmcclain@gmail.com
49
+ executables:
50
+ - cfcm
51
+ extensions: []
52
+ extra_rdoc_files: []
53
+ files:
54
+ - .gitignore
55
+ - Gemfile
56
+ - Gemfile.lock
57
+ - README.md
58
+ - Rakefile
59
+ - bin/cfcm
60
+ - cfcm.gemspec
61
+ - lib/cfcm/cf.rb
62
+ - lib/cfcm/cli.rb
63
+ - lib/cfcm/version.rb
64
+ homepage: https://github.com/BrianMMcClain/cloudfoundry-chaos-monkey
65
+ licenses: []
66
+ post_install_message:
67
+ rdoc_options: []
68
+ require_paths:
69
+ - lib
70
+ required_ruby_version: !ruby/object:Gem::Requirement
71
+ none: false
72
+ requirements:
73
+ - - ! '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ required_rubygems_version: !ruby/object:Gem::Requirement
77
+ none: false
78
+ requirements:
79
+ - - ! '>='
80
+ - !ruby/object:Gem::Version
81
+ version: '0'
82
+ requirements: []
83
+ rubyforge_project:
84
+ rubygems_version: 1.8.24
85
+ signing_key:
86
+ specification_version: 3
87
+ summary: ''
88
+ test_files: []
89
+ has_rdoc: