linux_admin 0.2.2 → 0.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.
- data/lib/linux_admin/disk.rb +50 -7
- data/lib/linux_admin/registration_system/rhn.rb +8 -3
- data/lib/linux_admin/registration_system/subscription_manager.rb +17 -3
- data/lib/linux_admin/version.rb +1 -1
- data/lib/linux_admin/yum.rb +3 -4
- data/spec/data/rhn/output_rhn-channel_list +2 -0
- data/spec/data/subscription_manager/output_list_installed_not_subscribed +19 -0
- data/spec/data/subscription_manager/output_list_installed_subscribed +19 -0
- data/spec/data/yum/{output_repoquery → output_repoquery_multiple} +0 -0
- data/spec/data/yum/output_repoquery_single +1 -0
- data/spec/disk_spec.rb +49 -3
- data/spec/rhn_spec.rb +7 -2
- data/spec/subscription_manager_spec.rb +24 -5
- data/spec/yum_spec.rb +8 -3
- metadata +12 -4
data/lib/linux_admin/disk.rb
CHANGED
@@ -25,6 +25,30 @@ class LinuxAdmin
|
|
25
25
|
val.to_f.gigabytes
|
26
26
|
end
|
27
27
|
end
|
28
|
+
|
29
|
+
def overlapping_ranges?(ranges)
|
30
|
+
ranges.find do |range1|
|
31
|
+
ranges.any? do |range2|
|
32
|
+
range1 != range2 &&
|
33
|
+
range1.overlaps?(range2)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def check_if_partitions_overlap(partitions)
|
39
|
+
ranges =
|
40
|
+
partitions.collect do |partition|
|
41
|
+
start = partition[:start]
|
42
|
+
finish = partition[:end]
|
43
|
+
start.delete('%')
|
44
|
+
finish.delete('%')
|
45
|
+
start.to_f..finish.to_f
|
46
|
+
end
|
47
|
+
|
48
|
+
if overlapping_ranges?(ranges)
|
49
|
+
raise ArgumentError, "overlapping partitions"
|
50
|
+
end
|
51
|
+
end
|
28
52
|
|
29
53
|
public
|
30
54
|
|
@@ -109,27 +133,46 @@ class LinuxAdmin
|
|
109
133
|
result_indicates_partition_table?(result)
|
110
134
|
end
|
111
135
|
|
112
|
-
def create_partition(partition_type,
|
136
|
+
def create_partition(partition_type, *args)
|
113
137
|
create_partition_table unless has_partition_table?
|
114
138
|
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
139
|
+
start = finish = size = nil
|
140
|
+
case args.length
|
141
|
+
when 1 then
|
142
|
+
start = partitions.empty? ? 0 : partitions.last.end_sector
|
143
|
+
size = args.first
|
144
|
+
finish = start + size
|
145
|
+
|
146
|
+
when 2 then
|
147
|
+
start = args[0]
|
148
|
+
finish = args[1]
|
149
|
+
|
150
|
+
else
|
151
|
+
raise ArgumentError, "must specify start/finish or size"
|
152
|
+
end
|
119
153
|
|
120
|
-
|
154
|
+
id = partitions.empty? ? 1 : (partitions.last.id + 1)
|
155
|
+
options = parted_options_array('mkpart', '-a opt', partition_type, start, finish)
|
121
156
|
run!(cmd(:parted), :params => { nil => options})
|
122
157
|
|
123
158
|
partition = Partition.new(:disk => self,
|
124
159
|
:id => id,
|
125
160
|
:start_sector => start,
|
126
|
-
:end_sector =>
|
161
|
+
:end_sector => finish,
|
127
162
|
:size => size,
|
128
163
|
:partition_type => partition_type)
|
129
164
|
partitions << partition
|
130
165
|
partition
|
131
166
|
end
|
132
167
|
|
168
|
+
def create_partitions(partition_type, *args)
|
169
|
+
check_if_partitions_overlap(args)
|
170
|
+
|
171
|
+
args.each { |arg|
|
172
|
+
self.create_partition(partition_type, arg[:start], arg[:end])
|
173
|
+
}
|
174
|
+
end
|
175
|
+
|
133
176
|
def clear!
|
134
177
|
@partitions = []
|
135
178
|
|
@@ -33,19 +33,24 @@ class LinuxAdmin
|
|
33
33
|
end
|
34
34
|
|
35
35
|
def subscribe(options)
|
36
|
-
raise ArgumentError, "
|
36
|
+
raise ArgumentError, "channels, username and password are required" if options[:channels].blank? || options[:username].blank? || options[:password].blank?
|
37
37
|
cmd = "rhn-channel -a"
|
38
38
|
|
39
|
-
|
39
|
+
channels = options[:channels].collect {|channel| ["--channel=", channel]}
|
40
40
|
|
41
41
|
params = {}
|
42
42
|
params["--user="] = options[:username]
|
43
43
|
params["--password="] = options[:password]
|
44
|
-
params = params.to_a +
|
44
|
+
params = params.to_a + channels
|
45
45
|
|
46
46
|
run!(cmd, :params => params)
|
47
47
|
end
|
48
48
|
|
49
|
+
def subscribed_products
|
50
|
+
cmd = "rhn-channel -l"
|
51
|
+
run!(cmd).output.split("\n").compact
|
52
|
+
end
|
53
|
+
|
49
54
|
private
|
50
55
|
|
51
56
|
def systemid_file
|
@@ -47,12 +47,25 @@ class LinuxAdmin
|
|
47
47
|
|
48
48
|
def subscribe(options)
|
49
49
|
cmd = "subscription-manager attach"
|
50
|
-
|
51
|
-
|
50
|
+
params = proxy_params(options)
|
51
|
+
|
52
|
+
if options[:pools].blank?
|
53
|
+
params.merge!({"--auto" => nil})
|
54
|
+
else
|
55
|
+
pools = options[:pools].collect {|pool| ["--pool", pool]}
|
56
|
+
params = params.to_a + pools
|
57
|
+
end
|
52
58
|
|
53
59
|
run!(cmd, :params => params)
|
54
60
|
end
|
55
61
|
|
62
|
+
def subscribed_products
|
63
|
+
cmd = "subscription-manager list --installed"
|
64
|
+
output = run!(cmd).output
|
65
|
+
|
66
|
+
parse_output(output).select {|p| p[:status].downcase == "subscribed"}.collect {|p| p[:product_id]}
|
67
|
+
end
|
68
|
+
|
56
69
|
def available_subscriptions
|
57
70
|
cmd = "subscription-manager list --all --available"
|
58
71
|
output = run!(cmd).output
|
@@ -80,7 +93,8 @@ class LinuxAdmin
|
|
80
93
|
end
|
81
94
|
|
82
95
|
def format_values(content_group)
|
83
|
-
content_group[:ends]
|
96
|
+
content_group[:ends] = Date.strptime(content_group[:ends], "%m/%d/%Y") if content_group[:ends]
|
97
|
+
content_group[:starts] = Date.strptime(content_group[:starts], "%m/%d/%Y") if content_group[:starts]
|
84
98
|
content_group
|
85
99
|
end
|
86
100
|
|
data/lib/linux_admin/version.rb
CHANGED
data/lib/linux_admin/yum.rb
CHANGED
@@ -66,10 +66,9 @@ class LinuxAdmin
|
|
66
66
|
|
67
67
|
out = run!(cmd, :params => params).output
|
68
68
|
|
69
|
-
|
70
|
-
|
71
|
-
name
|
72
|
-
versions[name.strip] = version.strip
|
69
|
+
out.split("\n").each_with_object({}) do |i, versions|
|
70
|
+
name, version = i.split(" ", 2)
|
71
|
+
versions[name.strip] = version.strip
|
73
72
|
end
|
74
73
|
end
|
75
74
|
|
@@ -0,0 +1,19 @@
|
|
1
|
+
+-------------------------------------------+
|
2
|
+
Installed Product Status
|
3
|
+
+-------------------------------------------+
|
4
|
+
Product Name: Red Hat Enterprise Linux Server
|
5
|
+
Product ID: 69
|
6
|
+
Version: 6.3
|
7
|
+
Arch: x86_64
|
8
|
+
Status: Not Subscribed
|
9
|
+
Starts: 09/27/2012
|
10
|
+
Ends: 09/26/2013
|
11
|
+
|
12
|
+
Product Name: Red Hat CloudForms
|
13
|
+
Product ID: 167
|
14
|
+
Version: 2.1
|
15
|
+
Arch: x86_64
|
16
|
+
Status: Subscribed
|
17
|
+
Starts: 01/03/2013
|
18
|
+
Ends: 01/03/2014
|
19
|
+
|
@@ -0,0 +1,19 @@
|
|
1
|
+
+-------------------------------------------+
|
2
|
+
Installed Product Status
|
3
|
+
+-------------------------------------------+
|
4
|
+
Product Name: Red Hat Enterprise Linux Server
|
5
|
+
Product ID: 69
|
6
|
+
Version: 6.3
|
7
|
+
Arch: x86_64
|
8
|
+
Status: Subscribed
|
9
|
+
Starts: 09/27/2012
|
10
|
+
Ends: 09/26/2013
|
11
|
+
|
12
|
+
Product Name: Red Hat CloudForms
|
13
|
+
Product ID: 167
|
14
|
+
Version: 2.1
|
15
|
+
Arch: x86_64
|
16
|
+
Status: Subscribed
|
17
|
+
Starts: 01/03/2013
|
18
|
+
Ends: 01/03/2014
|
19
|
+
|
File without changes
|
@@ -0,0 +1 @@
|
|
1
|
+
subscription-manager 1.1.23.1
|
data/spec/disk_spec.rb
CHANGED
@@ -99,6 +99,35 @@ eos
|
|
99
99
|
end
|
100
100
|
end
|
101
101
|
|
102
|
+
describe "#create_partitions" do
|
103
|
+
before(:each) do
|
104
|
+
@disk = LinuxAdmin::Disk.new(:path => '/dev/hda')
|
105
|
+
end
|
106
|
+
|
107
|
+
it "dispatches to create_partition" do
|
108
|
+
@disk.should_receive(:create_partition).with("primary", "0%", "50%")
|
109
|
+
@disk.create_partitions "primary", :start => "0%", :end => "50%"
|
110
|
+
end
|
111
|
+
|
112
|
+
context "multiple partitions specified" do
|
113
|
+
it "calls create_partition for each partition" do
|
114
|
+
@disk.should_receive(:create_partition).with("primary", "0%", "49%")
|
115
|
+
@disk.should_receive(:create_partition).with("primary", "50%", "100%")
|
116
|
+
@disk.create_partitions("primary", {:start => "0%", :end => "49%"},
|
117
|
+
{:start => "50%", :end => "100%"})
|
118
|
+
end
|
119
|
+
|
120
|
+
context "partitions overlap" do
|
121
|
+
it "raises argument error" do
|
122
|
+
expect{
|
123
|
+
@disk.create_partitions("primary", {:start => "0%", :end => "50%"},
|
124
|
+
{:start => "49%", :end => "100%"})
|
125
|
+
}.to raise_error(ArgumentError)
|
126
|
+
end
|
127
|
+
end
|
128
|
+
end
|
129
|
+
end
|
130
|
+
|
102
131
|
describe "#create_partition" do
|
103
132
|
before(:each) do
|
104
133
|
# test disk w/ existing partition
|
@@ -110,12 +139,29 @@ eos
|
|
110
139
|
end
|
111
140
|
|
112
141
|
it "uses parted" do
|
113
|
-
|
114
|
-
|
115
|
-
:params => { nil => ['--script', '/dev/hda', 'mkpart', 'primary', 1024, 2048] })
|
142
|
+
params = ['--script', '/dev/hda', 'mkpart', '-a opt', 'primary', 1024, 2048]
|
143
|
+
@disk.should_receive(:run!).with(@disk.cmd(:parted), :params => { nil => params })
|
116
144
|
@disk.create_partition 'primary', 1024
|
117
145
|
end
|
118
146
|
|
147
|
+
it "accepts start/end params" do
|
148
|
+
params = ['--script', '/dev/hda', 'mkpart', '-a opt', 'primary', "0%", "50%"]
|
149
|
+
@disk.should_receive(:run!).with(@disk.cmd(:parted), :params => { nil => params })
|
150
|
+
@disk.create_partition 'primary', "0%", "50%"
|
151
|
+
end
|
152
|
+
|
153
|
+
context "missing params" do
|
154
|
+
it "raises ArgumentError" do
|
155
|
+
expect{
|
156
|
+
@disk.create_partition 'primary'
|
157
|
+
}.to raise_error(ArgumentError)
|
158
|
+
|
159
|
+
expect{
|
160
|
+
@disk.create_partition 'primary', '0%', '50%', 100
|
161
|
+
}.to raise_error(ArgumentError)
|
162
|
+
end
|
163
|
+
end
|
164
|
+
|
119
165
|
it "returns partition" do
|
120
166
|
@disk.should_receive(:run!) # stub out call to parted
|
121
167
|
partition = @disk.create_partition 'primary', 1024
|
data/spec/rhn_spec.rb
CHANGED
@@ -52,13 +52,18 @@ describe LinuxAdmin::Rhn do
|
|
52
52
|
expect { described_class.new.subscribe({}) }.to raise_error(ArgumentError)
|
53
53
|
end
|
54
54
|
|
55
|
-
it "with
|
55
|
+
it "with channels" do
|
56
56
|
described_class.any_instance.should_receive(:run!).once.with("rhn-channel -a", {:params=>[["--user=", "SomeUser"], ["--password=", "SomePass"], ["--channel=", 123], ["--channel=", 456]]})
|
57
57
|
described_class.new.subscribe({
|
58
58
|
:username => "SomeUser",
|
59
59
|
:password => "SomePass",
|
60
|
-
:
|
60
|
+
:channels => [123, 456]
|
61
61
|
})
|
62
62
|
end
|
63
63
|
end
|
64
|
+
|
65
|
+
it "#subscribed_products" do
|
66
|
+
described_class.any_instance.should_receive(:run!).once.with("rhn-channel -l").and_return(double(:output => sample_output("rhn/output_rhn-channel_list")))
|
67
|
+
expect(described_class.new.subscribed_products).to eq(["rhel-x86_64-server-6", "rhel-x86_64-server-6-cf-me-2"])
|
68
|
+
end
|
64
69
|
end
|
@@ -24,10 +24,10 @@ describe LinuxAdmin::SubscriptionManager do
|
|
24
24
|
end
|
25
25
|
|
26
26
|
it "with username and password" do
|
27
|
-
run_options = ["subscription-manager register", {:params=>{"--username="=>"SomeUser", "--password="=>"SomePass", "--org="=>"IT", "--proxy="=>"1.2.3.4", "--proxyuser="=>"ProxyUser", "--proxypassword="=>"ProxyPass", "--serverurl="=>"192.168.1.1"}}]
|
27
|
+
run_options = ["subscription-manager register", {:params=>{"--username="=>"SomeUser@SomeDomain.org", "--password="=>"SomePass", "--org="=>"IT", "--proxy="=>"1.2.3.4", "--proxyuser="=>"ProxyUser", "--proxypassword="=>"ProxyPass", "--serverurl="=>"192.168.1.1"}}]
|
28
28
|
described_class.any_instance.should_receive(:run!).once.with(*run_options)
|
29
29
|
described_class.new.register(
|
30
|
-
:username => "SomeUser",
|
30
|
+
:username => "SomeUser@SomeDomain.org",
|
31
31
|
:password => "SomePass",
|
32
32
|
:org => "IT",
|
33
33
|
:proxy_address => "1.2.3.4",
|
@@ -38,9 +38,28 @@ describe LinuxAdmin::SubscriptionManager do
|
|
38
38
|
end
|
39
39
|
end
|
40
40
|
|
41
|
-
|
42
|
-
|
43
|
-
|
41
|
+
context "#subscribe" do
|
42
|
+
it "with pools" do
|
43
|
+
described_class.any_instance.should_receive(:run!).once.with("subscription-manager attach", {:params=>[["--pool", 123], ["--pool", 456]]})
|
44
|
+
described_class.new.subscribe({:pools => [123, 456]})
|
45
|
+
end
|
46
|
+
|
47
|
+
it "without pools" do
|
48
|
+
described_class.any_instance.should_receive(:run!).once.with("subscription-manager attach --auto", {:params=>{}})
|
49
|
+
described_class.new.subscribe({})
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
context "#subscribed_products" do
|
54
|
+
it "subscribed" do
|
55
|
+
described_class.any_instance.should_receive(:run!).once.with("subscription-manager list --installed").and_return(double(:output => sample_output("subscription_manager/output_list_installed_subscribed")))
|
56
|
+
expect(described_class.new.subscribed_products).to eq(["69", "167"])
|
57
|
+
end
|
58
|
+
|
59
|
+
it "not subscribed" do
|
60
|
+
described_class.any_instance.should_receive(:run!).once.with("subscription-manager list --installed").and_return(double(:output => sample_output("subscription_manager/output_list_installed_not_subscribed")))
|
61
|
+
expect(described_class.new.subscribed_products).to eq(["167"])
|
62
|
+
end
|
44
63
|
end
|
45
64
|
|
46
65
|
it "#available_subscriptions" do
|
data/spec/yum_spec.rb
CHANGED
@@ -110,9 +110,14 @@ describe LinuxAdmin::Yum do
|
|
110
110
|
expect { described_class.version_available }.to raise_error(ArgumentError)
|
111
111
|
end
|
112
112
|
|
113
|
-
it "with
|
114
|
-
described_class.should_receive(:run!).once.with("repoquery --qf=\"%{name} %{version}\"", {:params=>{nil=>["
|
115
|
-
expect(described_class.version_available("
|
113
|
+
it "with one package" do
|
114
|
+
described_class.should_receive(:run!).once.with("repoquery --qf=\"%{name} %{version}\"", {:params=>{nil=>["subscription-manager"]}}).and_return(double(:output => sample_output("yum/output_repoquery_single")))
|
115
|
+
expect(described_class.version_available("subscription-manager")).to eq({"subscription-manager" => "1.1.23.1"})
|
116
|
+
end
|
117
|
+
|
118
|
+
it "with multiple packages" do
|
119
|
+
described_class.should_receive(:run!).once.with("repoquery --qf=\"%{name} %{version}\"", {:params=>{nil=>["curl", "subscription-manager", "wget"]}}).and_return(double(:output => sample_output("yum/output_repoquery_multiple")))
|
120
|
+
expect(described_class.version_available("curl", "subscription-manager", "wget")).to eq({
|
116
121
|
"curl" => "7.19.7",
|
117
122
|
"subscription-manager" => "1.1.23.1",
|
118
123
|
"wget" => "1.12"
|
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: 0.2.
|
4
|
+
version: 0.2.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -12,7 +12,7 @@ authors:
|
|
12
12
|
autorequire:
|
13
13
|
bindir: bin
|
14
14
|
cert_chain: []
|
15
|
-
date: 2013-09-
|
15
|
+
date: 2013-09-20 00:00:00.000000000 Z
|
16
16
|
dependencies:
|
17
17
|
- !ruby/object:Gem::Dependency
|
18
18
|
name: bundler
|
@@ -189,13 +189,17 @@ files:
|
|
189
189
|
- lib/linux_admin/yum.rb
|
190
190
|
- linux_admin.gemspec
|
191
191
|
- spec/common_spec.rb
|
192
|
+
- spec/data/rhn/output_rhn-channel_list
|
192
193
|
- spec/data/rhn/systemid
|
193
194
|
- spec/data/rhn/systemid.missing_system_id
|
194
195
|
- spec/data/rpm/cmd_output_for_list_installed
|
195
196
|
- spec/data/subscription_manager/output_list_all_available
|
197
|
+
- spec/data/subscription_manager/output_list_installed_not_subscribed
|
198
|
+
- spec/data/subscription_manager/output_list_installed_subscribed
|
196
199
|
- spec/data/subscription_manager/output_orgs
|
197
200
|
- spec/data/yum/first.repo
|
198
|
-
- spec/data/yum/
|
201
|
+
- spec/data/yum/output_repoquery_multiple
|
202
|
+
- spec/data/yum/output_repoquery_single
|
199
203
|
- spec/data/yum/second.repo
|
200
204
|
- spec/disk_spec.rb
|
201
205
|
- spec/distro_spec.rb
|
@@ -240,13 +244,17 @@ specification_version: 3
|
|
240
244
|
summary: LinuxAdmin is a module to simplify management of linux systems.
|
241
245
|
test_files:
|
242
246
|
- spec/common_spec.rb
|
247
|
+
- spec/data/rhn/output_rhn-channel_list
|
243
248
|
- spec/data/rhn/systemid
|
244
249
|
- spec/data/rhn/systemid.missing_system_id
|
245
250
|
- spec/data/rpm/cmd_output_for_list_installed
|
246
251
|
- spec/data/subscription_manager/output_list_all_available
|
252
|
+
- spec/data/subscription_manager/output_list_installed_not_subscribed
|
253
|
+
- spec/data/subscription_manager/output_list_installed_subscribed
|
247
254
|
- spec/data/subscription_manager/output_orgs
|
248
255
|
- spec/data/yum/first.repo
|
249
|
-
- spec/data/yum/
|
256
|
+
- spec/data/yum/output_repoquery_multiple
|
257
|
+
- spec/data/yum/output_repoquery_single
|
250
258
|
- spec/data/yum/second.repo
|
251
259
|
- spec/disk_spec.rb
|
252
260
|
- spec/distro_spec.rb
|