Skip to content

Commit

Permalink
added new conf key SUBUTAI_DISK #105
Browse files Browse the repository at this point in the history
  • Loading branch information
jadilet committed May 31, 2018
1 parent 0a82ea0 commit 939b6e2
Show file tree
Hide file tree
Showing 12 changed files with 72 additions and 10 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ COMMANDS:
update - update Subutai management, container or Resource host
vxlan - VXLAN tunnels operation
register - register Subutai PeerOS to Bazaar
deregister - deregister Subutai PeerOS from Bazaar
unregister - unregister Subutai PeerOS from Bazaar
fingerprint - shows fingerprint Subutai Console
open - open the Subutai PeerOS in browser
blueprint - run blueprint provisioning
Expand Down
4 changes: 3 additions & 1 deletion lib/vagrant-subutai/command.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ def execute
subutai_cli.register(nil, nil, check_subutai_console_url(subutai_cli))
when 'deregister'
subutai_cli.deregister(nil, nil, check_subutai_console_url(subutai_cli))
when 'unregister'
subutai_cli.deregister(nil, nil, check_subutai_console_url(subutai_cli))
when 'fingerprint'
subutai_cli.fingerprint(check_subutai_console_url(subutai_cli))
when 'open'
Expand Down Expand Up @@ -102,7 +104,7 @@ def cli_info
update - update Subutai management, container or Resource host
vxlan - VXLAN tunnels operation
register - register Subutai PeerOS to Bazaar
deregister - deregister Subutai PeerOS from Bazaar
unregister - unregister Subutai PeerOS from Bazaar
fingerprint - shows fingerprint Subutai Console
open - open the Subutai PeerOS in browser
blueprint - run blueprint provisioning
Expand Down
3 changes: 2 additions & 1 deletion lib/vagrant-subutai/create_disk.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ def provision
file_disk = SubutaiDisk.file_path(grow_by, "hyper_v")

unless File.exist?(file_disk)
Put.warn "Disk size is growing by #{grow_by} gb."
Put.warn "==> default: Disk size configured to #{SubutaiConfig.disk_size}GB, increasing #{grow_by}GB default by 100GB."

if has_grow
if SubutaiDisk.hyperv_create_disk(grow_by, file_disk)
SubutaiDisk.save_path(SubutaiDisk.port, file_disk)
Expand Down
15 changes: 12 additions & 3 deletions lib/vagrant-subutai/packer/subutai_config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ module SubutaiConfig
LIBVIRT_MACVTAP
LIBVIRT_NO_BRIDGE
BAZAAR_NO_AUTO
SUBUTAI_DISK
].freeze

GENERATED_PARAMETERS = %i[
Expand Down Expand Up @@ -98,12 +99,12 @@ module SubutaiConfig
LIBVIRT_PORT: 22, # Libvirt kvm remote operation ssh port
LIBVIRT_MACVTAP: false, # Libvirt macvtap interface
BAZAAR_NO_AUTO: false, # PeerOs automatic registration to Bazaar (turn on(false), turn off(true))
PROVISION: true, # to provision or not to

# Configuration parameters below have not been implemented
SUBUTAI_DESKTOP: false, # install desktop with tray and p2p client
SUBUTAI_MAN_TMPL: nil, # provision alternative management template
APT_PROXY_URL: nil, # configure apt proxy URL
PROVISION: true # to provision or not to
APT_PROXY_URL: nil # configure apt proxy URL
}

# User provided configuration settings
Expand Down Expand Up @@ -180,8 +181,16 @@ def self.config
@config
end

# Now we support both configuration parameter DISK_SIZE and SUBUTAI_DISK
def self.disk_size
return get(:SUBUTAI_DISK) unless get(:SUBUTAI_DISK).nil?

get(:DISK_SIZE)
end

def self.get_grow_by
disk = get(:DISK_SIZE)
disk = disk_size

if disk.nil?
nil
else
Expand Down
4 changes: 2 additions & 2 deletions lib/vagrant-subutai/packer/subutai_disk.rb
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ def self.hyperv_create_disk(grow_by, file_disk)
id = SubutaiConfig.machine_id(:hyper_v)

if id.nil?
Put.error(" => [FAILED] Disk Creation. Not found machine id")
Put.error("[FAILED] Disk Creation. Not found machine id")
false
else
VagrantSubutai::Util::Powershell.execute(script, "-VmId", id, "-DiskPath", file_disk, "-DiskSize", "#{vmware_size(grow_by)}")
Expand All @@ -98,7 +98,7 @@ def self.hyperv_remove_disk
id = SubutaiConfig.machine_id(:hyper_v)

if id.nil?
Put.error(" => [FAILED] Remove virtual disk. Not found machine id")
Put.error("[FAILED] Remove virtual disk. Not found machine id")
false
else
VagrantSubutai::Util::Powershell.execute(script, "-VmId", id)
Expand Down
1 change: 1 addition & 0 deletions lib/vagrant-subutai/packer/subutai_validation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ module SubutaiValidation
"AUTHORIZED_KEYS": :path,
"PASSWORD_OVERRIDE": :string,
"DISK_SIZE": :int,
"SUBUTAI_DISK": :int,
"SUBUTAI_ENV_TYPE": :enum,
"SUBUTAI_NAME": :string,
"SUBUTAI_SCOPE": :enum,
Expand Down
3 changes: 2 additions & 1 deletion lib/vagrant-subutai/subutai_commands.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ def registered?(url)
end
end

# Unregister Subutai Peer OS from Bazaar
def deregister(username, password, url)
if registered?(url)
username, password = get_input_token if username.nil? || password.nil?
Expand All @@ -71,7 +72,7 @@ def deregister(username, password, url)
case response
when Net::HTTPOK
Put.success response.body
Put.success "Successfully PeerOS deregistered from Bazaar."
Put.success "Successfully PeerOS unregistered from Bazaar."
else
Put.error "Error: #{response.body}\n"
end
Expand Down
9 changes: 9 additions & 0 deletions lib/vagrant-subutai/util/terminal.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module VagrantSubutai
module Util
class Terminal
def self.execute_cmd(*command)
system(*command)
end
end
end
end
2 changes: 2 additions & 0 deletions test/both_disk.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
DISK_SIZE: 985
SUBUTAI_DISK: 654
2 changes: 1 addition & 1 deletion test/disk_size.yml
Original file line number Diff line number Diff line change
@@ -1 +1 @@
DISK_SIZE: 250
DISK_SIZE: 250
36 changes: 36 additions & 0 deletions test/subutai_config_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -477,4 +477,40 @@ def test_provider
SubutaiConfig.reset
assert_equal(nil, SubutaiConfig.provider)
end

def test_disk_size
SubutaiConfig.cleanup!
#SubutaiConfig.load_config_file('')

assert_equal(nil, SubutaiConfig.disk_size)
assert_equal(nil, SubutaiConfig.get(:DISK_SIZE))
assert_equal(nil, SubutaiConfig.get(:SUBUTAI_DISK))

SubutaiConfig.override_conf_file('./test/subutai_disk.yml')
SubutaiConfig.load_config('up', :hyper_v)

assert_equal(123, SubutaiConfig.get(:SUBUTAI_DISK))
assert_equal(123, SubutaiConfig.disk_size)
assert_equal(nil, SubutaiConfig.get(:DISK_SIZE))

SubutaiConfig.cleanup!
SubutaiConfig.override_conf_file('./test/disk_size.yml')
SubutaiConfig.load_config('up', :hyper_v)

assert_equal(250, SubutaiConfig.get(:DISK_SIZE))
assert_equal(250, SubutaiConfig.disk_size)
assert_nil(SubutaiConfig.get(:SUBUTAI_DISK))

SubutaiConfig.cleanup!
SubutaiConfig.override_conf_file('./test/both_disk.yml')
SubutaiConfig.load_config('up', :hyper_v)
assert_equal(654, SubutaiConfig.disk_size)
assert_equal(985, SubutaiConfig.get(:DISK_SIZE))
assert_equal(654, SubutaiConfig.get(:SUBUTAI_DISK))

SubutaiConfig.cleanup!
assert_nil(SubutaiConfig.disk_size)
assert_nil(SubutaiConfig.get(:DISK_SIZE))
assert_nil(SubutaiConfig.get(:SUBUTAI_DISK))
end
end
1 change: 1 addition & 0 deletions test/subutai_disk.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
SUBUTAI_DISK: 123

0 comments on commit 939b6e2

Please sign in to comment.