Advertisement
Guest User

Untitled

a guest
Jan 3rd, 2017
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 5.02 KB | None | 0 0
  1. #!/usr/bin/env ruby
  2. require "spacewalk"
  3. require "optparse"
  4.  
  5. class Channel
  6.     attr_accessor :sysobj
  7.     def initialize()
  8.         @sysobj = []
  9.     end
  10.     def add_system(id,name)
  11.         @sysobj << System.new(id,name)
  12.     end
  13.  
  14. end
  15.  
  16. class System
  17.     attr_accessor :id, :name, :channels, :user, :pass
  18.     def initialize(id,name)
  19.         @id = id
  20.         @name = name
  21.         @channels = []
  22.     end
  23.     def add_channel(channel)
  24.         @channels << channel
  25.     end
  26. end
  27.  
  28. class Options
  29.     attr_accessor :fromchannel, :tochannel, :precedence, :listing
  30. end
  31.  
  32. class Parser
  33.     def self.parse(options)
  34.         args = Options.new
  35.  
  36.  
  37.         opt_parser = OptionParser.new do | opts |
  38.             opts.banner = "Usage: script [-c channel]"
  39.             args.listing = false
  40.  
  41.             opts.on("-fFROMCHANNEL", "--from-channel=FROMCHANNEL", "Channel to pull system lists from") do |fromchannel|
  42.                 args.fromchannel = fromchannel
  43.             end
  44.  
  45.             opts.on("-uUSER", "--user=USER", "user") do |user|
  46.                 args.user = user
  47.             end
  48.  
  49.             opts.on("-uPASS", "--user=PASS", "password") do |pass|
  50.                 args.pass = pass
  51.             end
  52.  
  53.             opts.on("-tTOCHANNEL", "--to-channel=TOCHANNEL", "Channel to add system list to") do |tochannel|
  54.                 args.tochannel = tochannel
  55.             end
  56.  
  57.             opts.on("-pPRECEDENCE", "--precedence=PRECEDENCE", "high priority (1) or low (0)") do |precedence|
  58.                 args.precedence = precedence
  59.             end
  60.  
  61.             opts.on("-l", "--listing", "Get config channel listing") do
  62.                 args.listing = true
  63.             end
  64.             opts.on("-h", "--help", "Prints this help") do
  65.                 puts opts
  66.                 exit
  67.             end
  68.         end
  69.  
  70. #            missing = mandatory.select{ |param| options[param].nil? }
  71. #            unless missing.empty?
  72. #                raise OptionParser::MissingArgument.new(missing.join(', '))
  73. #            end
  74. #        rescue OptionParser::InvalidOption, OptionParser::MissingArgument
  75. #            puts $!.to_s
  76. #            puts optparse
  77. #            exit
  78. #        end
  79.         return args
  80.     end
  81. end
  82.  
  83. def login(user, pass)
  84.     $mysat=Spacewalk.new("https://janus.sedata.com/rpc/api", user, pass)
  85. end
  86.  
  87. def populate_systems
  88.     sat_channel = Channel.new
  89.  
  90.     systemlist = $mysat.exec( 'configchannel.listSubscribedSystems', 'mdm-internal-beta' )
  91.  
  92.     for system in systemlist
  93.         sat_channel.add_system(system['id'],system['name'])
  94.     end
  95.  
  96.     return sat_channel
  97. end
  98.  
  99. def populate_system_channels(sat_channel)
  100.     sat_channel.sysobj.each do | system |
  101.         channellist = $mysat.exec( 'system.config.listChannels', system.id )
  102.         channellist.each do | channel |
  103.             system.add_channel(channel['label'])
  104.         end
  105.     end
  106.  
  107.     return sat_channel
  108. end
  109.  
  110. #options = Parser.parse # %w[--help]
  111. options = Parser.parse ARGV
  112. puts options.inspect
  113. login()
  114. satellite = populate_systems()
  115. satellite = populate_system_channels(satellite)
  116. satellite.sysobj.each do | obj |
  117.    puts obj.inspect
  118. end
  119. ~                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          
  120. ~                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          
  121. ~                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          
  122. ~                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          
  123. ~
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement