secured-cloud-vagrant 1.0.0

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.
Files changed (41) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +19 -0
  3. data/Gemfile +12 -0
  4. data/LICENSE.txt +9 -0
  5. data/README.md +340 -0
  6. data/README.txt +358 -0
  7. data/Rakefile +22 -0
  8. data/Vagrantfile_multipleVMs +124 -0
  9. data/Vagrantfile_singleVM +43 -0
  10. data/dummy.box +0 -0
  11. data/example_box/README.md +13 -0
  12. data/example_box/metadata.json +3 -0
  13. data/lib/secured-cloud-vagrant.rb +22 -0
  14. data/lib/secured-cloud-vagrant/action.rb +259 -0
  15. data/lib/secured-cloud-vagrant/actions/assign_public_ips.rb +142 -0
  16. data/lib/secured-cloud-vagrant/actions/check_state.rb +64 -0
  17. data/lib/secured-cloud-vagrant/actions/create.rb +112 -0
  18. data/lib/secured-cloud-vagrant/actions/delete.rb +105 -0
  19. data/lib/secured-cloud-vagrant/actions/has_public_ips.rb +53 -0
  20. data/lib/secured-cloud-vagrant/actions/power_off.rb +22 -0
  21. data/lib/secured-cloud-vagrant/actions/power_on.rb +22 -0
  22. data/lib/secured-cloud-vagrant/actions/power_vm.rb +100 -0
  23. data/lib/secured-cloud-vagrant/actions/read_ssh_info.rb +148 -0
  24. data/lib/secured-cloud-vagrant/actions/reboot.rb +98 -0
  25. data/lib/secured-cloud-vagrant/actions/release_ips_confirm.rb +25 -0
  26. data/lib/secured-cloud-vagrant/actions/wait_for_state.rb +54 -0
  27. data/lib/secured-cloud-vagrant/actions/warn_networks.rb +32 -0
  28. data/lib/secured-cloud-vagrant/actions/warn_provision.rb +32 -0
  29. data/lib/secured-cloud-vagrant/commands/list.rb +149 -0
  30. data/lib/secured-cloud-vagrant/commands/ssh_config.rb +43 -0
  31. data/lib/secured-cloud-vagrant/configs/authentication_info.rb +49 -0
  32. data/lib/secured-cloud-vagrant/configs/config.rb +87 -0
  33. data/lib/secured-cloud-vagrant/configs/ip_mapping.rb +71 -0
  34. data/lib/secured-cloud-vagrant/configs/virtual_machine.rb +136 -0
  35. data/lib/secured-cloud-vagrant/plugin.rb +77 -0
  36. data/lib/secured-cloud-vagrant/provider.rb +73 -0
  37. data/lib/secured-cloud-vagrant/version.rb +5 -0
  38. data/locales/en.yml +91 -0
  39. data/secured-cloud-vagrant.gemspec +59 -0
  40. data/templates/os_templates.erb +12 -0
  41. metadata +160 -0
@@ -0,0 +1,22 @@
1
+ require 'rubygems'
2
+ require 'bundler/setup'
3
+ require 'rake/packagetask'
4
+
5
+ # Immediately sync all stdout so that tools like buildbot can
6
+ # immediately load in the output.
7
+ $stdout.sync = true
8
+ $stderr.sync = true
9
+
10
+ # Change to the directory of this file.
11
+ Dir.chdir(File.expand_path("../", __FILE__))
12
+
13
+ # This installs the tasks that help with gem creation and
14
+ # publishing.
15
+ Bundler::GemHelper.install_tasks
16
+
17
+ # Install the package task
18
+ Rake::PackageTask.new("secured-cloud-vagrant-plugin", :noversion) do |p|
19
+ p.need_zip = true
20
+ p.zip_command = '7z a -tzip secured-cloud-vagrant-plugin.zip lib/*.rb'
21
+ p.package_files.include("lib/*.rb")
22
+ end
@@ -0,0 +1,124 @@
1
+ # -*- mode: ruby -*-
2
+ # vi: set ft=ruby :
3
+
4
+ # Vagrantfile API/syntax version. Don't touch unless you know what you're doing!
5
+ VAGRANTFILE_API_VERSION = "2"
6
+
7
+ Vagrant.require_plugin('secured-cloud-vagrant')
8
+
9
+ ENV['VAGRANT_DEFAULT_PROVIDER'] = "secured_cloud"
10
+
11
+ Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
12
+
13
+ # API authentication
14
+ config.vm.provider :secured_cloud do |sc|
15
+ sc.auth.url = "http://secured_cloud_api_url"
16
+ sc.auth.applicationKey = "my_application_key"
17
+ sc.auth.sharedSecret = "my_shared_secret"
18
+ end
19
+
20
+
21
+ # VM 1
22
+ config.vm.define "vm01" do |vm01|
23
+
24
+ # SecuredCloud dummy box
25
+ vm01.vm.box = "sc_dummy"
26
+
27
+
28
+ # Configuration for VM #1
29
+ vm01.vm.provider :secured_cloud do |sc|
30
+
31
+ sc.vm.name = "myVM01"
32
+ sc.vm.description = "This is my first VM"
33
+ sc.vm.storageGB = 16
34
+ sc.vm.memoryMB = 1024
35
+ sc.vm.vcpus = 1
36
+ sc.vm.osTemplateUrl = "/ostemplate/178"
37
+ sc.vm.newOsPassword = "5tgb%TGB"
38
+ sc.vm.nodeResourceUrl = "/node/4"
39
+ sc.vm.orgResourceUrl = "/organization/10365"
40
+
41
+ sc.vm.ipMappings = [
42
+ {
43
+ :newPublicIpCount => 1,
44
+ :publicIpsFromReserved => "172.27.21.48"
45
+ },
46
+ {
47
+ :privateIp => "10.2.0.19",
48
+ :publicIpsFromReserved => ["172.27.21.40", "172.27.21.34"]
49
+ }
50
+ ]
51
+
52
+ end
53
+
54
+ end
55
+
56
+
57
+ # VM 2
58
+ config.vm.define "vm02" do |vm02|
59
+
60
+ # SecuredCloud dummy box
61
+ vm02.vm.box = "sc_dummy"
62
+
63
+
64
+ # Configuration for VM #2
65
+ vm02.vm.provider :secured_cloud do |sc|
66
+
67
+ sc.vm.name = "myVM02"
68
+ sc.vm.description = "This is my second VM"
69
+ sc.vm.storageGB = 16
70
+ sc.vm.memoryMB = 1024
71
+ sc.vm.vcpus = 1
72
+ sc.vm.imageResourceUrl = "/image/2796"
73
+ sc.vm.newOsPassword = "5tgb%TGB"
74
+ sc.vm.nodeResourceUrl = "/node/4"
75
+ sc.vm.orgResourceUrl = "/organization/10365"
76
+
77
+ sc.vm.ipMappings = [
78
+ {
79
+ :newPublicIpCount => 2
80
+ },
81
+ {
82
+ :publicIpsFromReserved => ["172.27.21.40", "172.27.21.49"]
83
+ }
84
+ ]
85
+
86
+ end
87
+
88
+ end
89
+
90
+
91
+ # VM 3
92
+ config.vm.define "vm03" do |vm03|
93
+
94
+ # SecuredCloud dummy box
95
+ vm03.vm.box = "sc_dummy"
96
+
97
+
98
+ # Configuration for VM #3
99
+ vm03.vm.provider :secured_cloud do |sc|
100
+
101
+ sc.vm.name = "myVM03"
102
+ sc.vm.description = "This is third VM"
103
+ sc.vm.storageGB = 60
104
+ sc.vm.memoryMB = 1024
105
+ sc.vm.vcpus = 1
106
+ sc.vm.osTemplateUrl = "/ostemplate/45"
107
+ sc.vm.newOsPassword = "5tgb%TGB"
108
+ sc.vm.nodeResourceUrl = "/node/4"
109
+ sc.vm.orgResourceUrl = "/organization/10365"
110
+
111
+ sc.vm.ipMappings = [
112
+ {
113
+ :newPublicIpCount => 2
114
+ },
115
+ {
116
+ :publicIpsFromReserved => ["172.27.21.40", "172.27.21.49"]
117
+ }
118
+ ]
119
+
120
+ end
121
+
122
+ end
123
+
124
+ end
@@ -0,0 +1,43 @@
1
+ # -*- mode: ruby -*-
2
+ # vi: set ft=ruby :
3
+
4
+ # Vagrantfile API/syntax version. Don't touch unless you know what you're doing!
5
+ VAGRANTFILE_API_VERSION = "2"
6
+
7
+ Vagrant.require_plugin('secured-cloud-vagrant')
8
+
9
+ ENV['VAGRANT_DEFAULT_PROVIDER'] = "secured_cloud"
10
+
11
+ Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
12
+
13
+ #SecuredCloud dummy box
14
+ config.vm.box = "sc_dummy"
15
+
16
+ config.vm.provider :secured_cloud do |sc|
17
+
18
+ #API authentication
19
+ sc.auth.url = "http://secured_cloud_api_url"
20
+ sc.auth.applicationKey = "my_application_key"
21
+ sc.auth.sharedSecret = "my_shared_secret"
22
+
23
+ # VM configuration
24
+ sc.vm.name = "myVM"
25
+ sc.vm.description = "This is my VM"
26
+ sc.vm.storageGB = 16
27
+ sc.vm.memoryMB = 1024
28
+ sc.vm.vcpus = 1
29
+ sc.vm.osTemplateUrl = "/ostemplate/178" #create VM from OS template
30
+ #sc.vm.imageResourceUrl = "/image/2796" #create VM from customer image
31
+ sc.vm.newOsPassword = "5tgb%TGB"
32
+ sc.vm.nodeResourceUrl = "/node/4"
33
+ sc.vm.orgResourceUrl = "/organization/10365"
34
+
35
+ sc.vm.ipMappings = [
36
+ {
37
+ :newPublicIpCount => 1 #assign a new public IP
38
+ }
39
+ ]
40
+
41
+ end
42
+
43
+ end
Binary file
@@ -0,0 +1,13 @@
1
+ # Vagrant Secured Cloud Example Box
2
+
3
+ Vagrant providers each require a custom provider-specific box format.
4
+ This folder shows the example contents of a box for the `secured_cloud`
5
+ provider. To turn this into a box:
6
+
7
+ ```
8
+ $ tar cvzf secured_cloud.box ./metadata.json ./Vagrantfile
9
+ ```
10
+
11
+ This box works by using Vagrant's built-in Vagrantfile merging to setup
12
+ defaults for SecuredCloud. These defaults can easily be overwritten by
13
+ higher-level Vagrantfiles (such as project root Vagrantfiles).
@@ -0,0 +1,3 @@
1
+ {
2
+ "provider": "secured_cloud"
3
+ }
@@ -0,0 +1,22 @@
1
+ require "pathname"
2
+
3
+ require "secured-cloud-vagrant/plugin"
4
+
5
+ module VagrantPlugins
6
+ module SecuredCloud
7
+
8
+ lib_path = Pathname.new(File.expand_path("../secured-cloud-vagrant", __FILE__))
9
+ autoload :Action, lib_path.join("action")
10
+ #autoload :Errors, lib_path.join("errors")
11
+
12
+ # This returns the path to the source of this plugin.
13
+ #
14
+ # @return [Pathname]
15
+ def self.source_root
16
+ @source_root ||= Pathname.new(File.expand_path("../../", __FILE__))
17
+ end
18
+
19
+ I18n.load_path << File.expand_path("locales/en.yml", source_root)
20
+
21
+ end
22
+ end
@@ -0,0 +1,259 @@
1
+ require "vagrant/action/builder"
2
+ require "log4r"
3
+ require "pathname"
4
+
5
+ module VagrantPlugins
6
+ module SecuredCloud
7
+ module Action
8
+
9
+ # Include the built-in modules so we can use them as top-level things
10
+ include Vagrant::Action::Builtin
11
+
12
+ # Define the logger
13
+ @logger = Log4r::Logger::new('vagrant::secured_cloud::action');
14
+
15
+
16
+ # This action is called to bring the box up from nothing
17
+ def self.up
18
+
19
+ @logger.debug("Calling 'UP' action ... ")
20
+
21
+ return Vagrant::Action::Builder.new.tap do |builder|
22
+
23
+ builder.use ConfigValidate
24
+
25
+ builder.use Call, CheckState do |env, b|
26
+
27
+ case env[:machine_state]
28
+ when :active
29
+ env[:ui].info I18n.t('secured_cloud_vagrant.info.already_active')
30
+ when :stopped
31
+ b.use PowerOn
32
+ b.use provision
33
+ when :not_created
34
+ b.use Create
35
+ b.use AssignPublicIps
36
+ b.use provision
37
+ end
38
+
39
+ end
40
+
41
+ builder.use WarnNetworks
42
+
43
+ end
44
+
45
+ end
46
+
47
+ # This action is called to provision a remote VM
48
+ def self.provision
49
+
50
+ @logger.debug("Calling 'PROVISION' action ... ")
51
+
52
+ return Vagrant::Action::Builder.new.tap do |builder|
53
+
54
+ builder.use WarnProvision
55
+
56
+ end
57
+
58
+ end
59
+
60
+
61
+ # This action is called to delete the VM
62
+ def self.destroy
63
+
64
+ @logger.debug("Calling 'DESTROY' action ... ")
65
+
66
+ return Vagrant::Action::Builder.new.tap do |builder|
67
+
68
+ # Validate the configurations
69
+ builder.use ConfigValidate
70
+
71
+ builder.use Call, CheckState do |env, b|
72
+
73
+ case env[:machine_state]
74
+ when :not_created
75
+ env[:ui].info I18n.t('secured_cloud_vagrant.info.not_created')
76
+ else
77
+ b.use Call, DestroyConfirm do |env2, b2|
78
+
79
+ if(env2[:result])
80
+
81
+ # Power OFF the VM if it's ON
82
+ if(env[:machine_state] == :active)
83
+ b2.use PowerOff
84
+ b2.use WaitForState
85
+ end
86
+
87
+ b2.use Call, HasPublicIps do |env3, b3|
88
+
89
+ if(env3[:has_public_ips])
90
+ b3.use ReleaseIpsConfirm
91
+ end
92
+
93
+ b3.use Delete
94
+ end
95
+ end
96
+ end
97
+ end
98
+ end
99
+ end
100
+ end
101
+
102
+ # This action is called to halt the VM
103
+ def self.halt
104
+
105
+ @logger.debug("Calling 'HALT' action ... ")
106
+
107
+ return Vagrant::Action::Builder.new.tap do |builder|
108
+
109
+ # Validate the configurations
110
+ builder.use ConfigValidate
111
+
112
+ builder.use Call, CheckState do |env, b|
113
+
114
+ case env[:machine_state]
115
+ when :active
116
+ b.use PowerOff
117
+ when :stopped
118
+ env[:ui].info I18n.t('secured_cloud_vagrant.info.already_off')
119
+ when :not_created
120
+ env[:ui].info I18n.t('secured_cloud_vagrant.info.not_created')
121
+ end
122
+ end
123
+ end
124
+
125
+ end
126
+
127
+ # This action is called to halt the VM
128
+ def self.reload
129
+
130
+ @logger.debug("Calling 'RELOAD' action ... ")
131
+
132
+ return Vagrant::Action::Builder.new.tap do |builder|
133
+
134
+ # Validate the configurations
135
+ builder.use ConfigValidate
136
+
137
+ builder.use Call, CheckState do |env, b|
138
+
139
+ case env[:machine_state]
140
+ when :active
141
+ b.use Reboot
142
+ when :stopped
143
+ b.use PowerOn
144
+ when :not_created
145
+ env[:ui].info I18n.t('secured_cloud_vagrant.states.not_created.long', :vm_name => env[:machine].provider_config.vm.name)
146
+ end
147
+ end
148
+ end
149
+
150
+ end
151
+
152
+ # This action is called to connect to the VM through SSH
153
+ def self.ssh
154
+
155
+ @logger.debug("Calling 'SSH' action ... ")
156
+
157
+ return Vagrant::Action::Builder.new.tap do |builder|
158
+
159
+ # Validate the configurations
160
+ builder.use ConfigValidate
161
+
162
+ builder.use Call, CheckState do |env, b|
163
+
164
+ case env[:machine_state]
165
+ when :active
166
+ b.use SSHExec
167
+ when :not_created, :stopped
168
+ vm_name = (env[:vm_name].nil? || env[:vm_name].empty?) ? env[:machine].provider_config.vm.name : env[:vm_name]
169
+ env[:ui].info I18n.t("secured_cloud_vagrant.states.#{env[:machine_state]}.long", :vm_name => vm_name)
170
+ end
171
+ end
172
+ end
173
+
174
+ end
175
+
176
+ # This action is called to connect to run a single SSH command
177
+ def self.ssh_run
178
+
179
+ @logger.debug("Calling 'SSH_RUN' action ... ")
180
+
181
+ return Vagrant::Action::Builder.new.tap do |builder|
182
+
183
+ # Validate the configurations
184
+ builder.use ConfigValidate
185
+
186
+ builder.use Call, CheckState do |env, b|
187
+
188
+ case env[:machine_state]
189
+ when :active
190
+ b.use SSHRun
191
+ when :not_created, :stopped
192
+ vm_name = (env[:vm_name].nil? || env[:vm_name].empty?) ? env[:machine].provider_config.vm.name : env[:vm_name]
193
+ env[:ui].info I18n.t("secured_cloud_vagrant.states.#{env[:machine_state]}.long", :vm_name => vm_name)
194
+ end
195
+
196
+ end
197
+
198
+ end
199
+
200
+ end
201
+
202
+ # This action is called to get the SSH information to connect to the VM
203
+ def self.read_ssh_info
204
+
205
+ @logger.debug("Calling 'READ_SSH_INFO' action ... ")
206
+
207
+ return Vagrant::Action::Builder.new.tap do |builder|
208
+
209
+ # Validate the configurations
210
+ builder.use ConfigValidate
211
+
212
+ builder.use Call, CheckState do |env, b|
213
+
214
+ case env[:machine_state]
215
+ when :not_created
216
+ env[:ui].info I18n.t('secured_cloud_vagrant.states.not_created.long',
217
+ :vm_name => env[:machine].provider_config.vm.name)
218
+ when :active, :stopped
219
+ b.use ReadSshInfo
220
+ end
221
+
222
+ end
223
+
224
+ end
225
+
226
+ end
227
+
228
+
229
+ # This action is called to get the state of the VM
230
+ def self.read_machine_state
231
+
232
+ @logger.debug("Calling 'READ_MACHINE_STATE' action ... ")
233
+
234
+ return Vagrant::Action::Builder.new.tap do |builder|
235
+
236
+ builder.use ConfigValidate
237
+ builder.use CheckState
238
+ end
239
+
240
+ end
241
+
242
+ # Autoload anything we might need in the action
243
+ action_root = Pathname.new(File.expand_path("../actions", __FILE__))
244
+ autoload :CheckState, action_root.join("check_state")
245
+ autoload :Create, action_root.join("create")
246
+ autoload :Delete, action_root.join("delete")
247
+ autoload :PowerOff, action_root.join("power_off")
248
+ autoload :PowerOn, action_root.join("power_on")
249
+ autoload :Reboot, action_root.join("reboot")
250
+ autoload :ReleaseIpsConfirm, action_root.join("release_ips_confirm")
251
+ autoload :HasPublicIps, action_root.join("has_public_ips")
252
+ autoload :ReadSshInfo, action_root.join("read_ssh_info")
253
+ autoload :WarnNetworks, action_root.join("warn_networks")
254
+ autoload :WarnProvision, action_root.join("warn_provision")
255
+ autoload :WaitForState, action_root.join("wait_for_state")
256
+ autoload :AssignPublicIps, action_root.join("assign_public_ips")
257
+ end
258
+ end
259
+ end