lib/vagrant-conoha/config.rb in vagrant-conoha-0.1.0 vs lib/vagrant-conoha/config.rb in vagrant-conoha-0.1.1

- old
+ new

@@ -65,10 +65,15 @@ # The name of the keypair to use. # # @return [String] attr_accessor :keypair_name + # The unix root password of OpenStack instance. + # + # @return [String] + attr_accessor :admin_pass + # The SSH username to use with this OpenStack instance. This overrides # the `config.ssh.username` variable. # # @return [String] attr_accessor :ssh_username @@ -211,10 +216,11 @@ @server_name = UNSET_VALUE @username = UNSET_VALUE @rsync_includes = [] @rsync_ignore_files = [] @keypair_name = UNSET_VALUE + @admin_pass = UNSET_VALUE @ssh_username = UNSET_VALUE @ssh_timeout = UNSET_VALUE @floating_ip = UNSET_VALUE @floating_ip_pool = [] @floating_ip_pool_always_allocate = UNSET_VALUE @@ -298,10 +304,11 @@ @floating_ip = nil if @floating_ip == UNSET_VALUE @floating_ip_pool = nil if @floating_ip_pool == UNSET_VALUE @floating_ip_pool_always_allocate = false if floating_ip_pool_always_allocate == UNSET_VALUE @sync_method = 'rsync' if @sync_method == UNSET_VALUE @keypair_name = nil if @keypair_name == UNSET_VALUE + @admin_pass = nil if @admin_pass == UNSET_VALUE @public_key_path = nil if @public_key_path == UNSET_VALUE @availability_zone = nil if @availability_zone == UNSET_VALUE @scheduler_hints = nil if @scheduler_hints == UNSET_VALUE @security_groups = nil if @security_groups == UNSET_VALUE @user_data = nil if @user_data == UNSET_VALUE @@ -338,10 +345,11 @@ errors << I18n.t('vagrant_openstack.config.invalid_endpoint_type') unless %w(publicURL adminURL internalURL).include?(@endpoint_type) validate_ssh_username(machine, errors) validate_stack_config(errors) validate_ssh_timeout(errors) + validate_admin_pass(errors) if machine.config.ssh.private_key_path puts I18n.t('vagrant_openstack.config.keypair_name_required').yellow unless @keypair_name || @public_key_path else errors << I18n.t('vagrant_openstack.config.private_key_missing') if @keypair_name || @public_key_path @@ -360,9 +368,16 @@ { 'Openstack Provider' => errors } end private + + def validate_admin_pass(errors) + return if @admin_pass == '' or @admin_pass == nil + + reg = /\A(?=.*?[A-Z])(?=.*?[a-z])(?=.*?\d)(?=.*?[!-~&&[^A-Za-z\d]])[!-~]{9,70}+\z/ + errors << I18n.t('vagrant_openstack.config.invalid_admin_pass') unless @admin_pass =~ reg + end def validate_stack_config(errors) @stacks.each do |stack| errors << I18n.t('vagrant_openstack.config.invalid_stack') unless stack[:name] && stack[:template] end unless @stacks.nil?