require 'rubygems' require 'hexy' require 'json/pure' require 'logger' require 'net/https' require 'nokogiri' require 'restclient' require 'uri' # Command-line tools and applications for using the Mu Dynamics REST Api's class Mu require 'mu/helper' @version = "5.7.2" Version = @version.freeze $log = Logger.new(STDOUT) $cookie = nil # http_helper extend Mu::Helper def self.run cmd, argv $log.datetime_format = "%Y-%m-%d %H:%M:%S" $log.level = Logger::INFO $log.formatter = proc { |severity, datetime, progname, msg| "[#{datetime} #{severity}]: #{msg}\n" } check_version kname, mname = cmd.split(':', 2) klass = Mu::Command.const_get kname.capitalize rescue nil mname ||= 'default' mname = "cmd_#{mname}".to_sym if klass and klass < Mu::Command and klass.method_defined? mname command = klass.new begin command.send mname, argv rescue => e error e.message.chomp('.') end else error "Unknown command #{cmd}" end end def self.check_version begin api = Mu::System.new(ENV['MU_IP'], ENV['MU_ADMIN_USER'], ENV['MU_ADMIN_PASS']) resp = Nokogiri::XML(api.status) version_string = resp.xpath("//versions/platform")[0].content version = version_string[0...version_string.rindex(".")] if @version > version puts "Warning. Version mismatch. Mu Gem version (#{@version}) is higher than Mu Platform version (#{version})" end rescue => e puts "#{e}. Check Mu env settings: $MU_IP (#{ENV['MU_IP']}), $MU_ADMIN_USER (#{ENV['MU_ADMIN_USER']}), $MU_ADMIN_PASS (#{ENV['MU_ADMIN_PASS']}) " end end end require 'mu/client' require 'mu/curl/error' require 'mu/curl/verify' require 'mu/command' require 'mu/http_helper'