vagrant-startcloud 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -1,19 +1,10 @@
1
1
  # Vagrant StartCloud Plugin
2
2
 
3
- [![Gem Version](https://badge.fury.io/rb/vagrant-startcloud.svg)](https://badge.fury.io/rb/vagrant-startcloud)
4
- [![Build Status](https://github.com/STARTcloud/vagrant-startcloud/workflows/CI/badge.svg)](https://github.com/STARTcloud/vagrant-startcloud/actions)
5
-
6
3
  A Vagrant plugin that provides support for provisioning machines using YAML configuration with multi-provider support.
7
4
 
8
- ## Features
5
+ ## Overview
9
6
 
10
- - YAML-based configuration for Vagrant machines
11
- - Support for multiple providers (VirtualBox, Zones, etc.)
12
- - Network configuration management
13
- - Shared folder configuration
14
- - Plugin management
15
- - Provisioner configuration (Shell, Ansible)
16
- - Provider-specific settings
7
+ This plugin allows you to define your Vagrant configuration in a YAML file (Hosts.yml) instead of a Ruby-based Vagrantfile. It supports both VirtualBox and Zones providers, and handles network configuration, disk management, shared folders, and more.
17
8
 
18
9
  ## Installation
19
10
 
@@ -23,157 +14,163 @@ vagrant plugin install vagrant-startcloud
23
14
 
24
15
  ## Usage
25
16
 
26
- 1. Create a `Hosts.yml` file in your project directory:
17
+ 1. Create a minimal Vagrantfile:
18
+
19
+ ```ruby
20
+ # Vagrantfile
21
+ Vagrant.configure('2') do |config|
22
+ StartCloud.configure(config)
23
+ end
24
+ ```
25
+
26
+ 2. Define your configuration in Hosts.yml:
27
27
 
28
28
  ```yaml
29
29
  hosts:
30
30
  - settings:
31
31
  hostname: web
32
32
  domain: example.com
33
- server_id: '1001'
33
+ server_id: "1001"
34
34
  box: ubuntu/focal64
35
35
  provider_type: virtualbox
36
- virtualbox:
37
- memory: 2048
38
- cpus: 2
36
+ memory: 2048
37
+ vcpus: 2
38
+ setup_wait: 300
39
+ vagrant_user: vagrant
40
+
39
41
  networks:
40
42
  - type: private_network
41
- ip: 192.168.50.10
42
- folders:
43
- - host: ./app
44
- guest: /var/www/app
45
- options:
46
- type: rsync
47
- provisioning:
48
- shell:
49
- path: setup.sh
50
- ```
51
-
52
- 2. Run Vagrant with the StartCloud plugin:
43
+ address: 192.168.56.10
44
+ netmask: 255.255.255.0
45
+ gateway: 192.168.56.1
46
+ dhcp4: false
47
+ autoconf: true
48
+
49
+ disks:
50
+ boot:
51
+ size: 40G
52
+ data:
53
+ size: 100G
54
+ mount: /data
53
55
 
54
- ```bash
55
- vagrant startcloud up
56
+ folders:
57
+ - map: ./app
58
+ to: /var/www/app
59
+ type: rsync
60
+ owner: www-data
61
+ group: www-data
56
62
  ```
57
63
 
58
64
  ## Configuration Reference
59
65
 
60
66
  ### Settings
61
67
 
62
- - `hostname`: Machine hostname
68
+ - `hostname`: VM hostname
63
69
  - `domain`: Domain name
64
- - `server_id`: Unique identifier for the machine
65
- - `box`: Vagrant box name
66
- - `box_version`: (Optional) Specific box version
67
- - `box_url`: (Optional) Custom box URL
68
- - `provider_type`: Provider to use (virtualbox, zones)
70
+ - `server_id`: Unique identifier for the VM
71
+ - `box`: Vagrant box to use
72
+ - `provider_type`: Provider to use (virtualbox or zones)
73
+ - `memory`: Memory allocation in MB
74
+ - `vcpus`: Number of virtual CPUs
75
+ - `setup_wait`: Boot timeout in seconds
76
+ - `vagrant_user`: SSH username
69
77
 
70
78
  ### Networks
71
79
 
72
80
  ```yaml
73
81
  networks:
74
- - type: private_network
75
- ip: 192.168.50.10
82
+ - type: private_network # or public_network
83
+ address: 192.168.56.10
76
84
  netmask: 255.255.255.0
77
- gateway: 192.168.50.1
78
- dhcp: true
79
- auto_config: true
85
+ gateway: 192.168.56.1
86
+ dhcp4: false
87
+ autoconf: true
88
+ mac: "00:11:22:33:44:55" # optional
89
+ nic_type: "82540EM" # optional
80
90
  ```
81
91
 
82
- ### Shared Folders
92
+ ### Disks
83
93
 
84
94
  ```yaml
85
- folders:
86
- - host: ./app
87
- guest: /var/www/app
88
- options:
89
- type: rsync
90
- owner: www-data
91
- group: www-data
95
+ disks:
96
+ boot:
97
+ size: 40G
98
+ additional_disks:
99
+ - volume_name: data
100
+ size: 100G
101
+ port: 1
92
102
  ```
93
103
 
94
- ### Provisioners
104
+ ### Shared Folders
95
105
 
96
106
  ```yaml
97
- provisioning:
98
- shell:
99
- path: setup.sh
100
- args: ['--debug']
101
- ansible:
102
- playbook: playbook.yml
103
- install_mode: pip
107
+ folders:
108
+ - map: ./local/path
109
+ to: /vm/path
110
+ type: rsync # or nfs, virtualbox
111
+ owner: vagrant
112
+ group: vagrant
113
+ mount_options: [] # optional
104
114
  ```
105
115
 
106
- ### Provider Settings
116
+ ### Provider-Specific Settings
107
117
 
108
118
  #### VirtualBox
109
119
 
110
120
  ```yaml
111
- virtualbox:
112
- memory: 2048
113
- cpus: 2
114
- gui: false
115
- customize:
116
- - ['modifyvm', '{{.Name}}', '--cpuexecutioncap', '50']
121
+ settings:
122
+ provider_type: virtualbox
123
+ show_console: false
124
+ firmware_type: UEFI # optional
125
+ vbox:
126
+ directives: # optional
127
+ - directive: usb
128
+ value: "on"
117
129
  ```
118
130
 
119
131
  #### Zones
120
132
 
121
133
  ```yaml
134
+ settings:
135
+ provider_type: zones
122
136
  zones:
123
- memory: 2048
124
- cpus: 2
125
- brand: lx
126
- image: ubuntu-20.04
127
- ```
128
-
129
- ## Commands
130
-
131
- - `vagrant startcloud`: Main command
132
- - `vagrant startcloud --list`: List configured machines
133
- - `vagrant startcloud --config FILE`: Use custom config file
134
- - `vagrant startcloud MACHINE`: Configure specific machine
135
-
136
- ## Development
137
-
138
- 1. Clone the repository:
139
- ```bash
140
- git clone https://github.com/STARTcloud/vagrant-startcloud.git
141
- cd vagrant-startcloud
137
+ brand: bhyve
138
+ autostart: true
142
139
  ```
143
140
 
144
- 2. Install dependencies:
145
- ```bash
146
- bundle install
141
+ ## Converting from Traditional Vagrantfile
142
+
143
+ This plugin replaces complex Vagrantfile configurations with a structured YAML format. For example, instead of:
144
+
145
+ ```ruby
146
+ Vagrant.configure("2") do |config|
147
+ config.vm.define "web" do |web|
148
+ web.vm.box = "ubuntu/focal64"
149
+ web.vm.network "private_network", ip: "192.168.56.10"
150
+ web.vm.provider "virtualbox" do |vb|
151
+ vb.memory = 2048
152
+ vb.cpus = 2
153
+ end
154
+ end
155
+ end
147
156
  ```
148
157
 
149
- 3. Run tests:
150
- ```bash
151
- bundle exec rake
152
- ```
158
+ You can use:
153
159
 
154
- 4. Build and install locally:
155
- ```bash
156
- bundle exec rake gem:install
160
+ ```yaml
161
+ hosts:
162
+ - settings:
163
+ hostname: web
164
+ domain: example.com
165
+ box: ubuntu/focal64
166
+ provider_type: virtualbox
167
+ memory: 2048
168
+ vcpus: 2
169
+ networks:
170
+ - type: private_network
171
+ address: 192.168.56.10
157
172
  ```
158
173
 
159
- ## Contributing
160
-
161
- 1. Fork it
162
- 2. Create your feature branch (`git checkout -b my-new-feature`)
163
- 3. Commit your changes (`git commit -am 'Add some feature'`)
164
- 4. Push to the branch (`git push origin my-new-feature`)
165
- 5. Create new Pull Request
166
-
167
174
  ## License
168
175
 
169
- This project is licensed under the AGPL-3.0 License - see the [LICENSE](LICENSE) file for details.
170
-
171
- ## Authors
172
-
173
- - Mark Gilbert ([@Makr91](https://github.com/Makr91))
174
- - Mark Gilbert ([@MarkProminic](https://github.com/MarkProminic))
175
-
176
- ## Acknowledgments
177
-
178
- - Based on the core_provisioner concept
179
- - Inspired by vagrant-zones and vagrant-scp-sync plugins
176
+ AGPL-3.0
@@ -0,0 +1,78 @@
1
+ # frozen_string_literal: true
2
+
3
+ module VagrantPlugins
4
+ module StartCloud
5
+ module Action
6
+ class ConfigureDisks
7
+ def initialize(app, env)
8
+ @app = app
9
+ @env = env
10
+ @machine = env[:machine]
11
+ @provider = env[:provider]
12
+ end
13
+
14
+ def call(env)
15
+ config = @machine.config.startcloud
16
+ disks = config.disks
17
+
18
+ if disks && !disks.empty?
19
+ @machine.ui.info I18n.t('vagrant_startcloud.configuring.disks')
20
+
21
+ case @provider
22
+ when :virtualbox
23
+ configure_virtualbox_disks(disks)
24
+ when :zones
25
+ configure_zones_disks(disks)
26
+ end
27
+ end
28
+
29
+ @app.call(env)
30
+ end
31
+
32
+ private
33
+
34
+ def configure_virtualbox_disks(disks)
35
+ return unless disks['additional_disks']
36
+
37
+ disks_directory = File.join(@env[:root_path], 'disks')
38
+ FileUtils.mkdir_p(disks_directory) unless File.directory?(disks_directory)
39
+
40
+ disks['additional_disks'].each do |disk|
41
+ local_disk_filename = File.join(disks_directory, "#{disk['volume_name']}.vdi")
42
+
43
+ unless File.exist?(local_disk_filename)
44
+ disk_size_gb = disk['size'].match(/(\d+(\.\d+)?)/)[0].to_f
45
+ disk_size_mb = (disk_size_gb * 1024).to_i
46
+
47
+ @machine.provider.driver.create_disk(
48
+ local_disk_filename,
49
+ disk_size_mb,
50
+ { format: 'VDI' }
51
+ )
52
+ end
53
+
54
+ @machine.provider.driver.attach_disk(
55
+ local_disk_filename,
56
+ {
57
+ controller: 'SCSI',
58
+ port: disk['port'],
59
+ device: 0
60
+ }
61
+ )
62
+ end
63
+ end
64
+
65
+ def configure_zones_disks(disks)
66
+ return unless @machine.provider.capability?(:configure_disks)
67
+
68
+ disk_options = {
69
+ boot: disks['boot'],
70
+ additional: disks['additional_disks']
71
+ }.compact
72
+
73
+ @machine.provider.capability(:configure_disks, disk_options)
74
+ end
75
+ end
76
+ end
77
+ end
78
+ end
@@ -22,8 +22,15 @@ module VagrantPlugins
22
22
  netmask: network['netmask'],
23
23
  gateway: network['gateway'],
24
24
  dhcp: network['dhcp4'],
25
- auto_config: network['autoconf']
26
- }
25
+ dhcp4: network['dhcp4'],
26
+ dhcp6: network['dhcp6'],
27
+ auto_config: network['autoconf'],
28
+ mac: format_mac_address(network['mac'], @provider),
29
+ nic_type: network['nic_type'],
30
+ vlan: network['vlan'],
31
+ dns: network['dns'],
32
+ bridge: network['bridge']
33
+ }.compact
27
34
 
28
35
  case network['type']
29
36
  when 'host'
@@ -51,59 +58,58 @@ module VagrantPlugins
51
58
  end
52
59
 
53
60
  def configure_virtualbox_network(machine, type, options)
61
+ adapter_number = machine.provider.driver.read_network_interfaces.length + 1
62
+ network_options = {
63
+ adapter: adapter_number,
64
+ ip: options[:ip],
65
+ netmask: options[:netmask],
66
+ auto_config: options[:auto_config],
67
+ mac: options[:mac],
68
+ nic_type: options[:nic_type],
69
+ vlan: options[:vlan]
70
+ }.compact
71
+
54
72
  case type
55
73
  when 'private_network'
56
- machine.provider.capability(
57
- :configure_networks,
58
- [{
59
- type: :static,
60
- adapter: machine.provider.driver.read_network_interfaces.length + 1,
61
- ip: options[:ip],
62
- netmask: options[:netmask],
63
- auto_config: options[:auto_config]
64
- }]
65
- )
74
+ network_options[:type] = :static
75
+ machine.provider.capability(:configure_networks, [network_options])
66
76
  when 'public_network'
67
- machine.provider.capability(
68
- :configure_networks,
69
- [{
70
- type: :bridged,
71
- adapter: machine.provider.driver.read_network_interfaces.length + 1,
72
- ip: options[:ip],
73
- netmask: options[:netmask],
74
- auto_config: options[:auto_config]
75
- }]
76
- )
77
+ network_options[:type] = :bridged
78
+ network_options[:bridge] = options[:bridge] if options[:bridge]
79
+ machine.provider.capability(:configure_networks, [network_options])
77
80
  end
78
81
  end
79
82
 
80
83
  def configure_zones_network(machine, type, options)
84
+ network_options = {
85
+ type: :vnic,
86
+ ip: options[:ip],
87
+ netmask: options[:netmask],
88
+ gateway: options[:gateway],
89
+ dhcp4: options[:dhcp4],
90
+ dhcp6: options[:dhcp6],
91
+ autoconf: options[:auto_config],
92
+ mac: options[:mac],
93
+ dns: options[:dns]
94
+ }.compact
95
+
81
96
  case type
82
97
  when 'private_network'
83
- machine.provider.capability(
84
- :configure_networks,
85
- [{
86
- type: :vnic,
87
- ip: options[:ip],
88
- netmask: options[:netmask],
89
- gateway: options[:gateway],
90
- dhcp4: options[:dhcp],
91
- autoconf: options[:auto_config]
92
- }]
93
- )
98
+ machine.provider.capability(:configure_networks, [network_options])
94
99
  when 'public_network'
95
- machine.provider.capability(
96
- :configure_networks,
97
- [{
98
- type: :vnic,
99
- public: true,
100
- ip: options[:ip],
101
- netmask: options[:netmask],
102
- gateway: options[:gateway],
103
- dhcp4: options[:dhcp],
104
- autoconf: options[:auto_config]
105
- }]
106
- )
100
+ network_options[:public] = true
101
+ machine.provider.capability(:configure_networks, [network_options])
102
+ end
103
+ end
104
+
105
+ def format_mac_address(mac, provider)
106
+ return nil unless mac
107
+
108
+ case provider
109
+ when :virtualbox
110
+ mac.tr(':', '') # VirtualBox requires MAC without colons
111
+ else
112
+ mac # Other providers use standard MAC format
107
113
  end
108
114
  end
109
115
  end
@@ -4,24 +4,26 @@ module VagrantPlugins
4
4
  module StartCloud
5
5
  module Action
6
6
  class ConfigureProviders
7
- def initialize(app, _env)
7
+ def initialize(app, env)
8
8
  @app = app
9
+ @env = env
10
+ @machine = env[:machine]
11
+ @provider = env[:provider]
9
12
  end
10
13
 
11
14
  def call(env)
12
- machine = env[:machine]
13
- config = machine.config.startcloud
15
+ config = @machine.config.startcloud
14
16
  settings = config.settings
15
17
 
16
18
  if settings && settings['provider_type']
17
- env[:ui].info(I18n.t('vagrant_startcloud.configuring.provider',
18
- provider: settings['provider_type']))
19
+ @machine.ui.info I18n.t('vagrant_startcloud.configuring.provider',
20
+ provider: settings['provider_type'])
19
21
 
20
22
  case settings['provider_type']
21
23
  when 'virtualbox'
22
- configure_virtualbox(machine, settings)
24
+ configure_virtualbox(settings)
23
25
  when 'zones'
24
- configure_zones(machine, settings, config.zones)
26
+ configure_zones(settings, config.zones)
25
27
  end
26
28
  end
27
29
 
@@ -30,55 +32,49 @@ module VagrantPlugins
30
32
 
31
33
  private
32
34
 
33
- def configure_virtualbox(machine, settings)
34
- machine.config.vm.provider :virtualbox do |vb|
35
- memory = if settings['memory'].to_s =~ /gb|g/i
36
- 1024 * settings['memory'].to_s.tr('^0-9', '').to_i
37
- else
38
- settings['memory'].to_s.tr('^0-9', '').to_i
39
- end
40
-
41
- vb.name = "#{settings['server_id']}--#{settings['hostname']}.#{settings['domain']}"
42
- vb.gui = settings['show_console']
43
- vb.customize ['modifyvm', :id, '--ostype', settings['os_type']] if settings['os_type']
44
- vb.customize ['modifyvm', :id, '--vrdeport', settings['consoleport']] if settings['consoleport']
45
- vb.customize ['modifyvm', :id, '--vrdeaddress', settings['consolehost']] if settings['consolehost']
46
- vb.customize ['modifyvm', :id, '--cpus', settings['vcpus']] if settings['vcpus']
47
- vb.customize ['modifyvm', :id, '--memory', memory] if memory.positive?
48
- vb.customize ['modifyvm', :id, '--firmware', 'efi'] if settings['firmware_type'] == 'UEFI'
49
-
50
- # Default VirtualBox settings
51
- vb.customize ['modifyvm', :id, '--vrde', 'on']
52
- vb.customize ['modifyvm', :id, '--natdnsproxy1', 'off']
53
- vb.customize ['modifyvm', :id, '--natdnshostresolver1', 'off']
54
- vb.customize ['modifyvm', :id, '--accelerate3d', 'off']
55
- vb.customize ['modifyvm', :id, '--vram', '256']
56
-
57
- # Apply custom VirtualBox directives if specified
58
- if settings['vbox']&.dig('directives')
59
- settings['vbox']['directives'].each do |directive|
60
- vb.customize ['modifyvm', :id, "--#{directive['directive']}", directive['value']]
61
- end
62
- end
35
+ def configure_virtualbox(settings)
36
+ @machine.provider.driver.customize ['modifyvm', @machine.id, '--memory', calculate_memory(settings['memory'])]
37
+ @machine.provider.driver.customize ['modifyvm', @machine.id, '--cpus', settings['vcpus']] if settings['vcpus']
38
+ @machine.provider.driver.customize ['modifyvm', @machine.id, '--ostype', settings['os_type']] if settings['os_type']
39
+
40
+ @machine.provider.driver.customize ['modifyvm', @machine.id, '--firmware', 'efi'] if settings['firmware_type'] == 'UEFI'
41
+
42
+ # Configure VirtualBox-specific settings
43
+ @machine.provider.driver.customize ['modifyvm', @machine.id, '--vrde', 'on']
44
+ @machine.provider.driver.customize ['modifyvm', @machine.id, '--natdnsproxy1', 'off']
45
+ @machine.provider.driver.customize ['modifyvm', @machine.id, '--natdnshostresolver1', 'off']
46
+ @machine.provider.driver.customize ['modifyvm', @machine.id, '--accelerate3d', 'off']
47
+ @machine.provider.driver.customize ['modifyvm', @machine.id, '--vram', '256']
48
+
49
+ # Apply custom VirtualBox directives if specified
50
+ return unless settings['vbox']&.dig('directives')
51
+
52
+ settings['vbox']['directives'].each do |directive|
53
+ @machine.provider.driver.customize ['modifyvm', @machine.id, "--#{directive['directive']}", directive['value']]
63
54
  end
64
55
  end
65
56
 
66
- def configure_zones(machine, settings, zones_config)
67
- machine.config.vm.provider :zones do |zones|
68
- zones.hostname = "#{settings['subdomain']}.#{settings['domain']}"
69
- zones.name = "#{settings['partition_id']}--#{settings['subdomain']}.#{settings['domain']}"
70
- zones.partition_id = settings['server_id']
57
+ def configure_zones(settings, zones_config)
58
+ return unless @machine.provider.capability?(:configure_zone)
71
59
 
72
- # Map settings to zones provider configuration
73
- zones_config.each do |key, value|
74
- zones.send("#{key}=", value) if zones.respond_to?("#{key}=")
75
- end
60
+ zone_options = {
61
+ hostname: "#{settings['hostname']}.#{settings['domain']}",
62
+ brand: zones_config['brand'],
63
+ memory: settings['memory'],
64
+ cpus: settings['vcpus'],
65
+ autostart: zones_config['autostart']
66
+ }.compact
67
+
68
+ @machine.provider.capability(:configure_zone, zone_options)
69
+ end
70
+
71
+ def calculate_memory(memory)
72
+ return 1024 unless memory # Default to 1GB if not specified
76
73
 
77
- # Set required settings
78
- zones.memory = settings['memory']
79
- zones.cpus = settings['vcpus']
80
- zones.brand = zones_config['brand']
81
- zones.image = zones_config['image']
74
+ if memory.to_s =~ /gb|g/i
75
+ 1024 * memory.to_s.tr('^0-9', '').to_i
76
+ else
77
+ memory.to_s.tr('^0-9', '').to_i
82
78
  end
83
79
  end
84
80
  end