linux_admin 1.2.2 → 1.2.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -5
- data/lib/linux_admin/disk.rb +20 -4
- data/lib/linux_admin/partition.rb +1 -1
- data/lib/linux_admin/version.rb +1 -1
- data/spec/disk_spec.rb +98 -37
- metadata +27 -23
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 7a836fda94b3dbbc618dcab138690adde8e2803a
|
4
|
+
data.tar.gz: b3e87b291a6dba82b58a0b924c44fb41dbebadb1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 78b8cd87fcbc328aa5c5910ab26b201bb48cd2f19029bc7da944c50bccc4d1a21324507e4c762fe76221604fe303a0f6f5fab1cac18b513780619aa2bcbd1a51
|
7
|
+
data.tar.gz: 5c2f30b0e6ac5fc86bb116ad68dfe3e5b25b446742ad16e23cb0866f4f68582d1297b6027c4945c91e4dffeb69f7a9e962b78f7c2d3b4127a91bc780dda7d055
|
data/lib/linux_admin/disk.rb
CHANGED
@@ -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
|
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\.]*)([
|
183
|
+
if val =~ /([0-9\.]*)([kKMG])B/
|
168
184
|
val = str_to_bytes($1, $2)
|
169
185
|
end
|
170
186
|
|
data/lib/linux_admin/version.rb
CHANGED
data/spec/disk_spec.rb
CHANGED
@@ -58,43 +58,104 @@ eos
|
|
58
58
|
expect(disk.partitions).to eq([])
|
59
59
|
end
|
60
60
|
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
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.
|
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:
|
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.
|
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:
|
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.
|
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: '
|
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.
|
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.
|