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,32 @@
1
+ require "log4r"
2
+
3
+ module VagrantPlugins
4
+ module SecuredCloud
5
+ module Action
6
+
7
+ # This can be used with "Call" built-in to check if the machine
8
+ # is created and branch in the middleware.
9
+ class WarnNetworks
10
+
11
+ def initialize(app, env)
12
+ @app = app
13
+ @machine = env[:machine]
14
+ @logger = Log4r::Logger.new('vagrant::secured_cloud::action::warn_networks')
15
+ end
16
+
17
+ def call(env)
18
+
19
+ @logger.debug("Checking Network Configurations included in Vagrantfile ...")
20
+
21
+ if !@machine.config.vm.networks.nil? && @machine.config.vm.networks.length > 1
22
+ env[:ui].warn(I18n.t('secured_cloud_vagrant.warnings.network_support'))
23
+ end
24
+
25
+ @app.call(env)
26
+ end
27
+
28
+ end
29
+
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,32 @@
1
+ require "log4r"
2
+
3
+ module VagrantPlugins
4
+ module SecuredCloud
5
+ module Action
6
+
7
+ # This can be used with "Call" built-in to check if the machine
8
+ # is created and branch in the middleware.
9
+ class WarnProvision
10
+
11
+ def initialize(app, env)
12
+ @app = app
13
+ @machine = env[:machine]
14
+ @logger = Log4r::Logger.new('vagrant::secured_cloud::action::warn_provision')
15
+ end
16
+
17
+ def call(env)
18
+
19
+ @logger.debug("Checking Provision Configurations included in Vagrantfile ...")
20
+
21
+ if !@machine.config.vm.provisions.nil?
22
+ env[:ui].warn(I18n.t('secured_cloud_vagrant.warnings.provision_support'))
23
+ end
24
+
25
+ @app.call(env)
26
+ end
27
+
28
+ end
29
+
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,149 @@
1
+ require "vagrant"
2
+ require "log4r"
3
+ require "pathname"
4
+ require "secured_cloud_api_client"
5
+
6
+ module VagrantPlugins
7
+ module SecuredCloud
8
+ module Command
9
+ class List < Vagrant.plugin(2, :command)
10
+
11
+ @logger = Log4r::Logger.new('vagrant::secured_cloud::command::list')
12
+
13
+ alias super_parse_options :parse_options
14
+ def self.synopsis
15
+ "Returns a list of OS templates from which VMs can be created\n\t\t " +
16
+ "by a particular given organization on the specified node"
17
+ end
18
+
19
+ def execute
20
+ options = {}
21
+
22
+ opts = OptionParser.new do |o|
23
+ o.banner = "Usage: vagrant list [-O org_resource_url] [-N node_resource_url] [-t]"
24
+ o.separator ""
25
+
26
+ o.on("-t", "--os_templates", "Retrieve OS templates") do |t|
27
+ options[:os_templates] = t
28
+ end
29
+
30
+ # o.on("-c", "--customer_images", "Retrieve customer images") do |c|
31
+ # options[:customer_images] = c
32
+ # end
33
+
34
+ o.on("-O org_resource_url", "The organization resource for which OS " +
35
+ "templates \n\t\t\t\t or customer images are to be retrieved.") do |org|
36
+ options[:orgResource] = org
37
+ end
38
+
39
+ o.on("-N node_resource_url", "The node resource for which OS templates " +
40
+ "or\n\t\t\t\t customer images are to be retrieved.") do |n|
41
+ options[:nodeResource] = n
42
+ end
43
+ end
44
+
45
+ argv = parse_options(opts, options)
46
+ return if !argv
47
+
48
+ authInfo = nil
49
+
50
+ with_target_vms(argv) do |machine|
51
+ authInfo = machine.provider_config.auth
52
+ end
53
+
54
+ if (options[:os_templates])
55
+
56
+ os_templates = get_os_templates(authInfo, options)
57
+
58
+ # If the OS templates is nil it means that the call was not successful
59
+ return 1 if(os_templates.nil?)
60
+
61
+ variables = {
62
+ :os_templates => os_templates
63
+ }
64
+
65
+ # Render the template and output directly to STDOUT
66
+ templates_root = Pathname.new(File.expand_path("../../../../templates", __FILE__))
67
+ template = templates_root.join("os_templates")
68
+ safe_puts(Vagrant::Util::TemplateRenderer.render(template, variables))
69
+
70
+ end
71
+
72
+ # Success, exit status 0
73
+ 0
74
+
75
+ end
76
+
77
+
78
+ # Parses the options passed in by the user
79
+ def parse_options(opts, options)
80
+
81
+ begin
82
+
83
+ argv = super_parse_options(opts)
84
+
85
+ raise OptionParser::MissingArgument if options[:orgResource].nil?
86
+ raise OptionParser::MissingArgument if options[:nodeResource].nil?
87
+ raise OptionParser::MissingArgument if options[:os_templates].nil? && options[:customer_images].nil?
88
+
89
+ return argv
90
+
91
+ rescue OptionParser::MissingArgument
92
+ raise Vagrant::Errors::CLIInvalidOptions, :help => opts.help.chomp
93
+ end
94
+
95
+ end
96
+
97
+ # Returns a list of OS templates for the given options
98
+ def get_os_templates(authInfo, options)
99
+
100
+ @logger.debug("Getting OS templates ...")
101
+
102
+ os_templates = nil
103
+
104
+ # If the authentication information is not specified in the Vagrantfile return a failure status
105
+ if(authInfo.nil? || authInfo.url.nil? || authInfo.applicationKey.nil? || authInfo.sharedSecret.nil?)
106
+ @env.ui.error(I18n.t('secured_cloud_vagrant.errors.unspecified_auth', :resource_type => "OS templates"))
107
+ return os_templates
108
+ end
109
+
110
+ begin
111
+
112
+ # Create a Secured Cloud Connection instance to connect to the SecuredCloud API
113
+ sc_connection = SecuredCloudConnection.new(authInfo.url, authInfo.applicationKey, authInfo.sharedSecret)
114
+
115
+ # Get the OS templates for the specified details
116
+ os_templates_urls = SecuredCloudRestClient.getOsTemplatesAvailable(sc_connection, options[:orgResource], options[:nodeResource])
117
+
118
+ if !os_templates_urls.nil?
119
+
120
+ # Create an array to hold the os templates details
121
+ os_templates = Hash.new
122
+
123
+ # Get the details for each retrieved os template resource URL and add it to the list
124
+ os_templates_urls.each do |os_template_url|
125
+ os_templates[os_template_url] = SecuredCloudRestClient.getOsTemplateDetails(sc_connection, os_template_url)
126
+ end
127
+
128
+ @logger.debug("Found #{os_templates.length} OS templates for organization '#{options[:orgResource]}' on node '#{options[:nodeResource]}'")
129
+
130
+ else
131
+
132
+ @logger.debug("No OS templates available for organization '#{options[:orgResource]}' on node '#{options[:nodeResource]}'")
133
+
134
+ end
135
+
136
+ rescue Errno::ETIMEDOUT
137
+ @env.ui.error(I18n.t("secured_cloud_vagrant.errors.request_timed_out", :request => "get the OS templates details"))
138
+ rescue Exception => e
139
+ @env.ui.error(I18n.t("secured_cloud_vagrant.errors.generic_error", :error_message => e.message))
140
+ end
141
+
142
+ return os_templates
143
+
144
+ end
145
+
146
+ end
147
+ end
148
+ end
149
+ end
@@ -0,0 +1,43 @@
1
+ require "vagrant"
2
+
3
+ module VagrantPlugins
4
+ module SecuredCloud
5
+ module Command
6
+
7
+ class SshConfig < Vagrant.plugin(2, :command)
8
+
9
+ def self.synopsis
10
+ "Outputs OpenSSH valid configuration to connect to the machine"
11
+ end
12
+
13
+ def execute
14
+ options = {}
15
+
16
+ opts = OptionParser.new do |o|
17
+ o.banner = "Usage: vagrant ssh-config [vm-name] [--host name]"
18
+ o.separator ""
19
+
20
+ o.on("--host COMMAND", "Name the host for the config..") do |h|
21
+ options[:host] = h
22
+ end
23
+ end
24
+
25
+ argv = parse_options(opts)
26
+ return if !argv
27
+
28
+ with_target_vms(argv, :single_target => true) do |machine|
29
+ env = machine.action(:read_ssh_info)
30
+
31
+ unless env[:vm_conn_info].nil? then
32
+ env[:ui].info(I18n.t('secured_cloud_vagrant.commands.vm-config', :host_name => env[:vm_conn_info][:host],
33
+ :port => env[:vm_conn_info][:port], :username => env[:vm_conn_info][:username]))
34
+ end
35
+ end
36
+
37
+ # Success, exit status 0
38
+ 0
39
+ end
40
+ end
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,49 @@
1
+ require "vagrant"
2
+
3
+ module VagrantPlugins
4
+ module SecuredCloud
5
+ module Configuration
6
+
7
+ class AuthenticationInfo < Vagrant.plugin(2, :config)
8
+
9
+ attr_accessor :url
10
+ attr_accessor :applicationKey
11
+ attr_accessor :sharedSecret
12
+
13
+ def initialize
14
+ @url = UNSET_VALUE
15
+ @applicationKey = UNSET_VALUE
16
+ @sharedSecret = UNSET_VALUE
17
+ end
18
+
19
+ def validate(machine)
20
+
21
+ end
22
+
23
+ def merge(other)
24
+
25
+ super.tap do |result|
26
+
27
+ result.url = (other.url == UNSET_VALUE) ? @url : other.url
28
+ result.applicationKey = (other.applicationKey == UNSET_VALUE) ? @url : other.applicationKey
29
+ result.sharedSecret = (other.sharedSecret == UNSET_VALUE) ? @sharedSecret : other.sharedSecret
30
+
31
+ end
32
+
33
+ end
34
+
35
+
36
+ def finalize!
37
+
38
+ @url = nil if(@url == UNSET_VALUE)
39
+ @applicationKey = nil if(@applicationKey == UNSET_VALUE)
40
+ @sharedSecret = nil if(@sharedSecret == UNSET_VALUE)
41
+
42
+ end
43
+
44
+ end
45
+
46
+ end
47
+ end
48
+ end
49
+
@@ -0,0 +1,87 @@
1
+ require "vagrant"
2
+
3
+ require_relative "virtual_machine"
4
+ require_relative "authentication_info"
5
+
6
+ module VagrantPlugins
7
+ module SecuredCloud
8
+ module Configuration
9
+
10
+ class Config < Vagrant.plugin(2, :config)
11
+
12
+ attr_accessor :vm
13
+ attr_accessor :auth
14
+
15
+
16
+ def initialize
17
+
18
+ @vm = VirtualMachine.new
19
+ @auth = AuthenticationInfo.new
20
+
21
+ end
22
+
23
+ def validate(machine)
24
+
25
+ errors = _detected_errors
26
+
27
+ # Validate the VM only if we don't specifically specify otherwise
28
+ if @vm.nil?
29
+ errors << "The VM properties must be properly defined "
30
+ else
31
+ @vm.validate(machine)
32
+ end
33
+
34
+ if @auth.nil?
35
+ errors << "The authentication properties must be properly defined "
36
+ else
37
+ @auth.validate(machine)
38
+ end
39
+
40
+ { "Secured Cloud Provider" => errors}
41
+
42
+ end
43
+
44
+ def merge(other)
45
+
46
+ super.tap do |result|
47
+
48
+ if(other.vm == UNSET_VALUE || other.vm.nil?)
49
+ result.vm = @vm
50
+ elsif @vm == UNSET_VALUE || @vm.nil?
51
+ result.vm = other.vm
52
+ else
53
+ result.vm = @vm.merge(other.vm)
54
+ end
55
+
56
+ if(other.auth == UNSET_VALUE || other.auth.nil?)
57
+ result.auth = @auth
58
+ elsif @auth == UNSET_VALUE || @auth.nil?
59
+ result.auth = other.auth
60
+ else
61
+ result.auth = @auth.merge(other.auth)
62
+ end
63
+
64
+ end
65
+ end
66
+
67
+ def finalize!
68
+
69
+ if (@vm == UNSET_VALUE || @vm == nil)
70
+ @vm = VirtualMachine.new
71
+ else
72
+ @vm.finalize!
73
+ end
74
+
75
+ if (@auth == UNSET_VALUE || @auth == nil)
76
+ @auth = VirtualMachine.new
77
+ else
78
+ @auth.finalize!
79
+ end
80
+
81
+ end
82
+
83
+ end
84
+
85
+ end
86
+ end
87
+ end
@@ -0,0 +1,71 @@
1
+ require "vagrant"
2
+
3
+ module VagrantPlugins
4
+ module SecuredCloud
5
+ module Configuration
6
+ class IpMapping < Vagrant.plugin(2, :config)
7
+
8
+ attr_accessor :privateIp
9
+ attr_accessor :newPublicIpCount
10
+ attr_accessor :publicIpsFromReserved
11
+
12
+ def initialize
13
+
14
+ @privateIp = UNSET_VALUE
15
+ @newPublicIpCount = UNSET_VALUE
16
+ @publicIpsFromReserved = UNSET_VALUE
17
+
18
+ end
19
+
20
+ def validate(machine)
21
+
22
+ errors = _detected_errors
23
+
24
+ if !@privateIp.nil? && !@privateIp.is_a?(String)
25
+ errors << "A valid private IP must be specified "
26
+ end
27
+
28
+ if !@newPublicIpCount.nil? && !@newPublicIpCount.is_a?(Integer)
29
+ errors << "A valid public IP count must be specified "
30
+ end
31
+
32
+ if !@publicIpsFromReserved.nil? && (!@publicIpsFromReserved.is_a?(String) || !@publicIpsFromReserved.respond_to?(:each))
33
+ errors << "A valid array of public IPs from reserve pool must be specified "
34
+ end
35
+
36
+ { "Secured Cloud Provider" => errors}
37
+
38
+ end
39
+
40
+
41
+ def merge(other)
42
+
43
+ super.tap do |result|
44
+
45
+ if(@privateIp == other.privateIp)
46
+
47
+ result.privateIp = @privateIp
48
+ result.newPublicIpCount = (other.newPublicIpCount == UNSET_VALUE) ? @newPublicIpCount : other.newPublicIpCount
49
+ result.publicIpsFromReserved = (other.publicIpsFromReserved == UNSET_VALUE) ? @publicIpsFromReserved : other.publicIpsFromReserved
50
+
51
+ end
52
+
53
+ end
54
+
55
+ end
56
+
57
+
58
+ def finalize!
59
+
60
+ @privateIp = nil if (@privateIp == UNSET_VALUE)
61
+ @newPublicIpCount = 0 if (@newPublicIpCount == UNSET_VALUE || @newPublicIpCount.nil?)
62
+ @publicIpsFromReserved = nil if (@publicIpsFromReserved == UNSET_VALUE)
63
+ @publicIpsFromReserved = [@publicIpsFromReserved] if @publicIpsFromReserved.is_a?(String)
64
+
65
+ end
66
+
67
+ end
68
+
69
+ end
70
+ end
71
+ end