mccloud 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +5 -0
- data/.rvmrc +4 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +74 -0
- data/README.md +123 -0
- data/Rakefile +5 -0
- data/bin/mccloud +116 -0
- data/lib/mccloud.rb +2 -0
- data/lib/mccloud/command/boot.rb +12 -0
- data/lib/mccloud/command/bootstrap.rb +31 -0
- data/lib/mccloud/command/command.rb +21 -0
- data/lib/mccloud/command/destroy.rb +19 -0
- data/lib/mccloud/command/halt.rb +19 -0
- data/lib/mccloud/command/init.rb +7 -0
- data/lib/mccloud/command/multi.rb +53 -0
- data/lib/mccloud/command/provision.rb +28 -0
- data/lib/mccloud/command/reload.rb +11 -0
- data/lib/mccloud/command/server.rb +30 -0
- data/lib/mccloud/command/ssh.rb +46 -0
- data/lib/mccloud/command/status.rb +31 -0
- data/lib/mccloud/command/suspend.rb +15 -0
- data/lib/mccloud/command/up.rb +65 -0
- data/lib/mccloud/config.rb +47 -0
- data/lib/mccloud/configurator/lb.rb +26 -0
- data/lib/mccloud/configurator/mccloud.rb +13 -0
- data/lib/mccloud/configurator/vm.rb +37 -0
- data/lib/mccloud/generators.rb +28 -0
- data/lib/mccloud/provisioner/chef_solo.rb +149 -0
- data/lib/mccloud/provisioner/puppet.rb +39 -0
- data/lib/mccloud/provisioner/vagrant/base.rb +63 -0
- data/lib/mccloud/provisioner/vagrant/chef.rb +130 -0
- data/lib/mccloud/provisioner/vagrant/chef_server.rb +103 -0
- data/lib/mccloud/provisioner/vagrant/chef_solo.rb +142 -0
- data/lib/mccloud/provisioner/vagrant/puppet.rb +137 -0
- data/lib/mccloud/provisioner/vagrant/puppet_server.rb +55 -0
- data/lib/mccloud/provisioner/vagrant/shell.rb +52 -0
- data/lib/mccloud/session.rb +199 -0
- data/lib/mccloud/templates/Mccloudfilet +44 -0
- data/lib/mccloud/type/forwarding.rb +11 -0
- data/lib/mccloud/type/lb.rb +34 -0
- data/lib/mccloud/type/vm.rb +46 -0
- data/lib/mccloud/util/iterator.rb +21 -0
- data/lib/mccloud/util/platform.rb +29 -0
- data/lib/mccloud/util/rsync.rb +21 -0
- data/lib/mccloud/util/ssh.rb +167 -0
- data/lib/mccloud/version.rb +3 -0
- data/mccloud.gemspec +37 -0
- data/ruby-bootstrap.sh +11 -0
- data/ruby-bootstrap2.sh +39 -0
- metadata +297 -0
data/.rvmrc
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
mccloud (0.0.1)
|
5
|
+
cucumber (= 0.8.5)
|
6
|
+
fog
|
7
|
+
highline (~> 1.6.1)
|
8
|
+
json
|
9
|
+
net-scp
|
10
|
+
net-ssh (~> 2.1.0)
|
11
|
+
net-ssh-multi
|
12
|
+
popen4 (~> 0.1.2)
|
13
|
+
progressbar
|
14
|
+
templater
|
15
|
+
thor (~> 0.14.6)
|
16
|
+
|
17
|
+
GEM
|
18
|
+
remote: http://rubygems.org/
|
19
|
+
specs:
|
20
|
+
Platform (0.4.0)
|
21
|
+
builder (2.1.2)
|
22
|
+
cucumber (0.8.5)
|
23
|
+
builder (~> 2.1.2)
|
24
|
+
diff-lcs (~> 1.1.2)
|
25
|
+
gherkin (~> 2.1.4)
|
26
|
+
json_pure (~> 1.4.3)
|
27
|
+
term-ansicolor (~> 1.0.4)
|
28
|
+
diff-lcs (1.1.2)
|
29
|
+
excon (0.6.1)
|
30
|
+
extlib (0.9.15)
|
31
|
+
fog (0.7.2)
|
32
|
+
builder
|
33
|
+
excon (>= 0.6.1)
|
34
|
+
formatador (>= 0.1.3)
|
35
|
+
json
|
36
|
+
mime-types
|
37
|
+
net-ssh (>= 2.1.3)
|
38
|
+
nokogiri (>= 1.4.4)
|
39
|
+
ruby-hmac
|
40
|
+
formatador (0.1.3)
|
41
|
+
gherkin (2.1.5)
|
42
|
+
trollop (~> 1.16.2)
|
43
|
+
highline (1.6.1)
|
44
|
+
json (1.5.1)
|
45
|
+
json_pure (1.4.6)
|
46
|
+
mime-types (1.16)
|
47
|
+
net-scp (1.0.4)
|
48
|
+
net-ssh (>= 1.99.1)
|
49
|
+
net-ssh (2.1.4)
|
50
|
+
net-ssh-gateway (1.0.1)
|
51
|
+
net-ssh (>= 1.99.1)
|
52
|
+
net-ssh-multi (1.1)
|
53
|
+
net-ssh (>= 2.1.4)
|
54
|
+
net-ssh-gateway (>= 0.99.0)
|
55
|
+
nokogiri (1.4.4)
|
56
|
+
open4 (1.0.1)
|
57
|
+
popen4 (0.1.2)
|
58
|
+
Platform (>= 0.4.0)
|
59
|
+
open4 (>= 0.4.0)
|
60
|
+
progressbar (0.9.0)
|
61
|
+
ruby-hmac (0.4.0)
|
62
|
+
templater (1.0.0)
|
63
|
+
diff-lcs (>= 1.1.2)
|
64
|
+
extlib (>= 0.9.5)
|
65
|
+
highline (>= 1.4.0)
|
66
|
+
term-ansicolor (1.0.5)
|
67
|
+
thor (0.14.6)
|
68
|
+
trollop (1.16.2)
|
69
|
+
|
70
|
+
PLATFORMS
|
71
|
+
ruby
|
72
|
+
|
73
|
+
DEPENDENCIES
|
74
|
+
mccloud!
|
data/README.md
ADDED
@@ -0,0 +1,123 @@
|
|
1
|
+
## Note:
|
2
|
+
- This is a quick copy and paste job(weekend hacking), you should not consider it anything but experimental right now
|
3
|
+
- But I wanted to share the idea already with others
|
4
|
+
|
5
|
+
## DISCLAIMER:
|
6
|
+
this is alpha sofware . Don't trust it:) And don't complain if it removes all your EC instances at once....
|
7
|
+
|
8
|
+
## Kudos to great stuff
|
9
|
+
- [Vagrant](http://www.vagrantup.com) is great for testing machines on your local machines
|
10
|
+
- [Fog](https://github.com/geemus/fog) is a great fog library for managing cloud systems
|
11
|
+
|
12
|
+
Without those two, this project would not be possible. Kudos to the authors!
|
13
|
+
|
14
|
+
This project tries to combine both:
|
15
|
+
- Because your local machine might outgrow your complexity your local machine can handle
|
16
|
+
- use the same vagrantfile for local dev, and cloud devel
|
17
|
+
|
18
|
+
## Some notes before you dive in
|
19
|
+
|
20
|
+
- I could probably have integrated with vagrant code but this would have taken me longer to understand vagrant code
|
21
|
+
- I didn't want the dependency on virtualbox
|
22
|
+
- The machines it creates will have the prefix as defined in the Mccloudfile, so this should not pollute your stuff
|
23
|
+
|
24
|
+
## Todo:
|
25
|
+
|
26
|
+
- provision to other providers than ec2
|
27
|
+
- try to stay fully compatible with Vagrantfile
|
28
|
+
|
29
|
+
## How it will work/works
|
30
|
+
|
31
|
+
### Create a config file for fog. Note that these are spaces in front and no tabs
|
32
|
+
$ cat $HOME/.fog
|
33
|
+
<pre>
|
34
|
+
:default:
|
35
|
+
:aws_access_key_id: <your id here>
|
36
|
+
:aws_secret_access_key: <your acess key here>
|
37
|
+
</pre>
|
38
|
+
|
39
|
+
### Create a Mccloud project
|
40
|
+
$ mccloud init
|
41
|
+
|
42
|
+
This will create a Mccloudfile
|
43
|
+
|
44
|
+
### Edit your Mccloud appropriate
|
45
|
+
|
46
|
+
<pre>
|
47
|
+
Mccloud::Config.run do |config|
|
48
|
+
# All Mccloud configuration is done here. For a detailed explanation
|
49
|
+
# and listing of configuration options, please view the documentation
|
50
|
+
# online.
|
51
|
+
|
52
|
+
config.mccloud.prefix="mccloud"
|
53
|
+
|
54
|
+
config.vm.define :web do |web_config|
|
55
|
+
web_config.vm.ami = "ami-cef405a7"
|
56
|
+
web_config.vm.provider="AWS"
|
57
|
+
|
58
|
+
#web_config.vm.provisioner=:chef_solo
|
59
|
+
#web_config.vm.provisioner=:puppet
|
60
|
+
|
61
|
+
web_config.vm.provider_options={
|
62
|
+
# ID = "ami-cef405a7" = x64 Ubuntu 10.10
|
63
|
+
:image_id => 'ami-cef405a7',
|
64
|
+
# Flavors
|
65
|
+
:flavor_id => 't1.micro',
|
66
|
+
#:flavor_id => 'm1.large',
|
67
|
+
:groups => %w(ec2securitygroup), :key_name => "ec2-keyname",
|
68
|
+
:availability_zone => "us-east-1b"
|
69
|
+
}
|
70
|
+
web_config.vm.forward_port("http", 80, 8080)
|
71
|
+
web_config.vm.user="ubuntu"
|
72
|
+
web_config.vm.bootstrap="ruby-bootstrap.sh"
|
73
|
+
web_config.vm.key="my-ec2-key.pem"
|
74
|
+
end
|
75
|
+
|
76
|
+
### Provisioners
|
77
|
+
config.vm.provision :puppet do |puppet|
|
78
|
+
puppet.pp_path = "/tmp/vagrant-puppet"
|
79
|
+
#puppet.manifests_path = "puppet/manifests"
|
80
|
+
#puppet.module_path = "puppet/modules"
|
81
|
+
puppet.manifest_file = "newbox.pp"
|
82
|
+
end
|
83
|
+
|
84
|
+
config.vm.provision :chef_solo do |chef|
|
85
|
+
chef.cookbooks_path = ["<your cookboopath>"]
|
86
|
+
chef.add_recipe("<some recipe>")
|
87
|
+
# You may also specify custom JSON attributes:
|
88
|
+
chef.json.merge!({})
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
</pre>
|
93
|
+
|
94
|
+
### Start your machines
|
95
|
+
# If the machine does not yet exist, it will also run bootstrap
|
96
|
+
$ mccloud up web
|
97
|
+
|
98
|
+
### Check the status
|
99
|
+
$ mccloud status
|
100
|
+
|
101
|
+
### Bootstrap the machine
|
102
|
+
$ mccloud bootstrap web
|
103
|
+
|
104
|
+
### (interactive) Login into the machine
|
105
|
+
$ mccloud ssh web
|
106
|
+
|
107
|
+
### run a command on a machine
|
108
|
+
$ mccloud command web "who am i"
|
109
|
+
|
110
|
+
### Halt the machine
|
111
|
+
$ mccloud halt web
|
112
|
+
|
113
|
+
### Start the machine again
|
114
|
+
$ mccloud up web
|
115
|
+
|
116
|
+
### Provision the machine
|
117
|
+
$ mccloud provision web
|
118
|
+
|
119
|
+
### Port forwarding server
|
120
|
+
$ mccloud server
|
121
|
+
|
122
|
+
### Destroy the machine again
|
123
|
+
$ mccloud destroy web
|
data/Rakefile
ADDED
data/bin/mccloud
ADDED
@@ -0,0 +1,116 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'thor'
|
5
|
+
require 'bundler'
|
6
|
+
require 'mccloud'
|
7
|
+
|
8
|
+
require 'mccloud/session'
|
9
|
+
|
10
|
+
class MccloudCLI < Thor
|
11
|
+
|
12
|
+
attr_accessor :all_servers
|
13
|
+
no_tasks do
|
14
|
+
def create_session
|
15
|
+
@session=Mccloud::Session.new
|
16
|
+
@session.load_config
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
|
21
|
+
desc "init [AMI-ID]", "initializes a box from a template"
|
22
|
+
method_options :force => :boolean
|
23
|
+
def init(amiId=nil)
|
24
|
+
end
|
25
|
+
|
26
|
+
desc "up", "bring a machine up"
|
27
|
+
method_options :force => :boolean
|
28
|
+
def up(selection=nil)
|
29
|
+
create_session
|
30
|
+
@session.up(selection,options)
|
31
|
+
end
|
32
|
+
|
33
|
+
desc "status", "show a status of all machines that are configured"
|
34
|
+
method_options :verbose => false
|
35
|
+
def status(selection=nil)
|
36
|
+
create_session
|
37
|
+
@session.status(selection,options)
|
38
|
+
end
|
39
|
+
|
40
|
+
desc "halt [NAME]", "shutdown the machine"
|
41
|
+
method_options :force => :boolean
|
42
|
+
def halt(selection=nil)
|
43
|
+
create_session
|
44
|
+
@session.halt(selection,options)
|
45
|
+
end
|
46
|
+
|
47
|
+
desc "ssh [NAME]", "spawns an ssh to the machine"
|
48
|
+
method_options :screen => :boolean
|
49
|
+
def ssh(selection=nil,command=nil)
|
50
|
+
create_session
|
51
|
+
@session.ssh(selection,command,options)
|
52
|
+
end
|
53
|
+
|
54
|
+
desc "suspend", "freeze"
|
55
|
+
method_options :force => :boolean
|
56
|
+
def suspend(selection=nil)
|
57
|
+
create_session
|
58
|
+
@session.suspend(selection,options)
|
59
|
+
end
|
60
|
+
|
61
|
+
desc "boot", "freeze"
|
62
|
+
method_options :force => :boolean
|
63
|
+
def boot(selection=nil)
|
64
|
+
create_session
|
65
|
+
@session.boot(selection,options)
|
66
|
+
end
|
67
|
+
|
68
|
+
desc "destroy [NAME]", "destroys the machine"
|
69
|
+
method_options :force => :boolean
|
70
|
+
def destroy(selection=nil)
|
71
|
+
create_session
|
72
|
+
@session.destroy(selection,options)
|
73
|
+
end
|
74
|
+
|
75
|
+
desc "reload [NAME]", "reloads the machine"
|
76
|
+
method_options :force => :boolean
|
77
|
+
def reload(selection=nil?)
|
78
|
+
create_session
|
79
|
+
@session.reload(selection,options)
|
80
|
+
end
|
81
|
+
|
82
|
+
desc "command [NAME] [COMMAND]", "exec a command on a box"
|
83
|
+
method_options :parallel => :boolean
|
84
|
+
def command(selection=nil,command="who am i")
|
85
|
+
create_session
|
86
|
+
@session.command(selection,command,options)
|
87
|
+
end
|
88
|
+
|
89
|
+
desc "bootstrap [NAME]", "exec a command on a box"
|
90
|
+
method_options :sudo => :boolean
|
91
|
+
def bootstrap(selection=nil,script="who am i")
|
92
|
+
create_session
|
93
|
+
@session.bootstrap(selection,script,options)
|
94
|
+
end
|
95
|
+
|
96
|
+
desc "multi","multi"
|
97
|
+
method_options :verbose => :boolean
|
98
|
+
def multi(selection=nil,command="who am i")
|
99
|
+
create_session
|
100
|
+
@session.multi(selection,command,options)
|
101
|
+
end
|
102
|
+
|
103
|
+
desc "provision", "provision the machine"
|
104
|
+
def provision(selection=nil)
|
105
|
+
create_session
|
106
|
+
@session.provision(selection,options)
|
107
|
+
end
|
108
|
+
|
109
|
+
desc "server", "runs a server+ forwards"
|
110
|
+
def server(selection=nil)
|
111
|
+
create_session
|
112
|
+
@session.server(selection,options)
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
MccloudCLI.start
|
data/lib/mccloud.rb
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'pp'
|
2
|
+
module Mccloud
|
3
|
+
module Command
|
4
|
+
def bootstrap(selection=nil,command="who am i",options=nil)
|
5
|
+
|
6
|
+
on_selected_machines(selection) do |id,vm|
|
7
|
+
puts "bootstrap #{selection} "
|
8
|
+
server=vm.instance
|
9
|
+
server.private_key_path=vm.key
|
10
|
+
server.username = vm.user
|
11
|
+
if server.state == "running"
|
12
|
+
puts "Uploading bootstrap code to machine #{vm.name}"
|
13
|
+
unless !File.exists?(vm.bootstrap)
|
14
|
+
server.scp(vm.bootstrap,"/tmp/bootstrap.sh")
|
15
|
+
puts "Enabling the bootstrap code to run"
|
16
|
+
result=server.ssh("chmod +x /tmp/bootstrap.sh")
|
17
|
+
else
|
18
|
+
puts "Error: bootstrap file #{vm.bootstrap} does not exist"
|
19
|
+
exit -1
|
20
|
+
end
|
21
|
+
else
|
22
|
+
puts "server is not running, so bootstrapping will do no good"
|
23
|
+
end
|
24
|
+
#instance=PROVIDER.servers.get(id)
|
25
|
+
#options={ :port => 22, :keys => [ vm.key ], :paranoid => false, :keys_only => true}
|
26
|
+
#Mccloud::Ssh.execute(instance.public_ip_address,vm.user,options,"sudo /tmp/bootstrap.sh")
|
27
|
+
end
|
28
|
+
multi(selection,"sudo /tmp/bootstrap.sh",options)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module Mccloud
|
2
|
+
module Command
|
3
|
+
def command(selection=nil,command="who am i")
|
4
|
+
unless options.parallel?
|
5
|
+
on_selected_machines(selection) do |id,vm|
|
6
|
+
server=PROVIDER.servers.get(id)
|
7
|
+
server.private_key_path=vm.key
|
8
|
+
server.username = vm.user
|
9
|
+
if server.state == "running"
|
10
|
+
result=server.ssh(command)
|
11
|
+
puts result[0].stdout
|
12
|
+
else
|
13
|
+
puts "not running so what's the point"
|
14
|
+
end
|
15
|
+
end
|
16
|
+
else
|
17
|
+
invoke :multi , [selection, command]
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'mccloud/util/iterator'
|
2
|
+
|
3
|
+
module Mccloud
|
4
|
+
module Command
|
5
|
+
def destroy(selection=nil,options=nil)
|
6
|
+
on_selected_machines(selection) do |id,vm|
|
7
|
+
unless vm.instance.state == "shutting-down" || vm.instance.state =="terminated"
|
8
|
+
puts "Destroying #{vm.name} with id - #{id}"
|
9
|
+
vm.instance.destroy
|
10
|
+
|
11
|
+
vm.instance.wait_for { print "."; STDOUT.flush; state=="terminated"}
|
12
|
+
puts
|
13
|
+
else
|
14
|
+
puts "Server #{vm.name} - Id: #{id} has state #{vm.instance.state} so not destroying it "
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'mccloud/util/iterator'
|
2
|
+
|
3
|
+
module Mccloud
|
4
|
+
module Command
|
5
|
+
include Mccloud::Util
|
6
|
+
def halt(selection=nil,options=nil)
|
7
|
+
on_selected_machines(selection) do |id,vm|
|
8
|
+
unless vm.instance.state == "stopping" || vm.instance.state =="stopped"
|
9
|
+
puts "halting #{id}"
|
10
|
+
vm.instance.stop
|
11
|
+
vm.instance.wait_for { printf "."; STDOUT.flush; state=="stopped"}
|
12
|
+
puts
|
13
|
+
else
|
14
|
+
puts "#{vm.name} has state: #{server.state} so we're not halting #{vm.name} - #{id}"
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|