Class: Itamae::Plugin::Resource::FirewalldService

Inherits:
Resource::Base
  • Object
show all
Defined in:
lib/itamae/plugin/resource/firewalld_service.rb

Instance Method Summary collapse

Instance Method Details

#action_create(options) ⇒ Object



61
62
63
64
# File 'lib/itamae/plugin/resource/firewalld_service.rb', line 61

def action_create(options)
  run_specinfra(:move_file, build_xmlfile_on_remote, service_xmlfile_path)
  attributes.status = :defined
end

#action_delete(options) ⇒ Object



66
67
68
69
70
71
# File 'lib/itamae/plugin/resource/firewalld_service.rb', line 66

def action_delete(options)
  return if current.status == :undefined

  run_command(['firewall-cmd', '--permanent', '--delete-service', attributes.name])
  attributes.status = :undefined
end

#pre_actionObject



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/itamae/plugin/resource/firewalld_service.rb', line 19

def pre_action
  current.status = current_status

  return if (@current_action != :create) || (current.status == :undefined)

  xml = run_specinfra(:get_file_content, service_xmlfile_path).stdout
  return if xml.empty?

  service = REXML::Document.new(xml).elements['/service'].elements

  if service['short']
    current.short = service['short'].text
  end

  if service['description']
    current.description = service['description'].text
  end

  current.ports = service.collect('port') do |port|
    if port.attributes['port'].nil? || port.attributes['port'].empty?
      port.attributes['protocol']
    else
      "#{port.attributes['port']}/#{port.attributes['protocol']}"
    end
  end

  if service['module']
    current.module_name = service['module'].attributes['name']
  end

  if service['destination']
    current.to_ipv4 = service['destination'].attributes['ipv4']
    current.to_ipv6 = service['destination'].attributes['ipv6']
  end
end

#show_differencesObject



55
56
57
58
59
# File 'lib/itamae/plugin/resource/firewalld_service.rb', line 55

def show_differences
  current.ports = normalize_ports(current.ports)
  attributes.ports = normalize_ports(attributes.ports)
  super
end