vagrant-subutai 7.0.0 → 7.0.1

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0f1ffa3b3284d337a4a95e72bc6d4646018dd918
4
- data.tar.gz: 56d9b489baaba74456e6dc4805f9862aaf31e93d
3
+ metadata.gz: 0fb87f283d63e40502762bcc7c5f51cc8b10d7d9
4
+ data.tar.gz: 9fd407a7c78bcca77980fd11384f06ac1dedbff6
5
5
  SHA512:
6
- metadata.gz: a30ba866838451e1b6d5a6c5542a2d1cf9f549ca512ee1bb4591cd1455d8c887a2d9bb12de1681f79d5c45af75f66196ce15b73786c7aa179703f309e434c6af
7
- data.tar.gz: 6c4720a5f36afabdca01cf0db9fdd32a110de9f8ad019f304ac063b759226bc2aee7e03b3f6f92c3c44fa353a642678956bcbac874065f18222d3af719a0cb45
6
+ metadata.gz: cb30136c96d640b7a9d4ac660b4ad836c2cfa660437e3fdee12bca47f4ee024da35d081de70ebcbc95ccfb56a97445bfff26e5739964f571284102dff749984c
7
+ data.tar.gz: 365aa19f7d517c4ac6e1cfee3096ce409a9b13b8fd18a06097ed4b9f8d2e6dd097871813f56ed8d94a0eaabb81ecb09a611038737954090ed7a1ba7e6211f746
data/CHANGELOG.md CHANGED
@@ -52,9 +52,15 @@ BUG FIXES:
52
52
  FEATURES:
53
53
  - User configuration new keys added (LIBVIRT_USER, LIBVIRT_HOST, LIBVIRT_PORT, LIBVIRT_MACVTAP, LIBVIRT_NO_BRIDGE)
54
54
 
55
- ## 7.0.0. (May 9, 2018)
55
+ ## 7.0.0 (May 9, 2018)
56
56
 
57
57
  FEATURES:
58
58
  - Support Vmware desktop and Parallels hypervisor
59
59
  - Auto registration PeerOs to Bazaar
60
- - User configuration new keys added (BAZAAR_NO_AUTO)
60
+ - User configuration new keys added (BAZAAR_NO_AUTO)
61
+
62
+ ## 7.0.1 (May 21, 2018)
63
+
64
+ FEATURES:
65
+ - Support HyperV hypervisor
66
+ - Improved validation (user configuration)
@@ -0,0 +1,61 @@
1
+ require_relative '../vagrant-subutai'
2
+
3
+
4
+ module VagrantSubutai
5
+ class CreateDisk < Vagrant.plugin(2, :provisioner)
6
+ attr_reader :machine
7
+ attr_reader :config
8
+
9
+ # Initializes the provisioner with the machine that it will be
10
+ # provisioning along with the provisioner configuration (if there
11
+ # is any).
12
+ #
13
+ # The provisioner should _not_ do anything at this point except
14
+ # initialize internal state.
15
+ #
16
+ # @param [Machine] machine The machine that this will be provisioning.
17
+ # @param [Object] config Provisioner configuration, if one was set.
18
+ def initialize(machine, config)
19
+ @machine = machine
20
+ @config = config
21
+ end
22
+
23
+ # Called with the root configuration of the machine so the provisioner
24
+ # can add some configuration on top of the machine.
25
+ #
26
+ # During this step, and this step only, the provisioner should modify
27
+ # the root machine configuration to add any additional features it
28
+ # may need. Examples include sharing folders, networking, and so on.
29
+ # This step is guaranteed to be called before any of those steps are
30
+ # done so the provisioner may do that.
31
+ #
32
+ # No return value is expected.
33
+ def configure(root_config)
34
+ end
35
+
36
+ # This is the method called when the actual provisioning should be
37
+ # done. The communicator is guaranteed to be ready at this point,
38
+ # and any shared folders or networks are already setup.
39
+ #
40
+ # No return value is expected.
41
+ def provision
42
+ has_grow, grow_by = SubutaiDisk.has_grow
43
+ file_disk = SubutaiDisk.file_path(grow_by, "hyper_v")
44
+
45
+ unless File.exist?(file_disk)
46
+ Put.warn "Disk size is growing by #{grow_by} gb."
47
+ if has_grow
48
+ if SubutaiDisk.hyperv_create_disk(grow_by, file_disk)
49
+ SubutaiDisk.save_conf(grow_by)
50
+ end
51
+ end
52
+ end
53
+ end
54
+
55
+ # This is the method called when destroying a machine that allows
56
+ # for any state related to the machine created by the provisioner
57
+ # to be cleaned up.
58
+ def cleanup
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,18 @@
1
+ param (
2
+ [string]$VmId = $(throw "-VmId is required."),
3
+ [string]$DiskPath = $(throw "-DiskPath is required."),
4
+ [Int32]$DiskSize = $(throw "-DiskSize is required.")
5
+ )
6
+
7
+ try {
8
+ $vm = Get-VM -Id $VmId -ErrorAction "stop"
9
+
10
+ # create new disk
11
+ # converting GB to Byte
12
+ NEW-VHD -Dynamic $DiskPath -SizeBytes $($DiskSize*1073741824)
13
+ # attach new disk to VM
14
+ ADD-VMHardDiskDrive -vmname $vm.Name -path $DiskPath -ControllerType SCSI
15
+ }
16
+ catch {
17
+ Write-Error-Message "Failed to create disk or attach to VM "
18
+ }
@@ -0,0 +1,17 @@
1
+ Try {
2
+ $adapters = Get-NetAdapter -Physical | where status -eq 'up'
3
+
4
+ foreach ($adapter in $adapters) {
5
+ $switch = Hyper-V\Get-VMSwitch -SwitchType External -ErrorAction SilentlyContinue | where { $_.NetAdapterInterfaceDescription -eq $adapter.InterfaceDescription }
6
+ if ($switch -eq $null) {
7
+ $switch = Hyper-V\New-VMSwitch -Name 'vagrant-subutai' -ErrorAction SilentlyContinue -NetAdapterName $adapter.Name -AllowManagementOS $TRUE -Notes 'Parent OS, VMs, WiFi'
8
+ }
9
+
10
+ if ($switch -ne $null) {
11
+ break
12
+ }
13
+ }
14
+ }
15
+ Catch {
16
+
17
+ }
@@ -6,6 +6,8 @@ require 'json'
6
6
 
7
7
  require_relative 'subutai_net'
8
8
  require_relative 'subutai_hooks'
9
+ require_relative 'subutai_validation'
10
+ require_relative '../../../lib/vagrant-subutai/util/powershell'
9
11
 
10
12
  # Vagrant Driven Subutai Configuration
11
13
  # noinspection RubyTooManyMethodsInspection
@@ -114,6 +116,11 @@ module SubutaiConfig
114
116
  @cmd == 'up'
115
117
  end
116
118
 
119
+ def self.reload?
120
+ raise 'SubutaiConfig.cmd not set' if @cmd.nil?
121
+ @cmd == 'reload'
122
+ end
123
+
117
124
  def self.delete?
118
125
  raise 'SubutaiConfig.cmd not set' if @cmd.nil?
119
126
  @cmd == 'destroy'
@@ -262,23 +269,8 @@ module SubutaiConfig
262
269
  raise "Invalid key in YAML file: '#{key}'" \
263
270
  unless USER_PARAMETERS.include?(key.to_sym)
264
271
 
265
- if key.to_sym == :SUBUTAI_ENV
266
- set_env(key.to_sym, temp[key].to_sym)
267
- elsif key.to_sym == :SUBUTAI_SCOPE
268
- set_scope(key.to_sym, temp[key].to_sym)
269
- elsif key.to_sym == :SUBUTAI_ENV_TYPE
270
- set_env_type(key.to_sym, temp[key].to_sym)
271
- elsif !temp[key].nil?
272
- # TODO add double checks type
273
-
274
- if temp[key] == 'true'
275
- temp[key] = true
276
- elsif temp[key] == 'false'
277
- temp[key] = false
278
- end
279
-
280
- @config.store(key.to_sym, temp[key])
281
- end
272
+ SubutaiValidation.validate(key.to_sym, temp[key])
273
+ @config.store(key.to_sym, temp[key]) unless temp[key].nil?
282
274
  end
283
275
  end
284
276
 
@@ -299,7 +291,7 @@ module SubutaiConfig
299
291
  def self.do_network(provider)
300
292
  # set the next available console port if provisioning a peer in nat mode
301
293
  put(:_CONSOLE_PORT, find_port(get(:DESIRED_CONSOLE_PORT)), true) \
302
- if boolean?(:SUBUTAI_PEER) && get(:_CONSOLE_PORT).nil? && (write? || delete?)
294
+ if boolean?(:SUBUTAI_PEER) && get(:_CONSOLE_PORT).nil? && (write? || delete? || read?)
303
295
 
304
296
  # set the SSH port if we are using bridged mode
305
297
  put(:_SSH_PORT, find_port(get(:DESIRED_SSH_PORT)), true) \
@@ -309,6 +301,23 @@ module SubutaiConfig
309
301
  if @bridged && get(:_BASE_MAC).nil? && write?
310
302
 
311
303
  put(:_BRIDGED, @bridged, true) if write?
304
+
305
+ generate_switch if provider == :hyper_v && write?
306
+ end
307
+
308
+ # Generates Virtual Switch for Hyper-V
309
+ def self.generate_switch
310
+ unless VagrantSubutai::Util::Powershell.execute(File.join(File.expand_path(File.dirname(__FILE__)), 'script/create_virtual_switch.ps1'))
311
+ Put.error("Failed to create virtual switch")
312
+ end
313
+ end
314
+
315
+ def self.machine_id(provider)
316
+ case provider
317
+ when :hyper_v
318
+ id = PARENT_DIR+'/machines/default/hyperv/id'
319
+ File.read(id) if File.exist?(id)
320
+ end
312
321
  end
313
322
 
314
323
  # Loads the generated and user configuration from YAML files
@@ -1,4 +1,5 @@
1
1
  require_relative 'subutai_config'
2
+ require_relative '../../../lib/vagrant-subutai/util/powershell'
2
3
 
3
4
  # For managing VM disks
4
5
  module SubutaiDisk
@@ -6,7 +7,9 @@ module SubutaiDisk
6
7
  DISK_FORMAT = "vdi".freeze
7
8
  DISK_FORMAT_VIRTUALBOX = "vdi".freeze
8
9
  DISK_FORMAT_VMWARE = "vmdk".freeze
10
+ DISK_FORMAT_HYPERV = "vhdx".freeze
9
11
  PROVIDER_VMWARE = "vmware".freeze
12
+ PROVIDER_HYPERV = "hyper_v".freeze
10
13
 
11
14
  # Checks disk size for adding new VM disks
12
15
  def self.has_grow
@@ -56,6 +59,17 @@ module SubutaiDisk
56
59
  end
57
60
  end
58
61
 
62
+ def self.hyperv_create_disk(grow_by, file_disk)
63
+ script = File.join(File.expand_path(File.dirname(__FILE__)), 'script/create_disk_and_attach.ps1')
64
+ id = SubutaiConfig.machine_id(:hyper_v)
65
+
66
+ if id.nil?
67
+ Put.error("Not found machine id")
68
+ else
69
+ VagrantSubutai::Util::Powershell.execute(script, "-VmId", id, "-DiskPath", file_disk, "-DiskSize", "#{vmware_size(grow_by)}")
70
+ end
71
+ end
72
+
59
73
  # Save disk size and port to generated.yml
60
74
  def self.save_conf(grow_by)
61
75
  SubutaiConfig.put(:_DISK_PORT, port, true)
@@ -98,8 +112,11 @@ module SubutaiDisk
98
112
  disk_port = port
99
113
  disk_format = DISK_FORMAT
100
114
 
101
- if provider == PROVIDER_VMWARE
115
+ case provider
116
+ when PROVIDER_VMWARE
102
117
  disk_format = DISK_FORMAT_VMWARE
118
+ when PROVIDER_HYPERV
119
+ disk_format = DISK_FORMAT_HYPERV
103
120
  end
104
121
 
105
122
  # get disk path from conf file
@@ -34,7 +34,7 @@ PROVIDER_MAC_PREFIXES = {
34
34
  :vmware_fusion => '______',
35
35
  :vmware => '005056',
36
36
  :parallels => '001c42',
37
- :hyper_v => '______'
37
+ :hyper_v => '0003ff'
38
38
  }
39
39
 
40
40
  os = nil
@@ -125,15 +125,12 @@ def random_mac_addr(provider)
125
125
  PROVIDER_MAC_PREFIXES[:libvirt] + 3.times.map { '%02x' % rand(0..255) }.join
126
126
  when :vmware_fusion
127
127
  PROVIDER_MAC_PREFIXES[:vmware] + 3.times.map { '%02x' % rand(0..255) }.join
128
- #raise "Unsupported provider #{provider}"
129
128
  when :vmware
130
129
  PROVIDER_MAC_PREFIXES[:vmware] + 3.times.map { '%02x' % rand(0..255) }.join
131
- #raise "Unsupported provider #{provider}"
132
130
  when :parallels
133
131
  PROVIDER_MAC_PREFIXES[:parallels] + 3.times.map { '%02x' % rand(0..255) }.join
134
- #raise "Unsupported provider #{provider}"
135
132
  when :hyper_v
136
- # PROVIDER_MAC_PREFIXES[:hyper_v] + 3.times.map { '%02x' % rand(0..255) }.join
133
+ PROVIDER_MAC_PREFIXES[:hyper_v] + 3.times.map { '%02x' % rand(0..255) }.join
137
134
  else
138
135
  raise "Unsupported provider #{provider}"
139
136
  end
@@ -0,0 +1,83 @@
1
+ require 'uri'
2
+ require_relative 'subutai_config'
3
+
4
+ module SubutaiValidation
5
+
6
+ USER_CONF_PARAMS_TYPE = {
7
+ "DESIRED_CONSOLE_PORT": :int,
8
+ "DESIRED_SSH_PORT": :int,
9
+ "ALLOW_INSECURE": :bool,
10
+ "SUBUTAI_ENV": :enum,
11
+ "SUBUTAI_CPU": :int,
12
+ "SUBUTAI_RAM": :int,
13
+ "SUBUTAI_PEER": :bool,
14
+ "SUBUTAI_DESKTOP": :bool,
15
+ "SUBUTAI_MAN_TMPL": :path,
16
+ "APT_PROXY_URL": :url,
17
+ "PROVISION": :bool,
18
+ "BRIDGE": :string,
19
+ "AUTHORIZED_KEYS": :path,
20
+ "PASSWORD_OVERRIDE": :string,
21
+ "DISK_SIZE": :int,
22
+ "SUBUTAI_ENV_TYPE": :enum,
23
+ "SUBUTAI_NAME": :string,
24
+ "SUBUTAI_SCOPE": :enum,
25
+ "SUBUTAI_USERNAME": :string,
26
+ "SUBUTAI_PASSWORD": :string,
27
+ "USER_VARIABLES": :json_object,
28
+ "BAZAAR_EMAIL": :string,
29
+ "BAZAAR_PASSWORD": :string,
30
+ "SUBUTAI_DISK_PATH": :path,
31
+ "LIBVIRT_USER": :string,
32
+ "LIBVIRT_HOST": :string,
33
+ "LIBVIRT_PORT": :int,
34
+ "LIBVIRT_MACVTAP": :bool,
35
+ "LIBVIRT_NO_BRIDGE": :bool,
36
+ "BAZAAR_NO_AUTO": :bool
37
+ }.freeze
38
+
39
+ def self.validate(key, value)
40
+ case USER_CONF_PARAMS_TYPE[key]
41
+ when :enum
42
+ if key == :SUBUTAI_ENV
43
+ SubutaiConfig.set_env(key, value.to_sym)
44
+ elsif key == :SUBUTAI_SCOPE
45
+ SubutaiConfig.set_scope(key, value.to_sym)
46
+ elsif key == :SUBUTAI_ENV_TYPE
47
+ SubutaiConfig.set_env_type(key, value.to_sym)
48
+ end
49
+ when :int
50
+ raise "Invalid #{key} type of #{value}: use int type " unless value.is_a?(Integer)
51
+ when :path
52
+ raise "Invalid #{key} path of #{value}: use valid path " unless File.exist?(value)
53
+ when :string
54
+ raise "Invalid #{key} type of #{value}: use string type " unless value.is_a?(String)
55
+ when :bool
56
+ raise "Invalid #{key} type of #{value}: use bool type " unless bool?(value)
57
+ when :url
58
+ raise "Invalid #{key} url of #{value}: use valid url " unless host =~ URI::regexp
59
+ when :json_object
60
+ raise "Invalid #{key} json of #{value}: use json object " unless is_json?(value)
61
+ end
62
+ end
63
+
64
+ def self.bool?(value)
65
+ if value == 'true' || value == true
66
+ true
67
+ elsif value == 'false' || value == false
68
+ true
69
+ else
70
+ false
71
+ end
72
+ end
73
+
74
+ def self.is_json?(json)
75
+ begin
76
+ JSON.parse(json)
77
+ rescue
78
+ false
79
+ end
80
+
81
+ true
82
+ end
83
+ end
@@ -22,6 +22,11 @@ module VagrantSubutai
22
22
  Registration
23
23
  end
24
24
 
25
+ provisioner "create_disk" do
26
+ require_relative "create_disk"
27
+ CreateDisk
28
+ end
29
+
25
30
  config 'subutai_console' do
26
31
  require_relative 'config'
27
32
  Config
@@ -0,0 +1,35 @@
1
+
2
+ module VagrantSubutai
3
+ module Util
4
+ class Powershell
5
+ def self.execute(path, *args)
6
+ command = [
7
+ "powershell.exe",
8
+ "-NoLogo",
9
+ "-NoProfile",
10
+ "-NonInteractive",
11
+ "-ExecutionPolicy", "Bypass",
12
+ "&('#{path}')",
13
+ *args
14
+ ].flatten
15
+
16
+ system(*command)
17
+ end
18
+
19
+ def self.cmd_execute(command)
20
+ c = [
21
+ executable,
22
+ "-NoLogo",
23
+ "-NoProfile",
24
+ "-NonInteractive",
25
+ "-ExecutionPolicy", "Bypass",
26
+ "-Command",
27
+ command
28
+ ].flatten.compact
29
+
30
+ system(*c)
31
+ end
32
+ end
33
+ end
34
+ end
35
+
@@ -1,3 +1,3 @@
1
1
  module VagrantSubutai
2
- VERSION = '7.0.0'
2
+ VERSION = '7.0.1'
3
3
  end
@@ -17,6 +17,7 @@ require 'vagrant-subutai/packer/subutai_config'
17
17
  require 'vagrant-subutai/packer/subutai_hooks'
18
18
  require 'vagrant-subutai/packer/subutai_net'
19
19
  require 'vagrant-subutai/packer/subutai_disk'
20
+ require 'vagrant-subutai/packer/subutai_validation'
20
21
 
21
22
  require 'vagrant-subutai/rest/bazaar'
22
23
  require 'vagrant-subutai/rest/gorjun'
@@ -24,6 +25,7 @@ require 'vagrant-subutai/rest/subutai_console'
24
25
 
25
26
  require 'vagrant-subutai/command'
26
27
  require 'vagrant-subutai/config'
28
+ require 'vagrant-subutai/create_disk'
27
29
  require 'vagrant-subutai/plugin'
28
30
  require 'vagrant-subutai/provisioner'
29
31
  require 'vagrant-subutai/put'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vagrant-subutai
3
3
  version: !ruby/object:Gem::Version
4
- version: 7.0.0
4
+ version: 7.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Subutai
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-05-09 00:00:00.000000000 Z
11
+ date: 2018-05-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -58,16 +58,20 @@ files:
58
58
  - lib/vagrant-subutai/command.rb
59
59
  - lib/vagrant-subutai/config.rb
60
60
  - lib/vagrant-subutai/configs/configs.rb
61
+ - lib/vagrant-subutai/create_disk.rb
61
62
  - lib/vagrant-subutai/models/ansible.rb
62
63
  - lib/vagrant-subutai/models/console/container.rb
63
64
  - lib/vagrant-subutai/models/console/environment.rb
64
65
  - lib/vagrant-subutai/models/container.rb
65
66
  - lib/vagrant-subutai/models/domain.rb
66
67
  - lib/vagrant-subutai/models/environment.rb
68
+ - lib/vagrant-subutai/packer/script/create_disk_and_attach.ps1
69
+ - lib/vagrant-subutai/packer/script/create_virtual_switch.ps1
67
70
  - lib/vagrant-subutai/packer/subutai_config.rb
68
71
  - lib/vagrant-subutai/packer/subutai_disk.rb
69
72
  - lib/vagrant-subutai/packer/subutai_hooks.rb
70
73
  - lib/vagrant-subutai/packer/subutai_net.rb
74
+ - lib/vagrant-subutai/packer/subutai_validation.rb
71
75
  - lib/vagrant-subutai/plugin.rb
72
76
  - lib/vagrant-subutai/provisioner.rb
73
77
  - lib/vagrant-subutai/put.rb
@@ -76,6 +80,7 @@ files:
76
80
  - lib/vagrant-subutai/rest/gorjun.rb
77
81
  - lib/vagrant-subutai/rest/subutai_console.rb
78
82
  - lib/vagrant-subutai/subutai_commands.rb
83
+ - lib/vagrant-subutai/util/powershell.rb
79
84
  - lib/vagrant-subutai/version.rb
80
85
  - lib/vagrant_init.rb
81
86
  - test/.rubocop.yml