Applying RuboCop suggestion.
This commit is contained in:
Родитель
8e08dba221
Коммит
88cf0ed4d6
|
@ -32,23 +32,19 @@ module Puppet::AffinityGroup
|
|||
|
||||
def add_description_option(action)
|
||||
action.option '--description=' do
|
||||
summary "Description of affinity group"
|
||||
description <<-EOT
|
||||
Description of affinity group.
|
||||
EOT
|
||||
summary 'Description of affinity group'
|
||||
description 'Description of affinity group.'
|
||||
end
|
||||
end
|
||||
|
||||
def add_label_option(action)
|
||||
action.option '--label=' do
|
||||
summary "Label of affinity group"
|
||||
description <<-EOT
|
||||
Label of affinity group.
|
||||
EOT
|
||||
summary 'Label of affinity group'
|
||||
description 'Label of affinity group.'
|
||||
required
|
||||
before_action do |action, args, options|
|
||||
if options[:label].empty?
|
||||
raise ArgumentError, "Label is required"
|
||||
fail ArgumentError, 'Label is required'
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -17,13 +17,11 @@ module Puppet
|
|||
def add_management_certificate_option(action)
|
||||
action.option '--management-certificate=' do
|
||||
summary 'The subscription identifier for the Windows Azure portal.'
|
||||
description <<-EOT
|
||||
The subscription identifier for the Windows Azure portal.
|
||||
EOT
|
||||
description 'The subscription identifier for the Windows Azure portal.'
|
||||
required
|
||||
before_action do |action, args, options|
|
||||
file = options[:management_certificate]
|
||||
validate_file(file,'Management certificate', ['pem','pfx'])
|
||||
validate_file(file, 'Management certificate', ['pem', 'pfx'])
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -31,13 +29,13 @@ module Puppet
|
|||
def add_subscription_id_option(action)
|
||||
action.option '--azure-subscription-id=' do
|
||||
summary 'The subscription identifier for the Windows Azure portal.'
|
||||
description <<-EOT
|
||||
description "
|
||||
The subscription identifier for the Windows Azure portal.
|
||||
EOT
|
||||
"
|
||||
required
|
||||
before_action do |action, args, options|
|
||||
if options[:azure_subscription_id].empty?
|
||||
raise ArgumentError, "Subscription id is required."
|
||||
fail ArgumentError, 'Subscription id is required.'
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -46,16 +44,14 @@ module Puppet
|
|||
def add_management_endpoint_option(action)
|
||||
action.option '--management-endpoint=' do
|
||||
summary 'The management endpoint for the Windows Azure portal.'
|
||||
description <<-EOT
|
||||
The management endpoint for the Windows Azure portal.
|
||||
EOT
|
||||
description 'The management endpoint for the Windows Azure portal.'
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
def add_location_option(action)
|
||||
action.option '--location=' do
|
||||
summary "The location identifier for the Windows Azure portal."
|
||||
summary 'The location identifier for the Windows Azure portal.'
|
||||
description <<-EOT
|
||||
The location identifier for the Windows Azure portal.
|
||||
valid choices are ('West US', 'East US', 'Southeast Asia',
|
||||
|
@ -64,7 +60,7 @@ module Puppet
|
|||
required
|
||||
before_action do |action, args, options|
|
||||
if options[:location].empty?
|
||||
raise ArgumentError, "Location is required"
|
||||
fail ArgumentError, 'Location is required'
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -72,14 +68,12 @@ module Puppet
|
|||
|
||||
def add_affinity_group_name_option(action)
|
||||
action.option '--affinity-group-name=' do
|
||||
summary "The affinity group name."
|
||||
description <<-EOT
|
||||
The affinity group name.
|
||||
EOT
|
||||
summary 'The affinity group name.'
|
||||
description 'The affinity group name.'
|
||||
required
|
||||
before_action do |action, args, options|
|
||||
if options[:affinity_group_name].empty?
|
||||
raise ArgumentError, "Affinity group name is required"
|
||||
fail ArgumentError, 'Affinity group name is required'
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -17,10 +17,10 @@ module Puppet
|
|||
elsif params[:ssh_user]
|
||||
results = bootstrap_linux_node(params)
|
||||
if results[:exit_code] != 0 then
|
||||
puts "The installation script exited with a non-zero exit status, indicating a failure."
|
||||
puts 'The installation script exited with a non-zero exit status, indicating a failure.'
|
||||
end
|
||||
else
|
||||
raise "Missing option ssh_user or winrm_user"
|
||||
fail 'Missing option ssh_user or winrm_user'
|
||||
end
|
||||
|
||||
end
|
||||
|
@ -39,13 +39,13 @@ module Puppet
|
|||
end
|
||||
|
||||
cmds = []
|
||||
cmds << "mkdir C:\\puppet"
|
||||
cmds << 'mkdir C:\\puppet'
|
||||
wget_script.each_line do |line|
|
||||
ln = line.gsub("\n"," ")
|
||||
ln = line.gsub("\n", ' ')
|
||||
cmds << "echo #{ln} >> C:\\puppet\\wget.vbs"
|
||||
end
|
||||
cmds << "cscript /nologo C:\\puppet\\wget.vbs https://downloads.puppetlabs.com/windows/puppet-3.3.2.msi %TEMP%\\puppet.msi"
|
||||
cmds << "copy %TEMP%\\puppet.msi C:\\puppet\\puppet.msi"
|
||||
cmds << 'cscript /nologo C:\\puppet\\wget.vbs https://downloads.puppetlabs.com/windows/puppet-3.3.2.msi %TEMP%\\puppet.msi'
|
||||
cmds << 'copy %TEMP%\\puppet.msi C:\\puppet\\puppet.msi'
|
||||
cmds << "msiexec /qn /i c:\\puppet\\puppet.msi PUPPET_MASTER_SERVER=#{master_ip}"
|
||||
cmds << 'sc config puppet start= demand'
|
||||
cmds << 'rmdir C:\\puppet /s /q'
|
||||
|
@ -54,7 +54,7 @@ module Puppet
|
|||
|
||||
def bootstrap_linux_node(params)
|
||||
login = params[:ssh_user]
|
||||
ssh_opts = { }
|
||||
ssh_opts = {}
|
||||
if params[:password]
|
||||
ssh_opts[:password] = params[:password]
|
||||
else
|
||||
|
@ -62,12 +62,12 @@ module Puppet
|
|||
end
|
||||
ssh_opts[:paranoid] = false
|
||||
ssh_opts[:port] = params[:ssh_port] || 22
|
||||
options = {:environment=>'production', :puppet_master_ip => params[:puppet_master_ip]}
|
||||
options[:tmp_dir] = File.join('/', 'tmp', random_string('puppet-tmp-location-',10))
|
||||
options = { :environment => 'production', puppet_master_ip: params[:puppet_master_ip] }
|
||||
options[:tmp_dir] = File.join('/', 'tmp', random_string('puppet-tmp-location-', 10))
|
||||
create_tmpdir_cmd = "bash -c 'umask 077; mkdir #{options[:tmp_dir]}'"
|
||||
ssh_remote_execute(params[:node_ipaddress], login, ssh_opts, create_tmpdir_cmd)
|
||||
tmp_script_file = compile_template(options)
|
||||
remote_script_path = File.join(options[:tmp_dir], "puppet_installation_script.sh")
|
||||
remote_script_path = File.join(options[:tmp_dir], 'puppet_installation_script.sh')
|
||||
scp_remote_upload(params[:node_ipaddress], login, ssh_opts, tmp_script_file.path, remote_script_path)
|
||||
cmd_prefix = login == 'root' ? '' : 'sudo '
|
||||
install_command = "#{cmd_prefix}bash -c 'chmod u+x #{remote_script_path}; sed -i 's/\r//' #{remote_script_path}; #{remote_script_path}'"
|
||||
|
@ -75,9 +75,9 @@ module Puppet
|
|||
end
|
||||
|
||||
def compile_template(options)
|
||||
puts "Installing Puppet ..."
|
||||
puts 'Installing Puppet ...'
|
||||
install_script = Installer.build_installer_template('puppet-agent-bootstrap', options)
|
||||
puts("Compiled installation script:")
|
||||
puts('Compiled installation script:')
|
||||
begin
|
||||
f = Tempfile.open('install_script')
|
||||
f.write(install_script)
|
||||
|
@ -91,4 +91,4 @@ module Puppet
|
|||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -21,11 +21,10 @@ module Puppet
|
|||
if File.exists?(lib_script)
|
||||
lib_script
|
||||
else
|
||||
raise "Could not find installation template for #{name}"
|
||||
fail "Could not find installation template for #{name}"
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -17,18 +17,18 @@ module Puppet
|
|||
e.remember_host!
|
||||
retry
|
||||
rescue Net::SSH::AuthenticationFailed => user
|
||||
raise "Authentication failure for user #{user}.".inspect
|
||||
fail "Authentication failure for user #{user}.".inspect
|
||||
rescue Exception => e
|
||||
raise e.message.inspect
|
||||
fail e.message.inspect
|
||||
end
|
||||
end
|
||||
|
||||
def ssh_remote_execute(server, login, ssh_opts, command)
|
||||
puts "Executing remote command ..."
|
||||
puts 'Executing remote command ...'
|
||||
puts "Command: #{command}"
|
||||
|
||||
buffer = String.new
|
||||
stdout = String.new
|
||||
buffer = ''
|
||||
stdout = ''
|
||||
exit_code = nil
|
||||
|
||||
begin
|
||||
|
@ -36,7 +36,7 @@ module Puppet
|
|||
session.open_channel do |channel|
|
||||
|
||||
channel.request_pty do |c, success|
|
||||
raise "could not request pty" unless success
|
||||
fail 'could not request pty' unless success
|
||||
channel.on_data do |ch, data|
|
||||
if data =~ /\[sudo\]/ || data =~ /Password/i
|
||||
channel.send_data "#{ssh_opts[:password]}\n"
|
||||
|
@ -58,7 +58,7 @@ module Puppet
|
|||
puts buffer
|
||||
end
|
||||
end
|
||||
channel.on_request("exit-status") do |ch, data|
|
||||
channel.on_request('exit-status') do |ch, data|
|
||||
exit_code = data.read_long
|
||||
puts "SSH Command Exit Code: #{exit_code}"
|
||||
end
|
||||
|
@ -73,22 +73,22 @@ module Puppet
|
|||
e.remember_host!
|
||||
retry
|
||||
rescue Net::SSH::AuthenticationFailed => user
|
||||
raise "Authentication failure for user #{user}.".inspect
|
||||
fail "Authentication failure for user #{user}.".inspect
|
||||
rescue Exception => e
|
||||
puts e.message
|
||||
end
|
||||
|
||||
puts "Executing remote command ... Done"
|
||||
{ :exit_code => exit_code, :stdout => stdout }
|
||||
puts 'Executing remote command ... Done'
|
||||
{ exit_code: exit_code, stdout: stdout }
|
||||
end
|
||||
|
||||
def winrm_remote_execute(node_ip, login, password, cmds, endpoint_protocol, port)
|
||||
endpoint = "#{endpoint_protocol}://#{node_ip}:#{port}/wsman"
|
||||
winrm = WinRM::WinRMWebService.new(endpoint,
|
||||
:plaintext,
|
||||
:user => login,
|
||||
:pass => password,
|
||||
:basic_auth_only => true)
|
||||
:plaintext,
|
||||
user: login,
|
||||
pass: password,
|
||||
basic_auth_only: true)
|
||||
cmds.each do |cmd|
|
||||
puts "Executing command #{cmd}"
|
||||
winrm.cmd(cmd) do |stdout, stderr|
|
||||
|
@ -100,4 +100,4 @@ module Puppet
|
|||
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -4,23 +4,23 @@ module Puppet
|
|||
module Core
|
||||
module Utility
|
||||
|
||||
def random_string(str='azure', no_of_char=5)
|
||||
str+(0...no_of_char).map{ ('a'..'z').to_a[rand(26)] }.join
|
||||
def random_string(str = 'azure', no_of_char = 5)
|
||||
str + (0...no_of_char).map { ('a'..'z').to_a[rand(26)] }.join
|
||||
end
|
||||
|
||||
def validate_file(filepath, filename, extensions)
|
||||
if filepath.empty?
|
||||
raise ArgumentError, "#{filename} file is required"
|
||||
fail ArgumentError, "#{filename} file is required"
|
||||
end
|
||||
unless test 'f', filepath
|
||||
raise ArgumentError, "Could not find file '#{filepath}'"
|
||||
fail ArgumentError, "Could not find file '#{filepath}'"
|
||||
end
|
||||
unless test 'r', filepath
|
||||
raise ArgumentError, "Could not read from file '#{filepath}'"
|
||||
fail ArgumentError, "Could not read from file '#{filepath}'"
|
||||
end
|
||||
ext_msg = extensions.map{|ele| '.'+ele}.join(' or ')
|
||||
ext_msg = extensions.map { |ele| '.' + ele }.join(' or ')
|
||||
if filepath !~ /(#{extensions.join('|')})$/
|
||||
raise RuntimeError, "#{filename} expects a #{ext_msg} file."
|
||||
fail RuntimeError, "#{filename} expects a #{ext_msg} file."
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -29,43 +29,43 @@ module Puppet
|
|||
password = options[:password]
|
||||
return options if !password.nil? && !password.match(regex).nil?
|
||||
password_required = 'y'
|
||||
if (options[:private_key_file] && options[:certificate_file] && os_type == 'Linux')
|
||||
password_required = ask("\nDo you want to enable password authentication (y/n)? ") {
|
||||
if options[:private_key_file] && options[:certificate_file] && os_type == 'Linux'
|
||||
password_required = ask("\nDo you want to enable password authentication (y/n)? ") do
|
||||
|pass| pass.validate = /^y{1}$|^n{1}$/
|
||||
}
|
||||
end
|
||||
end
|
||||
if password_required == 'y' or os_type == 'Windows'
|
||||
puts "The supplied password must be 6-72 characters long and meet password complexity requirements."
|
||||
puts "Require atleast 1 captial letter and digit."
|
||||
options[:password] = ask("\nPASSWORD? ") { |pass| pass.echo ="*"; pass.validate = regex }
|
||||
puts 'The supplied password must be 6-72 characters long and meet password complexity requirements.'
|
||||
puts 'Require atleast 1 captial letter and digit.'
|
||||
options[:password] = ask("\nPASSWORD? ") { |pass| pass.echo = '*'; pass.validate = regex }
|
||||
end
|
||||
options
|
||||
end
|
||||
|
||||
def test_tcp_connection(server)
|
||||
unless (server && server.ipaddress)
|
||||
Loggerx.error_with_exit("Instance is not running.")
|
||||
unless server && server.ipaddress
|
||||
Loggerx.error_with_exit('Instance is not running.')
|
||||
exit 1
|
||||
end
|
||||
puts("\n")
|
||||
if server.os_type == 'Linux'
|
||||
ip = server.ipaddress
|
||||
port = server.tcp_endpoints.collect{|x| x["PublicPort"] if x["Name"] == 'SSH'}.compact.first
|
||||
port = server.tcp_endpoints.map { |x| x['PublicPort'] if x['Name'] == 'SSH' }.compact.first
|
||||
Loggerx.info "Waiting for sshd on #{ip}:#{port}"
|
||||
|
||||
print("# ") until tcp_test_ssh(ip,port) {
|
||||
print('# ') until tcp_test_ssh(ip, port) do
|
||||
sleep 10
|
||||
Loggerx.info "done"
|
||||
}
|
||||
Loggerx.info 'done'
|
||||
end
|
||||
elsif server.os_type == 'Windows'
|
||||
ip = server.ipaddress
|
||||
port = 5985
|
||||
Loggerx.info "Waiting for winrm on #{ip}:#{port}"
|
||||
|
||||
print("# ") until tcp_test_winrm(ip,port) {
|
||||
print('# ') until tcp_test_winrm(ip, port) do
|
||||
sleep 10
|
||||
Loggerx.success("done")
|
||||
}
|
||||
Loggerx.success('done')
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -151,8 +151,8 @@ end
|
|||
|
||||
class String
|
||||
|
||||
def fix(size=18, padstr=' ')
|
||||
def fix(size = 18, padstr = ' ')
|
||||
self[0...size].ljust(size, padstr)
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
|
|
@ -64,4 +64,4 @@ Puppet::Face.define :azure_vm, '1.0.0' do
|
|||
--location "Southeast Asia" --tcp-endpoints "80,3889:3889"
|
||||
EOT
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -18,7 +18,7 @@ Puppet::Face.define :azure_vnet, '1.0.0' do
|
|||
subnets = []
|
||||
options[:subnets].split(',').each do |subnet|
|
||||
values = subnet.split(':')
|
||||
raise 'Missing argument name or ip_address or cidr in subnet' if values.size != 3
|
||||
fail 'Missing argument name or ip_address or cidr in subnet' if values.size != 3
|
||||
subnets << { name: values[0], ip_address: values[1], cidr: values[2] }
|
||||
end
|
||||
optional[:subnet] = subnets
|
||||
|
@ -27,7 +27,7 @@ Puppet::Face.define :azure_vnet, '1.0.0' do
|
|||
dns = []
|
||||
options[:dns_servers].split(',').each do |ds|
|
||||
values = ds.split(':')
|
||||
raise 'Missing argument name or ip_address in dns' if values.size != 2
|
||||
fail 'Missing argument name or ip_address in dns' if values.size != 2
|
||||
dns << { name: values[0], ip_address: values[1] }
|
||||
end
|
||||
optional[:dns] = dns
|
||||
|
|
|
@ -59,7 +59,7 @@ module Puppet::SqlDatabase
|
|||
required
|
||||
before_action do |action, args, options|
|
||||
if options[:login].empty?
|
||||
raise ArgumentError, "Login is required."
|
||||
fail ArgumentError, 'Login is required.'
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -68,13 +68,11 @@ module Puppet::SqlDatabase
|
|||
def add_password_option(action)
|
||||
action.option '--password=' do
|
||||
summary 'The pasword for the Windows Azure sql database server.'
|
||||
description <<-EOT
|
||||
The password for the Windows Azure sql database server.
|
||||
EOT
|
||||
description 'The password for the Windows Azure sql database server.'
|
||||
required
|
||||
before_action do |action, args, options|
|
||||
if options[:password].empty?
|
||||
raise ArgumentError, "Password is required."
|
||||
fail ArgumentError, 'Password is required.'
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -83,13 +81,11 @@ module Puppet::SqlDatabase
|
|||
def add_server_name_option(action)
|
||||
action.option '--server-name=' do
|
||||
summary 'The server name for the Windows Azure sql database server.'
|
||||
description <<-EOT
|
||||
The server name for the Windows Azure sql database server.
|
||||
EOT
|
||||
description 'The server name for the Windows Azure sql database server.'
|
||||
required
|
||||
before_action do |action, args, options|
|
||||
if options[:server_name].empty?
|
||||
raise ArgumentError, "Server name is required."
|
||||
fail ArgumentError, 'Server name is required.'
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -98,13 +94,11 @@ module Puppet::SqlDatabase
|
|||
def add_rule_name_option(action)
|
||||
action.option '--rule-name=' do
|
||||
summary 'The rule name for the sql database server firewall.'
|
||||
description <<-EOT
|
||||
The rule name for the sql database server firewall.
|
||||
EOT
|
||||
description 'The rule name for the sql database server firewall.'
|
||||
required
|
||||
before_action do |action, args, options|
|
||||
if options[:rule_name].empty?
|
||||
raise ArgumentError, "Firewall rule name is required."
|
||||
fail ArgumentError, 'Firewall rule name is required.'
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -122,9 +116,7 @@ module Puppet::SqlDatabase
|
|||
def add_end_ip_address_option(action)
|
||||
action.option '--end-ip-address=' do
|
||||
summary 'The end ip address for the sql database server firewall.'
|
||||
description <<-EOT
|
||||
The end ip address for the sql database server firewall.
|
||||
EOT
|
||||
description 'The end ip address for the sql database server firewall.'
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -11,18 +11,18 @@ module Puppet::VirtualMachine
|
|||
|
||||
def add_shutdown_options(action)
|
||||
add_deployment_options(action)
|
||||
add_vm_name_option(action,false)
|
||||
add_vm_name_option(action, false)
|
||||
end
|
||||
|
||||
def add_delete_options(action)
|
||||
add_default_options(action)
|
||||
add_vm_name_option(action,false)
|
||||
add_cloud_service_name_option(action,false)
|
||||
add_vm_name_option(action, false)
|
||||
add_cloud_service_name_option(action, false)
|
||||
end
|
||||
|
||||
def add_deployment_options(action)
|
||||
add_default_options(action)
|
||||
add_cloud_service_name_option(action,false)
|
||||
add_cloud_service_name_option(action, false)
|
||||
end
|
||||
|
||||
def add_bootstrap_options(action)
|
||||
|
@ -60,16 +60,14 @@ module Puppet::VirtualMachine
|
|||
add_affinity_group_option(action)
|
||||
end
|
||||
|
||||
def add_vm_name_option(action, optional=true)
|
||||
def add_vm_name_option(action, optional = true)
|
||||
action.option '--vm-name=' do
|
||||
summary 'The name of the virtual machine.'
|
||||
description <<-EOT
|
||||
The name of the virtual machine.
|
||||
EOT
|
||||
description 'The name of the virtual machine.'
|
||||
required unless optional
|
||||
before_action do |action, args, options|
|
||||
if options[:vm_name].empty?
|
||||
raise ArgumentError, "VM Name is required."
|
||||
fail ArgumentError, 'VM Name is required.'
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -84,12 +82,12 @@ module Puppet::VirtualMachine
|
|||
required
|
||||
before_action do |action, args, options|
|
||||
if options[:image].empty?
|
||||
raise ArgumentError, "Source image name is required"
|
||||
fail ArgumentError, 'Source image name is required'
|
||||
else
|
||||
Puppet::VirtualMachine.initialize_env_variable(options)
|
||||
image_service = Azure::VirtualMachineImageManagementService.new
|
||||
os_image = image_service.list_virtual_machine_images.select{|x| x.name == options[:image]}.first
|
||||
raise ArgumentError, "Source image name is invalid" unless os_image
|
||||
os_image = image_service.list_virtual_machine_images.select { |x| x.name == options[:image] }.first
|
||||
fail ArgumentError, 'Source image name is invalid' unless os_image
|
||||
@os_type = os_image.os_type
|
||||
end
|
||||
end
|
||||
|
@ -105,22 +103,20 @@ module Puppet::VirtualMachine
|
|||
end
|
||||
end
|
||||
|
||||
def add_cloud_service_name_option(action, optional=true)
|
||||
def add_cloud_service_name_option(action, optional = true)
|
||||
action.option '--cloud-service-name=' do
|
||||
summary 'The name of the cloud service.'
|
||||
description <<-EOT
|
||||
The name of the cloud service.
|
||||
EOT
|
||||
description 'The name of the cloud service.'
|
||||
required unless optional
|
||||
before_action do |action, args, options|
|
||||
if options[:cloud_service_name].empty?
|
||||
raise ArgumentError, "Cloud service name is required."
|
||||
fail ArgumentError, 'Cloud service name is required.'
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def add_vm_user_option(action, optional=true)
|
||||
def add_vm_user_option(action, optional = true)
|
||||
action.option '--vm-user=' do
|
||||
summary 'The VM user name.'
|
||||
description <<-EOT
|
||||
|
@ -129,13 +125,13 @@ module Puppet::VirtualMachine
|
|||
required unless optional
|
||||
before_action do |action, args, options|
|
||||
if options[:vm_user].empty?
|
||||
raise ArgumentError, "The VM user name is required."
|
||||
fail ArgumentError, 'The VM user name is required.'
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def add_puppet_master_ip_option(action, optional=true)
|
||||
def add_puppet_master_ip_option(action, optional = true)
|
||||
action.option '--puppet-master-ip=' do
|
||||
summary 'The puppet master ip address.'
|
||||
description <<-EOT
|
||||
|
@ -144,22 +140,20 @@ module Puppet::VirtualMachine
|
|||
required if !optional
|
||||
before_action do |action, args, options|
|
||||
if options[:puppet_master_ip].empty?
|
||||
raise ArgumentError, "The pupet master ip address is required."
|
||||
fail ArgumentError, 'The pupet master ip address is required.'
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def add_deployment_name_option(action, optional=true)
|
||||
def add_deployment_name_option(action, optional = true)
|
||||
action.option '--deployment-name=' do
|
||||
summary 'The vm instance deployment name.'
|
||||
description <<-EOT
|
||||
The vm instance deployment name.
|
||||
EOT
|
||||
description 'The vm instance deployment name.'
|
||||
required unless optional
|
||||
before_action do |action, args, options|
|
||||
if options[:deployment_name].empty?
|
||||
raise ArgumentError, "Deployment name is required."
|
||||
fail ArgumentError, 'Deployment name is required.'
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -168,13 +162,11 @@ module Puppet::VirtualMachine
|
|||
def add_password_option(action)
|
||||
action.option '--password=' do
|
||||
summary 'Authentication password for vm.'
|
||||
description <<-EOT
|
||||
Authentication password for vm.
|
||||
EOT
|
||||
description 'Authentication password for vm.'
|
||||
required if @os_type == 'Windows'
|
||||
before_action do |action, args, options|
|
||||
if options[:password].empty?
|
||||
raise ArgumentError, "The password is required."
|
||||
fail ArgumentError, 'The password is required.'
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -183,9 +175,7 @@ module Puppet::VirtualMachine
|
|||
def add_end_points_option(action)
|
||||
action.option '--tcp-endpoints=' do
|
||||
summary 'Tcp End Points. '
|
||||
description <<-EOT
|
||||
Add Tcp end points. example --tcp-endpoints="80,3889:3889"
|
||||
EOT
|
||||
description 'Add Tcp end points. example --tcp-endpoints="80,3889:3889"'
|
||||
|
||||
end
|
||||
end
|
||||
|
@ -193,20 +183,19 @@ module Puppet::VirtualMachine
|
|||
def add_node_ipaddress_options(action)
|
||||
action.option '--node-ipaddress=' do
|
||||
summary 'Node Ip address. '
|
||||
description <<-EOT
|
||||
The ip address where puppet need to install."
|
||||
EOT
|
||||
description 'The ip address where puppet need to install.'
|
||||
|
||||
required
|
||||
before_action do |action, args, options|
|
||||
if options[:ssh_user].nil? && options[:winrm_user].nil?
|
||||
raise ArgumentError, "winrm_user or ssh_user is required."
|
||||
fail ArgumentError, 'winrm_user or ssh_user is required.'
|
||||
elsif options[:ssh_user].nil?
|
||||
@os_type = 'Windows'
|
||||
elsif options[:winrm_user].nil?
|
||||
@os_type = 'Linux'
|
||||
end
|
||||
if options[:node_ipaddress].empty?
|
||||
raise ArgumentError, "The Node ip address is require."
|
||||
fail ArgumentError, 'The Node ip address is require.'
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -214,16 +203,14 @@ module Puppet::VirtualMachine
|
|||
|
||||
def add_certificate_file_option(action)
|
||||
action.option '--certificate-file=' do
|
||||
summary "Authentication using certificate instead of password."
|
||||
description <<-EOT
|
||||
Authentication using certificate instead of password.
|
||||
EOT
|
||||
summary 'Authentication using certificate instead of password.'
|
||||
description 'Authentication using certificate instead of password.'
|
||||
before_action do |action, args, options|
|
||||
unless test 'f', options[:certificate_file]
|
||||
raise ArgumentError, "Could not find file '#{options[:certificate_file]}'"
|
||||
fail ArgumentError, "Could not find file '#{options[:certificate_file]}'"
|
||||
end
|
||||
unless test 'r', options[:certificate_file]
|
||||
raise ArgumentError, "Could not read from file '#{options[:certificate_file]}'"
|
||||
fail ArgumentError, "Could not read from file '#{options[:certificate_file]}'"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -231,16 +218,14 @@ module Puppet::VirtualMachine
|
|||
|
||||
def add_private_key_file_option(action)
|
||||
action.option '--private-key-file=' do
|
||||
summary "Authentication using certificate instead of password."
|
||||
description <<-EOT
|
||||
Authentication using certificate instead of password..
|
||||
EOT
|
||||
summary 'Authentication using certificate instead of password.'
|
||||
description 'Authentication using certificate instead of password.'
|
||||
before_action do |action, args, options|
|
||||
unless test 'f', options[:private_key_file]
|
||||
raise ArgumentError, "Could not find file '#{options[:private_key_file]}'"
|
||||
fail ArgumentError, "Could not find file '#{options[:private_key_file]}'"
|
||||
end
|
||||
unless test 'r', options[:private_key_file]
|
||||
raise ArgumentError, "Could not read from file '#{options[:private_key_file]}'"
|
||||
fail ArgumentError, "Could not read from file '#{options[:private_key_file]}'"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -248,14 +233,15 @@ module Puppet::VirtualMachine
|
|||
|
||||
def add_winrm_transport_option(action)
|
||||
action.option '--winrm-transport=' do
|
||||
summary "Winrm authentication protocol. Valid choices are http or https or http,https"
|
||||
summary 'Winrm authentication protocol. Valid choices are http or https or http,https'
|
||||
description <<-EOT
|
||||
Winrm authentication protocol. Valid choices are http or https or http,https.
|
||||
EOT
|
||||
before_action do |action, args, options|
|
||||
winrm_transport = options[:winrm_transport].split(",")
|
||||
unless (!winrm_transport.nil? && (winrm_transport.select{|x| x.downcase == 'http' or x.downcase == 'https'}.size > 0))
|
||||
raise ArgumentError, "The winrm transport is not valid. Valid choices are http or https or http,https"
|
||||
winrm_transport = options[:winrm_transport].split(',')
|
||||
winrm_transport_size = winrm_transport.select { |x| x.downcase == 'http' or x.downcase == 'https' }.size
|
||||
unless !winrm_transport.nil? && (winrm_transport_size > 0)
|
||||
fail ArgumentError, 'The winrm transport is not valid. Valid choices are http or https or http,https'
|
||||
end
|
||||
options[:winrm_transport] = winrm_transport
|
||||
end
|
||||
|
@ -265,9 +251,7 @@ module Puppet::VirtualMachine
|
|||
def add_ssh_port_option(action)
|
||||
action.option '--ssh-port=' do
|
||||
summary 'Port for ssh server.'
|
||||
description <<-EOT
|
||||
Port for ssh server.
|
||||
EOT
|
||||
description 'Port for ssh server.'
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -280,7 +264,7 @@ module Puppet::VirtualMachine
|
|||
before_action do |action, args, options|
|
||||
valid_role_sizes = ['ExtraSmall', 'Small', 'Medium', 'Large', 'ExtraLarge', 'A6', 'A7']
|
||||
if options[:vm_size] && !valid_role_sizes.include?(options[:vm_size])
|
||||
raise ArgumentError, "The vm-size is not valid. Valid choice are ExtraSmall, Small, Medium, Large, ExtraLarge"
|
||||
fail ArgumentError, 'The vm-size is not valid. Valid choice are ExtraSmall, Small, Medium, Large, ExtraLarge'
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -289,9 +273,7 @@ module Puppet::VirtualMachine
|
|||
def add_virtual_network_option(action)
|
||||
action.option '--virtual-network-name=' do
|
||||
summary 'The virtual network name.'
|
||||
description <<-EOT
|
||||
The name of virtual network.
|
||||
EOT
|
||||
description 'The name of virtual network.'
|
||||
|
||||
end
|
||||
end
|
||||
|
@ -299,9 +281,7 @@ module Puppet::VirtualMachine
|
|||
def add_subnet_option(action)
|
||||
action.option '--virtual-network-subnet=' do
|
||||
summary 'The virtual network subnet.'
|
||||
description <<-EOT
|
||||
The subnet of virtual network.
|
||||
EOT
|
||||
description 'The subnet of virtual network.'
|
||||
|
||||
end
|
||||
end
|
||||
|
@ -309,10 +289,7 @@ module Puppet::VirtualMachine
|
|||
def add_affinity_group_option(action)
|
||||
action.option '--affinity-group-name=' do
|
||||
summary 'The affinity group name.'
|
||||
description <<-EOT
|
||||
The name of affinity group.
|
||||
EOT
|
||||
|
||||
description 'The name of affinity group.'
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -325,7 +302,7 @@ module Puppet::VirtualMachine
|
|||
required if @os_type == 'Linux'
|
||||
before_action do |action, args, options|
|
||||
if options[:ssh_user].empty?
|
||||
raise ArgumentError, "The ssh username is required."
|
||||
fail ArgumentError, 'The ssh username is required.'
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -340,7 +317,7 @@ module Puppet::VirtualMachine
|
|||
required if @os_type == 'Windows'
|
||||
before_action do |action, args, options|
|
||||
if options[:winrm_user].empty?
|
||||
raise ArgumentError, "The winrm username is required."
|
||||
fail ArgumentError, 'The winrm username is required.'
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -349,22 +326,20 @@ module Puppet::VirtualMachine
|
|||
def add_winrm_port_option(action)
|
||||
action.option '--winrm-port=' do
|
||||
summary 'Port for winrm.'
|
||||
description <<-EOT
|
||||
Port for winrm.
|
||||
EOT
|
||||
description 'Port for winrm.'
|
||||
end
|
||||
end
|
||||
|
||||
def add_bootstrap_winrm_transport_option(action)
|
||||
action.option '--winrm-transport=' do
|
||||
summary "Winrm authentication protocol. Valid choices are http or https"
|
||||
summary 'Winrm authentication protocol. Valid choices are http or https'
|
||||
description <<-EOT
|
||||
Winrm authentication protocol. Valid choices are http or https.
|
||||
EOT
|
||||
before_action do |action, args, options|
|
||||
winrm_transport = options[:winrm_transport]
|
||||
unless (['http', 'https', nil].include?(winrm_transport))
|
||||
raise ArgumentError, "The winrm transport is not valid. Valid choices are http or https"
|
||||
unless ['http', 'https', nil].include?(winrm_transport)
|
||||
fail ArgumentError, 'The winrm transport is not valid. Valid choices are http or https'
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -30,7 +30,7 @@ module Puppet::VirtualNetwork
|
|||
required
|
||||
before_action do |act, args, options|
|
||||
filepath = options[:xml_schema_file]
|
||||
validate_file(filepath, 'Network schema', ['xml'])
|
||||
validate_file(filepath, 'Network schema', ['xml'])
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -42,7 +42,7 @@ module Puppet::VirtualNetwork
|
|||
required
|
||||
before_action do |act, args, options|
|
||||
if options[:virtual_network_name].empty?
|
||||
raise ArgumentError, 'Virtual network name is required'
|
||||
fail ArgumentError, 'Virtual network name is required'
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -55,7 +55,7 @@ module Puppet::VirtualNetwork
|
|||
required
|
||||
before_action do |act, args, options|
|
||||
if options[:address_space].empty?
|
||||
raise ArgumentError, 'Virtual network address space is required'
|
||||
fail ArgumentError, 'Virtual network address space is required'
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Загрузка…
Ссылка в новой задаче