Class: SmartProxy

Inherits:
ActiveRecord::Base
  • Object
show all
Includes:
Authorization, Taxonomix
Defined in:
app/models/smart_proxy.rb

Constant Summary collapse

URL_HOSTNAME_MATCH =
%r{^(?:http|https):\/\/([^:\/]+)}

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Taxonomix

included

Methods included from Authorization

#enforce_create_permissions, #enforce_destroy_permissions, #enforce_edit_permissions, #enforce_permissions, included, #permission_failed?

Class Method Details

.name_mapObject


39
40
41
42
43
44
45
46
47
48
# File 'app/models/smart_proxy.rb', line 39

def self.name_map
  {
    "tftp"     => Feature.find_by_name("TFTP"),
    "bmc"      => Feature.find_by_name("BMC"),
    "dns"      => Feature.find_by_name("DNS"),
    "dhcp"     => Feature.find_by_name("DHCP"),
    "puppetca" => Feature.find_by_name("Puppet CA"),
    "puppet"   => Feature.find_by_name("Puppet")
  }
end

.smart_proxy_ids_for(hosts) ⇒ Object


65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'app/models/smart_proxy.rb', line 65

def self.smart_proxy_ids_for(hosts)
  ids = []
  ids << hosts.joins(:subnet).pluck('DISTINCT subnets.dhcp_id')
  ids << hosts.joins(:subnet).pluck('DISTINCT subnets.tftp_id')
  ids << hosts.joins(:subnet).pluck('DISTINCT subnets.dns_id')
  ids << hosts.joins(:domain).pluck('DISTINCT domains.dns_id')
  ids << hosts.pluck('DISTINCT puppet_proxy_id')
  ids << hosts.pluck('DISTINCT puppet_ca_proxy_id')
  ids << hosts.joins(:hostgroup).pluck('DISTINCT hostgroups.puppet_proxy_id')
  ids << hosts.joins(:hostgroup).pluck('DISTINCT hostgroups.puppet_ca_proxy_id')
  # returned both 7, "7". need to convert to integer or there are duplicates
  ids.flatten.compact.map{|i| i.to_i}.uniq
end

Instance Method Details

#hostnameObject


52
53
54
55
# File 'app/models/smart_proxy.rb', line 52

def hostname
  # This will always match as it is validated
  url.match(URL_HOSTNAME_MATCH)[1]
end

#pingObject


79
80
81
82
# File 'app/models/smart_proxy.rb', line 79

def ping
  associate_features
  errors
end

#to_paramObject


61
62
63
# File 'app/models/smart_proxy.rb', line 61

def to_param
  "#{id}-#{name.parameterize}"
end

#to_sObject


57
58
59
# File 'app/models/smart_proxy.rb', line 57

def to_s
  hostname =~ /^puppet\./ ? "puppet" : hostname
end