linux_admin 0.14.0 → 0.15.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (47) hide show
  1. checksums.yaml +4 -4
  2. data/lib/linux_admin/common.rb +4 -4
  3. data/lib/linux_admin/deb.rb +1 -1
  4. data/lib/linux_admin/disk.rb +6 -8
  5. data/lib/linux_admin/hosts.rb +4 -6
  6. data/lib/linux_admin/ip_address.rb +4 -6
  7. data/lib/linux_admin/logical_volume.rb +3 -3
  8. data/lib/linux_admin/mountable.rb +5 -8
  9. data/lib/linux_admin/network_interface.rb +4 -6
  10. data/lib/linux_admin/package.rb +0 -1
  11. data/lib/linux_admin/physical_volume.rb +3 -6
  12. data/lib/linux_admin/registration_system/rhn.rb +5 -5
  13. data/lib/linux_admin/registration_system/subscription_manager.rb +2 -2
  14. data/lib/linux_admin/registration_system.rb +1 -2
  15. data/lib/linux_admin/rpm.rb +7 -5
  16. data/lib/linux_admin/service/sys_v_init_service.rb +12 -12
  17. data/lib/linux_admin/service/systemd_service.rb +12 -12
  18. data/lib/linux_admin/service.rb +1 -3
  19. data/lib/linux_admin/system.rb +2 -4
  20. data/lib/linux_admin/time_date.rb +3 -4
  21. data/lib/linux_admin/version.rb +1 -1
  22. data/lib/linux_admin/volume.rb +1 -1
  23. data/lib/linux_admin/volume_group.rb +7 -10
  24. data/lib/linux_admin/yum.rb +6 -8
  25. data/lib/linux_admin.rb +0 -2
  26. data/spec/common_spec.rb +6 -8
  27. data/spec/deb_spec.rb +3 -3
  28. data/spec/disk_spec.rb +27 -27
  29. data/spec/hosts_spec.rb +5 -5
  30. data/spec/ip_address_spec.rb +4 -4
  31. data/spec/logical_volume_spec.rb +38 -38
  32. data/spec/mountable_spec.rb +22 -20
  33. data/spec/network_interface/network_interface_rh_spec.rb +13 -9
  34. data/spec/network_interface_spec.rb +4 -6
  35. data/spec/partition_spec.rb +1 -1
  36. data/spec/physical_volume_spec.rb +16 -20
  37. data/spec/rhn_spec.rb +22 -9
  38. data/spec/rpm_spec.rb +6 -4
  39. data/spec/service/sys_v_init_service_spec.rb +27 -28
  40. data/spec/service/systemd_service_spec.rb +20 -20
  41. data/spec/service_spec.rb +1 -1
  42. data/spec/subscription_manager_spec.rb +27 -15
  43. data/spec/system_spec.rb +2 -6
  44. data/spec/time_date_spec.rb +1 -1
  45. data/spec/volume_group_spec.rb +15 -19
  46. data/spec/yum_spec.rb +27 -15
  47. metadata +8 -6
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3139d54cf9cdb034bf5595831185048f4b2debca
4
- data.tar.gz: a8052367ff1a4db8d67f1f5ae916efd34fcc95d9
3
+ metadata.gz: a7f943a9e3b4af056d2c4e132e3c00a77d06b329
4
+ data.tar.gz: 907bbe718add84205e780e1232c8d4c390f3e6a3
5
5
  SHA512:
6
- metadata.gz: 999d53cd11c97f9d28e3e38d2e54d9e891ecbbcf433af3ea2de7a4815da27c379ebdb0d4ebe45c8201c624097058ee761aedb2e2746d0e25d17cdd973394848a
7
- data.tar.gz: 3a778591c7058988df9d447fc95fd86df26ab7d05e8b2c8b188242d7b48d7deb2d42ece634c420487ea7d363c152bdfcd433400469c2030ed05ce43c92baf0ac
6
+ metadata.gz: 2ffe71103397ec6bf5e82159f6441178c115655995a3f98d7dd7a81952199b919e4c5f10bbd4af74abe910ea4d8c9b0658729a45e7fb44ea032b69aee1432ca9
7
+ data.tar.gz: 8160c2a0eeab8b526531d9aed46703c6b00af1d383545a2ad801f47a34c769047881dfcd097e2daa0f8e2faef747ce9c32c60126a15dfda5489b6a71b4eb0fd2
@@ -6,20 +6,20 @@ module LinuxAdmin
6
6
 
7
7
  BIN_DIRS = %w(/bin /sbin /usr/bin /usr/sbin /usr/local/bin /usr/local/sbin)
8
8
 
9
- def cmd(name)
9
+ def self.cmd(name)
10
10
  BIN_DIRS.collect { |dir| "#{dir}/#{name}" }.detect { |cmd| File.exist?(cmd) }
11
11
  end
12
12
 
13
- def cmd?(name)
13
+ def self.cmd?(name)
14
14
  !cmd(name).nil?
15
15
  end
16
16
 
17
- def run(cmd, options = {})
17
+ def self.run(cmd, options = {})
18
18
  AwesomeSpawn.logger ||= logger
19
19
  AwesomeSpawn.run(cmd, options)
20
20
  end
21
21
 
22
- def run!(cmd, options = {})
22
+ def self.run!(cmd, options = {})
23
23
  AwesomeSpawn.logger ||= logger
24
24
  AwesomeSpawn.run!(cmd, options)
25
25
  end
@@ -27,7 +27,7 @@ module LinuxAdmin
27
27
  end
28
28
 
29
29
  def self.info(pkg)
30
- self.from_string(run!(APT_CACHE_CMD, :params => ["show", pkg]).output)
30
+ from_string(Common.run!(APT_CACHE_CMD, :params => ["show", pkg]).output)
31
31
  end
32
32
  end
33
33
  end
@@ -2,8 +2,6 @@ require 'linux_admin/partition'
2
2
 
3
3
  module LinuxAdmin
4
4
  class Disk
5
- include Common
6
-
7
5
  PARTED_FIELDS =
8
6
  [:id, :start_sector, :end_sector,
9
7
  :size, :partition_type, :fs_type]
@@ -62,7 +60,7 @@ module LinuxAdmin
62
60
  def size
63
61
  @size ||= begin
64
62
  size = nil
65
- out = run!(cmd(:fdisk), :params => {"-l" => nil}).output
63
+ out = Common.run!(Common.cmd(:fdisk), :params => {"-l" => nil}).output
66
64
  out.each_line do |l|
67
65
  /Disk #{path}: .*B, (\d+) bytes/.match(l) do |m|
68
66
  size = m[1].to_i
@@ -86,7 +84,7 @@ module LinuxAdmin
86
84
  # TODO: Should this really catch non-zero RC, set output to the default "" and silently return [] ?
87
85
  # If so, should other calls to parted also do the same?
88
86
  # requires sudo
89
- out = run(cmd(:parted),
87
+ out = Common.run(Common.cmd(:parted),
90
88
  :params => { nil => parted_options_array('print') }).output
91
89
  split = []
92
90
  out.each_line do |l|
@@ -121,11 +119,11 @@ module LinuxAdmin
121
119
  public
122
120
 
123
121
  def create_partition_table(type = "msdos")
124
- run!(cmd(:parted), :params => { nil => parted_options_array("mklabel", type)})
122
+ Common.run!(Common.cmd(:parted), :params => {nil => parted_options_array("mklabel", type)})
125
123
  end
126
124
 
127
125
  def has_partition_table?
128
- result = run(cmd(:parted), :params => { nil => parted_options_array("print")})
126
+ result = Common.run(Common.cmd(:parted), :params => {nil => parted_options_array("print")})
129
127
 
130
128
  result_indicates_partition_table?(result)
131
129
  end
@@ -150,7 +148,7 @@ module LinuxAdmin
150
148
 
151
149
  id = partitions.empty? ? 1 : (partitions.last.id + 1)
152
150
  options = parted_options_array('mkpart', '-a', 'opt', partition_type, start, finish)
153
- run!(cmd(:parted), :params => { nil => options})
151
+ Common.run!(Common.cmd(:parted), :params => {nil => options})
154
152
 
155
153
  partition = Partition.new(:disk => self,
156
154
  :id => id,
@@ -174,7 +172,7 @@ module LinuxAdmin
174
172
  @partitions = []
175
173
 
176
174
  # clear partition table
177
- run!(cmd(:dd),
175
+ Common.run!(Common.cmd(:dd),
178
176
  :params => { 'if=' => '/dev/zero', 'of=' => @path,
179
177
  'bs=' => 512, 'count=' => 1})
180
178
 
@@ -1,7 +1,5 @@
1
1
  module LinuxAdmin
2
2
  class Hosts
3
- include Common
4
-
5
3
  attr_accessor :filename
6
4
  attr_accessor :raw_lines
7
5
  attr_accessor :parsed_file
@@ -33,16 +31,16 @@ module LinuxAdmin
33
31
  end
34
32
 
35
33
  def hostname=(name)
36
- if cmd?("hostnamectl")
37
- run!(cmd('hostnamectl'), :params => ['set-hostname', name])
34
+ if Common.cmd?("hostnamectl")
35
+ Common.run!(Common.cmd('hostnamectl'), :params => ['set-hostname', name])
38
36
  else
39
37
  File.write("/etc/hostname", name)
40
- run!(cmd('hostname'), :params => {:file => "/etc/hostname"})
38
+ Common.run!(Common.cmd('hostname'), :params => {:file => "/etc/hostname"})
41
39
  end
42
40
  end
43
41
 
44
42
  def hostname
45
- result = run(cmd("hostname"))
43
+ result = Common.run(Common.cmd("hostname"))
46
44
  result.success? ? result.output.strip : nil
47
45
  end
48
46
 
@@ -2,8 +2,6 @@ require 'ipaddr'
2
2
 
3
3
  module LinuxAdmin
4
4
  class IpAddress
5
- include Common
6
-
7
5
  def address
8
6
  address_list.detect { |ip| IPAddr.new(ip).ipv4? }
9
7
  end
@@ -13,21 +11,21 @@ module LinuxAdmin
13
11
  end
14
12
 
15
13
  def mac_address(interface)
16
- result = run(cmd("ip"), :params => ["addr", "show", interface])
14
+ result = Common.run(Common.cmd("ip"), :params => ["addr", "show", interface])
17
15
  return nil if result.failure?
18
16
 
19
17
  parse_output(result.output, %r{link/ether}, 1)
20
18
  end
21
19
 
22
20
  def netmask(interface)
23
- result = run(cmd("ifconfig"), :params => [interface])
21
+ result = Common.run(Common.cmd("ifconfig"), :params => [interface])
24
22
  return nil if result.failure?
25
23
 
26
24
  parse_output(result.output, /netmask/, 3)
27
25
  end
28
26
 
29
27
  def gateway
30
- result = run(cmd("ip"), :params => ["route"])
28
+ result = Common.run(Common.cmd("ip"), :params => ["route"])
31
29
  return nil if result.failure?
32
30
 
33
31
  parse_output(result.output, /^default/, 2)
@@ -45,7 +43,7 @@ module LinuxAdmin
45
43
  # Added retry to account for slow DHCP not assigning an IP quickly at boot; specifically:
46
44
  # https://github.com/ManageIQ/manageiq-appliance/commit/160d8ccbfbfd617bdb5445e56cdab66b9323b15b
47
45
  5.times do
48
- result = run(cmd("hostname"), :params => ["-I"])
46
+ result = Common.run(Common.cmd("hostname"), :params => ["-I"])
49
47
  break if result.success?
50
48
  end
51
49
 
@@ -49,7 +49,7 @@ module LinuxAdmin
49
49
  end
50
50
 
51
51
  def extend_with(vg)
52
- run!(cmd(:lvextend),
52
+ Common.run!(Common.cmd(:lvextend),
53
53
  :params => [self.name, vg.name])
54
54
  self
55
55
  end
@@ -81,7 +81,7 @@ module LinuxAdmin
81
81
  size = value
82
82
  params.merge!({'-L' => bytes_to_string(size)})
83
83
  end
84
- run!(cmd(:lvcreate), :params => params)
84
+ Common.run!(Common.cmd(:lvcreate), :params => params)
85
85
 
86
86
  lv = LogicalVolume.new(:name => name,
87
87
  :volume_group => vg,
@@ -92,7 +92,7 @@ module LinuxAdmin
92
92
 
93
93
  def self.scan
94
94
  @lvs ||= begin
95
- scan_volumes(cmd(:lvdisplay)) do |fields, vg|
95
+ scan_volumes(Common.cmd(:lvdisplay)) do |fields, vg|
96
96
  LogicalVolume.new(:name => fields[0],
97
97
  :volume_group => vg,
98
98
  :sectors => fields[6].to_i)
@@ -2,13 +2,10 @@ module LinuxAdmin
2
2
  module Mountable
3
3
  attr_accessor :fs_type
4
4
  attr_accessor :mount_point
5
- include Common
6
5
 
7
6
  module ClassMethods
8
- include Common
9
-
10
7
  def mount_point_exists?(mount_point)
11
- result = run!(cmd(:mount))
8
+ result = Common.run!(Common.cmd(:mount))
12
9
  result.output.split("\n").any? { |line| line.split[2] == mount_point }
13
10
  end
14
11
 
@@ -22,8 +19,8 @@ module LinuxAdmin
22
19
  end
23
20
 
24
21
  def format_to(filesystem)
25
- run!(cmd(:mke2fs),
26
- :params => { '-t' => filesystem, nil => self.path})
22
+ Common.run!(Common.cmd(:mke2fs),
23
+ :params => {'-t' => filesystem, nil => path})
27
24
  @fs_type = filesystem
28
25
  end
29
26
 
@@ -34,12 +31,12 @@ module LinuxAdmin
34
31
  raise ArgumentError, "disk already mounted at #{mount_point}"
35
32
  end
36
33
 
37
- run!(cmd(:mount), :params => { nil => [self.path, mount_point] })
34
+ Common.run!(Common.cmd(:mount), :params => {nil => [path, mount_point]})
38
35
  @mount_point = mount_point
39
36
  end
40
37
 
41
38
  def umount
42
- run!(cmd(:umount), :params => { nil => [@mount_point] })
39
+ Common.run!(Common.cmd(:umount), :params => {nil => [@mount_point]})
43
40
  end
44
41
  end
45
42
  end
@@ -2,8 +2,6 @@ require 'ipaddr'
2
2
 
3
3
  module LinuxAdmin
4
4
  class NetworkInterface
5
- include Common
6
-
7
5
  # Cached class instance variable for what distro we are running on
8
6
  @dist_class = nil
9
7
 
@@ -53,7 +51,7 @@ module LinuxAdmin
53
51
 
54
52
  @network_conf[:mac] = parse_ip_output(ip_output, %r{link/ether}, 1)
55
53
 
56
- ip_route_res = run!(cmd("ip"), :params => ["route"])
54
+ ip_route_res = Common.run!(Common.cmd("ip"), :params => ["route"])
57
55
  @network_conf[:gateway] = parse_ip_output(ip_route_res.output, /^default/, 2) if ip_route_res.success?
58
56
  true
59
57
  rescue AwesomeSpawn::CommandResultError => e
@@ -121,14 +119,14 @@ module LinuxAdmin
121
119
  #
122
120
  # @return [Boolean] whether the command succeeded or not
123
121
  def start
124
- run(cmd("ifup"), :params => [@interface]).success?
122
+ Common.run(Common.cmd("ifup"), :params => [@interface]).success?
125
123
  end
126
124
 
127
125
  # Brings down the network interface
128
126
  #
129
127
  # @return [Boolean] whether the command succeeded or not
130
128
  def stop
131
- run(cmd("ifdown"), :params => [@interface]).success?
129
+ Common.run(Common.cmd("ifdown"), :params => [@interface]).success?
132
130
  end
133
131
 
134
132
  private
@@ -149,7 +147,7 @@ module LinuxAdmin
149
147
  # @return [String] The command output
150
148
  # @raise [NetworkInterfaceError] if the command fails
151
149
  def ip_show
152
- run!(cmd("ip"), :params => ["addr", "show", @interface]).output
150
+ Common.run!(Common.cmd("ip"), :params => ["addr", "show", @interface]).output
153
151
  rescue AwesomeSpawn::CommandResultError => e
154
152
  raise NetworkInterfaceError.new(e.message, e.result)
155
153
  end
@@ -1,5 +1,4 @@
1
1
  module LinuxAdmin
2
2
  class Package
3
- extend Common
4
3
  end
5
4
  end
@@ -1,8 +1,5 @@
1
1
  module LinuxAdmin
2
2
  class PhysicalVolume < Volume
3
- include Common
4
- extend Common
5
-
6
3
  # physical volume device name
7
4
  attr_accessor :device_name
8
5
 
@@ -29,7 +26,7 @@ module LinuxAdmin
29
26
  end
30
27
 
31
28
  def attach_to(vg)
32
- run!(cmd(:vgextend),
29
+ Common.run!(Common.cmd(:vgextend),
33
30
  :params => [vg.name, @device_name])
34
31
  self.volume_group = vg
35
32
  self
@@ -38,7 +35,7 @@ module LinuxAdmin
38
35
  # specify disk or partition instance to create physical volume on
39
36
  def self.create(device)
40
37
  self.scan # initialize local physical volumes
41
- run!(cmd(:pvcreate),
38
+ Common.run!(Common.cmd(:pvcreate),
42
39
  :params => { nil => device.path})
43
40
  pv = PhysicalVolume.new(:device_name => device.path,
44
41
  :volume_group => nil,
@@ -49,7 +46,7 @@ module LinuxAdmin
49
46
 
50
47
  def self.scan
51
48
  @pvs ||= begin
52
- scan_volumes(cmd(:pvdisplay)) do |fields, vg|
49
+ scan_volumes(Common.cmd(:pvdisplay)) do |fields, vg|
53
50
  PhysicalVolume.new(:device_name => fields[0],
54
51
  :volume_group => vg,
55
52
  :size => fields[2].to_i)
@@ -37,7 +37,7 @@ module LinuxAdmin
37
37
  params["--systemorgid="] = options[:org] if options[:server_url] && options[:org]
38
38
  params["--sslCACert="] = INSTALLED_SERVER_CERT_PATH if certificate_installed
39
39
 
40
- run!(cmd, :params => params)
40
+ Common.run!(cmd, :params => params)
41
41
  end
42
42
 
43
43
  def enable_channel(repo, options)
@@ -45,7 +45,7 @@ module LinuxAdmin
45
45
  params = user_pwd(options).merge("--channel=" => repo)
46
46
 
47
47
  logger.info("#{self.class.name}##{__method__} Enabling channel: #{repo}")
48
- run!(cmd, :params => params)
48
+ Common.run!(cmd, :params => params)
49
49
  end
50
50
  alias_method :subscribe, :enable_channel
51
51
  alias_method :enable_repo, :enable_channel
@@ -54,14 +54,14 @@ module LinuxAdmin
54
54
  cmd = "rhn-channel -r"
55
55
  params = user_pwd(options).merge("--channel=" => repo)
56
56
 
57
- run!(cmd, :params => params)
57
+ Common.run!(cmd, :params => params)
58
58
  end
59
59
  alias_method :disable_repo, :disable_channel
60
60
 
61
61
  def enabled_channels
62
62
  cmd = "rhn-channel -l"
63
63
 
64
- run!(cmd).output.split("\n").compact
64
+ Common.run!(cmd).output.split("\n").compact
65
65
  end
66
66
  alias_method :enabled_repos, :enabled_channels
67
67
  alias_method :subscribed_products, :enabled_channels
@@ -70,7 +70,7 @@ module LinuxAdmin
70
70
  cmd = "rhn-channel -L"
71
71
  params = user_pwd(options)
72
72
 
73
- run!(cmd, :params => params).output.chomp.split("\n").compact
73
+ Common.run!(cmd, :params => params).output.chomp.split("\n").compact
74
74
  end
75
75
 
76
76
  def all_repos(options)
@@ -3,7 +3,7 @@ require 'date'
3
3
  module LinuxAdmin
4
4
  class SubscriptionManager < RegistrationSystem
5
5
  def run!(cmd, options = {})
6
- super(cmd, options)
6
+ Common.run!(cmd, options)
7
7
  rescue AwesomeSpawn::CommandResultError => err
8
8
  raise CredentialError.new(err.result) if err.result.error.downcase.include?("invalid username or password")
9
9
  raise
@@ -16,7 +16,7 @@ module LinuxAdmin
16
16
  end
17
17
 
18
18
  def registered?
19
- run("subscription-manager identity").exit_status == 0
19
+ Common.run("subscription-manager identity").exit_status == 0
20
20
  end
21
21
 
22
22
  def refresh
@@ -1,6 +1,5 @@
1
1
  module LinuxAdmin
2
2
  class RegistrationSystem
3
- include Common
4
3
  include Logging
5
4
 
6
5
  def self.registration_type(reload = false)
@@ -51,4 +50,4 @@ module LinuxAdmin
51
50
  end
52
51
  end
53
52
 
54
- Dir.glob(File.join(File.dirname(__FILE__), "registration_system", "*.rb")).each { |f| require f }
53
+ Dir.glob(File.join(File.dirname(__FILE__), "registration_system", "*.rb")).each { |f| require f }
@@ -1,11 +1,13 @@
1
1
  module LinuxAdmin
2
2
  class Rpm < Package
3
+ extend Logging
4
+
3
5
  def self.rpm_cmd
4
- cmd(:rpm)
6
+ Common.cmd(:rpm)
5
7
  end
6
8
 
7
9
  def self.list_installed
8
- out = run!("#{rpm_cmd} -qa --qf \"%{NAME} %{VERSION}-%{RELEASE}\n\"").output
10
+ out = Common.run!("#{rpm_cmd} -qa --qf \"%{NAME} %{VERSION}-%{RELEASE}\n\"").output
9
11
  out.split("\n").each_with_object({}) do |line, pkg_hash|
10
12
  name, ver = line.split(" ")
11
13
  pkg_hash[name] = ver
@@ -17,13 +19,13 @@ module LinuxAdmin
17
19
  # Rpm.import_key("/etc/pki/my-gpg-key")
18
20
  def self.import_key(file)
19
21
  logger.info("#{self.class.name}##{__method__} Importing RPM-GPG-KEY: #{file}")
20
- run!("rpm", :params => {"--import" => file})
22
+ Common.run!("rpm", :params => {"--import" => file})
21
23
  end
22
24
 
23
25
  def self.info(pkg)
24
26
  params = { "-qi" => pkg}
25
27
  in_description = false
26
- out = run!(rpm_cmd, :params => params).output
28
+ out = Common.run!(rpm_cmd, :params => params).output
27
29
  # older versions of rpm may have multiple fields per line,
28
30
  # split up lines with multiple tags/values:
29
31
  out.gsub!(/(^.*:.*)\s\s+(.*:.*)$/, "\\1\n\\2")
@@ -47,7 +49,7 @@ module LinuxAdmin
47
49
  cmd = "rpm -U"
48
50
  params = { nil => pkg }
49
51
 
50
- run(cmd, :params => params).exit_status == 0
52
+ Common.run(cmd, :params => params).exit_status == 0
51
53
  end
52
54
  end
53
55
  end