knife-rhn 0.1.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/.gitignore +18 -0
- data/Gemfile +5 -0
- data/README.md +105 -0
- data/Rakefile +2 -0
- data/knife-rhn.gemspec +18 -0
- data/lib/chef/knife/BaseRHNCommand.rb +93 -0
- data/lib/chef/knife/rhn_system_delete.rb +44 -0
- data/lib/chef/knife/rhn_system_details.rb +60 -0
- data/lib/chef/knife/rhn_system_move.rb +51 -0
- data/lib/chef/knife/rhn_system_systemgroups.rb +38 -0
- data/lib/chef/knife/rhn_systemgroup_active.rb +49 -0
- data/lib/chef/knife/rhn_systemgroup_add.rb +43 -0
- data/lib/chef/knife/rhn_systemgroup_create.rb +37 -0
- data/lib/chef/knife/rhn_systemgroup_delete.rb +34 -0
- data/lib/chef/knife/rhn_systemgroup_inactive.rb +57 -0
- data/lib/chef/knife/rhn_systemgroup_list.rb +29 -0
- data/lib/chef/knife/rhn_systemgroup_outdated.rb +37 -0
- data/lib/chef/knife/rhn_systemgroup_remove.rb +43 -0
- data/lib/chef/knife/rhn_systemgroup_systems.rb +37 -0
- data/lib/knife-rhn/version.rb +5 -0
- metadata +98 -0
data/.gitignore
ADDED
data/README.md
ADDED
@@ -0,0 +1,105 @@
|
|
1
|
+
# Knife RHN
|
2
|
+
|
3
|
+
A knife plugin for managing RHN.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Uses `rhn_satellite` rubygem.
|
8
|
+
|
9
|
+
* `gem install knife-rhn` (once a gem is cut)
|
10
|
+
* or... clone repo to ~/.chef/plugins/knife or path/to/cheforg/.chef/plugins/knife
|
11
|
+
|
12
|
+
## Usage
|
13
|
+
|
14
|
+
### Common parameters
|
15
|
+
|
16
|
+
Configuration in knife.rb:
|
17
|
+
* `knife[:rhn_debug] = true` - Enable debugging for RHN connection
|
18
|
+
* `knife[:rhn_hostname] = "HOSTNAME"` - RHN hostname
|
19
|
+
* `knife[:rhn_no_https] = true` - Disable HTTPS for RHN connection
|
20
|
+
* `knife[:rhn_password] = "PASSWORD"` - RHN password
|
21
|
+
* `knife[:rhn_username] = "USERNAME"` - RHN username
|
22
|
+
|
23
|
+
Otherwise, from the command line:
|
24
|
+
* `--rhn-debug` - Enable debugging for RHN connection
|
25
|
+
* `--rhn-hostname HOSTNAME` - RHN hostname
|
26
|
+
* `--rhn-no-https` - Disable HTTPS for RHN connection
|
27
|
+
* `--rhn-password PASSWORD` - RHN password
|
28
|
+
* `--rhn-username USERNAME` - RHN username
|
29
|
+
|
30
|
+
### `knife rhn system delete SYSTEM`
|
31
|
+
|
32
|
+
Deletes the system profile for SYSTEM.
|
33
|
+
|
34
|
+
### `knife rhn system details SYSTEM`
|
35
|
+
|
36
|
+
Displays system details for SYSTEM.
|
37
|
+
|
38
|
+
### `knife rhn system move SYSTEM GROUP`
|
39
|
+
|
40
|
+
* Removes system SYSTEM from all current systemgroups.
|
41
|
+
* Adds system SYSTEM to systemgroup GROUP.
|
42
|
+
|
43
|
+
### `knife rhn system systemgroups SYSTEM`
|
44
|
+
|
45
|
+
Displays systemgroups for SYSTEM.
|
46
|
+
|
47
|
+
### `knife rhn systemgroup active GROUP`
|
48
|
+
|
49
|
+
Lists active systems in system group GROUP.
|
50
|
+
|
51
|
+
### `knife rhn systemgroup add GROUP SYSTEM`
|
52
|
+
|
53
|
+
Adds system SYSTEM to systemgroup GROUP.
|
54
|
+
|
55
|
+
### `knife rhn systemgroup create GROUP DESCRIPTION`
|
56
|
+
|
57
|
+
Creates systemgroup GROUP with DESCRIPTION.
|
58
|
+
|
59
|
+
### `knife rhn systemgroup delete GROUP`
|
60
|
+
|
61
|
+
Deletes systemgroup GROUP.
|
62
|
+
|
63
|
+
### `knife rhn systemgroup inactive GROUP`
|
64
|
+
|
65
|
+
Lists inactive systems in system group GROUP.
|
66
|
+
|
67
|
+
* `--days` - Number of inactive days
|
68
|
+
|
69
|
+
### `knife rhn systemgroup list`
|
70
|
+
|
71
|
+
Lists all systemgroups.
|
72
|
+
|
73
|
+
### `knife rhn systemgroup outdated GROUP`
|
74
|
+
|
75
|
+
Lists outdated systems in system group GROUP.
|
76
|
+
|
77
|
+
### `knife rhn systemgroup remove GROUP SYSTEM`
|
78
|
+
|
79
|
+
Removes system SYSTEM from systemgroup GROUP.
|
80
|
+
|
81
|
+
### `knife rhn systemgroup systems GROUP`
|
82
|
+
|
83
|
+
Lists all systems in system group GROUP.
|
84
|
+
|
85
|
+
## Contributing
|
86
|
+
|
87
|
+
Please use standard Github issues and pull requests.
|
88
|
+
|
89
|
+
## License and Author
|
90
|
+
|
91
|
+
Author:: Brian Flad (<bflad@wharton.upenn.edu>)
|
92
|
+
|
93
|
+
Copyright:: 2012
|
94
|
+
|
95
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
96
|
+
you may not use this file except in compliance with the License.
|
97
|
+
You may obtain a copy of the License at
|
98
|
+
|
99
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
100
|
+
|
101
|
+
Unless required by applicable law or agreed to in writing, software
|
102
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
103
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
104
|
+
See the License for the specific language governing permissions and
|
105
|
+
limitations under the License.
|
data/Rakefile
ADDED
data/knife-rhn.gemspec
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/knife-rhn/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.authors = ["Brian Flad"]
|
6
|
+
gem.email = ["bflad@wharton.upenn.edu"]
|
7
|
+
gem.description = %q{A knife plugin for managing RHN.}
|
8
|
+
gem.summary = gem.summary
|
9
|
+
gem.homepage = "https://github.com/bflad/knife-rhn"
|
10
|
+
|
11
|
+
gem.add_runtime_dependency "rhn_satellite"
|
12
|
+
|
13
|
+
gem.files = `git ls-files`.split($\)
|
14
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
15
|
+
gem.name = "knife-rhn"
|
16
|
+
gem.require_paths = ["lib"]
|
17
|
+
gem.version = Knife::Rhn::VERSION
|
18
|
+
end
|
@@ -0,0 +1,93 @@
|
|
1
|
+
#
|
2
|
+
# Author:: Brian Flad (<bflad417@gmail.com>)
|
3
|
+
# License:: Apache License, Version 2.0
|
4
|
+
#
|
5
|
+
|
6
|
+
module RhnKnifePlugin
|
7
|
+
|
8
|
+
require 'chef/knife'
|
9
|
+
require 'rhn_satellite'
|
10
|
+
|
11
|
+
class BaseRhnCommand < Chef::Knife
|
12
|
+
|
13
|
+
#deps do
|
14
|
+
# require 'highline/import'
|
15
|
+
#end
|
16
|
+
|
17
|
+
def self.get_common_options
|
18
|
+
unless defined? $default
|
19
|
+
$default = Hash.new
|
20
|
+
end
|
21
|
+
|
22
|
+
option :rhn_debug,
|
23
|
+
:long => "--rhn-debug",
|
24
|
+
:description => "Enable debugging for RHN connection",
|
25
|
+
:boolean => false
|
26
|
+
|
27
|
+
option :rhn_hostname,
|
28
|
+
:short => "-h HOSTNAME",
|
29
|
+
:long => "--rhn-hostname HOSTNAME",
|
30
|
+
:description => "The hostname for RHN"
|
31
|
+
|
32
|
+
option :rhn_no_https,
|
33
|
+
:long => "--rhn-no-https",
|
34
|
+
:description => "Disable HTTPS for RHN connection",
|
35
|
+
:boolean => false
|
36
|
+
|
37
|
+
option :rhn_password,
|
38
|
+
:short => "-p PASSWORD",
|
39
|
+
:long => "--rhn-password PASSWORD",
|
40
|
+
:description => "The password for RHN"
|
41
|
+
|
42
|
+
option :rhn_timeout,
|
43
|
+
:long => "--rhn-timeout SECONDS",
|
44
|
+
:description => "The timeout in seconds for RHN"
|
45
|
+
$default[:rhn_timeout] = 30
|
46
|
+
|
47
|
+
option :rhn_username,
|
48
|
+
:short => "-u USERNAME",
|
49
|
+
:long => "--rhn-username USERNAME",
|
50
|
+
:description => "The username for RHN"
|
51
|
+
end
|
52
|
+
|
53
|
+
def get_config(key)
|
54
|
+
key = key.to_sym
|
55
|
+
rval = config[key] || Chef::Config[:knife][key] || $default[key]
|
56
|
+
Chef::Log.debug("value for config item #{key}: #{rval}")
|
57
|
+
rval
|
58
|
+
end
|
59
|
+
|
60
|
+
def get_satellite_system(system)
|
61
|
+
satellite_system = RhnSatellite::System.get(system)
|
62
|
+
|
63
|
+
if satellite_system.nil?
|
64
|
+
ui.fatal "Could not find system in RHN!"
|
65
|
+
exit 1
|
66
|
+
end
|
67
|
+
|
68
|
+
satellite_system
|
69
|
+
end
|
70
|
+
|
71
|
+
def set_rhn_connection_options
|
72
|
+
RhnSatellite::Connection::Handler.debug_enabled = true if get_config(:rhn_debug)
|
73
|
+
RhnSatellite::Connection::Handler.default_hostname = get_config(:rhn_hostname)
|
74
|
+
RhnSatellite::Connection::Handler.default_https = false if get_config(:rhn_no_https)
|
75
|
+
# See: https://github.com/duritong/ruby-rhn_satellite/issues/3
|
76
|
+
RhnSatellite::ActivationKey.https = false if get_config(:rhn_no_https)
|
77
|
+
RhnSatellite::Api.https = false if get_config(:rhn_no_https)
|
78
|
+
RhnSatellite::Channel.https = false if get_config(:rhn_no_https)
|
79
|
+
RhnSatellite::ChannelAccess.https = false if get_config(:rhn_no_https)
|
80
|
+
RhnSatellite::ChannelSoftware.https = false if get_config(:rhn_no_https)
|
81
|
+
RhnSatellite::Packages.https = false if get_config(:rhn_no_https)
|
82
|
+
RhnSatellite::System.https = false if get_config(:rhn_no_https)
|
83
|
+
RhnSatellite::Systemgroup.https = false if get_config(:rhn_no_https)
|
84
|
+
# End of issue 3 workaround
|
85
|
+
RhnSatellite::Connection::Handler.default_timeout = get_config(:rhn_timeout)
|
86
|
+
RhnSatellite::Connection::Handler.default_username = get_config(:rhn_username)
|
87
|
+
password = get_config(:rhn_password)
|
88
|
+
password ||= ask("RHN Password for #{get_config(:rhn_username)}: ") { |q| q.echo = "*" }
|
89
|
+
RhnSatellite::Connection::Handler.default_password = password
|
90
|
+
end
|
91
|
+
|
92
|
+
end
|
93
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
#
|
2
|
+
# Author:: Brian Flad (<bflad@wharton.upenn.edu>)
|
3
|
+
# License:: Apache License, Version 2.0
|
4
|
+
#
|
5
|
+
|
6
|
+
module RhnKnifePlugin
|
7
|
+
|
8
|
+
require 'chef/knife'
|
9
|
+
|
10
|
+
# Until merged: https://github.com/duritong/ruby-rhn_satellite/pull/5
|
11
|
+
module System
|
12
|
+
def delete(system_id)
|
13
|
+
base.default_call('system.deleteSystems',[system_id.to_i])
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
class RhnSystemDelete < BaseRhnCommand
|
18
|
+
|
19
|
+
banner "knife rhn system delete SYSTEM (options)"
|
20
|
+
category "rhn"
|
21
|
+
|
22
|
+
get_common_options
|
23
|
+
|
24
|
+
def run
|
25
|
+
|
26
|
+
system = name_args.first
|
27
|
+
|
28
|
+
if system.nil?
|
29
|
+
ui.fatal "You need a system name!"
|
30
|
+
show_usage
|
31
|
+
exit 1
|
32
|
+
end
|
33
|
+
|
34
|
+
set_rhn_connection_options
|
35
|
+
|
36
|
+
satellite_system = get_satellite_system(system)
|
37
|
+
|
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
|
+
end
|
42
|
+
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
#
|
2
|
+
# Author:: Brian Flad (<bflad@wharton.upenn.edu>)
|
3
|
+
# License:: Apache License, Version 2.0
|
4
|
+
#
|
5
|
+
|
6
|
+
module RhnKnifePlugin
|
7
|
+
|
8
|
+
require 'chef/knife'
|
9
|
+
|
10
|
+
class RhnSystemDetails < BaseRhnCommand
|
11
|
+
|
12
|
+
banner "knife rhn system details SYSTEM (options)"
|
13
|
+
category "rhn"
|
14
|
+
|
15
|
+
get_common_options
|
16
|
+
|
17
|
+
def run
|
18
|
+
|
19
|
+
system = name_args.first
|
20
|
+
|
21
|
+
if system.nil?
|
22
|
+
ui.fatal "You need a system name!"
|
23
|
+
show_usage
|
24
|
+
exit 1
|
25
|
+
end
|
26
|
+
|
27
|
+
set_rhn_connection_options
|
28
|
+
|
29
|
+
satellite_system = get_satellite_system(system)
|
30
|
+
|
31
|
+
details = RhnSatellite::System.details(satellite_system['id'])
|
32
|
+
ui.info "#{ui.color "ID", :cyan}: #{details['id']}"
|
33
|
+
ui.info "#{ui.color "Profile Name", :cyan}: #{details['profile_name']}"
|
34
|
+
ui.info "#{ui.color "Hostname", :cyan}: #{details['hostname']}"
|
35
|
+
ui.info "#{ui.color "Release", :cyan}: #{details['release']}"
|
36
|
+
ui.info "#{ui.color "Auto Update", :cyan}: #{details['auto_update'] ? "Enabled" : "Disabled"}"
|
37
|
+
ui.info "#{ui.color "Locked", :cyan}: #{details['lock_status'] ? "Enabled" : "Disabled"}"
|
38
|
+
ui.info "#{ui.color "RHN URL", :cyan}: https://#{get_config(:rhn_hostname)}/rhn/systems/details/Overview.do?sid=#{details['id']}"
|
39
|
+
ui.info "#{ui.color "Description", :cyan}:"
|
40
|
+
ui.info "#{details['description']}"
|
41
|
+
|
42
|
+
base_channel = RhnSatellite::System.subscribed_base_channel(satellite_system['id'])
|
43
|
+
child_channels = RhnSatellite::System.subscribed_child_channels(satellite_system['id'])
|
44
|
+
ui.info "#{ui.color "Subscribed Channels", :cyan}:"
|
45
|
+
ui.info "#{ui.color base_channel['name'], :bold}"
|
46
|
+
child_channels.each do |child_channel|
|
47
|
+
ui.info " |_ #{child_channel['name']}"
|
48
|
+
end
|
49
|
+
|
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
|
+
end
|
58
|
+
|
59
|
+
end
|
60
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
#
|
2
|
+
# Author:: Brian Flad (<bflad@wharton.upenn.edu>)
|
3
|
+
# License:: Apache License, Version 2.0
|
4
|
+
#
|
5
|
+
|
6
|
+
module RhnKnifePlugin
|
7
|
+
|
8
|
+
require 'chef/knife'
|
9
|
+
|
10
|
+
class RhnSystemMove < BaseRhnCommand
|
11
|
+
|
12
|
+
banner "knife rhn system move SYSTEM GROUP (options)"
|
13
|
+
category "rhn"
|
14
|
+
|
15
|
+
get_common_options
|
16
|
+
|
17
|
+
def run
|
18
|
+
|
19
|
+
system = name_args.first
|
20
|
+
|
21
|
+
if system.nil?
|
22
|
+
ui.fatal "You need a system name!"
|
23
|
+
show_usage
|
24
|
+
exit 1
|
25
|
+
end
|
26
|
+
|
27
|
+
group = name_args[1]
|
28
|
+
|
29
|
+
if group.nil?
|
30
|
+
ui.fatal "You need a systemgroup name!"
|
31
|
+
show_usage
|
32
|
+
exit 1
|
33
|
+
end
|
34
|
+
|
35
|
+
set_rhn_connection_options
|
36
|
+
|
37
|
+
satellite_system = get_satellite_system(system)
|
38
|
+
system_groups = RhnSatellite::Systemgroup.all
|
39
|
+
system_groups.sort! {|a,b| a['name'] <=> b['name']}
|
40
|
+
system_groups.each do |system_group|
|
41
|
+
if RhnSatellite::Systemgroup.systems(system_group['name']).find{|s| s['id'] == satellite_system['id']}
|
42
|
+
RhnSatellite::Systemgroup.remove_systems(system_group['name'],[satellite_system['id']])
|
43
|
+
ui.info "Removed system #{system} from RHN systemgroup: #{system_group['name']}"
|
44
|
+
end
|
45
|
+
end
|
46
|
+
RhnSatellite::Systemgroup.add_systems(group,[satellite_system['id']])
|
47
|
+
ui.info "Added system #{system} to RHN systemgroup: #{group}"
|
48
|
+
end
|
49
|
+
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
#
|
2
|
+
# Author:: Brian Flad (<bflad@wharton.upenn.edu>)
|
3
|
+
# License:: Apache License, Version 2.0
|
4
|
+
#
|
5
|
+
|
6
|
+
module RhnKnifePlugin
|
7
|
+
|
8
|
+
require 'chef/knife'
|
9
|
+
|
10
|
+
class RhnSystemSystemgroups < BaseRhnCommand
|
11
|
+
|
12
|
+
banner "knife rhn system systemgroups SYSTEM (options)"
|
13
|
+
category "rhn"
|
14
|
+
|
15
|
+
get_common_options
|
16
|
+
|
17
|
+
def run
|
18
|
+
|
19
|
+
system = name_args.first
|
20
|
+
|
21
|
+
if system.nil?
|
22
|
+
ui.fatal "You need a system name!"
|
23
|
+
show_usage
|
24
|
+
exit 1
|
25
|
+
end
|
26
|
+
|
27
|
+
set_rhn_connection_options
|
28
|
+
|
29
|
+
satellite_system = get_satellite_system(system)
|
30
|
+
system_groups = RhnSatellite::Systemgroup.all
|
31
|
+
system_groups.sort! {|a,b| a['name'] <=> b['name']}
|
32
|
+
system_groups.each do |system_group|
|
33
|
+
ui.info "#{system_group['name']}" if RhnSatellite::Systemgroup.systems(system_group['name']).find{|s| s['id'] == satellite_system['id']}
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
#
|
2
|
+
# Author:: Brian Flad (<bflad@wharton.upenn.edu>)
|
3
|
+
# License:: Apache License, Version 2.0
|
4
|
+
#
|
5
|
+
|
6
|
+
module RhnKnifePlugin
|
7
|
+
|
8
|
+
require 'chef/knife'
|
9
|
+
|
10
|
+
# Until merged: https://github.com/duritong/ruby-rhn_satellite/pull/7
|
11
|
+
module Systemgroup
|
12
|
+
def active_systems(group_name)
|
13
|
+
base.default_call('systemgroup.listActiveSystemsInGroup',group_name)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
class RhnSystemgroupActive < BaseRhnCommand
|
18
|
+
|
19
|
+
banner "knife rhn systemgroup active GROUP (options)"
|
20
|
+
category "rhn"
|
21
|
+
|
22
|
+
get_common_options
|
23
|
+
|
24
|
+
def run
|
25
|
+
|
26
|
+
group = name_args.first
|
27
|
+
|
28
|
+
if group.nil?
|
29
|
+
ui.fatal "You need a systemgroup name!"
|
30
|
+
show_usage
|
31
|
+
exit 1
|
32
|
+
end
|
33
|
+
|
34
|
+
set_rhn_connection_options
|
35
|
+
|
36
|
+
RhnSatellite::Systemgroup.extend(Systemgroup)
|
37
|
+
system_ids = RhnSatellite::Systemgroup.active_systems(group)
|
38
|
+
systems = []
|
39
|
+
system_ids.each do |system_id|
|
40
|
+
systems << RhnSatellite::System.details(system_id)
|
41
|
+
end
|
42
|
+
systems.sort! {|a,b| a['profile_name'] <=> b['profile_name']}
|
43
|
+
systems.each do |system|
|
44
|
+
ui.info "#{system['id']},#{system['profile_name']}"
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
#
|
2
|
+
# Author:: Brian Flad (<bflad@wharton.upenn.edu>)
|
3
|
+
# License:: Apache License, Version 2.0
|
4
|
+
#
|
5
|
+
|
6
|
+
module RhnKnifePlugin
|
7
|
+
|
8
|
+
require 'chef/knife'
|
9
|
+
|
10
|
+
class RhnSystemgroupAdd < BaseRhnCommand
|
11
|
+
|
12
|
+
banner "knife rhn systemgroup add GROUP SYSTEM (options)"
|
13
|
+
category "rhn"
|
14
|
+
|
15
|
+
get_common_options
|
16
|
+
|
17
|
+
def run
|
18
|
+
|
19
|
+
group = name_args.first
|
20
|
+
|
21
|
+
if group.nil?
|
22
|
+
ui.fatal "You need a systemgroup name!"
|
23
|
+
show_usage
|
24
|
+
exit 1
|
25
|
+
end
|
26
|
+
|
27
|
+
system = name_args[1]
|
28
|
+
|
29
|
+
if system.nil?
|
30
|
+
ui.fatal "You need a system name!"
|
31
|
+
show_usage
|
32
|
+
exit 1
|
33
|
+
end
|
34
|
+
|
35
|
+
set_rhn_connection_options
|
36
|
+
|
37
|
+
satellite_system = get_satellite_system(system)
|
38
|
+
RhnSatellite::Systemgroup.add_systems(group,[satellite_system['id']])
|
39
|
+
ui.info "Added #{system} (ID: #{satellite_system['id']}) to RHN systemgroup: #{group}"
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
#
|
2
|
+
# Author:: Brian Flad (<bflad@wharton.upenn.edu>)
|
3
|
+
# License:: Apache License, Version 2.0
|
4
|
+
#
|
5
|
+
|
6
|
+
module RhnKnifePlugin
|
7
|
+
|
8
|
+
require 'chef/knife'
|
9
|
+
|
10
|
+
class RhnSystemgroupCreate < BaseRhnCommand
|
11
|
+
|
12
|
+
banner "knife rhn systemgroup create GROUP DESCRIPTION (options)"
|
13
|
+
category "rhn"
|
14
|
+
|
15
|
+
get_common_options
|
16
|
+
|
17
|
+
def run
|
18
|
+
|
19
|
+
group = name_args.first
|
20
|
+
|
21
|
+
if group.nil?
|
22
|
+
ui.fatal "You need a systemgroup name!"
|
23
|
+
show_usage
|
24
|
+
exit 1
|
25
|
+
end
|
26
|
+
|
27
|
+
description = name_args[1]
|
28
|
+
description ||= group
|
29
|
+
|
30
|
+
set_rhn_connection_options
|
31
|
+
|
32
|
+
RhnSatellite::Systemgroup.create(group,description)
|
33
|
+
ui.info "Created RHN Systemgroup: #{group}"
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
#
|
2
|
+
# Author:: Brian Flad (<bflad@wharton.upenn.edu>)
|
3
|
+
# License:: Apache License, Version 2.0
|
4
|
+
#
|
5
|
+
|
6
|
+
module RhnKnifePlugin
|
7
|
+
|
8
|
+
require 'chef/knife'
|
9
|
+
|
10
|
+
class RhnSystemgroupDelete < BaseRhnCommand
|
11
|
+
|
12
|
+
banner "knife rhn systemgroup delete GROUP (options)"
|
13
|
+
category "rhn"
|
14
|
+
|
15
|
+
get_common_options
|
16
|
+
|
17
|
+
def run
|
18
|
+
|
19
|
+
group = name_args.first
|
20
|
+
|
21
|
+
if group.nil?
|
22
|
+
ui.fatal "You need a systemgroup name!"
|
23
|
+
show_usage
|
24
|
+
exit 1
|
25
|
+
end
|
26
|
+
|
27
|
+
set_rhn_connection_options
|
28
|
+
|
29
|
+
RhnSatellite::Systemgroup.delete(group)
|
30
|
+
ui.info "Deleted RHN Systemgroup: #{group}"
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
#
|
2
|
+
# Author:: Brian Flad (<bflad@wharton.upenn.edu>)
|
3
|
+
# License:: Apache License, Version 2.0
|
4
|
+
#
|
5
|
+
|
6
|
+
module RhnKnifePlugin
|
7
|
+
|
8
|
+
require 'chef/knife'
|
9
|
+
|
10
|
+
# Until merged: https://github.com/duritong/ruby-rhn_satellite/pull/7
|
11
|
+
module Systemgroup
|
12
|
+
def inactive_systems(group_name,days=nil)
|
13
|
+
if days
|
14
|
+
base.default_call('systemgroup.listInactiveSystemsInGroup',group_name,days.to_i)
|
15
|
+
else
|
16
|
+
base.default_call('systemgroup.listInactiveSystemsInGroup',group_name)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
class RhnSystemgroupInactive < BaseRhnCommand
|
22
|
+
|
23
|
+
banner "knife rhn systemgroup inactive GROUP (options)"
|
24
|
+
category "rhn"
|
25
|
+
|
26
|
+
get_common_options
|
27
|
+
|
28
|
+
option :days,
|
29
|
+
:long => "--days DAYS",
|
30
|
+
:description => "The number of inactive days"
|
31
|
+
|
32
|
+
def run
|
33
|
+
|
34
|
+
group = name_args.first
|
35
|
+
|
36
|
+
if group.nil?
|
37
|
+
ui.fatal "You need a systemgroup name!"
|
38
|
+
show_usage
|
39
|
+
exit 1
|
40
|
+
end
|
41
|
+
|
42
|
+
set_rhn_connection_options
|
43
|
+
|
44
|
+
RhnSatellite::Systemgroup.extend(Systemgroup)
|
45
|
+
system_ids = RhnSatellite::Systemgroup.inactive_systems(group,get_config(:days))
|
46
|
+
systems = []
|
47
|
+
system_ids.each do |system_id|
|
48
|
+
systems << RhnSatellite::System.details(system_id)
|
49
|
+
end
|
50
|
+
systems.sort! {|a,b| a['profile_name'] <=> b['profile_name']}
|
51
|
+
systems.each do |system|
|
52
|
+
ui.info "#{system['id']},#{system['profile_name']}"
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
end
|
57
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
#
|
2
|
+
# Author:: Brian Flad (<bflad@wharton.upenn.edu>)
|
3
|
+
# License:: Apache License, Version 2.0
|
4
|
+
#
|
5
|
+
|
6
|
+
module RhnKnifePlugin
|
7
|
+
|
8
|
+
require 'chef/knife'
|
9
|
+
|
10
|
+
class RhnSystemgroupList < BaseRhnCommand
|
11
|
+
|
12
|
+
banner "knife rhn ystemgroup list (options)"
|
13
|
+
category "rhn"
|
14
|
+
|
15
|
+
get_common_options
|
16
|
+
|
17
|
+
def run
|
18
|
+
|
19
|
+
set_rhn_connection_options
|
20
|
+
|
21
|
+
system_groups = RhnSatellite::Systemgroup.all
|
22
|
+
system_groups.sort! {|a,b| a['name'] <=> b['name']}
|
23
|
+
system_groups.each do |system_group|
|
24
|
+
ui.info "#{system_group['name']}"
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
#
|
2
|
+
# Author:: Brian Flad (<bflad@wharton.upenn.edu>)
|
3
|
+
# License:: Apache License, Version 2.0
|
4
|
+
#
|
5
|
+
|
6
|
+
module RhnKnifePlugin
|
7
|
+
|
8
|
+
require 'chef/knife'
|
9
|
+
|
10
|
+
class RhnSystemgroupOutdated < BaseRhnCommand
|
11
|
+
|
12
|
+
banner "knife rhn systemgroup outdated GROUP (options)"
|
13
|
+
category "rhn"
|
14
|
+
|
15
|
+
get_common_options
|
16
|
+
|
17
|
+
def run
|
18
|
+
|
19
|
+
group = name_args.first
|
20
|
+
|
21
|
+
if group.nil?
|
22
|
+
ui.fatal "You need a systemgroup name!"
|
23
|
+
show_usage
|
24
|
+
exit 1
|
25
|
+
end
|
26
|
+
|
27
|
+
set_rhn_connection_options
|
28
|
+
|
29
|
+
systems = RhnSatellite::Systemgroup.systems(group)
|
30
|
+
systems.sort! {|a,b| a['profile_name'] <=> b['profile_name']}
|
31
|
+
systems.each do |system|
|
32
|
+
ui.info "#{system['id']},#{system['profile_name']}" unless RhnSatellite::System.uptodate?(system['id'])
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
#
|
2
|
+
# Author:: Brian Flad (<bflad@wharton.upenn.edu>)
|
3
|
+
# License:: Apache License, Version 2.0
|
4
|
+
#
|
5
|
+
|
6
|
+
module RhnKnifePlugin
|
7
|
+
|
8
|
+
require 'chef/knife'
|
9
|
+
|
10
|
+
class RhnSystemgroupRemove < BaseRhnCommand
|
11
|
+
|
12
|
+
banner "knife rhn systemgroup remove GROUP SYSTEM (options)"
|
13
|
+
category "rhn"
|
14
|
+
|
15
|
+
get_common_options
|
16
|
+
|
17
|
+
def run
|
18
|
+
|
19
|
+
group = name_args.first
|
20
|
+
|
21
|
+
if group.nil?
|
22
|
+
ui.fatal "You need a systemgroup name!"
|
23
|
+
show_usage
|
24
|
+
exit 1
|
25
|
+
end
|
26
|
+
|
27
|
+
system = name_args[1]
|
28
|
+
|
29
|
+
if system.nil?
|
30
|
+
ui.fatal "You need a system name!"
|
31
|
+
show_usage
|
32
|
+
exit 1
|
33
|
+
end
|
34
|
+
|
35
|
+
set_rhn_connection_options
|
36
|
+
|
37
|
+
satellite_system = get_satellite_system(system)
|
38
|
+
RhnSatellite::Systemgroup.remove_systems(group,[satellite_system['id']])
|
39
|
+
ui.info "Removed #{system} (ID: #{satellite_system['id']}) from RHN systemgroup: #{group}"
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
#
|
2
|
+
# Author:: Brian Flad (<bflad@wharton.upenn.edu>)
|
3
|
+
# License:: Apache License, Version 2.0
|
4
|
+
#
|
5
|
+
|
6
|
+
module RhnKnifePlugin
|
7
|
+
|
8
|
+
require 'chef/knife'
|
9
|
+
|
10
|
+
class RhnSystemgroupSystems < BaseRhnCommand
|
11
|
+
|
12
|
+
banner "knife rhn systemgroup systems GROUP (options)"
|
13
|
+
category "rhn"
|
14
|
+
|
15
|
+
get_common_options
|
16
|
+
|
17
|
+
def run
|
18
|
+
|
19
|
+
group = name_args.first
|
20
|
+
|
21
|
+
if group.nil?
|
22
|
+
ui.fatal "You need a systemgroup name!"
|
23
|
+
show_usage
|
24
|
+
exit 1
|
25
|
+
end
|
26
|
+
|
27
|
+
set_rhn_connection_options
|
28
|
+
|
29
|
+
systems = RhnSatellite::Systemgroup.systems(group)
|
30
|
+
systems.sort! {|a,b| a['profile_name'] <=> b['profile_name']}
|
31
|
+
systems.each do |system|
|
32
|
+
ui.info "#{system['id']},#{system['profile_name']}"
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
37
|
+
end
|
metadata
ADDED
@@ -0,0 +1,98 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: knife-rhn
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 27
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 1
|
9
|
+
- 0
|
10
|
+
version: 0.1.0
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Brian Flad
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2012-12-02 00:00:00 Z
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
name: rhn_satellite
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
+
none: false
|
25
|
+
requirements:
|
26
|
+
- - ">="
|
27
|
+
- !ruby/object:Gem::Version
|
28
|
+
hash: 3
|
29
|
+
segments:
|
30
|
+
- 0
|
31
|
+
version: "0"
|
32
|
+
type: :runtime
|
33
|
+
version_requirements: *id001
|
34
|
+
description: A knife plugin for managing RHN.
|
35
|
+
email:
|
36
|
+
- bflad@wharton.upenn.edu
|
37
|
+
executables: []
|
38
|
+
|
39
|
+
extensions: []
|
40
|
+
|
41
|
+
extra_rdoc_files: []
|
42
|
+
|
43
|
+
files:
|
44
|
+
- .gitignore
|
45
|
+
- Gemfile
|
46
|
+
- README.md
|
47
|
+
- Rakefile
|
48
|
+
- knife-rhn.gemspec
|
49
|
+
- lib/chef/knife/BaseRHNCommand.rb
|
50
|
+
- lib/chef/knife/rhn_system_delete.rb
|
51
|
+
- lib/chef/knife/rhn_system_details.rb
|
52
|
+
- lib/chef/knife/rhn_system_move.rb
|
53
|
+
- lib/chef/knife/rhn_system_systemgroups.rb
|
54
|
+
- lib/chef/knife/rhn_systemgroup_active.rb
|
55
|
+
- lib/chef/knife/rhn_systemgroup_add.rb
|
56
|
+
- lib/chef/knife/rhn_systemgroup_create.rb
|
57
|
+
- lib/chef/knife/rhn_systemgroup_delete.rb
|
58
|
+
- lib/chef/knife/rhn_systemgroup_inactive.rb
|
59
|
+
- lib/chef/knife/rhn_systemgroup_list.rb
|
60
|
+
- lib/chef/knife/rhn_systemgroup_outdated.rb
|
61
|
+
- lib/chef/knife/rhn_systemgroup_remove.rb
|
62
|
+
- lib/chef/knife/rhn_systemgroup_systems.rb
|
63
|
+
- lib/knife-rhn/version.rb
|
64
|
+
homepage: https://github.com/bflad/knife-rhn
|
65
|
+
licenses: []
|
66
|
+
|
67
|
+
post_install_message:
|
68
|
+
rdoc_options: []
|
69
|
+
|
70
|
+
require_paths:
|
71
|
+
- lib
|
72
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ">="
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
hash: 3
|
78
|
+
segments:
|
79
|
+
- 0
|
80
|
+
version: "0"
|
81
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
82
|
+
none: false
|
83
|
+
requirements:
|
84
|
+
- - ">="
|
85
|
+
- !ruby/object:Gem::Version
|
86
|
+
hash: 3
|
87
|
+
segments:
|
88
|
+
- 0
|
89
|
+
version: "0"
|
90
|
+
requirements: []
|
91
|
+
|
92
|
+
rubyforge_project:
|
93
|
+
rubygems_version: 1.8.24
|
94
|
+
signing_key:
|
95
|
+
specification_version: 3
|
96
|
+
summary: ""
|
97
|
+
test_files: []
|
98
|
+
|