mccloud 0.0.2 → 0.0.3

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.
@@ -7,6 +7,7 @@ module Mccloud
7
7
  def multi(selection=nil,command="who am i",options=nil)
8
8
  trap("INT") { puts "we hit CTRL_C"; exit }
9
9
 
10
+
10
11
  Net::SSH::Multi.start do |session|
11
12
  # Connect to remote machines
12
13
  ip2name=Hash.new
@@ -18,6 +19,12 @@ module Mccloud
18
19
  end
19
20
  end
20
21
 
22
+ unless options["sudo"].nil?
23
+ #check vm.sudo
24
+ sudo_cmd="sudo"
25
+ command="#{sudo_cmd} #{command}"
26
+ end
27
+
21
28
  puts "Executing #{command}"
22
29
  begin
23
30
  session.exec("#{command}") do |ch, stream, data|
@@ -5,6 +5,7 @@ module Mccloud
5
5
 
6
6
  def provision(selection=nil,options=nil)
7
7
  on_selected_machines(selection) do |id,vm|
8
+
8
9
  instance=vm.instance
9
10
  instance.private_key_path=vm.private_key
10
11
  instance.username = vm.user
@@ -13,9 +14,11 @@ module Mccloud
13
14
  provisioner=@session.config.provisioners[vm.provisioner.to_s]
14
15
  if provisioner.nil?
15
16
  # We take the first provisioner defined
16
- provisioner=@session.config.provisioners.first[1]
17
+ #provisioner=@session.config.provisioners.first[1]
18
+ else
19
+ puts "Starting provisioning on #{vm.name} with #{vm.provisioner} as provisioner"
20
+ provisioner.run(vm)
17
21
  end
18
- provisioner.run(vm)
19
22
  end
20
23
  ##on_selected_machines(selection) do |id,vm|
21
24
  #instance=PROVIDER.servers.get(id)
@@ -4,6 +4,7 @@ module Mccloud
4
4
  module Command
5
5
  def server(selection=nil,options=nil)
6
6
 
7
+ puts "Starting server mode"
7
8
  trap("INT") { puts "You've hit CTRL-C . Stopping server now"; exit }
8
9
  threads = []
9
10
  on_selected_machines(selection) do |id,vm|
@@ -14,17 +15,21 @@ module Mccloud
14
15
  ssh_options={ :keys => [ vm.private_key ], :paranoid => false, :keys_only => true}
15
16
  Net::SSH.start(public_ip_address, vm.user, ssh_options) do |ssh|
16
17
  vm.forwardings.each do |forwarding|
17
- puts "forwarding port #{forwarding.remote} from #{vm.name} to local port #{forwarding.local}"
18
- ssh.forward.local(forwarding.local, private_ip_address,forwarding.remote)
18
+ begin
19
+ puts "Forwarding remote port #{forwarding.remote} from #{vm.name} to local port #{forwarding.local}"
20
+ ssh.forward.local(forwarding.local, private_ip_address,forwarding.remote)
21
+ rescue Errno::EACCES
22
+ puts " Error - Access denied to forward remote port #{forwarding.remote} from #{vm.name} to local port #{forwarding.local}"
23
+ end
19
24
  end
20
25
  ssh.loop { true }
21
26
  end
22
27
  end
23
28
  end
24
29
  end
25
- # threads.each {|thr| thr.join}
26
- puts "and we continue here"
27
- sleep 30
30
+ threads.each {|thr| thr.join}
31
+ #puts "and we continue here"
32
+ #sleep 30
28
33
  end
29
34
  end
30
35
  end
@@ -17,6 +17,10 @@ module Mccloud
17
17
 
18
18
  name=selection
19
19
  vm=@session.config.vms[name]
20
+ if vm.instance.nil?
21
+ puts "#{name} is not available anymore"
22
+ return
23
+ end
20
24
  if vm.instance.state != "running"
21
25
  puts "#{name} is not running, move along"
22
26
  return
@@ -36,7 +40,9 @@ module Mccloud
36
40
  pid = fork if Mccloud::Util::Platform.leopard? || Mccloud::Util::Platform.tiger?
37
41
 
38
42
  command_exec="ssh #{command_options.join(" ")} #{options[:username]}@#{options[:host]} #{extra_command}".strip
39
- puts "#{command_exec}"
43
+
44
+ puts "Executing - #{command_exec}"
45
+ puts
40
46
  Kernel.exec command_exec if pid.nil?
41
47
  Process.wait(pid) if pid
42
48
  end
@@ -2,11 +2,13 @@ module Mccloud
2
2
  module Command
3
3
  def status(selection=nil,options=nil)
4
4
 
5
- printf "%-10s %-12s %-20s %-15s %-8s\n", "Name", "Instance Id", "IP", "Type","Status"
6
- 80.times { |i| printf "=" } ; puts
7
-
8
5
  unless options.verbose?
9
- filter=@session.config.mccloud.prefix
6
+
7
+ filter=@session.config.mccloud.filter
8
+ puts "Using Filter: #{filter}"
9
+
10
+ printf "%-10s %-12s %-20s %-15s %-8s\n", "Name", "Instance Id", "IP", "Type","Status"
11
+ 80.times { |i| printf "=" } ; puts
10
12
  else
11
13
  filter=""
12
14
  end
@@ -21,8 +23,15 @@ module Mccloud
21
23
  if name.start_with?(filter)
22
24
  unless filter==""
23
25
  name[filter+" - "]=""
26
+ printf "%-10s %-12s %-20s %-15s %-8s\n",name,vm.id, vm.public_ip_address, vm.flavor.name,vm.state
27
+ else
28
+ puts "Name: #{name}"
29
+ puts "Instance Id: #{vm.id}"
30
+ puts "Public Ip: #{vm.public_ip_address}"
31
+ puts "Flavor: #{vm.flavor.name}"
32
+ puts "State: #{vm.state}"
33
+ 80.times { |i| printf "=" } ; puts
24
34
  end
25
- printf "%-10s %-12s %-20s %-15s %-8s\n",name,vm.id, vm.public_ip_address, vm.flavor.name,vm.state
26
35
  end
27
36
  end #End 1 provider
28
37
  end #providers
@@ -10,26 +10,23 @@ module Mccloud
10
10
 
11
11
  provider=@session.config.providers[vm.provider]
12
12
  if (id.nil?)
13
- puts "Machine #{vm.name} doesn't yet exist"
14
13
  provider_options=vm.provider_options
15
14
  boxname=vm.name
16
15
  puts "Spinning up a new machine called #{boxname}"
17
16
 
18
17
  provider_options=provider_options.merge({ :private_key_path => vm.private_key , :public_key_path => vm.public_key, :username => vm.user})
19
18
 
20
- #pp provider_options
21
- instance=provider.servers.bootstrap(provider_options)
19
+ #instance=provider.servers.bootstrap(provider_options)
22
20
 
23
- #instance=provider.servers.create(provider_options)
21
+ instance=provider.servers.create(provider_options)
24
22
  #instance=provider.servers.create(provider_options)
25
23
 
26
- puts "Waiting for it the machine to become accessible"
24
+ puts "Waiting for the machine to become accessible"
27
25
  instance.wait_for { printf "."; STDOUT.flush; ready?}
28
26
  puts
29
- prefix=@session.config.mccloud.prefix
30
-
31
-
32
- provider.create_tags(instance.id, { "Name" => "#{prefix} - #{boxname}"})
27
+ filter=@session.config.mccloud.filter
28
+
29
+ provider.create_tags(instance.id, { "Name" => "#{filter} - #{boxname}"})
33
30
 
34
31
  # Resetting the in memory model of the new machine
35
32
  @all_servers[boxname.to_s]=instance.id
@@ -39,6 +36,8 @@ module Mccloud
39
36
 
40
37
  # Wait for ssh to become available ...
41
38
  puts "Waiting for ssh to be come available"
39
+ #puts instance.console_output.body["output"]
40
+
42
41
  Mccloud::Util.execute_when_tcp_available(instance.public_ip_address, { :port => 22, :timeout => 60 }) do
43
42
  puts "Ok, ssh is available , proceeding with bootstrap"
44
43
  end
@@ -48,12 +47,12 @@ module Mccloud
48
47
  else
49
48
  state=vm.instance.state
50
49
  if state =="stopped"
51
- puts "Machine #{vm.name} was stopped -> starting it again"
50
+ puts "Booting up machine #{vm.name}"
52
51
  vm.instance.start
53
52
  vm.instance.wait_for { printf ".";STDOUT.flush; ready?}
54
53
  puts
55
54
  else
56
- puts "Machine #{selection} already exists but is currently in state #{state} "
55
+ puts "Machine #{selection} is already running."
57
56
  end
58
57
  end
59
58
 
@@ -2,12 +2,32 @@ module Mccloud
2
2
  module Configurator
3
3
  class MccloudConfigurator
4
4
  attr_accessor :prefix
5
+ attr_accessor :environment
6
+
7
+ attr_accessor :identity
5
8
  attr_accessor :loglevel
6
9
 
7
10
  def initialize()
8
11
  @prefix="mccloud"
12
+ @environment=""
13
+ @identity=""
9
14
  @loglevel=:info
10
- end
15
+ end
16
+
17
+ def filter()
18
+ mcfilter=Array.new
19
+ if !@prefix.nil?
20
+ mcfilter << @prefix
21
+ end
22
+ if @environment!=""
23
+ mcfilter << @environment
24
+ end
25
+ if @identity!=""
26
+ mcfilter << @identity
27
+ end
28
+ return mcfilter.join(" - ")
29
+ end
30
+
11
31
  end
12
32
  end
13
33
  end
@@ -11,11 +11,24 @@ module Mccloud
11
11
 
12
12
  desc <<-DESC
13
13
  Initialize a mccloud environment
14
- mccloud init
14
+ mccloud init [ --imageId=ID]
15
15
  DESC
16
16
 
17
- # first_argument :ami_id, :required => true, :desc => 'AMI ID'
18
-
17
+ option :mcPrefix, :required => true, :desc => 'Mccloud Prefix'
18
+ option :mcEnvironment, :required => true, :desc => 'Mccloud Environment'
19
+ option :mcIdentity, :required => true, :desc => 'Mccloud Identity'
20
+
21
+ option :imageId, :required => true, :desc => 'Image ID'
22
+ option :userName, :required => true, :desc => 'User Name'
23
+ option :flavorId, :required => true, :desc => 'Flavor Id'
24
+ option :providerId, :required => true, :desc => 'Provider Id'
25
+ option :securityGroup, :required => true, :desc => 'Security Group'
26
+ option :keyName, :required => true, :desc => 'Key Name'
27
+ option :publicKeyPath, :required => false, :desc => 'Path to Public Key'
28
+ option :privateKeyPath, :required => true, :desc => 'Path to Private Key'
29
+
30
+ option :availabilityZone, :required => true, :desc => 'Availability Zone'
31
+
19
32
  template :mccloudfile, 'Mccloudfile'
20
33
 
21
34
  end
@@ -44,8 +44,11 @@ module Mccloud
44
44
 
45
45
  puts "Running chef-solo"
46
46
  options={ :port => 22, :keys => [ vm.private_key ], :paranoid => false, :keys_only => true}
47
- Mccloud::Util.ssh(vm.instance.public_ip_address,vm.user,options,"sudo chef-solo -c /tmp/solo.rb -j /tmp/dna.json -l debug")
48
-
47
+ if vm.user=="root"
48
+ Mccloud::Util.ssh(vm.instance.public_ip_address,vm.user,options,"sudo chef-solo -c /tmp/solo.rb -j /tmp/dna.json -l debug")
49
+ else
50
+ Mccloud::Util.ssh(vm.instance.public_ip_address,vm.user,options,"chef-solo -c /tmp/solo.rb -j /tmp/dna.json -l debug")
51
+ end
49
52
  end
50
53
  # Returns the run list for the provisioning
51
54
  def run_list
@@ -27,12 +27,16 @@ module Mccloud
27
27
  # Mccloud::Util.rsync(path,vm,vm.instance)
28
28
  # end
29
29
  vm.instance.ssh("mkdir -p #{@pp_path}")
30
+ puts "Synching manifest #{@manifest_file}"
30
31
  vm.instance.scp(@manifest_file,"#{@pp_path}/manifest.pp")
31
32
 
32
33
  puts "Running puppet"
33
34
  options={ :port => 22, :keys => [ vm.private_key ], :paranoid => false, :keys_only => true}
34
- Mccloud::Util.ssh(vm.instance.public_ip_address,vm.user,options,"sudo puppet #{@pp_path}/manifest.pp")
35
-
35
+ if vm.user=="root"
36
+ Mccloud::Util.ssh(vm.instance.public_ip_address,vm.user,options,"puppet #{@pp_path}/manifest.pp")
37
+ else
38
+ Mccloud::Util.ssh(vm.instance.public_ip_address,vm.user,options,"sudo puppet #{@pp_path}/manifest.pp")
39
+ end
36
40
  end
37
41
  end #Class
38
42
  end #Module Provisioners
@@ -41,7 +41,7 @@ module Mccloud
41
41
 
42
42
  def initialize(options=nil)
43
43
  @logger = Logger.new(STDOUT)
44
- @logger.level = Logger::DEBUG
44
+ @logger.level = Logger::INFO
45
45
 
46
46
  #http://www.ruby-doc.org/stdlib/libdoc/logger/rdoc/classes/Logger.html
47
47
  @logger.datetime_format = "%Y-%m-%d %H:%M:%S"
@@ -120,6 +120,7 @@ module Mccloud
120
120
  fogfile=File.new("#{File.join(ENV['HOME'],".fog")}","w")
121
121
  fogfile.puts "#{snippet}"
122
122
  fogfile.close
123
+ FileUtils.chmod(0600,fogfile)
123
124
  else
124
125
  puts "Ok, we won't write it, but we continue with your credentials in memory"
125
126
  exit -1
@@ -132,23 +133,28 @@ module Mccloud
132
133
  exit -1
133
134
  end
134
135
  end
136
+
137
+
138
+
139
+
140
+
135
141
  end
136
142
  end
137
143
 
138
144
  invalid_cache=false
139
145
  @session.config.vms.each do |name,vm|
140
- prefix=@session.config.mccloud.prefix
146
+ filter=@session.config.mccloud.filter
141
147
  id=@all_servers["#{name.to_s}"]
142
148
 
143
149
  #Check if not destroyed or something else
144
150
  instance=vm.instance
145
151
  if instance.nil?
146
- @logger.error "Cache is invalid"
152
+ @logger.debug "Cache is invalid"
147
153
  invalid_cache=true
148
154
  else
149
155
  if instance.state == "shutting-down" || instance.state == "terminated"
150
- @logger.info "parsing .mccloud json"
151
- @logger.info "rebuilding cache"
156
+ @logger.debug "parsing .mccloud json"
157
+ @logger.debug "rebuilding cache"
152
158
  invalid_cache=true
153
159
  end
154
160
  end
@@ -172,10 +178,10 @@ module Mccloud
172
178
  end
173
179
  servers_by_provider[name]=server_list
174
180
  end
175
- prefix=@session.config.mccloud.prefix
181
+ filter=@session.config.mccloud.filter
176
182
 
177
183
  @session.config.vms.each do |name,vm|
178
- id=servers_by_provider[vm.provider]["#{prefix} - #{name.to_s}"]
184
+ id=servers_by_provider[vm.provider]["#{filter} - #{name.to_s}"]
179
185
 
180
186
 
181
187
  if !id.nil?
@@ -0,0 +1,26 @@
1
+ #http://www.catapult-creative.com/2009/02/04/installing-rails-on-centos-5/
2
+
3
+ yum install -y httpd-devel openssl-devel zlib-devel gcc gcc-c++ curl-devel expat-devel gettext-devel
4
+
5
+ mkdir /usr/local/src
6
+ cd /usr/local/src
7
+ curl -O ftp://ftp.ruby-lang.org/pub/ruby/1.8/ruby-1.8.7-p72.tar.gz
8
+ tar xzvf ruby-1.8.7-p72.tar.gz
9
+ cd ruby-1.8.7-p72
10
+ ./configure --enable-shared --enable-pthread
11
+ make
12
+ make install
13
+
14
+
15
+ cd /usr/local/src
16
+ wget http://rubyforge.org/frs/download.php/60718/rubygems-1.3.5.tgz
17
+ tar xzvf rubygems-1.3.5.tgz
18
+ cd rubygems-1.3.5
19
+ ruby setup.rb
20
+ gem install rubygems-update
21
+ update_rubygems
22
+
23
+
24
+ gem install chef --no-ri --no-rdoc
25
+ gem install puppet --no-ri --no-rdoc
26
+
@@ -0,0 +1,12 @@
1
+ #!/bin/bash -ex
2
+
3
+ yum install -y bash curl git
4
+ bash < <(curl -s -B https://rvm.beginrescueend.com/install/rvm)
5
+ yum install -y gcc-c++ patch readline readline-devel zlib zlib-devel lib
6
+ yaml-devel libffi-devel openssl-devel
7
+ source /usr/local/rvm/scripts/rvm
8
+ rvm install ruby-1.8.7
9
+ rvm use 1.8.7 --default
10
+
11
+ gem install chef --no-ri --no-rdoc
12
+ gem install puppet --no-ri --no-rdoc
@@ -0,0 +1,12 @@
1
+ #!/bin/bash -ex
2
+
3
+ yum install -y bash curl git
4
+ bash < <(curl -s -B https://rvm.beginrescueend.com/install/rvm)
5
+ yum install -y gcc-c++ patch readline readline-devel zlib zlib-devel lib
6
+ yaml-devel libffi-devel openssl-devel
7
+ source /usr/local/rvm/scripts/rvm
8
+ rvm install ruby-1.9.2
9
+ rvm use 1.9.2 --default
10
+
11
+ gem install chef --no-ri --no-rdoc
12
+ gem install puppet --no-ri --no-rdoc
@@ -0,0 +1,12 @@
1
+ #!/bin/bash -ex
2
+
3
+ yum install -y bash curl git
4
+ bash < <(curl -s -B https://rvm.beginrescueend.com/install/rvm)
5
+ yum install -y gcc-c++ patch readline readline-devel zlib zlib-devel lib
6
+ yaml-devel libffi-devel openssl-devel
7
+ source /usr/local/rvm/scripts/rvm
8
+ rvm install ree-1.8.7
9
+ rvm use ree-1.8.7 --default
10
+
11
+ gem install chef --no-ri --no-rdoc
12
+ gem install puppet --no-ri --no-rdoc
@@ -0,0 +1 @@
1
+ # This is an empty bootstrap , ready for you to customize!
@@ -0,0 +1,14 @@
1
+ #!/bin/bash -ex
2
+
3
+ apt-get update
4
+ apt-get -y install libopenssl-ruby build-essential wget ssl-cert
5
+
6
+ bash < <(curl -s -B https://rvm.beginrescueend.com/install/rvm)
7
+ source /usr/local/rvm/scripts/rvm
8
+
9
+ rvm install 1.8.7
10
+ rvm use 1.8.7 --default
11
+
12
+ gem install chef --no-ri --no-rdoc
13
+ gem install puppet --no-ri --no-rdoc
14
+
@@ -7,5 +7,4 @@ test ! -f rubygems-1.3.7 && wget http://production.cf.rubygems.org/rubygems/ruby
7
7
  test -f rubygems-1.3.7.tgz && tar zxf rubygems-1.3.7.tgz
8
8
  cd rubygems-1.3.7 && ruby setup.rb --no-format-executable
9
9
  gem install chef --no-ri --no-rdoc
10
- gem install puppet --no-ri --no-rdoc
11
-
10
+ gem install puppet --no-ri --no-rdoc