Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env ruby
- require "spacewalk"
- require "optparse"
- class Channel
- attr_accessor :sysobj
- def initialize()
- @sysobj = []
- end
- def add_system(id,name)
- @sysobj << System.new(id,name)
- end
- end
- class System
- attr_accessor :id, :name, :channels, :user, :pass
- def initialize(id,name)
- @id = id
- @name = name
- @channels = []
- end
- def add_channel(channel)
- @channels << channel
- end
- end
- class Options
- attr_accessor :fromchannel, :tochannel, :precedence, :listing
- end
- class Parser
- def self.parse(options)
- args = Options.new
- opt_parser = OptionParser.new do | opts |
- opts.banner = "Usage: script [-c channel]"
- args.listing = false
- opts.on("-fFROMCHANNEL", "--from-channel=FROMCHANNEL", "Channel to pull system lists from") do |fromchannel|
- args.fromchannel = fromchannel
- end
- opts.on("-uUSER", "--user=USER", "user") do |user|
- args.user = user
- end
- opts.on("-uPASS", "--user=PASS", "password") do |pass|
- args.pass = pass
- end
- opts.on("-tTOCHANNEL", "--to-channel=TOCHANNEL", "Channel to add system list to") do |tochannel|
- args.tochannel = tochannel
- end
- opts.on("-pPRECEDENCE", "--precedence=PRECEDENCE", "high priority (1) or low (0)") do |precedence|
- args.precedence = precedence
- end
- opts.on("-l", "--listing", "Get config channel listing") do
- args.listing = true
- end
- opts.on("-h", "--help", "Prints this help") do
- puts opts
- exit
- end
- end
- # missing = mandatory.select{ |param| options[param].nil? }
- # unless missing.empty?
- # raise OptionParser::MissingArgument.new(missing.join(', '))
- # end
- # rescue OptionParser::InvalidOption, OptionParser::MissingArgument
- # puts $!.to_s
- # puts optparse
- # exit
- # end
- return args
- end
- end
- def login(user, pass)
- $mysat=Spacewalk.new("https://janus.sedata.com/rpc/api", user, pass)
- end
- def populate_systems
- sat_channel = Channel.new
- systemlist = $mysat.exec( 'configchannel.listSubscribedSystems', 'mdm-internal-beta' )
- for system in systemlist
- sat_channel.add_system(system['id'],system['name'])
- end
- return sat_channel
- end
- def populate_system_channels(sat_channel)
- sat_channel.sysobj.each do | system |
- channellist = $mysat.exec( 'system.config.listChannels', system.id )
- channellist.each do | channel |
- system.add_channel(channel['label'])
- end
- end
- return sat_channel
- end
- #options = Parser.parse # %w[--help]
- options = Parser.parse ARGV
- puts options.inspect
- login()
- satellite = populate_systems()
- satellite = populate_system_channels(satellite)
- satellite.sysobj.each do | obj |
- puts obj.inspect
- end
- ~
- ~
- ~
- ~
- ~
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement