mccloud 0.0.13 → 0.0.14

Sign up to get free protection for your applications and to get access to all the features.
Files changed (225) hide show
  1. data/.gitignore +13 -8
  2. data/.rvmrc +2 -0
  3. data/Gemfile +10 -1
  4. data/Guardfile +10 -0
  5. data/README.md +453 -89
  6. data/Rakefile +29 -2
  7. data/bin/mccloud +17 -116
  8. data/bin/mccloud_old +159 -0
  9. data/doc/old-README.md +81 -0
  10. data/lib/mccloud/cli.rb +55 -0
  11. data/lib/mccloud/command/balance.rb +21 -0
  12. data/lib/mccloud/command/base.rb +106 -0
  13. data/lib/mccloud/command/bootstrap.rb +12 -24
  14. data/lib/mccloud/command/define.rb +18 -0
  15. data/lib/mccloud/command/destroy.rb +12 -13
  16. data/lib/mccloud/command/forward.rb +29 -0
  17. data/lib/mccloud/command/group_base.rb +107 -0
  18. data/lib/mccloud/command/halt.rb +11 -13
  19. data/lib/mccloud/command/helpers.rb +13 -0
  20. data/lib/mccloud/command/image.rb +37 -0
  21. data/lib/mccloud/command/init.rb +8 -504
  22. data/lib/mccloud/command/init_vagrant.rb +14 -0
  23. data/lib/mccloud/command/ip.rb +32 -0
  24. data/lib/mccloud/command/ips.rb +22 -0
  25. data/lib/mccloud/command/keypair.rb +27 -0
  26. data/lib/mccloud/command/keystore.rb +29 -0
  27. data/lib/mccloud/command/lb.rb +38 -0
  28. data/lib/mccloud/command/named_base.rb +14 -0
  29. data/lib/mccloud/command/package.rb +17 -0
  30. data/lib/mccloud/command/provider.rb +30 -0
  31. data/lib/mccloud/command/provision.rb +10 -24
  32. data/lib/mccloud/command/reload.rb +12 -6
  33. data/lib/mccloud/command/sorry.rb +20 -0
  34. data/lib/mccloud/command/ssh.rb +11 -45
  35. data/lib/mccloud/command/status.rb +14 -35
  36. data/lib/mccloud/command/template.rb +16 -0
  37. data/lib/mccloud/command/undefine.rb +23 -0
  38. data/lib/mccloud/command/up.rb +8 -62
  39. data/lib/mccloud/command/version.rb +14 -0
  40. data/lib/mccloud/command/vm.rb +27 -0
  41. data/lib/mccloud/command.rb +36 -0
  42. data/lib/mccloud/config/collection.rb +107 -0
  43. data/lib/mccloud/config/component.rb +20 -0
  44. data/lib/mccloud/config/definition.rb +35 -0
  45. data/lib/mccloud/config/keypair.rb +36 -0
  46. data/lib/mccloud/config/mccloud.rb +39 -0
  47. data/lib/mccloud/config/provider.rb +55 -0
  48. data/lib/mccloud/config/template.rb +35 -0
  49. data/lib/mccloud/config.rb +128 -41
  50. data/lib/mccloud/definition.rb +104 -0
  51. data/lib/mccloud/definitions.rb +91 -0
  52. data/lib/mccloud/environment.rb +222 -0
  53. data/lib/mccloud/error.rb +20 -0
  54. data/lib/mccloud/generator.rb +49 -0
  55. data/lib/mccloud/keypair.rb +48 -0
  56. data/lib/mccloud/mccloudfile.rb +78 -0
  57. data/lib/mccloud/provider/aws/image.rb +107 -0
  58. data/lib/mccloud/provider/aws/ip/associate.rb +33 -0
  59. data/lib/mccloud/provider/aws/ip.rb +31 -0
  60. data/lib/mccloud/provider/aws/keystore.rb +21 -0
  61. data/lib/mccloud/provider/aws/lb/associate.rb +53 -0
  62. data/lib/mccloud/provider/aws/lb/sorry.rb +14 -0
  63. data/lib/mccloud/provider/aws/lb.rb +37 -0
  64. data/lib/mccloud/provider/aws/provider/image_destroy.rb +27 -0
  65. data/lib/mccloud/provider/aws/provider/image_list.rb +19 -0
  66. data/lib/mccloud/provider/aws/provider/ip_list.rb +17 -0
  67. data/lib/mccloud/provider/aws/provider/keystore_list.rb +22 -0
  68. data/lib/mccloud/provider/aws/provider/keystore_sync.rb +62 -0
  69. data/lib/mccloud/provider/aws/provider/lb_list.rb +21 -0
  70. data/lib/mccloud/provider/aws/provider/old_deregister.rb +39 -0
  71. data/lib/mccloud/provider/aws/provider/old_flavors.rb +18 -0
  72. data/lib/mccloud/provider/aws/provider/old_ips.rb +42 -0
  73. data/lib/mccloud/provider/aws/provider/old_loadbalance.rb +46 -0
  74. data/lib/mccloud/provider/aws/provider/old_package.rb +75 -0
  75. data/lib/mccloud/provider/aws/provider/old_sorry.rb +51 -0
  76. data/lib/mccloud/provider/aws/provider/old_status.rb +119 -0
  77. data/lib/mccloud/provider/aws/provider/old_validate.rb +51 -0
  78. data/lib/mccloud/provider/aws/provider/status.rb +58 -0
  79. data/lib/mccloud/provider/aws/provider.rb +219 -0
  80. data/lib/mccloud/provider/aws/stack/old_destroy.rb +43 -0
  81. data/lib/mccloud/provider/aws/stack/old_up.rb +59 -0
  82. data/lib/mccloud/provider/aws/stack/old_vm.rb +98 -0
  83. data/lib/mccloud/provider/aws/stack.rb +243 -0
  84. data/lib/mccloud/provider/aws/vm/bootstrap.rb +13 -0
  85. data/lib/mccloud/provider/aws/vm/destroy.rb +21 -0
  86. data/lib/mccloud/provider/aws/vm/forward.rb +17 -0
  87. data/lib/mccloud/provider/aws/vm/halt.rb +24 -0
  88. data/lib/mccloud/provider/aws/vm/package.rb +63 -0
  89. data/lib/mccloud/provider/aws/vm/provision.rb +25 -0
  90. data/lib/mccloud/provider/aws/vm/reload.rb +13 -0
  91. data/lib/mccloud/provider/aws/vm/resume.rb +0 -0
  92. data/lib/mccloud/provider/aws/vm/rsync.rb +11 -0
  93. data/lib/mccloud/provider/aws/vm/scp.rb +21 -0
  94. data/lib/mccloud/provider/aws/vm/ssh.rb +11 -0
  95. data/lib/mccloud/provider/aws/vm/suspend.rb +0 -0
  96. data/lib/mccloud/provider/aws/vm/up.rb +133 -0
  97. data/lib/mccloud/provider/aws/vm.rb +123 -0
  98. data/lib/mccloud/{type → provider/core}/forwarding.rb +6 -3
  99. data/lib/mccloud/provider/core/ip.rb +24 -0
  100. data/lib/mccloud/provider/core/keystore.rb +23 -0
  101. data/lib/mccloud/provider/core/lb.rb +23 -0
  102. data/lib/mccloud/provider/core/provider.rb +99 -0
  103. data/lib/mccloud/provider/core/vm/old_halt.rb +19 -0
  104. data/lib/mccloud/{generators.rb → provider/core/vm/old_init.rb} +0 -0
  105. data/lib/mccloud/provider/core/vm/old_multi.rb +60 -0
  106. data/lib/mccloud/provider/core/vm/old_reload.rb +11 -0
  107. data/lib/mccloud/{command/server.rb → provider/core/vm/old_server.rb} +2 -2
  108. data/lib/mccloud/provider/core/vm/old_ssh_command.rb +21 -0
  109. data/lib/mccloud/{command/suspend.rb → provider/core/vm/old_suspend.rb} +2 -2
  110. data/lib/mccloud/provider/core/vm/old_wizard.rb +511 -0
  111. data/lib/mccloud/provider/core/vm/rsync.rb +67 -0
  112. data/lib/mccloud/provider/core/vm/ssh.rb +137 -0
  113. data/lib/mccloud/provider/core/vm/ssh_bootstrap.rb +62 -0
  114. data/lib/mccloud/provider/core/vm/ssh_forward.rb +47 -0
  115. data/lib/mccloud/provider/core/vm.rb +121 -0
  116. data/lib/mccloud/provider/fog/fogconfig.rb +44 -0
  117. data/lib/mccloud/provider/fog/provider.rb +46 -0
  118. data/lib/mccloud/provider/host/provider/status.rb +12 -0
  119. data/lib/mccloud/provider/host/provider.rb +85 -0
  120. data/lib/mccloud/provider/host/vm/bootstrap.rb +11 -0
  121. data/lib/mccloud/provider/host/vm/forward.rb +12 -0
  122. data/lib/mccloud/provider/host/vm/provision.rb +19 -0
  123. data/lib/mccloud/provider/host/vm/scp.rb +35 -0
  124. data/lib/mccloud/provider/host/vm/ssh.rb +11 -0
  125. data/lib/mccloud/provider/host/vm.rb +28 -0
  126. data/lib/mccloud/provider/libvirt/provider/status.rb +43 -0
  127. data/lib/mccloud/provider/libvirt/provider.rb +96 -0
  128. data/lib/mccloud/provider/libvirt/vm/bootstrap.rb +17 -0
  129. data/lib/mccloud/provider/libvirt/vm/destroy.rb +33 -0
  130. data/lib/mccloud/provider/libvirt/vm/forward.rb +12 -0
  131. data/lib/mccloud/provider/libvirt/vm/halt.rb +20 -0
  132. data/lib/mccloud/provider/libvirt/vm/provision.rb +25 -0
  133. data/lib/mccloud/provider/libvirt/vm/reload.rb +13 -0
  134. data/lib/mccloud/provider/libvirt/vm/rsync.rb +11 -0
  135. data/lib/mccloud/provider/libvirt/vm/scp.rb +15 -0
  136. data/lib/mccloud/provider/libvirt/vm/ssh.rb +11 -0
  137. data/lib/mccloud/provider/libvirt/vm/up.rb +65 -0
  138. data/lib/mccloud/provider/libvirt/vm.rb +67 -0
  139. data/lib/mccloud/provider/script/provider/status.rb +12 -0
  140. data/lib/mccloud/provider/script/provider.rb +125 -0
  141. data/lib/mccloud/provider/script/vm.rb +13 -0
  142. data/lib/mccloud/provider/vagrant/provider/status.rb +14 -0
  143. data/lib/mccloud/provider/vagrant/provider.rb +135 -0
  144. data/lib/mccloud/provider/vagrant/vm/destroy.rb +11 -0
  145. data/lib/mccloud/provider/vagrant/vm/forward.rb +12 -0
  146. data/lib/mccloud/provider/vagrant/vm/halt.rb +11 -0
  147. data/lib/mccloud/provider/vagrant/vm/provision.rb +11 -0
  148. data/lib/mccloud/provider/vagrant/vm/reload.rb +11 -0
  149. data/lib/mccloud/provider/vagrant/vm/resume.rb +11 -0
  150. data/lib/mccloud/provider/vagrant/vm/ssh.rb +11 -0
  151. data/lib/mccloud/provider/vagrant/vm/suspend.rb +11 -0
  152. data/lib/mccloud/provider/vagrant/vm/up.rb +11 -0
  153. data/lib/mccloud/provider/vagrant/vm.rb +46 -0
  154. data/lib/mccloud/provider/vmfusion/provider/status.rb +24 -0
  155. data/lib/mccloud/provider/vmfusion/provider.rb +98 -0
  156. data/lib/mccloud/provider/vmfusion/vm/forward.rb +12 -0
  157. data/lib/mccloud/provider/vmfusion/vm/halt.rb +11 -0
  158. data/lib/mccloud/provider/vmfusion/vm/resume.rb +11 -0
  159. data/lib/mccloud/provider/vmfusion/vm/suspend.rb +11 -0
  160. data/lib/mccloud/provider/vmfusion/vm/up.rb +11 -0
  161. data/lib/mccloud/provider/vmfusion/vm.rb +47 -0
  162. data/lib/mccloud/provisioner/chef_solo.rb +193 -79
  163. data/lib/mccloud/provisioner/puppet.rb +205 -32
  164. data/lib/mccloud/provisioner/shell.rb +48 -0
  165. data/lib/mccloud/template.rb +74 -0
  166. data/lib/mccloud/templates/Mccloudfile.erb +212 -39
  167. data/lib/mccloud/templates/{bootstrap-centos-rubysource-1.8.7.sh → bootstrap/bootstrap-centos-rubysource-1.8.7.sh} +0 -0
  168. data/lib/mccloud/templates/{bootstrap-centos-rvm-1.8.7.sh → bootstrap/bootstrap-centos-rvm-1.8.7.sh} +0 -0
  169. data/lib/mccloud/templates/{bootstrap-centos-rvm-1.9.2.sh → bootstrap/bootstrap-centos-rvm-1.9.2.sh} +0 -0
  170. data/lib/mccloud/templates/{bootstrap-centos-rvm-ree-1.8.7.sh → bootstrap/bootstrap-centos-rvm-ree-1.8.7.sh} +0 -0
  171. data/lib/mccloud/templates/bootstrap/bootstrap-chef-omnibus.sh +8 -0
  172. data/lib/mccloud/templates/{bootstrap-custom.sh → bootstrap/bootstrap-custom.sh} +0 -0
  173. data/lib/mccloud/templates/{bootstrap-ubuntu-rvm-1.8.7.sh → bootstrap/bootstrap-ubuntu-rvm-1.8.7.sh} +0 -0
  174. data/lib/mccloud/templates/{bootstrap-ubuntu-system.sh → bootstrap/bootstrap-ubuntu-system.sh} +0 -0
  175. data/lib/mccloud/templates/locales/en.yml +30 -0
  176. data/lib/mccloud/templates/vm.erb +9 -0
  177. data/lib/mccloud/templates.rb +35 -0
  178. data/lib/mccloud/ui.rb +82 -0
  179. data/lib/mccloud/util/rostruct.rb +24 -0
  180. data/lib/mccloud/util/rsync.rb +12 -8
  181. data/lib/mccloud/util/ssh.rb +18 -12
  182. data/lib/mccloud/util/sshkey.rb +3 -2
  183. data/lib/mccloud/version.rb +4 -1
  184. data/lib/mccloud/vm.rb +62 -0
  185. data/lib/mccloud/vms.rb +60 -0
  186. data/lib/mccloud.rb +24 -1
  187. data/mccloud.gemspec +12 -3
  188. data/samples/Mccloudfile +117 -0
  189. data/samples/bitnami_drupal_cloud.json +102 -0
  190. data/samples/bootstrap-ubuntu-system.sh +16 -0
  191. data/samples/mcollective_cloud.json +198 -0
  192. data/samples/stack_cloud.json +93 -0
  193. data/samples/stacks.txt +5 -0
  194. data/spec/commands/define_spec.rb +96 -0
  195. data/spec/commands/init_spec.rb +30 -0
  196. data/spec/environment/environment_spec.rb +26 -0
  197. data/spec/generator_spec.rb +30 -0
  198. data/spec/keypair_spec.rb +38 -0
  199. data/spec/provider/aws/credentials_spec.rb +37 -0
  200. data/spec/provisioner/puppet/Mccloud-puppet-test +32 -0
  201. data/spec/provisioner/puppet/puppet_spec.rb +110 -0
  202. data/spec/spec_helper.rb +0 -0
  203. data/templates/ubuntu-10.10-server-amd64/aws.json +3 -0
  204. data/templates/ubuntu-10.10-server-amd64/bootstrap.sh +16 -0
  205. data/templates/ubuntu-10.10-server-amd64/definition.old +51 -0
  206. data/templates/ubuntu-10.10-server-amd64/mccloud.erb +6 -0
  207. metadata +293 -67
  208. data/Gemfile.lock +0 -53
  209. data/lib/mccloud/command/boot.rb +0 -12
  210. data/lib/mccloud/command/command.rb +0 -21
  211. data/lib/mccloud/command/multi.rb +0 -60
  212. data/lib/mccloud/configurator/lb.rb +0 -26
  213. data/lib/mccloud/configurator/mccloud.rb +0 -33
  214. data/lib/mccloud/configurator/vm.rb +0 -37
  215. data/lib/mccloud/provisioner/vagrant/base.rb +0 -63
  216. data/lib/mccloud/provisioner/vagrant/chef.rb +0 -130
  217. data/lib/mccloud/provisioner/vagrant/chef_server.rb +0 -103
  218. data/lib/mccloud/provisioner/vagrant/chef_solo.rb +0 -142
  219. data/lib/mccloud/provisioner/vagrant/puppet.rb +0 -137
  220. data/lib/mccloud/provisioner/vagrant/puppet_server.rb +0 -55
  221. data/lib/mccloud/provisioner/vagrant/shell.rb +0 -52
  222. data/lib/mccloud/session.rb +0 -206
  223. data/lib/mccloud/type/lb.rb +0 -34
  224. data/lib/mccloud/type/vm.rb +0 -47
  225. data/lib/mccloud/util/iterator.rb +0 -20
data/bin/mccloud CHANGED
@@ -1,128 +1,29 @@
1
1
  #!/usr/bin/env ruby
2
-
3
- require 'rubygems'
4
- require 'thor'
5
2
  require 'mccloud'
6
3
 
7
- require 'mccloud/version'
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", "Creates a Mccloud Config File"
22
- method_options :force => :boolean
23
- def init(amiId=nil)
24
- Mccloud::Command.init(amiId,options)
25
- end
26
-
27
- desc "up [NAME]", "Fires up a machine, bootstrap and provision"
28
- method_options :force => :boolean
29
- def up(selection=nil)
30
- create_session
31
- @session.up(selection,options)
32
- end
33
-
34
- desc "status", "Show a status of all machines that are configured"
35
- method_options :verbose => false
36
- def status(selection=nil)
37
- create_session
38
- @session.status(selection,options)
39
- end
40
-
41
- desc "halt [NAME]", "Shutdown the machine"
42
- method_options :force => :boolean
43
- def halt(selection=nil)
44
- create_session
45
- @session.halt(selection,options)
46
- end
47
-
48
- desc "ssh [NAME]", "Spawns an ssh client to the machine"
49
- method_options :screen => :boolean
50
- def ssh(selection=nil,command=nil)
51
- create_session
52
- @session.ssh(selection,command,options)
53
- end
54
-
55
- desc "suspend [NAME]", "Shutdown of the machine"
56
- method_options :force => :boolean
57
- def suspend(selection=nil)
58
- create_session
59
- @session.suspend(selection,options)
60
- end
61
-
62
- # desc "boot", "same a"
63
- # method_options :force => :boolean
64
- # def boot(selection=nil)
65
- # create_session
66
- # @session.boot(selection,options)
67
- # end
68
4
 
69
- desc "destroy [NAME]", "Destroys the machine"
70
- method_options :force => :boolean
71
- def destroy(selection=nil)
72
- create_session
73
- @session.destroy(selection,options)
74
- end
5
+ begin
75
6
 
76
- desc "reload [NAME]", "Reboots the machine"
77
- method_options :force => :boolean
78
- def reload(selection=nil?)
79
- create_session
80
- @session.reload(selection,options)
81
- end
7
+ # Disable color if the proper argument was passed
8
+ shell = ARGV.include?("--no-color") ? Thor::Shell::Basic.new : Thor::Base.shell.new
82
9
 
83
- # desc "command [NAME] [COMMAND]", "exec a command on a box"
84
- # method_options :parallel => :boolean
85
- # def command(selection=nil,command="who am i")
86
- # create_session
87
- # @session.command(selection,command,options)
88
- # end
89
10
 
90
- desc "bootstrap [NAME]", "Executes the bootstrap sequence"
91
- method_options :sudo => :boolean
92
- def bootstrap(selection=nil,script="who am i")
93
- create_session
94
- @session.bootstrap(selection,script,options)
95
- end
11
+ # Start the CLI
12
+ begin
13
+ env = Mccloud::Environment.new(:cwd => ".")
96
14
 
97
- # desc "multi","multi"
98
- # method_options :verbose => :boolean
99
- # def multi(selection=nil,command="who am i")
100
- # create_session
101
- # @session.multi(selection,command,options)
102
- # end
15
+ # # Attach the UI
16
+ env.ui = ::Mccloud::UI::Shell.new(env, shell)
103
17
 
104
- desc "provision [NAME]", "Runs the provisioner the machine"
105
- def provision(selection=nil)
106
- create_session
107
- @session.provision(selection,options)
18
+ ::Mccloud::CLI.start(ARGV,:env => env)
19
+ rescue Mccloud::Error => ex
20
+ env.ui.error "#{ex}"
21
+ rescue Exception => ex
22
+ puts "Something blew up Mccloud. Time for McGuyver:"
23
+ puts ""
24
+ puts "#{ex}"
25
+ puts ex.backtrace
26
+ exit 1
108
27
  end
109
28
 
110
- desc "server", "Runs a server+ forwards network ports"
111
- def server(selection=nil)
112
- create_session
113
- @session.server(selection,options)
114
- end
115
29
  end
116
-
117
- puts
118
- 80.times { |i| printf "*" } ; puts
119
- myversion="* Mccloud v#{Mccloud::VERSION} - alpha - use at your own risk"
120
- puts "#{myversion}"
121
- puts "- github : https://github.com/jedi4ever/mccloud"
122
-
123
- 80.times { |i| printf "*" } ; puts
124
- puts
125
-
126
-
127
- MccloudCLI.start
128
- puts
data/bin/mccloud_old ADDED
@@ -0,0 +1,159 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'rubygems'
4
+ require 'thor'
5
+ require 'mccloud'
6
+
7
+
8
+ class MccloudCLI < Thor
9
+
10
+ no_tasks do
11
+ # def create_environment
12
+ # @environment=Mccloud::Environment.new.
13
+ # @environment.load_config
14
+ # end
15
+ end
16
+
17
+ desc "init", "Creates a Mccloud Config File"
18
+ method_options :force => :boolean
19
+ def init(name=nil)
20
+ Mccloud::Environment.new().load!().init(name,options)
21
+ end
22
+
23
+ desc "up [NAME]", "Fires up a machine, bootstrap and provision"
24
+ method_options :force => :boolean
25
+ method_options :noprovision => :boolean
26
+ def up(selection=nil)
27
+ Mccloud::Environment.new().load!().up(selection,options)
28
+ end
29
+
30
+ desc "status", "Show a status of all machines and images that are configured"
31
+ method_options :verbose => false
32
+ def status(selection=nil)
33
+ Mccloud::Environment.new().load!().status(selection,options)
34
+ end
35
+
36
+ desc "halt [NAME]", "Shutdown the machine"
37
+ method_options :force => :boolean
38
+ def halt(selection=nil)
39
+ Mccloud::Environment.new().load!().halt(selection,options)
40
+ end
41
+
42
+ desc "ssh [NAME]", "Spawns an ssh client to the machine"
43
+ method_options :screen => :boolean
44
+ def ssh(selection=nil,command=nil)
45
+ Mccloud::Environment.new().load!().ssh(selection,command,options)
46
+ end
47
+
48
+ desc "rsync [PATH]", "Syncs the directory to the remote machine"
49
+ method_options :screen => :boolean
50
+ def rsync(selection=nil,path=nil)
51
+ Mccloud::Environment.new().load!().rsync(selection,path,options)
52
+ end
53
+
54
+ desc "suspend [NAME]", "Shutdown of the machine"
55
+ method_options :force => :boolean
56
+ def suspend(selection=nil)
57
+ Mccloud::Environment.new().load!().suspend(selection,options)
58
+ end
59
+
60
+ desc "flavors", "Lists all available flavors"
61
+ method_options :force => :boolean
62
+ def flavors()
63
+ Mccloud::Environment.new().load!().flavors()
64
+ end
65
+
66
+ # desc "boot", "same a"
67
+ # method_options :force => :boolean
68
+ # def boot(selection=nil)
69
+ # create_environment
70
+ # @environment.boot(selection,options)
71
+ # end
72
+
73
+ desc "loadbalance [NAME]", "Updates the server instances of the loadbalancer"
74
+ method_options :force => :boolean
75
+ def loadbalance(selection=nil)
76
+ Mccloud::Environment.new().load!().loadbalance(selection,options)
77
+ end
78
+
79
+ desc "sorry [NAME]", "Activates the sorry server instances of the loadbalancer"
80
+ method_options :force => :boolean
81
+ def sorry(selection=nil)
82
+ Mccloud::Environment.new().load!().sorry(selection,options)
83
+ end
84
+
85
+ desc "ips [NAME]", "Associates instances with Ips"
86
+ method_options :force => :boolean
87
+ def ips(selection=nil)
88
+ Mccloud::Environment.new().load!().ips(selection,options)
89
+ end
90
+
91
+ desc "destroy [NAME]", "Destroys the machine"
92
+ method_options :force => :boolean
93
+ def destroy(selection=nil)
94
+ Mccloud::Environment.new().load!().destroy(selection,options)
95
+ end
96
+
97
+ desc "reload [NAME]", "Reboots the machine"
98
+ method_options :force => :boolean
99
+ def reload(selection=nil?)
100
+ Mccloud::Environment.new().load!().reload(selection,options)
101
+ end
102
+
103
+ # desc "command [NAME] [COMMAND]", "exec a command on a box"
104
+ # method_options :parallel => :boolean
105
+ # def command(selection=nil,command="who am i")
106
+ # create_environment
107
+ # @environment.command(selection,command,options)
108
+ # end
109
+
110
+ desc "bootstrap [NAME]", "Executes the bootstrap sequence"
111
+ method_options :sudo => :boolean
112
+ def bootstrap(selection=nil)
113
+ Mccloud::Environment.new().load!().bootstrap(selection,options)
114
+ end
115
+
116
+ desc "package [NAME]", "Packages the current state of a machine into an image"
117
+ method_options :name => :string
118
+ method_options :description => :string
119
+ method_options :dontwait => :boolean
120
+ def package(selection=nil)
121
+ Mccloud::Environment.new().load!().package(selection,options)
122
+ end
123
+
124
+ desc "deregister [IMAGE-ID]", "Deregisters an image"
125
+ def deregister(imageId=nil)
126
+ Mccloud::Environment.new().load!().deregister(imageId,options)
127
+ end
128
+
129
+
130
+ # desc "multi","multi"
131
+ # method_options :verbose => :boolean
132
+ # def multi(selection=nil,command="who am i")
133
+ # create_environment
134
+ # @environment.multi(selection,command,options)
135
+ # end
136
+
137
+ desc "provision [NAME]", "Runs the provisioner the machine"
138
+ def provision(selection=nil)
139
+ Mccloud::Environment.new().load!().provision(selection,options)
140
+ end
141
+
142
+ desc "server", "Runs a server+ forwards network ports"
143
+ def server(selection=nil)
144
+ Mccloud::Environment.new().load!().server(selection,options)
145
+ end
146
+ end
147
+
148
+ puts
149
+ 80.times { |i| printf "*" } ; puts
150
+ myversion="* Mccloud v#{Mccloud::VERSION} - alpha - use at your own risk"
151
+ puts "#{myversion}"
152
+ puts "- github : https://github.com/jedi4ever/mccloud"
153
+
154
+ 80.times { |i| printf "*" } ; puts
155
+ puts
156
+
157
+
158
+ MccloudCLI.start
159
+ puts
data/doc/old-README.md ADDED
@@ -0,0 +1,81 @@
1
+ # This needs to be completely rewritten for the new version!!!
2
+
3
+
4
+ ## Note:
5
+ - This is a quick copy and paste job(weekend hacking), you should not consider it anything but experimental right now
6
+ - But I wanted to share the idea already with others
7
+
8
+ ## DISCLAIMER:
9
+ this is alpha sofware . Don't trust it:) And don't complain if it removes all your EC instances at once....
10
+
11
+ ## Kudos to great stuff
12
+ - [Vagrant](http://www.vagrantup.com) is great for testing machines on your local machines
13
+ - [Fog](https://github.com/geemus/fog) is a great fog library for managing cloud systems
14
+
15
+ Without those two, this project would not be possible. Kudos to the authors!
16
+
17
+ This project tries to combine both:
18
+ - Because your local machine might outgrow your complexity your local machine can handle
19
+ - use the same vagrantfile for local dev, and cloud devel
20
+
21
+ ## Some notes before you dive in
22
+
23
+ - I could probably have integrated with vagrant code but this would have taken me longer to understand vagrant code
24
+ - I didn't want the dependency on virtualbox
25
+ - The machines it creates will have the prefix as defined in the Mccloudfile, so this should not pollute your stuff
26
+
27
+ ## Todo:
28
+
29
+ - provision to other providers than ec2
30
+ - try to stay fully compatible with Vagrantfile
31
+
32
+ ## How it will work/works
33
+
34
+ ### Create a config file for fog. Note that these are spaces in front and no tabs
35
+ $ cat $HOME/.fog
36
+ <pre>
37
+ :default:
38
+ :aws_access_key_id: <your id here>
39
+ :aws_secret_access_key: <your acess key here>
40
+ </pre>
41
+
42
+ ### Create a Mccloud project
43
+ $ mccloud init
44
+
45
+ This will create a Mccloudfile
46
+
47
+ ### Edit your Mccloud appropriate
48
+
49
+ <pre>
50
+ </pre>
51
+
52
+ ### Start your machines
53
+ # If the machine does not yet exist, it will also run bootstrap
54
+ $ mccloud up web
55
+
56
+ ### Check the status
57
+ $ mccloud status
58
+
59
+ ### Bootstrap the machine
60
+ $ mccloud bootstrap web
61
+
62
+ ### (interactive) Login into the machine
63
+ $ mccloud ssh web
64
+
65
+ ### run a command on a machine
66
+ $ mccloud command web "who am i"
67
+
68
+ ### Halt the machine
69
+ $ mccloud halt web
70
+
71
+ ### Start the machine again
72
+ $ mccloud up web
73
+
74
+ ### Provision the machine
75
+ $ mccloud provision web
76
+
77
+ ### Port forwarding server
78
+ $ mccloud server
79
+
80
+ ### Destroy the machine again
81
+ $ mccloud destroy web
@@ -0,0 +1,55 @@
1
+ require 'thor'
2
+
3
+ module Mccloud
4
+ # Entrypoint for the Mccloud CLI. This class should never be
5
+ # initialized directly (like a typical Thor class). Instead,
6
+ # use {Environment#cli} to invoke the CLI.
7
+ #
8
+ # # Defining Custom CLI Commands
9
+ #
10
+ # If you're looking to define custom CLI commands, then look at
11
+ # one of the two following classes:
12
+ #
13
+ # * {Command::Base} - Implementing a single command such as `mccloud up`, e.g.
14
+ # one without subcommands. Also take a look at {Command::NamedBase}.
15
+ # * {Command::GroupBase} - Implementing a command with subcommands, such as
16
+ # `mccloud box`, which has the `list`, `add`, etc. subcommands.
17
+ #
18
+ # The above linked classes contain the main documentation for each
19
+ # type of command.
20
+ class CLI < Thor
21
+ # Registers the given class with the CLI so it can be accessed.
22
+ # The class must be a subclass of either {Command::Base} or {Command::GroupBase}.
23
+ # Don't call this method directly, instead call the {Command::Base.register}
24
+ # or {Command::GroupBase.register} methods.
25
+ #
26
+ # @param [Class] klass Command class
27
+ # @param [String] name Command name, accessed at `mccloud NAME`
28
+ # @param [String] usage Command usage, such as "mccloud NAME [--option]"
29
+ # @param [String] description Description of the command shown during the
30
+ # command listing.
31
+ # @param [Hash] opts Other options (not gone into detail here, look at
32
+ # the source instead).
33
+ def self.register(klass, name, usage, description, opts=nil)
34
+ opts ||= {}
35
+
36
+ if klass <= Command::GroupBase
37
+ # A subclass of GroupBase is a subcommand, since it contains
38
+ # many smaller commands within it.
39
+ desc usage, description, opts
40
+ subcommand name, klass
41
+ elsif klass <= Command::Base
42
+ # A subclass of Base is a single command, since it
43
+ # is invoked as a whole (as Thor::Group)
44
+ desc usage, description, opts
45
+ define_method(name) { |*args| invoke klass, args }
46
+ end
47
+
48
+ if opts[:alias]
49
+ # Alises are defined for this command, so properly alias the
50
+ # newly defined method/subcommand:
51
+ map opts[:alias] => name
52
+ end
53
+ end
54
+ end
55
+ end #Mccloud
@@ -0,0 +1,21 @@
1
+ module Mccloud
2
+ module Command
3
+ class BalanceCommand < Base
4
+
5
+ register "balance [LB-NAME]", "Balances loadbalancers"
6
+ argument :selection, :type => :string, :optional => true, :default => nil
7
+
8
+ def execute
9
+ env.load!
10
+ env.config.providers.each do |name,provider|
11
+ env.logger.debug("Asking provider #{name} to associate to #{selection}")
12
+ provider.on_selected_components("lb",selection) do |id,lb|
13
+ lb.associate(options)
14
+ end
15
+ end
16
+ end
17
+
18
+ end
19
+
20
+ end
21
+ end
@@ -0,0 +1,106 @@
1
+ require 'thor/group'
2
+ require 'thor/actions'
3
+
4
+ module Mccloud
5
+ module Command
6
+ # A {Base} is the superclass for all commands which are single
7
+ # commands, e.g. `mccloud init`, `mccloud up`. Not commands like
8
+ # `mccloud box add`. For commands which have more subcommands, use
9
+ # a {GroupBase}.
10
+ #
11
+ # A {Base} is a subclass of `Thor::Group`, so view the documentation
12
+ # there on how to add arguments, descriptions etc. The important note
13
+ # about this is that when invoked, _all public methods_ will be called
14
+ # in the order they are defined. If you don't want a method called when
15
+ # the command is invoked, it must be made `protected` or `private`.
16
+ #
17
+ # The best way to get examples of how to create your own command is to
18
+ # view the various Mccloud commands, which are relatively simple, and
19
+ # can be found in the Mccloud source tree at `lib/mccloud/command/`.
20
+ #
21
+ # # Defining a New Command
22
+ #
23
+ # To define a new single command, create a new class which inherits
24
+ # from this class, then call {register} to register the command. That's
25
+ # it! When the command is invoked, _all public methods_ will be called.
26
+ # Below is an example `SayHello` class:
27
+ #
28
+ # class SayHello < Mccloud::Command::Base
29
+ # register "hello", "Says hello"
30
+ #
31
+ # def hello
32
+ # env.ui.info "Hello"
33
+ # end
34
+ # end
35
+ #
36
+ # In this case, the above class is invokable via `mccloud hello`. To give
37
+ # this a try, just copy and paste the above into a Mccloudfile somewhere.
38
+ # The command will be available for that project!
39
+ #
40
+ # Also note that the above example uses `env.ui` to output. It is recommended
41
+ # you use this instead of raw "puts" since it is configurable and provides
42
+ # additional functionality, such as colors and asking for user input. See
43
+ # the {UI} class for more information.
44
+ #
45
+ # ## Defining Command-line Options
46
+ #
47
+ # Most command line actions won't be as simple as `mccloud hello`, and will
48
+ # probably require parameters or switches. Luckily, Thor makes adding these
49
+ # easy:
50
+ #
51
+ # class SayHello < Mccloud::Command::Base
52
+ # register "hello", "Says hello"
53
+ # argument :name, :type => :string
54
+ #
55
+ # def hello
56
+ # env.ui.info "Hello, #{name}"
57
+ # end
58
+ # end
59
+ #
60
+ # Then, the above can be invoked with `mccloud hello Mitchell` which would
61
+ # output "Hello, Mitchell." If instead you're looking for switches, such as
62
+ # "--name Mitchell", then take a look at `class_option`, an example of which
63
+ # can be found in the {PackageCommand}.
64
+ class Base < Thor::Group
65
+ include Thor::Actions
66
+ include Helpers
67
+
68
+ attr_reader :env
69
+
70
+ # Register the command with the main Mccloud CLI under the
71
+ # given name. The name will be used for accessing it from the CLI,
72
+ # so if you name it "lamp", then the command to invoke this
73
+ # will be `mccloud lamp`.
74
+ #
75
+ # The description is used when the help is listed, and is meant to be
76
+ # a brief (one sentence) description of what the command does.
77
+ #
78
+ # Some additional options may be passed in as the last parameter:
79
+ #
80
+ # * `:alias` - If given as an array or string, these will be aliases
81
+ # for the same command. For example, `mccloud version` is also
82
+ # `mccloud --version` and `mccloud -v`
83
+ #
84
+ # @param [String] usage
85
+ # @param [String] description
86
+ # @param [Hash] opts
87
+ def self.register(usage, description, opts=nil)
88
+ desc description
89
+ ::Mccloud::CLI.register(self, extract_name_from_usage(usage), usage, desc, opts)
90
+ end
91
+
92
+ def initialize(*args)
93
+ super
94
+ initialize_environment(*args)
95
+ end
96
+
97
+ protected
98
+
99
+ # Extracts the name of the command from a usage string. Example:
100
+ # `init [box_name] [box_url]` becomes just `init`.
101
+ def self.extract_name_from_usage(usage)
102
+ /^([-_a-zA-Z0-9]+)(\s+(.+?))?$/.match(usage).to_a[1]
103
+ end
104
+ end
105
+ end
106
+ end
@@ -1,31 +1,19 @@
1
- require 'pp'
2
1
  module Mccloud
3
2
  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.private_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"
3
+ class BootstrapCommand < Base
4
+
5
+ argument :box_name, :type => :string, :optional => true, :default => nil
6
+ argument :command, :type => :string, :optional => true, :default => nil
7
+
8
+ register "bootstrap [NAME] [FILENAME]", "Executes the bootstrap sequence"
9
+
10
+ def execute
11
+ env.load!
12
+ env.config.providers.each do |name,provider|
13
+ env.logger.debug("Asking provider #{name} to reload box #{box_name}")
14
+ provider.bootstrap(box_name,command,options)
23
15
  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
16
  end
28
- multi(selection,"/tmp/bootstrap.sh",options.merge({ "sudo" => true}))
29
17
  end
30
18
  end
31
19
  end
@@ -0,0 +1,18 @@
1
+ require 'fileutils'
2
+ module Mccloud
3
+ module Command
4
+ class DefineCommand < Base
5
+
6
+ register "define NAME TEMPLATE-NAME", "Creates a new definition based on a tempate"
7
+ argument :name, :type => :string, :optional => false, :default => nil
8
+ argument :template, :type => :string, :optional => false, :default => nil
9
+
10
+ def execute
11
+ env.ui.info "Define #{name} with template #{template}"
12
+ env.config.definitions.define(name,template)
13
+ end
14
+
15
+ end
16
+
17
+ end
18
+ end
@@ -1,19 +1,18 @@
1
- require 'mccloud/util/iterator'
2
-
3
1
  module Mccloud
4
2
  module Command
5
- def destroy(selection=nil,options=nil)
6
- on_selected_machines(selection) do |id,vm|
7
- unless vm.instance.nil? || vm.instance.state == "shutting-down" || vm.instance.state =="terminated"
8
- puts "Destroying machine #{vm.name} (#{id})"
9
- vm.instance.destroy
10
-
11
- vm.instance.wait_for { print "."; STDOUT.flush; state=="terminated"}
12
- puts
13
- else
14
- puts "Machine #{vm.name} is already terminated"
3
+ class DestroyCommand < Base
4
+
5
+ argument :box_name, :type => :string, :optional => false, :default => nil
6
+
7
+ register "destroy [NAME]", "Destroys the machine"
8
+
9
+ def execute
10
+ env.load!
11
+ env.config.providers.each do |name,provider|
12
+ env.logger.debug("Asking provider #{name} to destroy box #{box_name}")
13
+ provider.destroy(box_name,options)
15
14
  end
16
15
  end
17
16
  end
18
17
  end
19
- end
18
+ end