staypuft 0.4.1 → 0.4.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (28) hide show
  1. checksums.yaml +13 -5
  2. data/app/assets/javascripts/staypuft/new_subnet.js +9 -0
  3. data/app/assets/javascripts/staypuft/staypuft.js +39 -0
  4. data/app/assets/javascripts/staypuft/subnets_assignment.js +5 -1
  5. data/app/controllers/staypuft/concerns/hosts_api_extensions.rb +18 -0
  6. data/app/controllers/staypuft/concerns/hosts_controller_extensions.rb +38 -0
  7. data/app/controllers/staypuft/subnets_controller.rb +25 -0
  8. data/app/lib/staypuft/seeder.rb +71 -19
  9. data/app/models/staypuft/deployment.rb +11 -2
  10. data/app/models/staypuft/deployment/cinder_service.rb +1 -1
  11. data/app/models/staypuft/deployment/cinder_service/equallogic.rb +1 -23
  12. data/app/models/staypuft/deployment/ip_address_validator.rb +30 -0
  13. data/app/models/staypuft/deployment/neutron_service.rb +55 -9
  14. data/app/models/staypuft/deployment/neutron_service/cisconexus.rb +1 -12
  15. data/app/models/staypuft/simple_subnet.rb +115 -0
  16. data/app/overrides/foreman_hosts_edit.rb +13 -0
  17. data/app/overrides/select_multiple_systems_hostgroup.rb +15 -0
  18. data/app/views/staypuft/steps/_neutron.html.erb +35 -22
  19. data/app/views/staypuft/steps/deployment_settings.html.erb +2 -0
  20. data/app/views/staypuft/steps/network_configuration.html.erb +28 -1
  21. data/app/views/staypuft/subnets/_form.html.erb +24 -0
  22. data/app/views/staypuft/subnets/create.js.erb +14 -0
  23. data/app/views/staypuft/subnets/new.html.erb +3 -0
  24. data/config/routes.rb +4 -0
  25. data/db/migrate/20141009064907_add_custom_repos_to_deployment.rb +5 -0
  26. data/lib/staypuft/engine.rb +5 -2
  27. data/lib/staypuft/version.rb +1 -1
  28. metadata +151 -140
checksums.yaml CHANGED
@@ -1,7 +1,15 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: a03caebb78c982156156e14071fb90cef35627dd
4
- data.tar.gz: 96d1b6b7f38b74f6b081d1e061b7a9d7e5dbab89
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ NDI4ZGUzMDk5ZjA2ZDgyODNkYTFjMzgxNGI3MzhmNDhkOGZmM2ZhMA==
5
+ data.tar.gz: !binary |-
6
+ OWYwYTdhNDhkYmZjMGVjNmUzMmM5YjM5NWViNDkxNDNkMDA1OWM1Mw==
5
7
  SHA512:
6
- metadata.gz: 213f86077425ac3969d84c220fce82fe6bc941234ea136e8332d594c9bc93c58e440ba919c7be841ae2e4848c598eb4c9c00cd64076471440331ad6d0fed392f
7
- data.tar.gz: 114c5a5a5ad09fc049bb8c6504265a8da3a05717acfb6b7fe232b83a4c023b491bc10f3c78e16349fc50372dd1732535a6f6bc267fc507e072fca1890979825e
8
+ metadata.gz: !binary |-
9
+ OWYyNmY4NThhYzU4NmNiNmY4MTcyOGY3NGE1ZmYzNmE0MTIzYzFjZjU3ZDE3
10
+ OTM5NTU0Nzk2Yjk1Y2JlMGRkZDkwN2YwNDM4NDJhMjQ4NWI4ZjBlNmU2YzBj
11
+ MzMwNjVjMDllZGUxMzgwNTIzODdiN2Q1ZDUyYzNlNDRhZGQ5ZGI=
12
+ data.tar.gz: !binary |-
13
+ MjY0ZjVkZjVhNjBhYjVhMjkwMzU3NDdlMWJlMWUyNDFjODE0M2VjNWFhMDE4
14
+ NTU3NGU3YjdkYzRlMDM5YWVhYzEzMjg3ZWU1M2Q3OTdjNmFkYmMwYTQ5OGRm
15
+ ZjZhN2I1NjNkODRlMTMwNGQ1OWFmMmJjMjg3ZDBmMzljZGRiYjk=
@@ -0,0 +1,9 @@
1
+ var new_subnet = (function() {
2
+ $('#staypuft_simple_subnet_dhcp_server').on('change', function(event) {
3
+ if($(event.target).find(":selected").val() == 'none') {
4
+ $('#no_existing_dhcp_fields').show();
5
+ } else {
6
+ $('#no_existing_dhcp_fields').hide();
7
+ }
8
+ });
9
+ });
@@ -103,6 +103,30 @@ $(function () {
103
103
  }
104
104
  }
105
105
 
106
+ showNeutronMl2Mechanisms();
107
+ $("input[name='staypuft_deployment[neutron][core_plugin]']").change(showNeutronMl2Mechanisms);
108
+ function showNeutronMl2Mechanisms() {
109
+ $('#staypuft_deployment_neutron_core_plugin_ml2').parent().parent().parent().removeClass('col-md-4').addClass('col-md-6')
110
+ if ($('#staypuft_deployment_neutron_core_plugin_ml2').is(":checked")) {
111
+ $('#staypuft_deployment_neutron_core_plugin_ml2').parent().after($('.neutron_ml2_mechanisms'));
112
+ $('.neutron_ml2_mechanisms').fadeIn(duration);
113
+ } else {
114
+ $('.neutron_ml2_mechanisms').fadeOut(duration);
115
+ }
116
+ }
117
+
118
+ showNeutronN1kvParameters();
119
+ $("input[name='staypuft_deployment[neutron][core_plugin]']").change(showNeutronN1kvParameters);
120
+ function showNeutronN1kvParameters() {
121
+ $('#staypuft_deployment_neutron_core_plugin_n1kv').parent().parent().parent().removeClass('col-md-4').addClass('col-md-6')
122
+ if ($('#staypuft_deployment_neutron_core_plugin_n1kv').is(":checked")) {
123
+ $('#staypuft_deployment_neutron_core_plugin_n1kv').parent().after($('.neutron_n1kv_parameters'));
124
+ $('.neutron_n1kv_parameters').fadeIn(duration);
125
+ } else {
126
+ $('.neutron_n1kv_parameters').fadeOut(duration);
127
+ }
128
+ }
129
+
106
130
  showNeutronExternalInterface();
107
131
  $("input[name='staypuft_deployment[neutron][use_external_interface]']").change(showNeutronExternalInterface);
108
132
  function showNeutronExternalInterface() {
@@ -260,6 +284,21 @@ $(function () {
260
284
  })
261
285
  });
262
286
 
287
+ $('#new_subnet_modal').on('shown.bs.modal', function(e) {
288
+ var height = $(window).height() - 200;
289
+ $(this).find(".modal-body").css("max-height", height);
290
+ var to_path = $('#new_subnet_modal').data('path');
291
+ $.ajax({
292
+ url: to_path,
293
+ type: "GET",
294
+ success: function(data){
295
+ $('#new_subnet_ajax_content').html(data).promise().done(function(){
296
+ new_subnet();
297
+ });
298
+ }
299
+ });
300
+ });
301
+
263
302
  var scrolled = false;
264
303
 
265
304
  $(window).scroll(function(){
@@ -1,4 +1,4 @@
1
- $(function() {
1
+ var subnets_assigments = (function() {
2
2
  $("div.subnet-type-pull").draggable({
3
3
  revert: 'invalid'
4
4
  });
@@ -69,3 +69,7 @@ $(function() {
69
69
  }
70
70
  });
71
71
  });
72
+
73
+ $(function() {
74
+ subnets_assigments();
75
+ });
@@ -0,0 +1,18 @@
1
+ module Staypuft::Concerns::HostsApiExtensions
2
+ extend ActiveSupport::Concern
3
+
4
+ included do
5
+ prepend_before_filter :check_openstack_hostgroup, only: [:create, :update]
6
+ end
7
+
8
+ def check_openstack_hostgroup
9
+ if params[:host] and params[:host][:hostgroup_id]
10
+ hostgroup_id = params[:host][:hostgroup_id]
11
+ hg = Hostgroup.find(hostgroup_id)
12
+ if hg.ancestors.include? Hostgroup.get_base_hostgroup
13
+ Rails.logger.error "Cannot set a deployment hostgroup directly."
14
+ render :json => {:error => {:message => _('Cannot set a deployment hostgroup directly.') } }, :status => :forbidden
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,38 @@
1
+ module Staypuft::Concerns::HostsControllerExtensions
2
+ extend ActiveSupport::Concern
3
+
4
+ included do
5
+ before_filter :check_openstack_hostgroup, only: [:create, :update]
6
+ before_filter :check_openstack_hostgroup_multiple, only: [:update_multiple_hostgroup]
7
+ end
8
+
9
+ def check_openstack_hostgroup
10
+ if params[:host] and params[:host][:hostgroup_id]
11
+ hostgroup_id = params[:host][:hostgroup_id]
12
+ if openstack_hostgroup? hostgroup_id
13
+ Rails.logger.error "Cannot set a deployment hostgroup directly."
14
+ error _('Invalid host group selected! Cannot select OpenStack deployment host group.')
15
+ render :action => :edit and return
16
+ end
17
+ end
18
+ end
19
+
20
+ def check_openstack_hostgroup_multiple
21
+ if params["hostgroup"] and params["hostgroup"]["id"]
22
+ check_hostgroup params["hostgroup"]["id"] do
23
+ if openstack_hostgroup? hostgroup_id
24
+ error _('Invalid host group selected! Cannot select OpenStack deployment host group.')
25
+ redirect_to(select_multiple_hostgroup_hosts_path) and return
26
+ end
27
+ end
28
+ end
29
+
30
+ private
31
+
32
+ def openstack_hostgroup?(id)
33
+ hg = Hostgroup.find(id)
34
+ hg.ancestors.include? Hostgroup.get_base_hostgroup
35
+ rescue
36
+ false
37
+ end
38
+ end
@@ -0,0 +1,25 @@
1
+ module Staypuft
2
+ class SubnetsController < Staypuft::ApplicationController
3
+
4
+ layout false
5
+
6
+ before_filter :get_deployment
7
+
8
+ def new
9
+ @simple_subnet = SimpleSubnet.new
10
+ end
11
+
12
+ def create
13
+ @simple_subnet = SimpleSubnet.new(params[:staypuft_simple_subnet])
14
+ @simple_subnet.deployment = @deployment
15
+ @result = @simple_subnet.save
16
+ end
17
+
18
+ private
19
+
20
+ def get_deployment
21
+ @deployment = Deployment.find(params[:deployment_id])
22
+ end
23
+
24
+ end
25
+ end
@@ -256,6 +256,13 @@ module Staypuft
256
256
  network_private_iface = { :string => "<%= @host.network_query.interface_for_host('#{Staypuft::SubnetType::TENANT}') %>" }
257
257
  network_public_iface = { :string => "<%= @host.network_query.interface_for_host('#{Staypuft::SubnetType::EXTERNAL}') %>" }
258
258
  network_create_networks = true
259
+ nova_conf_additional_params = { :hash => { 'quota_instances' => 'default',
260
+ 'quota_cores' => 'default',
261
+ 'quota_ram' => 'default',
262
+ 'quota_floating_ips' => 'default',
263
+ 'quota_fixed_ips' => 'default',
264
+ 'quota_driver' => 'default' }
265
+ }
259
266
 
260
267
  # Neutron
261
268
  ovs_vlan_ranges = { :array => '<%= @host.deployment.neutron.networker_vlan_ranges %>' }
@@ -274,6 +281,17 @@ module Staypuft
274
281
  compute_ovs_bridge_mappings = { :array => '<%= @host.deployment.neutron.compute_ovs_bridge_mappings(@host) %>' }
275
282
  compute_ovs_bridge_uplinks = { :array => '<%= @host.deployment.neutron.compute_ovs_bridge_uplinks(@host) %>' }
276
283
  enable_tunneling = { :string => '<%= @host.deployment.neutron.enable_tunneling?.to_s %>' }
284
+ neutron_core_plugin_module = { :string => '<%= @host.deployment.neutron.core_plugin_module %>' }
285
+ neutron_agent_type = 'ovs'
286
+ neutron_security_group_api = 'neutron'
287
+ neutron_conf_additional_params = { :hash => { 'default_quota' => 'default',
288
+ 'quota_network' => 'default',
289
+ 'quota_subnet' => 'default',
290
+ 'quota_port' => 'default',
291
+ 'quota_security_group' => 'default',
292
+ 'quota_security_group_rule' => 'default',
293
+ 'network_auto_schedule' => 'default' }
294
+ }
277
295
 
278
296
  # Glance
279
297
  backend = { :string => '<%= @host.deployment.glance.backend %>' }
@@ -288,17 +306,18 @@ module Staypuft
288
306
  # Cinder
289
307
  volume = true
290
308
  cinder_backend_gluster = false
291
- cinder_backend_gluster_name = 'gluster_backend'
309
+ cinder_backend_gluster_name = 'gluster'
292
310
  cinder_backend_iscsi = { :string => '<%= @host.deployment.cinder.lvm_backend? %>' }
293
- cinder_backend_iscsi_name = 'iscsi_backend'
311
+ cinder_backend_iscsi_name = 'iscsi'
294
312
  cinder_backend_nfs = { :string => '<%= @host.deployment.cinder.nfs_backend? %>' }
295
- cinder_backend_nfs_name = 'nfs_backend'
313
+ cinder_backend_nfs_name = 'nfs'
296
314
  cinder_multiple_backends = { :string => '<%= @host.deployment.cinder.multiple_backends? %>' }
315
+ cinder_create_volume_types = true
297
316
  cinder_nfs_shares = ['<%= @host.deployment.cinder.nfs_uri %>']
298
317
  cinder_nfs_mount_options = 'nosharecache'
299
318
 
300
319
  cinder_backend_rbd = { :string => '<%= @host.deployment.cinder.ceph_backend? %>' }
301
- cinder_backend_rbd_name = 'rbd_backend'
320
+ cinder_backend_rbd_name = 'rbd'
302
321
  cinder_rbd_pool = 'volumes'
303
322
  cinder_rbd_ceph_conf = '/etc/ceph/ceph.conf'
304
323
  cinder_rbd_flatten_volume_from_snapshot = 'false'
@@ -401,6 +420,18 @@ module Staypuft
401
420
  # Cisco Nexus
402
421
  cisco_nexus_config = { :hash => '<%= n = @host.deployment.neutron; (n.active? && n.cisco_nexus_mechanism?) ? n.compute_cisco_nexus_config : {} %>' }
403
422
 
423
+ # Cisco N1KV params
424
+ n1kv_vsm_ip = { :string => '<%= n = @host.deployment.neutron; (n.active? && n.n1kv_plugin?) ? n.n1kv_vsm_ip : "" %>' }
425
+ n1kv_vsm_password = { :string => '<%= n = @host.deployment.neutron; (n.active? && n.n1kv_plugin?) ? n.n1kv_vsm_password : "" %>' }
426
+ n1kv_plugin_additional_params = { :hash => { 'default_policy_profile' => 'default-pp',
427
+ 'network_node_policy_profile' => 'default-pp',
428
+ 'poll_duration' => '10',
429
+ 'http_pool_size' => '4',
430
+ 'http_timeout' => '120',
431
+ 'firewall_driver' => 'neutron.agent.firewall.NoopFirewallDriver',
432
+ 'enable_sync_on_start' => 'True' }
433
+ }
434
+
404
435
  {
405
436
  'quickstack::nova_network::controller' => {
406
437
  'amqp_provider' => amqp_provider,
@@ -422,6 +453,7 @@ module Staypuft
422
453
  'cinder_backend_eqlx' => cinder_backend_eqlx,
423
454
  'cinder_backend_eqlx_name' => cinder_backend_eqlx_name,
424
455
  'cinder_multiple_backends' => cinder_multiple_backends,
456
+ 'cinder_create_volume_types' => cinder_create_volume_types,
425
457
  'cinder_nfs_shares' => cinder_nfs_shares,
426
458
  'cinder_nfs_mount_options' => cinder_nfs_mount_options,
427
459
  'cinder_rbd_pool' => cinder_rbd_pool,
@@ -499,6 +531,7 @@ module Staypuft
499
531
  'cinder_backend_eqlx' => cinder_backend_eqlx,
500
532
  'cinder_backend_eqlx_name' => cinder_backend_eqlx_name,
501
533
  'cinder_multiple_backends' => cinder_multiple_backends,
534
+ 'cinder_create_volume_types' => cinder_create_volume_types,
502
535
  'cinder_nfs_shares' => cinder_nfs_shares,
503
536
  'cinder_nfs_mount_options' => cinder_nfs_mount_options,
504
537
  'cinder_rbd_pool' => cinder_rbd_pool,
@@ -552,7 +585,14 @@ module Staypuft
552
585
  'controller_admin_host' => controller_admin_host,
553
586
  'controller_priv_host' => controller_priv_host,
554
587
  'controller_pub_host' => controller_pub_host,
555
- 'nexus_config' => cisco_nexus_config },
588
+ 'nexus_config' => cisco_nexus_config,
589
+ 'neutron_conf_additional_params' => neutron_conf_additional_params,
590
+ 'nova_conf_additional_params' => nova_conf_additional_params,
591
+ 'n1kv_plugin_additional_params' => n1kv_plugin_additional_params,
592
+ 'n1kv_vsm_ip' => n1kv_vsm_ip,
593
+ 'n1kv_vsm_password' => n1kv_vsm_password,
594
+ 'security_group_api' => neutron_security_group_api,
595
+ 'neutron_core_plugin' => neutron_core_plugin_module },
556
596
  'quickstack::pacemaker::params' => {
557
597
  'include_swift' => 'false',
558
598
  'include_neutron' => neutron,
@@ -618,7 +658,9 @@ module Staypuft
618
658
  'private_ip' => private_ip,
619
659
  'cluster_control_ip' => { :string => "<%= @host.deployment.network_query.controller_ips('#{Staypuft::SubnetType::MANAGEMENT}').first %>" },
620
660
  'lb_backend_server_addrs' => { :array => "<%= @host.deployment.network_query.controller_ips('#{Staypuft::SubnetType::MANAGEMENT}') %>" },
621
- 'lb_backend_server_names' => { :array => '<%= @host.deployment.network_query.controller_fqdns %>' } },
661
+ 'lb_backend_server_names' => { :array => '<%= @host.deployment.network_query.controller_fqdns %>' },
662
+ 'agent_type' => neutron_agent_type,
663
+ 'n1kv_plugin_additional_params' => n1kv_plugin_additional_params },
622
664
  'quickstack::pacemaker::common' => {
623
665
  'pacemaker_cluster_members' => { :string => "<%= @host.deployment.network_query.controller_ips('#{Staypuft::SubnetType::CLUSTER_MGMT}').join(' ') %>" },
624
666
  'fencing_type' => fencing_type,
@@ -631,17 +673,24 @@ module Staypuft
631
673
  'fence_ipmilan_expose_lanplus' => fence_ipmilan_expose_lanplus,
632
674
  'fence_ipmilan_lanplus_options' => fence_ipmilan_lanplus_options },
633
675
  'quickstack::pacemaker::neutron' => {
634
- 'ml2_network_vlan_ranges' => ml2_network_vlan_ranges,
635
- 'ml2_tenant_network_types' => ml2_tenant_network_types,
636
- 'ml2_tunnel_id_ranges' => ml2_tunnel_id_ranges,
637
- 'ml2_mechanism_drivers' => ml2_mechanism_drivers,
638
- 'enable_tunneling' => enable_tunneling,
639
- 'ovs_bridge_mappings' => ovs_bridge_mappings,
640
- 'ovs_bridge_uplinks' => ovs_bridge_uplinks,
641
- 'ovs_tunnel_iface' => ovs_tunnel_iface,
642
- 'ovs_tunnel_types' => ovs_tunnel_types,
643
- 'ovs_vlan_ranges' => ovs_vlan_ranges,
644
- 'nexus_config' => cisco_nexus_config },
676
+ 'ml2_network_vlan_ranges' => ml2_network_vlan_ranges,
677
+ 'ml2_tenant_network_types' => ml2_tenant_network_types,
678
+ 'ml2_tunnel_id_ranges' => ml2_tunnel_id_ranges,
679
+ 'ml2_mechanism_drivers' => ml2_mechanism_drivers,
680
+ 'enable_tunneling' => enable_tunneling,
681
+ 'ovs_bridge_mappings' => ovs_bridge_mappings,
682
+ 'ovs_bridge_uplinks' => ovs_bridge_uplinks,
683
+ 'ovs_tunnel_iface' => ovs_tunnel_iface,
684
+ 'ovs_tunnel_types' => ovs_tunnel_types,
685
+ 'ovs_vlan_ranges' => ovs_vlan_ranges,
686
+ 'nexus_config' => cisco_nexus_config,
687
+ 'core_plugin' => neutron_core_plugin_module,
688
+ 'neutron_conf_additional_params' => neutron_conf_additional_params,
689
+ 'nova_conf_additional_params' => nova_conf_additional_params,
690
+ 'n1kv_plugin_additional_params' => n1kv_plugin_additional_params,
691
+ 'n1kv_vsm_ip' => n1kv_vsm_ip,
692
+ 'n1kv_vsm_password' => n1kv_vsm_password,
693
+ 'security_group_api' => neutron_security_group_api },
645
694
  'quickstack::pacemaker::glance' => {
646
695
  'backend' => backend,
647
696
  'pcmk_fs_type' => pcmk_fs_type,
@@ -705,7 +754,8 @@ module Staypuft
705
754
  'neutron_metadata_proxy_secret' => neutron_metadata_proxy_secret,
706
755
  'amqp_host' => amqp_host,
707
756
  'mysql_host' => mysql_host,
708
- 'controller_priv_host' => controller_priv_host },
757
+ 'controller_priv_host' => controller_priv_host,
758
+ 'agent_type' => neutron_agent_type },
709
759
  'quickstack::storage_backend::cinder' => {
710
760
  'amqp_provider' => amqp_provider,
711
761
  'cinder_db_password' => cinder_db_pw,
@@ -782,7 +832,9 @@ module Staypuft
782
832
  'auth_host' => auth_host,
783
833
  'neutron_host' => neutron_host,
784
834
  'nova_host' => nova_host,
785
- 'private_ip' => private_ip },
835
+ 'private_ip' => private_ip,
836
+ 'agent_type' => neutron_agent_type,
837
+ 'security_group_api' => neutron_security_group_api },
786
838
  'quickstack::pacemaker::rsync::keystone' => {
787
839
  'keystone_private_vip' => vip_format(:keystone) },
788
840
  'quickstack::ceph::config' => {
@@ -16,7 +16,8 @@ module Staypuft
16
16
  EXPORT_SERVICES = [:nova, :neutron, :glance, :cinder, :passwords, :ceph]
17
17
 
18
18
  attr_accessible :description, :name, :layout_id, :layout,
19
- :amqp_provider, :layout_name, :networking, :platform
19
+ :amqp_provider, :layout_name, :networking, :platform,
20
+ :custom_repos
20
21
  after_save :update_hostgroup_name
21
22
  after_validation :check_form_complete
22
23
 
@@ -198,7 +199,7 @@ module Staypuft
198
199
  class Jail < Safemode::Jail
199
200
  allow :amqp_provider, :networking, :layout_name, :platform, :nova_networking?, :neutron_networking?,
200
201
  :nova, :neutron, :glance, :cinder, :passwords, :ceph, :ha?, :non_ha?,
201
- :hide_ceph_notification?, :network_query
202
+ :hide_ceph_notification?, :network_query, :has_custom_repos?, :custom_repos_paths
202
203
  end
203
204
 
204
205
  # TODO(mtaylor)
@@ -288,6 +289,14 @@ module Staypuft
288
289
  @network_query || NetworkQuery.new(self)
289
290
  end
290
291
 
292
+ def has_custom_repos?
293
+ self.custom_repos.present?
294
+ end
295
+
296
+ def custom_repos_paths
297
+ self.custom_repos.split("\n")
298
+ end
299
+
291
300
  private
292
301
 
293
302
  def update_layout
@@ -136,7 +136,7 @@ module Staypuft
136
136
  end
137
137
 
138
138
  def compute_eqlx_backend_names
139
- self.eqlxs.collect.with_index { |e,i| "eqlx_backend#{i+1}" }
139
+ self.eqlxs.collect.with_index { |e,i| "eqlx#{i+1}" }
140
140
  end
141
141
 
142
142
  private
@@ -37,29 +37,7 @@ module Staypuft
37
37
  end
38
38
 
39
39
  class SanIpValueValidator < ActiveModel::EachValidator
40
- def validate_each(record, attribute, value)
41
- return if value.empty?
42
-
43
- begin
44
- ip_addr = IPAddr.new(value)
45
- ip_range = ip_addr.to_range
46
- if ip_range.begin == ip_range.end
47
- true
48
- else
49
- record.errors.add attribute, "Specify single IP address, not range"
50
- false
51
- end
52
- rescue
53
- # not IP addr
54
- # validating as fqdn
55
- if /(?=^.{1,254}$)(^(((?!-)[a-zA-Z0-9-]{1,63}(?<!-))|((?!-)[a-zA-Z0-9-]{1,63}(?<!-)\.)+[a-zA-Z]{2,63})$)/ =~ value
56
- true
57
- else
58
- record.errors.add attribute, "Invalid IP address or FQDN supplied"
59
- false
60
- end
61
- end
62
- end
40
+ include Staypuft::Deployment::IpAddressValidator
63
41
  end
64
42
 
65
43
  validates :san_ip,
@@ -0,0 +1,30 @@
1
+ module Staypuft
2
+ module Deployment::IpAddressValidator
3
+ NOT_RANGE_MSG = N_("Specify single IP address, not range")
4
+ INVALID_IP_OR_FQDN_MSG = N_("Invalid IP address or FQDN supplied")
5
+
6
+ def validate_each(record, attribute, value)
7
+ return if value.empty?
8
+
9
+ begin
10
+ ip_addr = IPAddr.new(value)
11
+ ip_range = ip_addr.to_range
12
+ if ip_range.begin == ip_range.end
13
+ true
14
+ else
15
+ record.errors.add attribute, NOT_RANGE_MSG
16
+ false
17
+ end
18
+ rescue
19
+ # not IP addr
20
+ # validating as fqdn
21
+ if /(?=^.{1,254}$)(^(((?!-)[a-zA-Z0-9-]{1,63}(?<!-))|((?!-)[a-zA-Z0-9-]{1,63}(?<!-)\.)+[a-zA-Z]{2,63})$)/ =~ value
22
+ true
23
+ else
24
+ record.errors.add attribute, INVALID_IP_OR_FQDN_MSG
25
+ false
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end