knife-rhn 0.1.0 → 0.2.0
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/README.md +69 -9
- data/lib/chef/knife/rhn_base.rb +98 -0
- data/lib/chef/knife/rhn_system_delete.rb +29 -27
- data/lib/chef/knife/rhn_system_details.rb +52 -50
- data/lib/chef/knife/rhn_system_move.rb +34 -32
- data/lib/chef/knife/rhn_system_systemgroups.rb +24 -22
- data/lib/chef/knife/rhn_systemgroup_active.rb +36 -33
- data/lib/chef/knife/rhn_systemgroup_add.rb +27 -25
- data/lib/chef/knife/rhn_systemgroup_create.rb +22 -20
- data/lib/chef/knife/rhn_systemgroup_delete.rb +20 -18
- data/lib/chef/knife/rhn_systemgroup_inactive.rb +47 -45
- data/lib/chef/knife/rhn_systemgroup_list.rb +16 -14
- data/lib/chef/knife/rhn_systemgroup_outdated.rb +23 -21
- data/lib/chef/knife/rhn_systemgroup_remove.rb +27 -25
- data/lib/chef/knife/rhn_systemgroup_systems.rb +23 -21
- data/lib/knife-rhn/version.rb +2 -1
- metadata +35 -52
- data/lib/chef/knife/BaseRHNCommand.rb +0 -93
data/README.md
CHANGED
@@ -1,13 +1,14 @@
|
|
1
1
|
# Knife RHN
|
2
2
|
|
3
|
-
A knife plugin for managing
|
3
|
+
A knife plugin for managing Red Hat Network.
|
4
4
|
|
5
5
|
## Installation
|
6
6
|
|
7
|
-
Uses
|
7
|
+
Uses [rhn_satellite rubygem](https://github.com/duritong/ruby-rhn_satellite) for the backend.
|
8
8
|
|
9
|
-
* `gem install knife-rhn` (
|
10
|
-
* or...
|
9
|
+
* `gem install knife-rhn` (if using omnibus install, `/opt/chef/embedded/bin/gem install knife-rhn`)
|
10
|
+
* or... copy `lib/chef/knife/*` files to `~/.chef/plugins/knife`
|
11
|
+
* or... copy `lib/chef/knife/*` files to `path/to/cheforg/.chef/plugins/knife`
|
11
12
|
|
12
13
|
## Usage
|
13
14
|
|
@@ -35,6 +36,30 @@ Deletes the system profile for SYSTEM.
|
|
35
36
|
|
36
37
|
Displays system details for SYSTEM.
|
37
38
|
|
39
|
+
Example output:
|
40
|
+
|
41
|
+
ID: 1000023160
|
42
|
+
Profile Name: bflad-test2
|
43
|
+
Hostname: bflad-test2
|
44
|
+
Release: 6Server
|
45
|
+
Auto Update: Disabled
|
46
|
+
Locked: Disabled
|
47
|
+
RHN URL: https://example.com/rhn/systems/details/Overview.do?sid=1000023160
|
48
|
+
Description:
|
49
|
+
Initial Registration Parameters:
|
50
|
+
OS: redhat-release-server
|
51
|
+
Release: 6Server
|
52
|
+
CPU Arch: x86_64
|
53
|
+
Subscribed Channels:
|
54
|
+
Red Hat Enterprise Linux Server (v. 6 for 64-bit x86_64)
|
55
|
+
|_ Shibboleth RHEL 6 x86_64
|
56
|
+
|_ RHEL Server Optional (v. 6 64-bit x86_64)
|
57
|
+
|_ RHEL Server Supplementary (v. 6 64-bit x86_64)
|
58
|
+
|_ EPEL 6 Server x86_64
|
59
|
+
Critical Errata: 1
|
60
|
+
Non-Critical Errata: 2
|
61
|
+
Upgradable Packages: 4
|
62
|
+
|
38
63
|
### `knife rhn system move SYSTEM GROUP`
|
39
64
|
|
40
65
|
* Removes system SYSTEM from all current systemgroups.
|
@@ -44,9 +69,20 @@ Displays system details for SYSTEM.
|
|
44
69
|
|
45
70
|
Displays systemgroups for SYSTEM.
|
46
71
|
|
72
|
+
Example output:
|
73
|
+
|
74
|
+
Core Systems
|
75
|
+
Research Computing
|
76
|
+
|
47
77
|
### `knife rhn systemgroup active GROUP`
|
48
78
|
|
49
|
-
Lists active systems in
|
79
|
+
Lists active systems (systems that have checked into RHN in the last 24 hours) in systemgroup GROUP.
|
80
|
+
|
81
|
+
Example output:
|
82
|
+
|
83
|
+
1000010619,server1.example.com
|
84
|
+
1000018560,server2.example.com
|
85
|
+
1000010446,server3.example.com
|
50
86
|
|
51
87
|
### `knife rhn systemgroup add GROUP SYSTEM`
|
52
88
|
|
@@ -62,18 +98,34 @@ Deletes systemgroup GROUP.
|
|
62
98
|
|
63
99
|
### `knife rhn systemgroup inactive GROUP`
|
64
100
|
|
65
|
-
Lists inactive systems in
|
101
|
+
Lists inactive systems (systems that have not checked into RHN in 24 hours) in systemgroup GROUP.
|
102
|
+
|
103
|
+
* `--days DAYS` - optionally set number of inactive days
|
104
|
+
|
105
|
+
Example output:
|
66
106
|
|
67
|
-
|
107
|
+
1000010004,server4.example.com
|
108
|
+
1000017215,server5.example.com
|
68
109
|
|
69
110
|
### `knife rhn systemgroup list`
|
70
111
|
|
71
112
|
Lists all systemgroups.
|
72
113
|
|
114
|
+
Example output:
|
115
|
+
|
116
|
+
Accounting
|
117
|
+
Core Systems
|
118
|
+
Research Computing
|
119
|
+
|
73
120
|
### `knife rhn systemgroup outdated GROUP`
|
74
121
|
|
75
122
|
Lists outdated systems in system group GROUP.
|
76
123
|
|
124
|
+
Example output:
|
125
|
+
|
126
|
+
1000018560,server2.example.com
|
127
|
+
1000017215,server5.example.com
|
128
|
+
|
77
129
|
### `knife rhn systemgroup remove GROUP SYSTEM`
|
78
130
|
|
79
131
|
Removes system SYSTEM from systemgroup GROUP.
|
@@ -82,15 +134,23 @@ Removes system SYSTEM from systemgroup GROUP.
|
|
82
134
|
|
83
135
|
Lists all systems in system group GROUP.
|
84
136
|
|
137
|
+
Example output:
|
138
|
+
|
139
|
+
1000010619,server1.example.com
|
140
|
+
1000018560,server2.example.com
|
141
|
+
1000010446,server3.example.com
|
142
|
+
1000010004,server4.example.com
|
143
|
+
1000017215,server5.example.com
|
144
|
+
|
85
145
|
## Contributing
|
86
146
|
|
87
147
|
Please use standard Github issues and pull requests.
|
88
148
|
|
89
149
|
## License and Author
|
90
|
-
|
150
|
+
|
91
151
|
Author:: Brian Flad (<bflad@wharton.upenn.edu>)
|
92
152
|
|
93
|
-
Copyright:: 2012
|
153
|
+
Copyright:: 2012-2013
|
94
154
|
|
95
155
|
Licensed under the Apache License, Version 2.0 (the "License");
|
96
156
|
you may not use this file except in compliance with the License.
|
@@ -0,0 +1,98 @@
|
|
1
|
+
#
|
2
|
+
# Author:: Brian Flad (<bflad417@gmail.com>)
|
3
|
+
# License:: Apache License, Version 2.0
|
4
|
+
#
|
5
|
+
|
6
|
+
require 'chef/knife'
|
7
|
+
require 'rhn_satellite'
|
8
|
+
|
9
|
+
class Chef
|
10
|
+
class Knife
|
11
|
+
module RhnBase
|
12
|
+
|
13
|
+
def self.included(includer)
|
14
|
+
includer.class_eval do
|
15
|
+
|
16
|
+
deps do
|
17
|
+
require 'readline'
|
18
|
+
require 'chef/json_compat'
|
19
|
+
end
|
20
|
+
|
21
|
+
unless defined? $default
|
22
|
+
$default = Hash.new
|
23
|
+
end
|
24
|
+
|
25
|
+
option :rhn_debug,
|
26
|
+
:long => "--rhn-debug",
|
27
|
+
:description => "Enable debugging for RHN connection",
|
28
|
+
:boolean => false
|
29
|
+
|
30
|
+
option :rhn_hostname,
|
31
|
+
:short => "-h HOSTNAME",
|
32
|
+
:long => "--rhn-hostname HOSTNAME",
|
33
|
+
:description => "The hostname for RHN"
|
34
|
+
|
35
|
+
option :rhn_no_https,
|
36
|
+
:long => "--rhn-no-https",
|
37
|
+
:description => "Disable HTTPS for RHN connection",
|
38
|
+
:boolean => false
|
39
|
+
|
40
|
+
option :rhn_password,
|
41
|
+
:short => "-p PASSWORD",
|
42
|
+
:long => "--rhn-password PASSWORD",
|
43
|
+
:description => "The password for RHN"
|
44
|
+
|
45
|
+
option :rhn_timeout,
|
46
|
+
:long => "--rhn-timeout SECONDS",
|
47
|
+
:description => "The timeout in seconds for RHN"
|
48
|
+
$default[:rhn_timeout] = 30
|
49
|
+
|
50
|
+
option :rhn_username,
|
51
|
+
:short => "-u USERNAME",
|
52
|
+
:long => "--rhn-username USERNAME",
|
53
|
+
:description => "The username for RHN"
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
def get_config(key)
|
58
|
+
key = key.to_sym
|
59
|
+
rval = config[key] || Chef::Config[:knife][key] || $default[key]
|
60
|
+
Chef::Log.debug("value for config item #{key}: #{rval}")
|
61
|
+
rval
|
62
|
+
end
|
63
|
+
|
64
|
+
def get_satellite_system(system)
|
65
|
+
satellite_system = RhnSatellite::System.get(system)
|
66
|
+
|
67
|
+
if satellite_system.nil?
|
68
|
+
ui.fatal "Could not find system in RHN!"
|
69
|
+
exit 1
|
70
|
+
end
|
71
|
+
|
72
|
+
satellite_system
|
73
|
+
end
|
74
|
+
|
75
|
+
def set_rhn_connection_options
|
76
|
+
RhnSatellite::Connection::Handler.debug_enabled = true if get_config(:rhn_debug)
|
77
|
+
RhnSatellite::Connection::Handler.default_hostname = get_config(:rhn_hostname)
|
78
|
+
RhnSatellite::Connection::Handler.default_https = false if get_config(:rhn_no_https)
|
79
|
+
# See: https://github.com/duritong/ruby-rhn_satellite/issues/3
|
80
|
+
RhnSatellite::ActivationKey.https = false if get_config(:rhn_no_https)
|
81
|
+
RhnSatellite::Api.https = false if get_config(:rhn_no_https)
|
82
|
+
RhnSatellite::Channel.https = false if get_config(:rhn_no_https)
|
83
|
+
RhnSatellite::ChannelAccess.https = false if get_config(:rhn_no_https)
|
84
|
+
RhnSatellite::ChannelSoftware.https = false if get_config(:rhn_no_https)
|
85
|
+
RhnSatellite::Packages.https = false if get_config(:rhn_no_https)
|
86
|
+
RhnSatellite::System.https = false if get_config(:rhn_no_https)
|
87
|
+
RhnSatellite::Systemgroup.https = false if get_config(:rhn_no_https)
|
88
|
+
# End of issue 3 workaround
|
89
|
+
RhnSatellite::Connection::Handler.default_timeout = get_config(:rhn_timeout)
|
90
|
+
RhnSatellite::Connection::Handler.default_username = get_config(:rhn_username)
|
91
|
+
password = get_config(:rhn_password)
|
92
|
+
password ||= ask("RHN Password for #{get_config(:rhn_username)}: ") { |q| q.echo = "*" }
|
93
|
+
RhnSatellite::Connection::Handler.default_password = password
|
94
|
+
end
|
95
|
+
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
@@ -3,42 +3,44 @@
|
|
3
3
|
# License:: Apache License, Version 2.0
|
4
4
|
#
|
5
5
|
|
6
|
-
|
6
|
+
require 'chef/knife/rhn_base'
|
7
7
|
|
8
|
-
|
8
|
+
class Chef
|
9
|
+
class Knife
|
10
|
+
class RhnSystemDelete < Knife
|
9
11
|
|
10
|
-
|
11
|
-
module System
|
12
|
-
def delete(system_id)
|
13
|
-
base.default_call('system.deleteSystems',[system_id.to_i])
|
14
|
-
end
|
15
|
-
end
|
12
|
+
include Knife::RhnBase
|
16
13
|
|
17
|
-
|
14
|
+
banner "knife rhn system delete SYSTEM (options)"
|
15
|
+
category "rhn"
|
18
16
|
|
19
|
-
|
20
|
-
|
17
|
+
# Until released: https://github.com/duritong/ruby-rhn_satellite/pull/5
|
18
|
+
module System
|
19
|
+
def delete(system_id)
|
20
|
+
base.default_call('system.deleteSystems',[system_id.to_i])
|
21
|
+
end
|
22
|
+
end
|
21
23
|
|
22
|
-
|
24
|
+
def run
|
25
|
+
$stdout.sync = true
|
26
|
+
|
27
|
+
system = name_args.first
|
23
28
|
|
24
|
-
|
25
|
-
|
26
|
-
|
29
|
+
if system.nil?
|
30
|
+
ui.fatal "You need a system name!"
|
31
|
+
show_usage
|
32
|
+
exit 1
|
33
|
+
end
|
27
34
|
|
28
|
-
|
29
|
-
ui.fatal "You need a system name!"
|
30
|
-
show_usage
|
31
|
-
exit 1
|
32
|
-
end
|
35
|
+
set_rhn_connection_options
|
33
36
|
|
34
|
-
|
37
|
+
satellite_system = get_satellite_system(system)
|
35
38
|
|
36
|
-
|
39
|
+
RhnSatellite::System.extend(System)
|
40
|
+
RhnSatellite::System.delete(satellite_system['id'])
|
41
|
+
ui.info "Deleted RHN System: #{satellite_system['name']} (ID: #{satellite_system['id']})"
|
42
|
+
end
|
37
43
|
|
38
|
-
RhnSatellite::System.extend(System)
|
39
|
-
RhnSatellite::System.delete(satellite_system['id'])
|
40
|
-
ui.info "Deleted RHN System: #{satellite_system['name']} (ID: #{satellite_system['id']})"
|
41
44
|
end
|
42
|
-
|
43
45
|
end
|
44
|
-
end
|
46
|
+
end
|
@@ -3,58 +3,60 @@
|
|
3
3
|
# License:: Apache License, Version 2.0
|
4
4
|
#
|
5
5
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
6
|
+
require 'chef/knife/rhn_base'
|
7
|
+
|
8
|
+
class Chef
|
9
|
+
class Knife
|
10
|
+
class RhnSystemDelete < Knife
|
11
|
+
|
12
|
+
include Knife::RhnBase
|
13
|
+
|
14
|
+
banner "knife rhn system details SYSTEM (options)"
|
15
|
+
category "rhn"
|
16
|
+
|
17
|
+
def run
|
18
|
+
$stdout.sync = true
|
19
|
+
|
20
|
+
system = name_args.first
|
21
|
+
|
22
|
+
if system.nil?
|
23
|
+
ui.fatal "You need a system name!"
|
24
|
+
show_usage
|
25
|
+
exit 1
|
26
|
+
end
|
27
|
+
|
28
|
+
set_rhn_connection_options
|
29
|
+
|
30
|
+
satellite_system = get_satellite_system(system)
|
31
|
+
|
32
|
+
details = RhnSatellite::System.details(satellite_system['id'])
|
33
|
+
ui.info "#{ui.color "ID", :cyan}: #{details['id']}"
|
34
|
+
ui.info "#{ui.color "Profile Name", :cyan}: #{details['profile_name']}"
|
35
|
+
ui.info "#{ui.color "Hostname", :cyan}: #{details['hostname']}"
|
36
|
+
ui.info "#{ui.color "Release", :cyan}: #{details['release']}"
|
37
|
+
ui.info "#{ui.color "Auto Update", :cyan}: #{details['auto_update'] ? "Enabled" : "Disabled"}"
|
38
|
+
ui.info "#{ui.color "Locked", :cyan}: #{details['lock_status'] ? "Enabled" : "Disabled"}"
|
39
|
+
ui.info "#{ui.color "RHN URL", :cyan}: https://#{get_config(:rhn_hostname)}/rhn/systems/details/Overview.do?sid=#{details['id']}"
|
40
|
+
ui.info "#{ui.color "Description", :cyan}:"
|
41
|
+
ui.info "#{details['description']}"
|
42
|
+
|
43
|
+
base_channel = RhnSatellite::System.subscribed_base_channel(satellite_system['id'])
|
44
|
+
child_channels = RhnSatellite::System.subscribed_child_channels(satellite_system['id'])
|
45
|
+
ui.info "#{ui.color "Subscribed Channels", :cyan}:"
|
46
|
+
ui.info "#{ui.color base_channel['name'], :bold}"
|
47
|
+
child_channels.each do |child_channel|
|
48
|
+
ui.info " |_ #{child_channel['name']}"
|
49
|
+
end
|
50
|
+
|
51
|
+
relevant_erratas = RhnSatellite::System.relevant_erratas(satellite_system['id'])
|
52
|
+
critical_errata = relevant_erratas.select{|e| e["advisory_type"] == "Security Advisory"}.length
|
53
|
+
ui.info "#{ui.color "Critical Errata", :cyan}: #{critical_errata}"
|
54
|
+
ui.info "#{ui.color "Non-Critical Errata", :cyan}: #{relevant_erratas.length - critical_errata}"
|
55
|
+
|
56
|
+
upgradable_packages = RhnSatellite::System.latest_upgradable_packages(satellite_system['id'])
|
57
|
+
ui.info "#{ui.color "Upgradable Packages", :cyan}: #{upgradable_packages.length}"
|
48
58
|
end
|
49
59
|
|
50
|
-
relevant_erratas = RhnSatellite::System.relevant_erratas(satellite_system['id'])
|
51
|
-
critical_errata = relevant_erratas.select{|e| e["advisory_type"] == "Security Advisory"}.length
|
52
|
-
ui.info "#{ui.color "Critical Errata", :cyan}: #{critical_errata}"
|
53
|
-
ui.info "#{ui.color "Non-Critical Errata", :cyan}: #{relevant_erratas.length - critical_errata}"
|
54
|
-
|
55
|
-
upgradable_packages = RhnSatellite::System.latest_upgradable_packages(satellite_system['id'])
|
56
|
-
ui.info "#{ui.color "Upgradable Packages", :cyan}: #{upgradable_packages.length}"
|
57
60
|
end
|
58
|
-
|
59
61
|
end
|
60
62
|
end
|
@@ -3,49 +3,51 @@
|
|
3
3
|
# License:: Apache License, Version 2.0
|
4
4
|
#
|
5
5
|
|
6
|
-
|
6
|
+
require 'chef/knife/rhn_base'
|
7
7
|
|
8
|
-
|
8
|
+
class Chef
|
9
|
+
class Knife
|
10
|
+
class RhnSystemMove < Knife
|
9
11
|
|
10
|
-
|
12
|
+
include Knife::RhnBase
|
11
13
|
|
12
|
-
|
13
|
-
|
14
|
+
banner "knife rhn system move SYSTEM GROUP (options)"
|
15
|
+
category "rhn"
|
14
16
|
|
15
|
-
|
17
|
+
def run
|
18
|
+
$stdout.sync = true
|
19
|
+
|
20
|
+
system = name_args.first
|
16
21
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
ui.fatal "You need a system name!"
|
23
|
-
show_usage
|
24
|
-
exit 1
|
25
|
-
end
|
22
|
+
if system.nil?
|
23
|
+
ui.fatal "You need a system name!"
|
24
|
+
show_usage
|
25
|
+
exit 1
|
26
|
+
end
|
26
27
|
|
27
|
-
|
28
|
+
group = name_args[1]
|
28
29
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
30
|
+
if group.nil?
|
31
|
+
ui.fatal "You need a systemgroup name!"
|
32
|
+
show_usage
|
33
|
+
exit 1
|
34
|
+
end
|
34
35
|
|
35
|
-
|
36
|
+
set_rhn_connection_options
|
36
37
|
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
38
|
+
satellite_system = get_satellite_system(system)
|
39
|
+
system_groups = RhnSatellite::Systemgroup.all
|
40
|
+
system_groups.sort! {|a,b| a['name'] <=> b['name']}
|
41
|
+
system_groups.each do |system_group|
|
42
|
+
if RhnSatellite::Systemgroup.systems(system_group['name']).find{|s| s['id'] == satellite_system['id']}
|
43
|
+
RhnSatellite::Systemgroup.remove_systems(system_group['name'],[satellite_system['id']])
|
44
|
+
ui.info "Removed system #{system} from RHN systemgroup: #{system_group['name']}"
|
45
|
+
end
|
44
46
|
end
|
47
|
+
RhnSatellite::Systemgroup.add_systems(group,[satellite_system['id']])
|
48
|
+
ui.info "Added system #{system} to RHN systemgroup: #{group}"
|
45
49
|
end
|
46
|
-
RhnSatellite::Systemgroup.add_systems(group,[satellite_system['id']])
|
47
|
-
ui.info "Added system #{system} to RHN systemgroup: #{group}"
|
48
|
-
end
|
49
50
|
|
51
|
+
end
|
50
52
|
end
|
51
53
|
end
|