linux_admin 0.6.0 → 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/linux_admin/registration_system/rhn.rb +47 -9
- data/lib/linux_admin/registration_system/subscription_manager.rb +26 -0
- data/lib/linux_admin/version.rb +1 -1
- data/spec/data/rhn/output_rhn-channel_list_available +4 -0
- data/spec/data/subscription_manager/output_repos +18 -0
- data/spec/rhn_spec.rb +56 -15
- data/spec/subscription_manager_spec.rb +47 -0
- metadata +8 -4
@@ -40,27 +40,65 @@ class LinuxAdmin
|
|
40
40
|
run!(cmd, :params => params)
|
41
41
|
end
|
42
42
|
|
43
|
-
def
|
44
|
-
|
45
|
-
|
43
|
+
def enable_channel(repo, options)
|
44
|
+
cmd = "rhn-channel -a"
|
45
|
+
params = user_pwd(options).merge("--channel=" => repo)
|
46
46
|
|
47
|
-
|
47
|
+
run!(cmd, :params => params)
|
48
|
+
end
|
49
|
+
alias_method :subscribe, :enable_channel
|
50
|
+
alias_method :enable_repo, :enable_channel
|
48
51
|
|
49
|
-
|
50
|
-
|
51
|
-
params
|
52
|
-
params = params.to_a + channels
|
52
|
+
def disable_channel(repo, options)
|
53
|
+
cmd = "rhn-channel -r"
|
54
|
+
params = user_pwd(options).merge("--channel=" => repo)
|
53
55
|
|
54
56
|
run!(cmd, :params => params)
|
55
57
|
end
|
58
|
+
alias_method :disable_repo, :disable_channel
|
56
59
|
|
57
|
-
def
|
60
|
+
def enabled_channels
|
58
61
|
cmd = "rhn-channel -l"
|
62
|
+
|
59
63
|
run!(cmd).output.split("\n").compact
|
60
64
|
end
|
65
|
+
alias_method :enabled_repos, :enabled_channels
|
66
|
+
alias_method :subscribed_products, :enabled_channels
|
67
|
+
|
68
|
+
def available_channels(options)
|
69
|
+
cmd = "rhn-channel -L"
|
70
|
+
params = user_pwd(options)
|
71
|
+
|
72
|
+
run!(cmd, :params => params).output.chomp.split("\n").compact
|
73
|
+
end
|
74
|
+
|
75
|
+
def all_repos(options)
|
76
|
+
available = available_channels_with_status(options)
|
77
|
+
merge_enabled_channels_with_status(available)
|
78
|
+
end
|
61
79
|
|
62
80
|
private
|
63
81
|
|
82
|
+
def available_channels_with_status(options)
|
83
|
+
available_channels(options).collect { |ac| {:repo_id => ac, :enabled => false} }
|
84
|
+
end
|
85
|
+
|
86
|
+
def merge_enabled_channels_with_status(available)
|
87
|
+
enabled_channels.each_with_object(available) do |enabled, all|
|
88
|
+
if repo = all.detect { |i| i[:repo_id] == enabled }
|
89
|
+
repo[:enabled] = true
|
90
|
+
else
|
91
|
+
all.push({:repo_id => enabled, :enabled => true})
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
def user_pwd(options)
|
97
|
+
raise ArgumentError, "username and password are required" if options[:username].blank? || options[:password].blank?
|
98
|
+
|
99
|
+
{"--user=" => options[:username], "--password=" => options[:password]}
|
100
|
+
end
|
101
|
+
|
64
102
|
def systemid_file
|
65
103
|
"/etc/sysconfig/rhn/systemid"
|
66
104
|
end
|
@@ -80,6 +80,31 @@ class LinuxAdmin
|
|
80
80
|
parse_output(output).index_by {|i| i[:pool_id]}
|
81
81
|
end
|
82
82
|
|
83
|
+
def enable_repo(repo, options = nil)
|
84
|
+
cmd = "subscription-manager repos"
|
85
|
+
params = {"--enable=" => repo}
|
86
|
+
|
87
|
+
run!(cmd, :params => params)
|
88
|
+
end
|
89
|
+
|
90
|
+
def disable_repo(repo, options = nil)
|
91
|
+
cmd = "subscription-manager repos"
|
92
|
+
params = {"--disable=" => repo}
|
93
|
+
|
94
|
+
run!(cmd, :params => params)
|
95
|
+
end
|
96
|
+
|
97
|
+
def all_repos(options = nil)
|
98
|
+
cmd = "subscription-manager repos"
|
99
|
+
output = run!(cmd).output
|
100
|
+
|
101
|
+
parse_output(output)
|
102
|
+
end
|
103
|
+
|
104
|
+
def enabled_repos
|
105
|
+
all_repos.select { |i| i[:enabled] }.collect { |r| r[:repo_id] }
|
106
|
+
end
|
107
|
+
|
83
108
|
private
|
84
109
|
|
85
110
|
def parse_output(output)
|
@@ -101,6 +126,7 @@ class LinuxAdmin
|
|
101
126
|
end
|
102
127
|
|
103
128
|
def format_values(content_group)
|
129
|
+
content_group[:enabled] = content_group[:enabled].to_i == 1 if content_group[:enabled]
|
104
130
|
content_group[:ends] = Date.strptime(content_group[:ends], "%m/%d/%Y") if content_group[:ends]
|
105
131
|
content_group[:starts] = Date.strptime(content_group[:starts], "%m/%d/%Y") if content_group[:starts]
|
106
132
|
content_group
|
data/lib/linux_admin/version.rb
CHANGED
@@ -0,0 +1,18 @@
|
|
1
|
+
+----------------------------------------------------------+
|
2
|
+
Available Repositories in /etc/yum.repos.d/redhat.repo
|
3
|
+
+----------------------------------------------------------+
|
4
|
+
Repo ID: some-repo-source-rpms
|
5
|
+
Repo Name: Some Repo (Source RPMs)
|
6
|
+
Repo URL: https://my.host.example.com/repos/some-repo/source/rpms
|
7
|
+
Enabled: 1
|
8
|
+
|
9
|
+
Repo ID: some-repo-rpms
|
10
|
+
Repo Name: Some Repo
|
11
|
+
Repo URL: https://my.host.example.com/repos/some-repo/rpms
|
12
|
+
Enabled: 1
|
13
|
+
|
14
|
+
Repo ID: some-repo-2-beta-rpms
|
15
|
+
Repo Name: Some Repo (Beta RPMs)
|
16
|
+
Repo URL: https://my.host.example.com/repos/some-repo-2/beta/rpms
|
17
|
+
Enabled: 0
|
18
|
+
|
data/spec/rhn_spec.rb
CHANGED
@@ -70,23 +70,64 @@ describe LinuxAdmin::Rhn do
|
|
70
70
|
end
|
71
71
|
end
|
72
72
|
|
73
|
-
|
74
|
-
|
75
|
-
expect { described_class.new.subscribe({}) }.to raise_error(ArgumentError)
|
76
|
-
end
|
73
|
+
it "#enable_channel" do
|
74
|
+
described_class.any_instance.should_receive(:run!).once.with("rhn-channel -a", {:params=>{"--user="=>"SomeUser", "--password="=>"SomePass", "--channel="=>123}})
|
77
75
|
|
78
|
-
|
79
|
-
described_class.any_instance.should_receive(:run!).once.with("rhn-channel -a", {:params=>[["--user=", "SomeUser"], ["--password=", "SomePass"], ["--channel=", 123], ["--channel=", 456]]})
|
80
|
-
described_class.new.subscribe({
|
81
|
-
:username => "SomeUser",
|
82
|
-
:password => "SomePass",
|
83
|
-
:channels => [123, 456]
|
84
|
-
})
|
85
|
-
end
|
76
|
+
described_class.new.enable_channel(123, :username => "SomeUser", :password => "SomePass")
|
86
77
|
end
|
87
78
|
|
88
|
-
it "#
|
79
|
+
it "#enabled_channels" do
|
89
80
|
described_class.any_instance.should_receive(:run!).once.with("rhn-channel -l").and_return(double(:output => sample_output("rhn/output_rhn-channel_list")))
|
90
|
-
|
81
|
+
|
82
|
+
expect(described_class.new.enabled_channels).to eq(["rhel-x86_64-server-6", "rhel-x86_64-server-6-cf-me-2"])
|
83
|
+
end
|
84
|
+
|
85
|
+
it "#disable_channel" do
|
86
|
+
described_class.any_instance.should_receive(:run!).once.with("rhn-channel -r", {:params=>{"--user="=>"SomeUser", "--password="=>"SomePass", "--channel="=>123}})
|
87
|
+
|
88
|
+
described_class.new.disable_channel(123, :username => "SomeUser", :password => "SomePass")
|
89
|
+
end
|
90
|
+
|
91
|
+
it "#available_channels" do
|
92
|
+
credentials = {
|
93
|
+
:username => "some_user",
|
94
|
+
:password => "password"
|
95
|
+
}
|
96
|
+
expected = [
|
97
|
+
"rhel-x86_64-server-6-cf-me-2",
|
98
|
+
"rhel-x86_64-server-6-cf-me-2-beta",
|
99
|
+
"rhel-x86_64-server-6-cf-me-3",
|
100
|
+
"rhel-x86_64-server-6-cf-me-3-beta"
|
101
|
+
]
|
102
|
+
cmd = "rhn-channel -L"
|
103
|
+
params = {
|
104
|
+
:params => {
|
105
|
+
"--user=" => "some_user",
|
106
|
+
"--password=" => "password"
|
107
|
+
}
|
108
|
+
}
|
109
|
+
|
110
|
+
described_class.any_instance.should_receive(:run!).once.with(cmd, params).and_return(double(:output => sample_output("rhn/output_rhn-channel_list_available")))
|
111
|
+
|
112
|
+
expect(described_class.new.available_channels(credentials)).to eq(expected)
|
113
|
+
end
|
114
|
+
|
115
|
+
it "#all_repos" do
|
116
|
+
credentials = {
|
117
|
+
:username => "some_user",
|
118
|
+
:password => "password"
|
119
|
+
}
|
120
|
+
expected = [
|
121
|
+
{:repo_id => "rhel-x86_64-server-6-cf-me-2", :enabled => true},
|
122
|
+
{:repo_id => "rhel-x86_64-server-6-cf-me-2-beta", :enabled => false},
|
123
|
+
{:repo_id => "rhel-x86_64-server-6-cf-me-3", :enabled => false},
|
124
|
+
{:repo_id => "rhel-x86_64-server-6-cf-me-3-beta", :enabled => false},
|
125
|
+
{:repo_id => "rhel-x86_64-server-6", :enabled => true}
|
126
|
+
]
|
127
|
+
|
128
|
+
described_class.any_instance.should_receive(:run!).once.and_return(double(:output => sample_output("rhn/output_rhn-channel_list_available")))
|
129
|
+
described_class.any_instance.should_receive(:run!).once.with("rhn-channel -l").and_return(double(:output => sample_output("rhn/output_rhn-channel_list")))
|
130
|
+
|
131
|
+
expect(described_class.new.all_repos(credentials)).to eq(expected)
|
91
132
|
end
|
92
|
-
end
|
133
|
+
end
|
@@ -144,4 +144,51 @@ describe LinuxAdmin::SubscriptionManager do
|
|
144
144
|
expect { described_class.new.organizations({:username=>"BadUser", :password=>"BadPass"}) }.to raise_error(LinuxAdmin::CredentialError)
|
145
145
|
end
|
146
146
|
end
|
147
|
+
|
148
|
+
it "#enable_repo" do
|
149
|
+
described_class.any_instance.should_receive(:run!).once.with("subscription-manager repos", {:params=>{"--enable="=>"abc"}})
|
150
|
+
|
151
|
+
described_class.new.enable_repo("abc")
|
152
|
+
end
|
153
|
+
|
154
|
+
it "#disable_repo" do
|
155
|
+
described_class.any_instance.should_receive(:run!).once.with("subscription-manager repos", {:params=>{"--disable="=>"abc"}})
|
156
|
+
|
157
|
+
described_class.new.disable_repo("abc")
|
158
|
+
end
|
159
|
+
|
160
|
+
it "#all_repos" do
|
161
|
+
expected = [
|
162
|
+
{
|
163
|
+
:repo_id => "some-repo-source-rpms",
|
164
|
+
:repo_name => "Some Repo (Source RPMs)",
|
165
|
+
:repo_url => "https://my.host.example.com/repos/some-repo/source/rpms",
|
166
|
+
:enabled => true
|
167
|
+
},
|
168
|
+
{
|
169
|
+
:repo_id => "some-repo-rpms",
|
170
|
+
:repo_name => "Some Repo",
|
171
|
+
:repo_url => "https://my.host.example.com/repos/some-repo/rpms",
|
172
|
+
:enabled => true
|
173
|
+
},
|
174
|
+
{
|
175
|
+
:repo_id => "some-repo-2-beta-rpms",
|
176
|
+
:repo_name => "Some Repo (Beta RPMs)",
|
177
|
+
:repo_url => "https://my.host.example.com/repos/some-repo-2/beta/rpms",
|
178
|
+
:enabled => false
|
179
|
+
}
|
180
|
+
]
|
181
|
+
|
182
|
+
described_class.any_instance.should_receive(:run!).once.with("subscription-manager repos").and_return(double(:output => sample_output("subscription_manager/output_repos")))
|
183
|
+
|
184
|
+
expect(described_class.new.all_repos).to eq(expected)
|
185
|
+
end
|
186
|
+
|
187
|
+
it "#enabled_repos" do
|
188
|
+
expected = ["some-repo-source-rpms", "some-repo-rpms"]
|
189
|
+
|
190
|
+
described_class.any_instance.should_receive(:run!).once.with("subscription-manager repos").and_return(double(:output => sample_output("subscription_manager/output_repos")))
|
191
|
+
|
192
|
+
expect(described_class.new.enabled_repos).to eq(expected)
|
193
|
+
end
|
147
194
|
end
|
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.
|
4
|
+
version: 0.7.0
|
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: 2014-
|
15
|
+
date: 2014-02-03 00:00:00.000000000 Z
|
16
16
|
dependencies:
|
17
17
|
- !ruby/object:Gem::Dependency
|
18
18
|
name: bundler
|
@@ -196,6 +196,7 @@ files:
|
|
196
196
|
- spec/command_result_spec.rb
|
197
197
|
- spec/common_spec.rb
|
198
198
|
- spec/data/rhn/output_rhn-channel_list
|
199
|
+
- spec/data/rhn/output_rhn-channel_list_available
|
199
200
|
- spec/data/rhn/systemid
|
200
201
|
- spec/data/rhn/systemid.missing_system_id
|
201
202
|
- spec/data/rpm/cmd_output_for_list_installed
|
@@ -203,6 +204,7 @@ files:
|
|
203
204
|
- spec/data/subscription_manager/output_list_installed_not_subscribed
|
204
205
|
- spec/data/subscription_manager/output_list_installed_subscribed
|
205
206
|
- spec/data/subscription_manager/output_orgs
|
207
|
+
- spec/data/subscription_manager/output_repos
|
206
208
|
- spec/data/yum/first.repo
|
207
209
|
- spec/data/yum/output_repo_list
|
208
210
|
- spec/data/yum/output_repoquery_multiple
|
@@ -243,7 +245,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
243
245
|
version: '0'
|
244
246
|
segments:
|
245
247
|
- 0
|
246
|
-
hash:
|
248
|
+
hash: 1694480219788171348
|
247
249
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
248
250
|
none: false
|
249
251
|
requirements:
|
@@ -252,7 +254,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
252
254
|
version: '0'
|
253
255
|
segments:
|
254
256
|
- 0
|
255
|
-
hash:
|
257
|
+
hash: 1694480219788171348
|
256
258
|
requirements: []
|
257
259
|
rubyforge_project:
|
258
260
|
rubygems_version: 1.8.23
|
@@ -263,6 +265,7 @@ test_files:
|
|
263
265
|
- spec/command_result_spec.rb
|
264
266
|
- spec/common_spec.rb
|
265
267
|
- spec/data/rhn/output_rhn-channel_list
|
268
|
+
- spec/data/rhn/output_rhn-channel_list_available
|
266
269
|
- spec/data/rhn/systemid
|
267
270
|
- spec/data/rhn/systemid.missing_system_id
|
268
271
|
- spec/data/rpm/cmd_output_for_list_installed
|
@@ -270,6 +273,7 @@ test_files:
|
|
270
273
|
- spec/data/subscription_manager/output_list_installed_not_subscribed
|
271
274
|
- spec/data/subscription_manager/output_list_installed_subscribed
|
272
275
|
- spec/data/subscription_manager/output_orgs
|
276
|
+
- spec/data/subscription_manager/output_repos
|
273
277
|
- spec/data/yum/first.repo
|
274
278
|
- spec/data/yum/output_repo_list
|
275
279
|
- spec/data/yum/output_repoquery_multiple
|