vagrant-masonry 0.13.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 (55) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +3 -0
  3. data/.yardopts +6 -0
  4. data/CHANGELOG +190 -0
  5. data/Gemfile +16 -0
  6. data/LICENSE +15 -0
  7. data/README.md +129 -0
  8. data/docs/GettingStarted.markdown +175 -0
  9. data/examples/Vagrantfile +1 -0
  10. data/examples/roles.yaml +29 -0
  11. data/examples/vms.yaml +12 -0
  12. data/lib/config_builder.rb +24 -0
  13. data/lib/config_builder/action/load_extensions.rb +14 -0
  14. data/lib/config_builder/class_registry.rb +72 -0
  15. data/lib/config_builder/extension_handler.rb +22 -0
  16. data/lib/config_builder/filter.rb +6 -0
  17. data/lib/config_builder/filter/boxes.rb +22 -0
  18. data/lib/config_builder/filter/roles.rb +149 -0
  19. data/lib/config_builder/filter_stack.rb +37 -0
  20. data/lib/config_builder/loader.rb +23 -0
  21. data/lib/config_builder/loader/yaml.rb +44 -0
  22. data/lib/config_builder/loader/yaml_erb.rb +24 -0
  23. data/lib/config_builder/model.rb +67 -0
  24. data/lib/config_builder/model/base.rb +101 -0
  25. data/lib/config_builder/model/network/forwarded_port.rb +37 -0
  26. data/lib/config_builder/model/network/private_network.rb +15 -0
  27. data/lib/config_builder/model/provider/azure.rb +66 -0
  28. data/lib/config_builder/model/provider/libvirt.rb +108 -0
  29. data/lib/config_builder/model/provider/virtualbox.rb +35 -0
  30. data/lib/config_builder/model/provider/vmware.rb +40 -0
  31. data/lib/config_builder/model/provider/vmware_fusion.rb +8 -0
  32. data/lib/config_builder/model/provider/vmware_workstation.rb +8 -0
  33. data/lib/config_builder/model/provider/vsphere.rb +30 -0
  34. data/lib/config_builder/model/provisioner/file.rb +24 -0
  35. data/lib/config_builder/model/provisioner/puppet.rb +37 -0
  36. data/lib/config_builder/model/provisioner/puppet_server.rb +27 -0
  37. data/lib/config_builder/model/provisioner/shell.rb +27 -0
  38. data/lib/config_builder/model/root.rb +69 -0
  39. data/lib/config_builder/model/ssh.rb +110 -0
  40. data/lib/config_builder/model/synced_folder.rb +43 -0
  41. data/lib/config_builder/model/vm.rb +235 -0
  42. data/lib/config_builder/model/winrm.rb +56 -0
  43. data/lib/config_builder/model_delegator.rb +30 -0
  44. data/lib/config_builder/plugin.rb +15 -0
  45. data/lib/config_builder/runner.rb +33 -0
  46. data/lib/config_builder/version.rb +3 -0
  47. data/lib/vagrant-masonry.rb +1 -0
  48. data/spec/config_builder/filter/boxes_spec.rb +87 -0
  49. data/spec/config_builder/filter/roles_spec.rb +287 -0
  50. data/spec/config_builder/loader/yaml_spec.rb +76 -0
  51. data/spec/config_builder/model/provider/vmware_fusion_spec.rb +29 -0
  52. data/spec/spec_helper.rb +4 -0
  53. data/templates/locales/en.yml +11 -0
  54. data/vagrant-masonry.gemspec +24 -0
  55. metadata +128 -0
@@ -0,0 +1,24 @@
1
+ require 'erb'
2
+
3
+ class ConfigBuilder::Loader::YAML_ERB < ConfigBuilder::Loader::YAML
4
+
5
+ # Load configuration from a YAML file with ERB interpolation first
6
+ #
7
+ # @param file_path [String]
8
+ #
9
+ # @example the following config file will be processed by ERB first so it can
10
+ # determine whether to use the environment variable 'VAGRANT_MANIFEST' or the
11
+ # default value 'init.pp' for the puppet manifest file.
12
+ #
13
+ # ---
14
+ # provisioner:
15
+ # - type: puppet
16
+ # manifest_file: <%= ENV['VAGRANT_MANIFEST'] || 'init.pp' >
17
+ #
18
+ # @return [Hash]
19
+ def yamlfile(file_path)
20
+ ::YAML.load(::ERB.new(File.read(file_path)).result)
21
+ end
22
+
23
+ ConfigBuilder::Loader.register(:yaml_erb, self)
24
+ end
@@ -0,0 +1,67 @@
1
+ require 'vagrant/errors'
2
+ require 'config_builder/class_registry'
3
+ require 'config_builder/model_delegator'
4
+
5
+ module ConfigBuilder
6
+
7
+ module Model
8
+
9
+ require 'config_builder/model/base'
10
+
11
+ require 'config_builder/model/root'
12
+
13
+ require 'config_builder/model/ssh'
14
+ require 'config_builder/model/winrm'
15
+ #require 'config_builder/model/host'
16
+
17
+ require 'config_builder/model/vm'
18
+ require 'config_builder/model/synced_folder'
19
+
20
+ def self.generate(hash)
21
+ ConfigBuilder::Model::Root.new_from_hash(hash)
22
+ end
23
+
24
+ module Network
25
+ require 'config_builder/model/network/forwarded_port'
26
+ require 'config_builder/model/network/private_network'
27
+ end
28
+
29
+ module Provider
30
+
31
+ @registry = ConfigBuilder::ClassRegistry.new(:provider)
32
+
33
+ def self.new_from_hash(hash)
34
+ @registry.generate(hash)
35
+ end
36
+
37
+ def self.register(name, klass)
38
+ @registry.register(name, klass)
39
+ end
40
+
41
+ require 'config_builder/model/provider/virtualbox'
42
+ require 'config_builder/model/provider/vmware'
43
+ require 'config_builder/model/provider/vmware_fusion'
44
+ require 'config_builder/model/provider/vmware_workstation'
45
+ require 'config_builder/model/provider/libvirt'
46
+ require 'config_builder/model/provider/vsphere'
47
+ require 'config_builder/model/provider/azure'
48
+ end
49
+
50
+ module Provisioner
51
+
52
+ @registry = ConfigBuilder::ClassRegistry.new(:provisioner)
53
+
54
+ def self.new_from_hash(hash)
55
+ @registry.generate(hash)
56
+ end
57
+
58
+ def self.register(name, klass)
59
+ @registry.register(name, klass)
60
+ end
61
+
62
+ require 'config_builder/model/provisioner/shell'
63
+ require 'config_builder/model/provisioner/puppet'
64
+ require 'config_builder/model/provisioner/puppet_server'
65
+ end
66
+ end
67
+ end
@@ -0,0 +1,101 @@
1
+ # A ConfigBuilder model implements a logic-less interface to a component of
2
+ # Vagrant.
3
+ #
4
+ # A model should implement the following methods:
5
+ #
6
+ # ## `self.new_from_hash`
7
+ #
8
+ # This method takes an arbitrarily nested data structure of basic data types
9
+ # (Arrays, Hashes, Numerics, Strings, etc) and instantiates a new object
10
+ # with attributes set based on that data structure.
11
+ #
12
+ # ## `#to_proc`
13
+ #
14
+ # This method takes the object attributes and generates a lambda that will
15
+ # create a Vagrant config with the state specified by the attributes. The
16
+ # lambda should have an arity of one and should be passed a `config` object.
17
+ # The generated block will generate the Vagrant config that implements the
18
+ # behavior specified by the object attributes.
19
+ #
20
+ # If the Model delegates certain configuration to other models, the generated
21
+ # lambda should be able to evaluate lambdas from the delegated models.
22
+ #
23
+ # Implementing classes do not need to inherit from ConfigBuilder::Model::Base,
24
+ # but it makes life easier.
25
+ class ConfigBuilder::Model::Base
26
+
27
+ # Deserialize a hash into a configbuilder model
28
+ #
29
+ # @param attributes [Hash] The model attributes as represented in a hash.
30
+ # @return [Object < ConfigBuilder::Model]
31
+ def self.new_from_hash(attributes)
32
+ obj = new()
33
+ obj.attrs = attributes
34
+ obj
35
+ end
36
+
37
+ # @api private
38
+ def attrs=(config)
39
+ hash = config.inject({}) { |hash, (key, value)| hash[key.to_sym] = value; hash }
40
+
41
+ if @defaults
42
+ @attrs = @defaults.merge(hash)
43
+ else
44
+ @attrs = hash
45
+ end
46
+ end
47
+
48
+ # Generate a block based on configuration specified by the attributes
49
+ #
50
+ # @abstract
51
+ # @return [Proc]
52
+ def to_proc
53
+ raise NotImplementedError
54
+ end
55
+
56
+ # Generate a block based on the attribute configuration and call it with
57
+ # the given config.
58
+ #
59
+ # @param config [Vagrant.plugin('2', :config)]
60
+ # @return [void]
61
+ def call(config)
62
+ to_proc.call(config)
63
+ end
64
+
65
+ # @param identifier [Symbol]
66
+ #
67
+ # @return [Object] The value of the model attribute specified by `identifier`
68
+ #
69
+ # @todo validate identifier
70
+ def attr(identifier)
71
+ @attrs[identifier]
72
+ end
73
+ private :attr
74
+
75
+ # Conditionally evaluate a block with a model attribute if it's defined
76
+ #
77
+ # @since 0.6.0
78
+ #
79
+ # @param identifier [Symbol] The attribute identifier
80
+ #
81
+ # @return [void]
82
+ def with_attr(identifier)
83
+ val = @attrs[identifier]
84
+ unless val.nil?
85
+ yield val
86
+ end
87
+ end
88
+ private :with_attr
89
+
90
+ class << self
91
+
92
+ # @param identifier [Symbol]
93
+ def def_model_attribute(identifier)
94
+ model_attributes << identifier
95
+ end
96
+
97
+ def model_attributes
98
+ (@identifiers ||= [])
99
+ end
100
+ end
101
+ end
@@ -0,0 +1,37 @@
1
+ # Vagrant forwarded port model
2
+ #
3
+ # @see http://docs.vagrantup.com/v2/networking/forwarded_ports.html
4
+ class ConfigBuilder::Model::Network::ForwardedPort < ConfigBuilder::Model::Base
5
+
6
+ # @!attribute [rw] guest
7
+ # @return [Fixnum] The guest port
8
+ def_model_attribute :guest
9
+
10
+ # @!attribute [rw] host
11
+ # @return [Fixnum] The host port
12
+ def_model_attribute :host
13
+
14
+ # @!attribute [rw] auto_correct
15
+ # @return [Boolean] Whether to automatically correct port collisions
16
+ def_model_attribute :auto_correct
17
+
18
+ # @!attribute [rw] id
19
+ # @return [String, nil] An optional name used to identify this port forward
20
+ def_model_attribute :id
21
+
22
+ def initialize
23
+ @defaults = {:auto_correct => false, :id => nil}
24
+ end
25
+
26
+ def to_proc
27
+ Proc.new do |vm_config|
28
+ vm_config.network(
29
+ :forwarded_port,
30
+ :guest => attr(:guest),
31
+ :host => attr(:host),
32
+ :auto_correct => attr(:auto_correct),
33
+ :id => attr(:id),
34
+ )
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,15 @@
1
+ # Vagrant private network
2
+ #
3
+ # @see http://docs.vagrantup.com/v2/networking/private_network.html
4
+ class ConfigBuilder::Model::Network::PrivateNetwork < ConfigBuilder::Model::Base
5
+
6
+ # @!attribute [rw] :ip
7
+ # @return [String] The IP address to use for the private network interface
8
+ def_model_attribute :ip
9
+
10
+ def to_proc
11
+ Proc.new do |vm_config|
12
+ vm_config.network(:private_network, @attrs)
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,66 @@
1
+ # @see https://github.com/MSOpenTech/vagrant-azure
2
+ class ConfigBuilder::Model::Provider::Azure < ConfigBuilder::Model::Base
3
+
4
+ def_model_attribute :mgmt_certificate
5
+ def_model_attribute :mgmt_endpoint
6
+ def_model_attribute :subscription_id
7
+ def_model_attribute :storage_acct_name
8
+ def_model_attribute :storage_access_key
9
+
10
+ def_model_attribute :vm_name
11
+ def_model_attribute :vm_user
12
+ def_model_attribute :vm_password
13
+ def_model_attribute :vm_image
14
+ def_model_attribute :vm_location
15
+ def_model_attribute :vm_affinity_group
16
+
17
+ def_model_attribute :cloud_service_name
18
+ def_model_attribute :deployment_name
19
+ def_model_attribute :tcp_endpoints
20
+ def_model_attribute :ssh_private_key_file
21
+ def_model_attribute :ssh_certificate_file
22
+ def_model_attribute :ssh_port
23
+ def_model_attribute :vm_size
24
+ def_model_attribute :winrm_transport
25
+ def_model_attribute :winrm_http_port
26
+ def_model_attribute :winrm_https_port
27
+ def_model_attribute :availability_set_name
28
+
29
+ def_model_attribute :state_read_timeout
30
+
31
+ def initialize
32
+ @defaults = {}
33
+ end
34
+
35
+ def to_proc
36
+ Proc.new do |vm_config|
37
+ vm_config.provider 'azure' do |config|
38
+ with_attr(:mgmt_certificate) { |val| config.mgmt_certificate = val }
39
+ with_attr(:mgmt_endpoint) { |val| config.mgmt_endpoint = val }
40
+ with_attr(:subscription_id) { |val| config.subscription_id = val }
41
+ with_attr(:storage_acct_name) { |val| config.storage_acct_name = val }
42
+ with_attr(:storage_access_key) { |val| config.storage_access_key = val }
43
+ with_attr(:vm_name) { |val| config.vm_name = val }
44
+ with_attr(:vm_user) { |val| config.vm_user = val }
45
+ with_attr(:vm_password) { |val| config.vm_password = val }
46
+ with_attr(:vm_image) { |val| config.vm_image = val }
47
+ with_attr(:vm_location) { |val| config.vm_location = val }
48
+ with_attr(:vm_affinity_group) { |val| config.vm_affinity_group = val }
49
+ with_attr(:cloud_service_name) { |val| config.cloud_service_name = val }
50
+ with_attr(:deployment_name) { |val| config.deployment_name = val }
51
+ with_attr(:tcp_endpoints) { |val| config.tcp_endpoints = val }
52
+ with_attr(:ssh_private_key_file) { |val| config.ssh_private_key_file = val }
53
+ with_attr(:ssh_certificate_file) { |val| config.ssh_certificate_file = val }
54
+ with_attr(:ssh_port) { |val| config.ssh_port = val }
55
+ with_attr(:vm_size) { |val| config.vm_size = val }
56
+ with_attr(:winrm_transport) { |val| config.winrm_transport = val }
57
+ with_attr(:winrm_http_port) { |val| config.winrm_http_port = val }
58
+ with_attr(:winrm_https_port) { |val| config.winrm_https_port = val }
59
+ with_attr(:availability_set_name) { |val| config.availability_set_name = val }
60
+ with_attr(:state_read_timeout) { |val| config.state_read_timeout = val }
61
+ end
62
+ end
63
+ end
64
+
65
+ ConfigBuilder::Model::Provider.register('azure', self)
66
+ end
@@ -0,0 +1,108 @@
1
+ # @see http://github.com/pradels/vagrant-libvirt
2
+ class ConfigBuilder::Model::Provider::Libvirt < ConfigBuilder::Model::Base
3
+
4
+ # @!attribute [rw] uri
5
+ # @return [String] Manually specify URI
6
+ def_model_attribute :uri
7
+
8
+ # @!attribute [rw] driver
9
+ # @return [String] A hypervisor name to access via Libvirt.
10
+ def_model_attribute :driver
11
+
12
+ # @!attribute [rw] host
13
+ # @return [String] The name of the server, where libvirtd is running.
14
+ def_model_attribute :host
15
+
16
+ # @!attribute [rw] connect_via_ssh
17
+ # @return [String] If use ssh tunnel to connect to Libvirt.
18
+ def_model_attribute :connect_via_ssh
19
+
20
+ # @!attribute [rw] socket
21
+ # @return [String] Path towards the libvirt socket
22
+ def_model_attribute :socket
23
+
24
+ # @!attribute [rw] username
25
+ # @return [String] The username to access Libvirt.
26
+ def_model_attribute :username
27
+
28
+ # @!attribute [rw] password
29
+ # @return [String] Password for Libvirt connection.
30
+ def_model_attribute :password
31
+
32
+ # @!attribute [rw] id_ssh_key_file
33
+ # @return [String] ID SSH key file
34
+ def_model_attribute :id_ssh_key_file
35
+
36
+ # @!attribute [rw] storage_pool_name
37
+ # @return [String] Libvirt storage pool name, where box image and instance
38
+ # snapshots will be stored.
39
+ def_model_attribute :storage_pool_name
40
+
41
+ # @!attribute [rw] random_hostname
42
+ # @return [String] Turn on to prevent hostname conflicts
43
+ def_model_attribute :random_hostname
44
+
45
+ # @!attribute [rw] management_network_name
46
+ # @return [String] Libvirt default network name
47
+ def_model_attribute :management_network_name
48
+
49
+ # @!attribute [rw] management_network_address
50
+ # @return [String] Libvirt default network address
51
+ def_model_attribute :management_network_address
52
+
53
+ # @!attribute [rw] default_prefix
54
+ # @return [String] Default host prefix (alternative to use project folder
55
+ # name)
56
+ def_model_attribute :default_prefix
57
+
58
+ # Domain specific settings used while creating new domain.
59
+ def_model_attribute :memory
60
+ def_model_attribute :cpus
61
+ def_model_attribute :cpu_mode
62
+ def_model_attribute :disk_bus
63
+ def_model_attribute :nested
64
+ def_model_attribute :volume_cache
65
+ def_model_attribute :kernel
66
+ def_model_attribute :cmd_line
67
+ def_model_attribute :initrd
68
+
69
+ def initialize
70
+ @defaults = {}
71
+ end
72
+
73
+ def to_proc
74
+ Proc.new do |vm_config|
75
+ vm_config.provider 'libvirt' do |vb_config|
76
+
77
+ with_attr(:uri) { |val| vb_config.host = val }
78
+ with_attr(:driver) { |val| vb_config.host = val }
79
+ with_attr(:host) { |val| vb_config.host = val }
80
+ with_attr(:connect_via_ssh) { |val| vb_config.connect_via_ssh = val }
81
+ with_attr(:socket) { |val| vb_config.socket = val }
82
+ with_attr(:username) { |val| vb_config.username = val }
83
+ with_attr(:password) { |val| vb_config.username = val }
84
+ with_attr(:id_ssh_key_file) { |val| vb_config.id_ssh_key_file = val }
85
+ with_attr(:storage_pool_name) { |val| vb_config.storage_pool_name = val }
86
+ with_attr(:random_hostname) { |val| vb_config.random_hostname = val }
87
+ with_attr(:management_network_name) { |val|
88
+ vb_config.username = val
89
+ }
90
+ with_attr(:management_network_address) { |val|
91
+ vb_config.username = val
92
+ }
93
+ with_attr(:default_prefix) { |val| vb_config.username = val }
94
+ with_attr(:memory) { |val| vb_config.memory = val }
95
+ with_attr(:cpus) { |val| vb_config.cpus = val }
96
+ with_attr(:cpu_mode) { |val| vb_config.cpu_mode = val }
97
+ with_attr(:disk_bus) { |val| vb_config.disk_bus = val }
98
+ with_attr(:nested) { |val| vb_config.nested = val }
99
+ with_attr(:volume_cache) { |val| vb_config.volume_cache = val }
100
+ with_attr(:kernel) { |val| vb_config.kernel = val }
101
+ with_attr(:cmd_line) { |val| vb_config.cmd_line = val }
102
+ with_attr(:initrd) { |val| vb_config.initrd = val }
103
+ end
104
+ end
105
+ end
106
+
107
+ ConfigBuilder::Model::Provider.register('libvirt', self)
108
+ end
@@ -0,0 +1,35 @@
1
+ # @see http://docs.vagrantup.com/v2/virtualbox/configuration.html
2
+ class ConfigBuilder::Model::Provider::Virtualbox < ConfigBuilder::Model::Base
3
+
4
+ # @!attribute [rw] name
5
+ # @return [String] The name of the created VM in the Virtualbox GUI
6
+ def_model_attribute :name
7
+
8
+ # @!attribute [rw] customize
9
+ # @return [Array<String>] A list of customize arguments to use upon VM instantiation.
10
+ def_model_attribute :customize
11
+
12
+ # @!attribute [rw] gui
13
+ # @return [Boolean] Whether the GUI should be launched when the VM is created
14
+ def_model_attribute :gui
15
+
16
+ def initialize
17
+ @defaults = {:customize => []}
18
+ end
19
+
20
+ def to_proc
21
+ Proc.new do |vm_config|
22
+ vm_config.provider 'virtualbox' do |vb_config|
23
+ with_attr(:name) { |val| vb_config.name = val }
24
+
25
+ attr(:customize).each do |cmd|
26
+ vb_config.customize cmd
27
+ end
28
+
29
+ with_attr(:gui) { |val| vb_config.gui = val }
30
+ end
31
+ end
32
+ end
33
+
34
+ ConfigBuilder::Model::Provider.register('virtualbox', self)
35
+ end