linux_admin 1.2.2 → 1.2.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA256:
3
- metadata.gz: a7e59d030d792e7f4855c26079a6603b4283e6327438316e2b8acf77659cf36a
4
- data.tar.gz: 333842257625f0836cc5dd8f34f2512d4714f239d61e88aebee6642543a9e1fb
2
+ SHA1:
3
+ metadata.gz: 7a836fda94b3dbbc618dcab138690adde8e2803a
4
+ data.tar.gz: b3e87b291a6dba82b58a0b924c44fb41dbebadb1
5
5
  SHA512:
6
- metadata.gz: 4e131edeb3e983f65beebf33818e98956da47aaad6346cb3a6f8c72b936ddc6e82e97e20edf712f407b08f5053b45ff0c61fe959e316e9afdd99fe6823288c3b
7
- data.tar.gz: 986bd3e4510e9a9b3cba5fb013a79af6d37e71c895fee414e1568e78c39767c946133a70dfc59bace475f7084a9ffd4c23f7bede8fb5156677628d4f06b8522f
6
+ metadata.gz: 78b8cd87fcbc328aa5c5910ab26b201bb48cd2f19029bc7da944c50bccc4d1a21324507e4c762fe76221604fe303a0f6f5fab1cac18b513780619aa2bcbd1a51
7
+ data.tar.gz: 5c2f30b0e6ac5fc86bb116ad68dfe3e5b25b446742ad16e23cb0866f4f68582d1297b6027c4945c91e4dffeb69f7a9e962b78f7c2d3b4127a91bc780dda7d055
@@ -6,7 +6,7 @@ module LinuxAdmin
6
6
  [:id, :start_sector, :end_sector,
7
7
  :size, :partition_type, :fs_type]
8
8
 
9
- attr_accessor :path
9
+ attr_accessor :path, :model
10
10
 
11
11
  def self.local
12
12
  result = Common.run!(Common.cmd("lsblk"), :params => {:d => nil, :n => nil, :p => nil, :o => "NAME"})
@@ -16,7 +16,8 @@ module LinuxAdmin
16
16
  end
17
17
 
18
18
  def initialize(args = {})
19
- @path = args[:path]
19
+ @path = args[:path]
20
+ @model = "unknown"
20
21
  end
21
22
 
22
23
  def size
@@ -101,11 +102,20 @@ module LinuxAdmin
101
102
  self
102
103
  end
103
104
 
105
+ def partition_path(id)
106
+ case model
107
+ when "nvme"
108
+ "#{path}p#{id}"
109
+ else
110
+ "#{path}#{id}"
111
+ end
112
+ end
113
+
104
114
  private
105
115
 
106
116
  def str_to_bytes(val, unit)
107
117
  case unit
108
- when 'K' then
118
+ when 'K', 'k' then
109
119
  val.to_f * 1_024 # 1.kilobytes
110
120
  when 'M' then
111
121
  val.to_f * 1_048_576 # 1.megabyte
@@ -152,11 +162,17 @@ module LinuxAdmin
152
162
  out.each_line do |l|
153
163
  if l =~ /^ [0-9].*/
154
164
  split << l.split
165
+ elsif l =~ /^Model:.*/
166
+ parse_model(l)
155
167
  end
156
168
  end
157
169
  split
158
170
  end
159
171
 
172
+ def parse_model(parted_line)
173
+ matches = parted_line.match(/^Model:.*\((?<model>\w+)\)$/)
174
+ @model = matches[:model] if matches
175
+ end
160
176
 
161
177
  def partition_from_parted(output_disk)
162
178
  args = {:disk => self}
@@ -164,7 +180,7 @@ module LinuxAdmin
164
180
  val = output_disk[i]
165
181
  case PARTED_FIELDS[i]
166
182
  when :start_sector, :end_sector, :size
167
- if val =~ /([0-9\.]*)([KMG])B/
183
+ if val =~ /([0-9\.]*)([kKMG])B/
168
184
  val = str_to_bytes($1, $2)
169
185
  end
170
186
 
@@ -22,7 +22,7 @@ module LinuxAdmin
22
22
  end
23
23
 
24
24
  def path
25
- "#{disk.path}#{id}"
25
+ disk.partition_path(id)
26
26
  end
27
27
 
28
28
  def mount(mount_point=nil)
@@ -1,3 +1,3 @@
1
1
  module LinuxAdmin
2
- VERSION = "1.2.2".freeze
2
+ VERSION = "1.2.3".freeze
3
3
  end
data/spec/disk_spec.rb CHANGED
@@ -58,43 +58,104 @@ eos
58
58
  expect(disk.partitions).to eq([])
59
59
  end
60
60
 
61
- it "sets partitons" do
62
- partitions = <<eos
63
- Model: ATA TOSHIBA MK5061GS (scsi)
64
- Disk /dev/sda: 500GB
65
- Sector size (logical/physical): 512B/512B
66
- Partition Table: msdos
67
- Disk Flags:
68
-
69
- Number Start End Size Type File system Flags
70
- 1 1259MB 81.8GB 80.5GB primary ntfs
71
- 2 81.8GB 162GB 80.5GB primary ext4
72
- 3 162GB 163GB 1074MB logical linux-swap(v1)
73
- eos
74
- disk = LinuxAdmin::Disk.new
75
- expect(LinuxAdmin::Common).to receive(:run).and_return(double(:output => partitions))
76
-
77
- expect(disk.partitions[0].id).to eq(1)
78
- expect(disk.partitions[0].disk).to eq(disk)
79
- expect(disk.partitions[0].size).to eq(86_436_216_832.0) # 80.5.gigabytes
80
- expect(disk.partitions[0].start_sector).to eq(1_320_157_184) # 1259.megabytes
81
- expect(disk.partitions[0].end_sector).to eq(87_832_081_203.2) # 81.8.gigabytes
82
- expect(disk.partitions[0].partition_type).to eq('primary')
83
- expect(disk.partitions[0].fs_type).to eq('ntfs')
84
- expect(disk.partitions[1].id).to eq(2)
85
- expect(disk.partitions[1].disk).to eq(disk)
86
- expect(disk.partitions[1].size).to eq(86_436_216_832.0) # 80.5.gigabytes
87
- expect(disk.partitions[1].start_sector).to eq(87_832_081_203.2) # 81.8.gigabytes
88
- expect(disk.partitions[1].end_sector).to eq(173_946_175_488) # 162.gigabytes
89
- expect(disk.partitions[1].partition_type).to eq('primary')
90
- expect(disk.partitions[1].fs_type).to eq('ext4')
91
- expect(disk.partitions[2].id).to eq(3)
92
- expect(disk.partitions[2].disk).to eq(disk)
93
- expect(disk.partitions[2].size).to eq(1_126_170_624) # 1074.megabytes
94
- expect(disk.partitions[2].start_sector).to eq(173_946_175_488) # 162.gigabytes
95
- expect(disk.partitions[2].end_sector).to eq(175_019_917_312) # 163.gigabytes
96
- expect(disk.partitions[2].partition_type).to eq('logical')
97
- expect(disk.partitions[2].fs_type).to eq('linux-swap(v1)')
61
+ context "with nvme parted output" do
62
+ let(:parted_output) do
63
+ <<~PARTED
64
+ Model: NVMe Device (nvme)
65
+ Disk /dev/nvme0n1: 512GB
66
+ Sector size (logical/physical): 512B/512B
67
+ Partition Table: msdos
68
+ Disk Flags:
69
+
70
+ Number Start End Size Type File system Flags
71
+ 1 1049kB 1075MB 1074MB primary ext4 boot
72
+ 2 1075MB 17.7GB 16.6GB primary
73
+ 3 17.7GB 512GB 494GB primary
74
+
75
+ PARTED
76
+ end
77
+
78
+ it "sets partitons" do
79
+ expect(LinuxAdmin::Common).to receive(:run).and_return(double(:output => parted_output))
80
+ disk = LinuxAdmin::Disk.new(:path => "/dev/nvme0n1")
81
+ partitions = disk.partitions
82
+
83
+ expect(disk.model).to eq("nvme")
84
+
85
+ expect(partitions[0].id).to eq(1)
86
+ expect(partitions[0].disk).to eq(disk)
87
+ expect(partitions[0].size).to eq(1_126_170_624.0)
88
+ expect(partitions[0].start_sector).to eq(1_074_176.0)
89
+ expect(partitions[0].end_sector).to eq(1_127_219_200.0)
90
+ expect(partitions[0].partition_type).to eq('primary')
91
+ expect(partitions[0].fs_type).to eq('ext4')
92
+ expect(partitions[0].path).to eq('/dev/nvme0n1p1')
93
+ expect(partitions[1].id).to eq(2)
94
+ expect(partitions[1].disk).to eq(disk)
95
+ expect(partitions[1].size).to eq(17_824_114_278.4)
96
+ expect(partitions[1].start_sector).to eq(1_127_219_200.0)
97
+ expect(partitions[1].end_sector).to eq(19_005_230_284.8)
98
+ expect(partitions[1].partition_type).to eq('primary')
99
+ expect(partitions[1].path).to eq('/dev/nvme0n1p2')
100
+ expect(partitions[2].id).to eq(3)
101
+ expect(partitions[2].disk).to eq(disk)
102
+ expect(partitions[2].size).to eq(530_428_461_056.0)
103
+ expect(partitions[2].start_sector).to eq(19_005_230_284.8)
104
+ expect(partitions[2].end_sector).to eq(549_755_813_888.0)
105
+ expect(partitions[2].partition_type).to eq('primary')
106
+ expect(partitions[2].path).to eq('/dev/nvme0n1p3')
107
+ end
108
+ end
109
+
110
+ context "with scsi parted output" do
111
+ let(:parted_output) do
112
+ <<~PARTED
113
+ Model: ATA TOSHIBA MK5061GS (scsi)
114
+ Disk /dev/sda: 500GB
115
+ Sector size (logical/physical): 512B/512B
116
+ Partition Table: msdos
117
+ Disk Flags:
118
+
119
+ Number Start End Size Type File system Flags
120
+ 1 1259kB 81.8GB 80.5GB primary ntfs
121
+ 2 81.8GB 162GB 80.5GB primary ext4
122
+ 3 162GB 163GB 1074MB logical linux-swap(v1)
123
+
124
+ PARTED
125
+ end
126
+
127
+ it "sets partitons" do
128
+ expect(LinuxAdmin::Common).to receive(:run).and_return(double(:output => parted_output))
129
+ disk = LinuxAdmin::Disk.new(:path => "/dev/sda")
130
+ partitions = disk.partitions
131
+
132
+ expect(disk.model).to eq("scsi")
133
+
134
+ expect(partitions[0].id).to eq(1)
135
+ expect(partitions[0].disk).to eq(disk)
136
+ expect(partitions[0].size).to eq(86_436_216_832.0)
137
+ expect(partitions[0].start_sector).to eq(1_289_216.0)
138
+ expect(partitions[0].end_sector).to eq(87_832_081_203.2)
139
+ expect(partitions[0].partition_type).to eq('primary')
140
+ expect(partitions[0].fs_type).to eq('ntfs')
141
+ expect(partitions[0].path).to eq('/dev/sda1')
142
+ expect(partitions[1].id).to eq(2)
143
+ expect(partitions[1].disk).to eq(disk)
144
+ expect(partitions[1].size).to eq(86_436_216_832.0)
145
+ expect(partitions[1].start_sector).to eq(87_832_081_203.2)
146
+ expect(partitions[1].end_sector).to eq(173_946_175_488)
147
+ expect(partitions[1].partition_type).to eq('primary')
148
+ expect(partitions[1].fs_type).to eq('ext4')
149
+ expect(partitions[1].path).to eq('/dev/sda2')
150
+ expect(partitions[2].id).to eq(3)
151
+ expect(partitions[2].disk).to eq(disk)
152
+ expect(partitions[2].size).to eq(1_126_170_624)
153
+ expect(partitions[2].start_sector).to eq(173_946_175_488)
154
+ expect(partitions[2].end_sector).to eq(175_019_917_312)
155
+ expect(partitions[2].partition_type).to eq('logical')
156
+ expect(partitions[2].fs_type).to eq('linux-swap(v1)')
157
+ expect(partitions[2].path).to eq('/dev/sda3')
158
+ end
98
159
  end
99
160
  end
100
161
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: linux_admin
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.2
4
+ version: 1.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brandon Dunne
@@ -24,22 +24,8 @@ authors:
24
24
  autorequire:
25
25
  bindir: bin
26
26
  cert_chain: []
27
- date: 2018-09-27 00:00:00.000000000 Z
27
+ date: 2019-05-14 00:00:00.000000000 Z
28
28
  dependencies:
29
- - !ruby/object:Gem::Dependency
30
- name: bundler
31
- requirement: !ruby/object:Gem::Requirement
32
- requirements:
33
- - - "~>"
34
- - !ruby/object:Gem::Version
35
- version: '1.3'
36
- type: :development
37
- prerelease: false
38
- version_requirements: !ruby/object:Gem::Requirement
39
- requirements:
40
- - - "~>"
41
- - !ruby/object:Gem::Version
42
- version: '1.3'
43
29
  - !ruby/object:Gem::Dependency
44
30
  name: rake
45
31
  requirement: !ruby/object:Gem::Requirement
@@ -144,20 +130,38 @@ dependencies:
144
130
  requirements:
145
131
  - - ">="
146
132
  - !ruby/object:Gem::Version
147
- version: 1.8.2
148
- - - "~>"
133
+ version: 1.8.5
134
+ - - "!="
135
+ - !ruby/object:Gem::Version
136
+ version: 1.10.0
137
+ - - "!="
138
+ - !ruby/object:Gem::Version
139
+ version: 1.10.1
140
+ - - "!="
149
141
  - !ruby/object:Gem::Version
150
- version: '1.8'
142
+ version: 1.10.2
143
+ - - "<"
144
+ - !ruby/object:Gem::Version
145
+ version: '2'
151
146
  type: :runtime
152
147
  prerelease: false
153
148
  version_requirements: !ruby/object:Gem::Requirement
154
149
  requirements:
155
150
  - - ">="
156
151
  - !ruby/object:Gem::Version
157
- version: 1.8.2
158
- - - "~>"
152
+ version: 1.8.5
153
+ - - "!="
154
+ - !ruby/object:Gem::Version
155
+ version: 1.10.0
156
+ - - "!="
157
+ - !ruby/object:Gem::Version
158
+ version: 1.10.1
159
+ - - "!="
160
+ - !ruby/object:Gem::Version
161
+ version: 1.10.2
162
+ - - "<"
159
163
  - !ruby/object:Gem::Version
160
- version: '1.8'
164
+ version: '2'
161
165
  - !ruby/object:Gem::Dependency
162
166
  name: openscap
163
167
  requirement: !ruby/object:Gem::Requirement
@@ -322,7 +326,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
322
326
  version: '0'
323
327
  requirements: []
324
328
  rubyforge_project:
325
- rubygems_version: 2.7.7
329
+ rubygems_version: 2.6.14.3
326
330
  signing_key:
327
331
  specification_version: 4
328
332
  summary: LinuxAdmin is a module to simplify management of linux systems.