Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow user to pick administrator password upon vApp provisioning #196

Merged
merged 1 commit into from
Feb 28, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,16 @@ def stack_create_options
def customize_vapp_template(vm_params, vapp_net_params)
source_vms = vm_params.map do |_, vm_opts|
src_vm = {
:vm_id => "vm-#{vm_opts[:vm_id]}",
:networks => parse_nics(vm_opts),
:hardware => {
:vm_id => "vm-#{vm_opts[:vm_id]}",
:networks => parse_nics(vm_opts),
:hardware => {
:cpu => { :num_cores => vm_opts['num_cores'], :cores_per_socket => vm_opts['cores_per_socket'] },
:memory => { :quantity_mb => vm_opts['memory_mb'] },
:disk => parse_disks(vm_opts)
}
},
:guest_customization => parse_guest_customization(vm_opts)
}
src_vm[:name] = vm_opts["instance_name"] if vm_opts.key?("instance_name")
src_vm[:guest_customization] = { :ComputerName => vm_opts['hostname'] } if vm_opts.key?("hostname")
src_vm
end

Expand All @@ -49,7 +49,10 @@ def customize_vapp_template(vm_params, vapp_net_params)

def collect_vm_params(template)
vm_params = collect_stack_parameters(
%w(instance_name vdc_network num_cores cores_per_socket memory_mb disk_mb hostname nic_network nic_mode nic_ip_address)
%w(
instance_name vdc_network num_cores cores_per_socket memory_mb disk_mb hostname nic_network nic_mode
nic_ip_address admin_password admin_reset
)
)
# Reverse lookup by indeces.
vm_params.each do |vm_idx, obj|
Expand Down Expand Up @@ -119,6 +122,19 @@ def parse_nics(opts)
end
end

def parse_guest_customization(opts)
admin_pass = opts['admin_password']
res = {
:Enabled => true,
:ComputerName => opts['hostname'],
:AdminPasswordEnabled => true,
:AdminPasswordAuto => admin_pass.blank?,
:ResetPasswordRequired => opts['admin_reset'] == 't'
}
res[:AdminPassword] = admin_pass if admin_pass.present?
res
end

def option_value(opts_group, subkeys)
opt = opts_group.detect { |o| o[:subkeys] == subkeys }
opt[:value] unless opt.nil?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,23 @@ def vm_param_groups(template)
:constraints => [
OrchestrationTemplate::OrchestrationParameterRange.new(:min_value => 4)
]
)
),
OrchestrationTemplate::OrchestrationParameter.new(
:name => param_name('admin_password', [vm_idx]),
:label => 'Administrator Password',
:description => 'Leave empty to auto generate',
:data_type => 'string'
),
OrchestrationTemplate::OrchestrationParameter.new(
:name => param_name('admin_reset', [vm_idx]),
:label => 'Require password change',
:description => 'Require administrator to change password on first login',
:data_type => 'boolean',
:default_value => false,
:constraints => [
OrchestrationTemplate::OrchestrationParameterBoolean.new
]
),
]

# Disks.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
'dialog_param_num_cores-0' => 8,
'dialog_param_cores_per_socket-0' => 4,
'dialog_param_memory_mb-0' => 8192,
'dialog_param_admin_password-0' => 'admin-password',
'dialog_param_admin_reset-0' => 't',
'dialog_param_disk_mb-0-0' => 40_960,
'dialog_param_disk_mb-0-1' => 20_480,
'dialog_param_nic_network-0-0' => 'VM Network',
Expand All @@ -34,6 +36,8 @@
'dialog_param_num_cores-1' => 4,
'dialog_param_cores_per_socket-1' => 1,
'dialog_param_memory_mb-1' => 2048,
'dialog_param_admin_password-1' => '',
'dialog_param_admin_reset-1' => 'f',
'dialog_param_disk_mb-1-0' => 4096,
'dialog_param_nic_network-1-0' => 'RedHat Private network 43',
'dialog_param_nic_mode-1-0' => 'DHCP',
Expand Down Expand Up @@ -91,7 +95,14 @@
expect(options[:source_vms][0]).to eq(
:name => 'my VM1',
:vm_id => 'vm-e9b55b85-640b-462c-9e7a-d18c47a7a5f3',
:guest_customization => { :ComputerName => 'my-vm-1' },
:guest_customization => {
:Enabled => true,
:ComputerName => 'my-vm-1',
:AdminPasswordEnabled => true,
:AdminPassword => 'admin-password',
:AdminPasswordAuto => false,
:ResetPasswordRequired => true
},
:hardware => {
:cpu => { :num_cores => 8, :cores_per_socket => 4 },
:memory => { :quantity_mb => 8192 },
Expand All @@ -112,7 +123,13 @@
expect(options[:source_vms][1]).to eq(
:name => 'my VM2',
:vm_id => 'vm-04f85cca-3f8d-43b4-8473-7aa099f95c1b',
:guest_customization => { :ComputerName => 'my-vm-2' },
:guest_customization => {
:Enabled => true,
:ComputerName => 'my-vm-2',
:AdminPasswordEnabled => true,
:AdminPasswordAuto => true,
:ResetPasswordRequired => false
},
:hardware => {
:cpu => { :num_cores => 4, :cores_per_socket => 1 },
:memory => { :quantity_mb => 2048 },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@
:num_cores => 2,
:cores_per_socket => 2,
:memory_mb => 2048,
:admin_password => nil,
:admin_reset => false,
:disks => [
{ :disk_id => '2000', :disk_address => '0', :size => 16_384 },
{ :disk_id => '2001', :disk_address => '1', :size => 40_960 }
Expand All @@ -76,6 +78,8 @@
:num_cores => 2,
:cores_per_socket => 2,
:memory_mb => 4096,
:admin_password => nil,
:admin_reset => false,
:disks => [{ :disk_id => '2000', :disk_address => '0', :size => 40_960 }],
:nics => [
{ :idx => '0', :network => 'RedHat Private network 43', :mode => 'MANUAL', :ip_address => '192.168.43.100' },
Expand Down Expand Up @@ -125,12 +129,26 @@
:data_type => 'integer',
:required => true,
:default_value => args[:memory_mb]
},
'admin_password' => {
:name => "admin_password-#{vm_idx}",
:label => 'Administrator Password',
:data_type => 'string',
:required => nil,
:default_value => args[:admin_password]
},
'admin_reset' => {
:name => "admin_reset-#{vm_idx}",
:label => 'Require password change',
:data_type => 'boolean',
:required => nil,
:default_value => args[:admin_reset]
}
)
assert_vm_disks(vm_group, args[:disks], vm_idx)
assert_vm_nics(vm_group, args[:nics], vm_idx)
# Group has not extra parameters.
expect(vm_group.parameters.size).to eq(5 + args[:disks].count + 3 * args[:nics].count)
expect(vm_group.parameters.size).to eq(7 + args[:disks].count + 3 * args[:nics].count)
end
end

Expand Down