Class: NVentory::Client
- Inherits:
-
Object
- Object
- NVentory::Client
- Defined in:
- lib/nventory.rb
Instance Attribute Summary collapse
-
#delete ⇒ Object
Returns the value of attribute delete.
Class Method Summary collapse
- .get_hardware_profile ⇒ Object
-
.get_uniqueid ⇒ Object
Helper methods.
- .getuuid ⇒ Object
Instance Method Summary collapse
-
#add_graffiti(obj_type, obj_hash, graffiti, login, password_callback = PasswordCallback) ⇒ Object
Add a new graffiti to given objects.
-
#add_node_group_node_assignment(node_id, node_group_id, login, password_callback = PasswordCallback) ⇒ Object
Add the given node into the given nodegroup by directly creating the node_group_node_assignment First argument is the id of the node Second argument is the id of the nodegroup.
-
#add_node_group_node_assignments(nodes, nodegroups, login, password_callback = PasswordCallback) ⇒ Object
The first argument is a hash returned by a ‘nodes’ call to get_objects The second argument is a hash returned by a ‘node_groups’ call to get_objects This method does the same thing as the add_nodes_to_nodegroups method.
-
#add_nodegroups_to_nodegroups(child_groups, parent_groups, login, password_callback = PasswordCallback) ⇒ Object
Both arguments are hashes returned by a ‘node_groups’ call to get_objects NOTE: For the parent groups you must have requested that the server include ‘child_groups’ in the result.
-
#add_nodes_to_nodegroups(nodes, nodegroups, login, password_callback = PasswordCallback) ⇒ Object
The first argument is a hash returned by a ‘nodes’ call to get_objects The second argument is a hash returned by a ‘node_groups’ call to get_objects NOTE: For the node groups you must have requested that the server include ‘nodes’ in the result.
-
#add_tag_to_node_group(ng_hash, tag_name, login, password_callback = PasswordCallback) ⇒ Object
Add a new or pre-existing tag (by name string) to a node_group (by hash returned from get_objects).
-
#delete_graffiti(obj_type, obj_hash, graffiti_name, login, password_callback = PasswordCallback) ⇒ Object
Delete the graffiti (based on the name) from the given objects obj_type is a string that describe the type of the obj (e.g NodeGroup) obj_hash is the hash returned from calling get_objects.
-
#delete_objects(objecttypes, results, login, password_callback = PasswordCallback) ⇒ Object
The results argument should be a reference to a hash returned by a call to get_objects.
- #get_expanded_nodegroup(nodegroup) ⇒ Object
- #get_field_names(objecttype, login = nil, password_callback = PasswordCallback) ⇒ Object
-
#get_objects(data, *moredata) ⇒ Object
FIXME: get, exactget, regexget, exclude and includes should all merge into a single search options hash parameter.
- #get_service_tree(service_name) ⇒ Object
-
#initialize(data = nil, *moredata) ⇒ Client
constructor
A new instance of Client.
- #legacy_getparms(data, moredata) ⇒ Object
- #legacy_initializeparms(data, moredata) ⇒ Object
- #register ⇒ Object
-
#remove_nodegroups_from_nodegroups(child_groups, parent_groups, login, password_callback = PasswordCallback) ⇒ Object
Both arguments are hashes returned by a ‘node_groups’ call to get_objects NOTE: For the parent groups you must have requested that the server include ‘child_groups’ in the result.
-
#remove_nodes_from_nodegroups(nodes, nodegroups, login, password_callback = PasswordCallback) ⇒ Object
The first argument is a hash returned by a ‘nodes’ call to get_objects The second argument is a hash returned by a ‘node_groups’ call to get_objects NOTE: For the node groups you must have requested that the server include ‘nodes’ in the result.
-
#remove_tag_from_node_group(ng_hash, tag_name, login, password_callback = PasswordCallback) ⇒ Object
Add a new or pre-existing tag (by name string) to a node_group (by hash returned from get_objects).
-
#set_nodegroup_node_assignments(nodes, nodegroups, login, password_callback = PasswordCallback) ⇒ Object
The first argument is a hash returned by a ‘nodes’ call to get_objects The second argument is a hash returned by a ‘node_groups’ call to get_objects.
-
#set_nodegroup_nodegroup_assignments(child_groups, parent_groups, login, password_callback = PasswordCallback) ⇒ Object
Both arguments are hashes returned by a ‘node_groups’ call to get_objects.
-
#set_objects(objecttypes, results, data, login, password_callback = PasswordCallback) ⇒ Object
The results argument can be a reference to a hash returned by a call to get_objects, in which case the data will be PUT to each object there, thus updating them.
Constructor Details
#initialize(data = nil, *moredata) ⇒ Client
Returns a new instance of Client.
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 |
# File 'lib/nventory.rb', line 71 def initialize(data=nil,*moredata) if data || moredata parms = legacy_initializeparms(data,moredata) # def initialize(debug=false, dryrun=false, configfile=nil, server=nil) parms[:debug] ? (@debug = parms[:debug]) : @debug = (nil) parms[:dryrun] ? (@dryrun = parms[:dryrun]) : @dryrun = (nil) parms[:server] ? (@server = parms[:server]) : @server = (nil) parms[:cookiefile] ? @cookiefile = parms[:cookiefile] : @cookiefile = "#{ENV['HOME']}/.nventory_cookie" if parms[:proxy_server] == false @proxy_server = 'nil' elsif parms[:proxy_server] @proxy_server = parms[:proxy_server] else @proxy_server = nil end parms[:sso_server] ? (@sso_server = parms[:sso_server]) : (@sso_server = nil) parms[:configfile] ? (configfile = parms[:configfile]) : (configfile = nil) end @ca_file = nil @ca_path = nil @delete = false # Initialize the variable, see attr_accessor above @dmi_data = nil CONFIG_FILES << configfile if configfile CONFIG_FILES.each do |configfile| if File.exist?(configfile) IO.foreach(configfile) do |line| line.chomp! next if (line =~ /^\s*$/); # Skip blank lines next if (line =~ /^\s*#/); # Skip comments key, value = line.split(/\s*=\s*/, 2) if key == 'server' @server = value # Warn the user, as this could potentially be confusing # if they don't realize there's a config file lying # around warn "Using server #{@server} from #{configfile}" if (@debug) elsif key == 'sso_server' && !@sso_server @sso_server = value warn "Using sso_server #{@sso_server} from #{configfile}" if (@debug) elsif key == 'proxy_server' && !@proxy_server @proxy_server = value warn "Using proxy_server #{@proxy_server} from #{configfile}" if (@debug) elsif key == 'ca_file' @ca_file = value warn "Using ca_file #{@ca_file} from #{configfile}" if (@debug) elsif key == 'ca_path' @ca_path = value warn "Using ca_path #{@ca_path} from #{configfile}" if (@debug) elsif key == 'cookiefile' @cookiefile = value warn "Using cookiefile #{@cookiefile} from #{configfile}" if (@debug) end end end end unless @server @server = 'http://nventory/' warn "Using server #{@server}" if @debug end @sso_server = 'https://sso.example.com/' unless @sso_server # Make sure the server URL ends in a / so that we can append paths to it # using URI.join if @server !~ %r{/$} @server << '/' end end |
Instance Attribute Details
#delete ⇒ Object
Returns the value of attribute delete.
69 70 71 |
# File 'lib/nventory.rb', line 69 def delete @delete end |
Class Method Details
.get_hardware_profile ⇒ Object
1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 |
# File 'lib/nventory.rb', line 1145 def self.get_hardware_profile result = {:manufacturer => 'Unknown', :model => 'Unknown'} if Facter['manufacturer'] && Facter['manufacturer'].value # dmidecode result[:manufacturer] = Facter['manufacturer'].value.strip result[:model] = Facter['productname'].value.strip elsif Facter['sp_machine_name'] && Facter['sp_machine_name'].value # Mac OS X # There's a small chance of this not being true... result[:manufacturer] = 'Apple' result[:model] = Facter['sp_machine_name'].value.strip end return result end |
.get_uniqueid ⇒ Object
Helper methods
1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 |
# File 'lib/nventory.rb', line 1095 def self.get_uniqueid os = Facter['kernel'].value hardware_profile = NVentory::Client::get_hardware_profile if os == 'Linux' or os == 'FreeBSD' # if File.exist?('/proc/modules') && `grep -q ^xen /proc/modules` && $? == 0 uuid = Facter['macaddress'].value # Dell C6100 don't have unique uuid elsif hardware_profile[:manufacturer] =~ /Dell/ && hardware_profile[:model] == 'C6100' uuid = Facter['macaddress'].value else # best to use UUID from dmidecode uuid = getuuid end # Stupid SeaMicro boxes all have the same UUID below. So we won't # want to use it, use mac address instead if uuid && uuid != "78563412-3412-7856-90AB-CDDEEFAABBCC" uniqueid = uuid # next best thing to use is macaddress else uniqueid = Facter['macaddress'].value end elsif Facter['uniqueid'] && Facter['uniqueid'].value # This sucks, it's just using hostid, which is generally tied to an # IP address, not the physical hardware uniqueid = Facter['uniqueid'].value elsif Facter['sp_serial_number'] && Facter['sp_serial_number'].value # I imagine Mac serial numbers are unique uniqueid = Facter['sp_serial_number'].value end return uniqueid end |
.getuuid ⇒ Object
1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 |
# File 'lib/nventory.rb', line 1128 def self.getuuid uuid = nil # dmidecode will fail if not run as root if Process.euid != 0 raise "This must be run as root" end uuid_entry = `/usr/sbin/dmidecode | grep UUID` if uuid_entry uuid = uuid_entry.split(":")[1] end if uuid return uuid.strip else return nil end end |
Instance Method Details
#add_graffiti(obj_type, obj_hash, graffiti, login, password_callback = PasswordCallback) ⇒ Object
Add a new graffiti to given objects. We’re assuming that graffiti is a string of “key:value” format obj_type is a string that describe the type of the obj (e.g NodeGroup) obj_hash is the hash returned from calling get_objects
1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 |
# File 'lib/nventory.rb', line 1042 def add_graffiti(obj_type, obj_hash, graffiti, login, password_callback=PasswordCallback) name,value = graffiti.split(':') obj_hash.each_value do |obj| set_objects('graffitis', nil, { :name => name, :value => value, :graffitiable_id => obj['id'], :graffitiable_type => obj_type, }, login, password_callback); end end |
#add_node_group_node_assignment(node_id, node_group_id, login, password_callback = PasswordCallback) ⇒ Object
Add the given node into the given nodegroup by directly creating the node_group_node_assignment First argument is the id of the node Second argument is the id of the nodegroup
838 839 840 841 842 |
# File 'lib/nventory.rb', line 838 def add_node_group_node_assignment(node_id, node_group_id, login, password_callback=PasswordCallback) setdata = {:node_id => node_id, :node_group_id => node_group_id} puts "Adding using the following setdata #{setdata.inspect}" set_objects('node_group_node_assignments', nil, setdata, login, password_callback) end |
#add_node_group_node_assignments(nodes, nodegroups, login, password_callback = PasswordCallback) ⇒ Object
The first argument is a hash returned by a ‘nodes’ call to get_objects The second argument is a hash returned by a ‘node_groups’ call to get_objects This method does the same thing as the add_nodes_to_nodegroups method. However, it will not be susceptible to the race condition mentioned in add_nodes_to_nodegroups method This is because it directly talks to the node_group_node_assignments controller
850 851 852 853 854 855 856 |
# File 'lib/nventory.rb', line 850 def add_node_group_node_assignments(nodes, nodegroups, login, password_callback=PasswordCallback) nodegroups.each do |nodegroup_name, nodegroup| nodes.each do |nodename, node| add_node_group_node_assignment(node['id'], nodegroup['id'], login, password_callback) end end end |
#add_nodegroups_to_nodegroups(child_groups, parent_groups, login, password_callback = PasswordCallback) ⇒ Object
Both arguments are hashes returned by a ‘node_groups’ call to get_objects NOTE: For the parent groups you must have requested that the server include ‘child_groups’ in the result
930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 |
# File 'lib/nventory.rb', line 930 def add_nodegroups_to_nodegroups(child_groups, parent_groups, login, password_callback=PasswordCallback) # The server only supports setting a complete list of assignments for # a node group. So we need to retreive the current list of assignments # for each group, merge in the additional node groups that the user wants # added, and pass that off to set_nodegroup_nodegroup_assignments to perform # the update. # FIXME: This should talk directly to the node_group_node_groups_assignments # controller, so that we aren't exposed to the race conditions this # method currently suffers from. parent_groups.each_pair do |parent_group_name, parent_group| # Use a hash to merge the current and new members and # eliminate duplicates merged_nodegroups = child_groups if parent_group['child_groups'] parent_group['child_groups'].each do |child_group| name = child_group['name'] merged_nodegroups[name] = child_group end end set_nodegroup_nodegroup_assignments(merged_nodegroups, {parent_group_name => parent_group}, login, password_callback) end end |
#add_nodes_to_nodegroups(nodes, nodegroups, login, password_callback = PasswordCallback) ⇒ Object
The first argument is a hash returned by a ‘nodes’ call to get_objects The second argument is a hash returned by a ‘node_groups’ call to get_objects NOTE: For the node groups you must have requested that the server include ‘nodes’ in the result
862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 |
# File 'lib/nventory.rb', line 862 def add_nodes_to_nodegroups(nodes, nodegroups, login, password_callback=PasswordCallback) # The server only supports setting a complete list of members of # a node group. So we need to retreive the current list of members # for each group, merge in the additional nodes that the user wants # added, and pass that off to set_nodegroup_assignments to perform # the update. # FIXME: This should talk directly to the node_group_node_assignments # controller, so that we aren't exposed to the race conditions this # method currently suffers from. nodegroups.each_pair do |nodegroup_name, nodegroup| # Use a hash to merge the current and new members and # eliminate duplicates merged_nodes = nodes.clone nodegroup["nodes"].each do |node| name = node['name'] merged_nodes[name] = node end set_nodegroup_node_assignments(merged_nodes, {nodegroup_name => nodegroup}, login, password_callback) end end |
#add_tag_to_node_group(ng_hash, tag_name, login, password_callback = PasswordCallback) ⇒ Object
Add a new or pre-existing tag (by name string) to a node_group (by hash returned from get_objects)
998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 |
# File 'lib/nventory.rb', line 998 def add_tag_to_node_group(ng_hash, tag_name, login, password_callback=PasswordCallback) tag_found = get_objects({:objecttype => 'tags', :exactget => {:name => tag_name}}) if tag_found.empty? = { :name => tag_name } set_objects('tags',{},,login, password_callback) tag_found = get_objects({:objecttype => 'tags', :exactget => {:name => tag_name}}) end # tag_found is hash, even tho only one result (tag_data = tag_found[tag_found.keys.first]) && (tag_id = tag_data['id']) ng_hash.each_pair do |ng_name,ng_data| setdata = { :taggable_type => 'NodeGroup', :taggable_id => ng_data['id'], :tag_id => tag_id } set_objects('taggings',{},setdata,login,password_callback) end end |
#delete_graffiti(obj_type, obj_hash, graffiti_name, login, password_callback = PasswordCallback) ⇒ Object
Delete the graffiti (based on the name) from the given objects obj_type is a string that describe the type of the obj (e.g NodeGroup) obj_hash is the hash returned from calling get_objects
1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 |
# File 'lib/nventory.rb', line 1058 def delete_graffiti(obj_type, obj_hash, graffiti_name, login, password_callback=PasswordCallback) obj_hash.each_value do |obj| getdata = {:objecttype => 'graffitis', :exactget => {:name => graffiti_name, :graffitiable_id => obj['id'], :graffitiable_type => obj_type} } graffitis_to_delete = get_objects(getdata) delete_objects('graffitis', graffitis_to_delete, login, password_callback) end end |
#delete_objects(objecttypes, results, login, password_callback = PasswordCallback) ⇒ Object
The results argument should be a reference to a hash returned by a call to get_objects.
512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 |
# File 'lib/nventory.rb', line 512 def delete_objects(objecttypes, results, login, password_callback=PasswordCallback) successcount = 0 results.each_pair do |result_name, result| if result['id'] uri = URI::join(@server, "#{objecttypes}/#{result['id']}.xml") req = Net::HTTP::Delete.new(uri.request_uri) response = send_request(req, uri, login, password_callback) while response.kind_of?(Net::HTTPMovedPermanently) uri = URI.parse(response['Location']) req = Net::HTTP::Delete.new(uri.request_uri) response = send_request(req, uri, login, password_callback) end if response.kind_of?(Net::HTTPOK) successcount = 0 else warn "Delete of #{result_name} (#{result['id']}) failed:\n" + response.body end else warn "delete_objects passed a bogus results hash, #{result_name} has no id field" end end successcount end |
#get_expanded_nodegroup(nodegroup) ⇒ Object
400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 |
# File 'lib/nventory.rb', line 400 def (nodegroup) getdata = {} getdata[:objecttype] = 'node_groups' getdata[:exactget] = {'name' => [nodegroup]} getdata[:includes] = ['nodes', 'child_groups'] results = get_objects(getdata) nodes = {} if results.has_key?(nodegroup) if results[nodegroup].has_key?('nodes') results[nodegroup]['nodes'].each { |node| nodes[node['name']] = true } end if results[nodegroup].has_key?('child_groups') results[nodegroup]['child_groups'].each do |child_group| (child_group['name']).each { |child_group_node| nodes[child_group_node] = true } end end end nodes.keys.sort end |
#get_field_names(objecttype, login = nil, password_callback = PasswordCallback) ⇒ Object
372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 |
# File 'lib/nventory.rb', line 372 def get_field_names(objecttype, login=nil, password_callback=PasswordCallback) uri = URI::join(@server, "#{objecttype}/field_names.xml") req = Net::HTTP::Get.new(uri.request_uri) warn "GET URL: #{uri}" if (@debug) response = send_request(req, uri, login, password_callback) while response.kind_of?(Net::HTTPMovedPermanently) uri = URI.parse(response['Location']) req = Net::HTTP::Get.new(uri.request_uri) response = send_request(req, uri, login, password_callback) end if !response.kind_of?(Net::HTTPOK) puts response.body response.error! end puts response.body if (@debug) results_xml = REXML::Document.new(response.body) field_names = [] results_xml.root.elements['/field_names'].each do |elem| # For some reason Elements[] is returning things other than elements, # like text nodes next if elem.node_type != :element field_names << elem.text end field_names end |
#get_objects(data, *moredata) ⇒ Object
FIXME: get, exactget, regexget, exclude and includes should all merge into a single search options hash parameter
196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 |
# File 'lib/nventory.rb', line 196 def get_objects(data,*moredata) parms = legacy_getparms(data,moredata) # def get_objects(objecttype, get, exactget, regexget, exclude, andget, includes=nil, login=nil, password_callback=PasswordCallback) objecttype = parms[:objecttype] get = parms[:get] exactget = parms[:exactget] regexget = parms[:regexget] exclude = parms[:exclude] andget = parms[:andget] includes = parms[:includes] login = parms[:login] password_callback = parms[:password_callback] # PS-704 - node_groups controller when format.xml, includes some custom model methods that create a lot of querying joins, so this is # a way to 'override' it on cli side - the server will look for that param to skip these def methods when it renders. webparams = {:nodefmeth => 1} webparams = parms[:webparams] # # Package up the search parameters in the format the server expects # = [] if get get.each_pair do |key,values| if key == 'enable_aliases' && values == 1 << "#{key}=#{values}" elsif values.length > 1 values.each do |value| << "#{key}[]=#{CGI.escape(value)}" end else # This isn't strictly necessary, specifying a single value via # 'key[]=[value]' would work fine, but this makes for a cleaner URL # and slightly reduced processing on the backend << "#{key}=#{CGI.escape(values[0])}" end end end if exactget exactget.each_pair do |key,values| if key == 'enable_aliases' && values == 1 << "#{key}=#{values}" elsif values.length > 1 values.each do |value| << "exact_#{key}[]=#{CGI.escape(value)}" end else # This isn't strictly necessary, specifying a single value via # 'key[]=[value]' would work fine, but this makes for a cleaner URL # and slightly reduced processing on the backend << "exact_#{key}=#{CGI.escape(values[0])}" end end end if regexget regexget.each_pair do |key,values| if values.length > 1 values.each do |value| << "regex_#{key}[]=#{CGI.escape(value)}" end else # This isn't strictly necessary, specifying a single value via # 'key[]=[value]' would work fine, but this makes for a cleaner URL # and slightly reduced processing on the backend << "regex_#{key}=#{CGI.escape(values[0])}" end end end if exclude exclude.each_pair do |key,values| if values.length > 1 values.each do |value| << "exclude_#{key}[]=#{CGI.escape(value)}" end else # This isn't strictly necessary, specifying a single value via # 'key[]=[value]' would work fine, but this makes for a cleaner URL # and slightly reduced processing on the backend << "exclude_#{key}=#{CGI.escape(values[0])}" end end end if andget andget.each_pair do |key,values| if values.length > 1 values.each do |value| << "and_#{key}[]=#{CGI.escape(value)}" end else # This isn't strictly necessary, specifying a single value via # 'key[]=[value]' would work fine, but this makes for a cleaner URL # and slightly reduced processing on the backend << "and_#{key}=#{CGI.escape(values[0])}" end end end if includes # includes = ['status', 'rack:datacenter'] # maps to # include[status]=&include[rack]=datacenter includes.each do |inc| incstring = '' if inc.include?(':') incparts = inc.split(':') lastpart = incparts.pop incstring = 'include' incparts.each { |part| incstring << "[#{part}]" } incstring << "=#{lastpart}" else incstring = "include[#{inc}]=" end << incstring end end if webparams && webparams.kind_of?(Hash) webparams.each_pair{|k,v| << "#{k}=#{v}"} end querystring = .join('&') # # Send the query to the server # if parms[:format] == 'json' if HAS_JSON_GEM uri = URI::join(@server, "#{objecttype}.json?#{querystring}") else warn "Warning: Cannot use json format because json gem is not installed. Using xml format instead." parms[:format] = 'xml' uri = URI::join(@server, "#{objecttype}.xml?#{querystring}") end else uri = URI::join(@server, "#{objecttype}.xml?#{querystring}") end req = Net::HTTP::Get.new(uri.request_uri) warn "GET URL: #{uri}" if (@debug) response = send_request(req, uri, login, password_callback) while response.kind_of?(Net::HTTPMovedPermanently) uri = URI.parse(response['Location']) req = Net::HTTP::Get.new(uri.request_uri) response = send_request(req, uri, login, password_callback) end if !response.kind_of?(Net::HTTPOK) puts response.body response.error! end if parms[:format] == 'json' results = JSON.parse(response.body) else # # Parse the XML data from the server # This tries to render the XML into the best possible representation # as a Perl hash. It may need to evolve over time. puts response.body if (@debug) results_xml = REXML::Document.new(response.body) results = {} if results_xml.root.elements["/#{objecttype}"] results_xml.root.elements["/#{objecttype}"].each do |elem| # For some reason Elements[] is returning things other than elements, # like text nodes next if elem.node_type != :element data = xml_to_ruby(elem) name = data['name'] || data['id'] if !results[name].nil? warn "Duplicate entries for #{name}. Only one will be shown." end results[name] = data end end end #puts results.inspect if (@debug) puts YAML.dump(results) if (@debug) results end |
#get_service_tree(service_name) ⇒ Object
1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 |
# File 'lib/nventory.rb', line 1070 def get_service_tree(service_name) getdata = {} getdata[:objecttype] = 'services' getdata[:exactget] = {'name' => [service_name]} getdata[:includes] = ['nodes', 'parent_services'] services = {service_name => []} results = get_objects(getdata) if results.has_key?(service_name) if results[service_name].has_key?('parent_services') && !results[service_name]['parent_services'].empty? results[service_name]['parent_services'].each do |service| services[service_name] << get_service_tree(service['name']) end else return service_name end else # no such service return {} end return services end |
#legacy_getparms(data, moredata) ⇒ Object
169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 |
# File 'lib/nventory.rb', line 169 def legacy_getparms(data,moredata) # if data is string, it is legacy method of supplying get_objects params: # def get_objects(objecttype, get, exactget, regexget, exclude, andget, includes=nil, login=nil, password_callback=PasswordCallback) newdata = {} if data.kind_of?(String) raise 'Syntax Error: Missing :objecttype' unless data.kind_of?(String) newdata[:objecttype] = data newdata[:get] = moredata[0] newdata[:exactget] = moredata[1] newdata[:regexget] = moredata[2] newdata[:exclude] = moredata[3] newdata[:andget] = moredata[4] newdata[:includes] = moredata[5] newdata[:login] = moredata[6] newdata[:password_callback] = PasswordCallback elsif data.kind_of?(Hash) raise 'Syntax Error: Missing :objecttype' unless data[:objecttype].kind_of?(String) newdata = data newdata[:password_callback] = PasswordCallback unless newdata[:password_callback] else raise 'Syntax Error' end return newdata end |
#legacy_initializeparms(data, moredata) ⇒ Object
142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 |
# File 'lib/nventory.rb', line 142 def legacy_initializeparms(data,moredata) # if data is string, it is legacy method of supplying initialize params: # def initialize(debug=false, dryrun=false, configfile=nil, server=nil) newdata = {} if data.kind_of?(Hash) newdata = data elsif data || moredata newdata[:debug] = data newdata[:dryrun] = moredata[0] newdata[:configfile] = moredata[1] if moredata[2] server = moredata[2] if moredata[2] if server =~ /^http/ (server =~ /\/$/) ? (newdata[:server] = server) : (newdata[:server] = "#{server}/") else newdata[:server] = "http://#{server}/" end end newdata[:proxy_server] = moredata[3] else raise 'Syntax Error' end warn "** Using server #{newdata[:server]} **" if newdata[:server] warn "** Using proxy_server #{newdata[:proxy_server]} **" if newdata[:proxy_server] return newdata end |
#register ⇒ Object
536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 |
# File 'lib/nventory.rb', line 536 def register data = {} # Tell facter to load everything, otherwise it tries to dynamically # load the individual fact libraries using a very broken mechanism Facter.loadfacts # # Gather software-related information # data['name'] = Facter['fqdn'].value data['updated_at'] = Time.now.strftime("%Y-%m-%d %H:%M:%S") if Facter['kernel'] && Facter['kernel'].value == 'Linux' && Facter['lsbdistdescription'] && Facter['lsbdistdescription'].value # Strip release version and code name from lsbdistdescription lsbdistdesc = Facter['lsbdistdescription'].value lsbdistdesc.gsub!(/ release \S+/, '') lsbdistdesc.gsub!(/ \([^)]\)/, '') data['operating_system[variant]'] = lsbdistdesc data['operating_system[version_number]'] = Facter['lsbdistrelease'].value elsif Facter['kernel'] && Facter['kernel'].value == 'Darwin' && Facter['macosx_productname'] && Facter['macosx_productname'].value data['operating_system[variant]'] = Facter['macosx_productname'].value data['operating_system[version_number]'] = Facter['macosx_productversion'].value else data['operating_system[variant]'] = Facter['operatingsystem'].value data['operating_system[version_number]'] = Facter['operatingsystemrelease'].value end if Facter['architecture'] && Facter['architecture'].value data['operating_system[architecture]'] = Facter['architecture'].value else # Not sure if this is reasonable data['operating_system[architecture]'] = Facter['hardwaremodel'].value end data['kernel_version'] = Facter['kernelrelease'].value if Facter.value('memorysize') data['os_memory'] = Facter.value('memorysize') elsif Facter.value('sp_physical_memory') # Mac OS X # More or less a safe bet that OS memory == physical memory on Mac OS X data['os_memory'] = Facter.value('sp_physical_memory') end if Facter['swapsize'] data['swap'] = Facter['swapsize'].value end # Currently the processorcount fact doesn't even get defined on most platforms if Facter['processorcount'] && Facter['processorcount'].value # This is generally a virtual processor count (cores and HTs), # not a physical CPU count data['os_processor_count'] = Facter['processorcount'].value elsif Facter['sp_number_processors'] && Facter['sp_number_processors'].value data['os_processor_count'] = Facter['sp_number_processors'].value end data['timezone'] = Facter['timezone'].value if Facter['timezone'] # Need custom facts for these #data['virtual_client_ids'] = cpu_percent = getcpupercent login_count = getlogincount disk_usage = getdiskusage # have to round it up because server code only takes integer data['utilization_metric[percent_cpu][value]'] = cpu_percent.round if cpu_percent data['utilization_metric[login_count][value]'] = login_count if login_count data['used_space'] = disk_usage[:used_space] if disk_usage data['avail_space'] = disk_usage[:avail_space] if disk_usage getvolumes.each do |key, value| data[key] = value end # # Gather hardware-related information # hardware_profile = NVentory::Client::get_hardware_profile data['hardware_profile[manufacturer]'] = hardware_profile[:manufacturer] data['hardware_profile[model]'] = hardware_profile[:model] if Facter['serialnumber'] && Facter['serialnumber'].value data['serial_number'] = Facter['serialnumber'].value elsif Facter['sp_serial_number'] && Facter['sp_serial_number'].value # Mac OS X data['serial_number'] = Facter['sp_serial_number'].value end if Facter['processor0'] && Facter['processor0'].value # FIXME: Parsing this string is less than ideal, as these things # are reported as seperate fields by dmidecode, but facter isn't # reading that data. # Example: Intel(R) Core(TM)2 Duo CPU T7300 @ 2.00GHz # Example: Intel(R) Pentium(R) 4 CPU 3.60GHz processor = Facter['processor0'].value if processor =~ /(\S+)\s(.+)/ manufacturer = $1 model = $2 speed = nil if model =~ /(.+\S)\s+\@\s+([\d\.]+.Hz)/ model = $1 speed = $2 elsif model =~ /(.+\S)\s+([\d\.]+.Hz)/ model = $1 speed = $2 end data['processor_manufacturer'] = manufacturer.gsub(/\(R\)/, '') data['processor_model'] = model data['processor_speed'] = speed end elsif Facter['sp_cpu_type'] && Facter['sp_cpu_type'].value # FIXME: Assuming the manufacturer is the first word is # less than ideal cpu_type = Facter['sp_cpu_type'].value if cpu_type =~ /(\S+)\s(.+)/ data['processor_manufacturer'] = $1 data['processor_model'] = $2 end data['processor_speed'] = Facter['sp_current_processor_speed'].value # It's not clear if system_profiler is reporting the number # of physical CPUs or the number seen by the OS. I'm not # sure if there are situations in Mac OS where those two can # get out of sync. As such this is identical to what is reported # for the os_processor_count above. data['processor_count'] = Facter['sp_number_processors'].value end if Facter['physicalprocessorcount'] data['processor_count'] = Facter['physicalprocessorcount'].value else # need to get from dmidecode end data['processor_core_count'] = get_cpu_core_count #data['processor_socket_count'] = #data['power_supply_count'] = #data['physical_memory_sizes'] = physical_memory = get_physical_memory data['physical_memory'] = Facter::Memory.scale_number(physical_memory, "MB") if physical_memory nics = [] if Facter['interfaces'] && Facter['interfaces'].value nics = Facter['interfaces'].value.split(',') nics.each do |nic| data["network_interfaces[#{nic}][name]"] = nic data["network_interfaces[#{nic}][hardware_address]"] = Facter["macaddress_#{nic}"].value #data["network_interfaces[#{nic}][interface_type]"] #data["network_interfaces[#{nic}][physical]"] = #data["network_interfaces[#{nic}][up]"] = #data["network_interfaces[#{nic}][link]"] = #data["network_interfaces[#{nic}][autonegotiate]"] = #data["network_interfaces[#{nic}][speed]"] = #data["network_interfaces[#{nic}][full_duplex]"] = # Facter only captures one address per interface data["network_interfaces[#{nic}][ip_addresses][0][address]"] = Facter["ipaddress_#{nic}"].value data["network_interfaces[#{nic}][ip_addresses][0][address_type]"] = 'ipv4' data["network_interfaces[#{nic}][ip_addresses][0][netmask]"] = Facter["netmask_#{nic}"].value #data["network_interfaces[#{nic}][ip_addresses][0][broadcast]"] = end end # get additional nic info that facter doesn't know about nic_info = get_nic_info nic_info.each do |nic, info| next if !nics.include?(nic) info.each do |key, value| data["network_interfaces[#{nic}][#{key}]"] = value end end # Mark our NIC data as authoritative so that the server properly # updates its records (removing any NICs and IPs we don't specify) data['network_interfaces[authoritative]'] = true data['uniqueid'] = NVentory::Client::get_uniqueid # TODO: figure out list of guests if it's a host vmstatus = getvmstatus if vmstatus == 'xenu' data['virtualmode'] = 'guest' data['virtualarch'] = 'xen' elsif vmstatus == 'xen0' data['virtualmode'] = 'host' data['virtualarch'] = 'xen' elsif vmstatus == 'vmware_server' data['virtualmode'] = 'host' data['virtualarch'] = 'vmware' elsif vmstatus == 'vmware' data['virtualmode'] = 'guest' data['virtualarch'] = 'vmware' elsif vmstatus == 'kvm_host' data['virtualmode'] = 'host' data['virtualarch'] = 'kvm' end if vmstatus == 'kvm_host' guests = get_kvm_hostinfo guests.each do |vm, vminfo| data["vmguest[#{vm}][vmimg_size]"] = vminfo['vmimg_size'] data["vmguest[#{vm}][vmspace_used]"] = vminfo['vmspace_used'] end end # Looks like this no longer works. virtual_client_ids is not valid # field and causes ALL nodes to return.... # if data['hardware_profile[model]'] == 'VMware Virtual Platform' # getdata = {} # getdata[:objecttype] = 'nodes' # getdata[:exactget] = {'virtual_client_ids' => [data['uniqueid']]} # getdata[:login] = 'autoreg' # results = get_objects(getdata) # if results.length == 1 # data['virtual_parent_node_id'] = results.values.first['id'] # elsif results.length > 1 # warn "Multiple hosts claim this virtual client: #{results.keys.sort.join(',')}" # end # end # Get console info console_type = get_console_type if console_type == "Dell DRAC" data['console_type'] = "Dell DRAC" drac_info = get_drac_info # Create a NIC for the DRAC and associate it this node unless drac_info.empty? drac_name = (drac_info[:name] && !drac_info[:name].empty?)? drac_info[:name] : "DRAC" data["network_interfaces[#{drac_name}][name]"] = drac_name data["network_interfaces[#{drac_name}][hardware_address]"] = drac_info[:mac_address] data["network_interfaces[#{drac_name}][ip_addresses][0][address]"] = drac_info[:ip_address] data["network_interfaces[#{drac_name}][ip_addresses][0][address_type]"] = "ipv4" end end # See what chassis/blade enclosure the node is in chassis = get_chassis_info data["chassis[service_tag]"] = chassis[:service_tag] if !chassis.empty? data["chassis[slot_num]"] = chassis[:slot_num] if !chassis.empty? # # Report data to server # # Check to see if there's an existing entry for this host that matches # our unique id. If so we want to update it, even if the hostname # doesn't match our current hostname (as it probably indicates this # host was renamed). results = nil if data['uniqueid'] getdata = {} getdata[:objecttype] = 'nodes' getdata[:exactget] = {'uniqueid' => [data['uniqueid']]} getdata[:login] = 'autoreg' results = get_objects(getdata) # # Check for a match of the reverse uniqueid. # Background: # Dmidecode versions earlier than 2.10 display # the first three fields of the UUID in reverse order # due to the use of Big-endian rather than Little-endian # byte encoding. # Starting with version 2.10, dmidecode uses Little-endian # when it finds an SMBIOS >= 2.6. UUID's reported from SMBIOS' # earlier than 2.6 are considered "incorrect". # # After a rebuild/upgrade, rather than creating a new node # entry for an existing asset, we'll check for the flipped # version of the uniqueid. # if results.empty? && data['uniqueid'].include?('-') reverse_uniqueid = [data['uniqueid'].split('-')[0..2].map { |n| n.split(/(\w\w)/).reverse.join }.join('-'), data['uniqueid'].split('-',4)[3]].join('-') getdata[:exactget] = {'uniqueid' => [reverse_uniqueid]} results = get_objects(getdata) end end # If we failed to find an existing entry based on the unique id, # fall back to the hostname. if results.empty? && data['name'] getdata = {} getdata[:objecttype] = 'nodes' getdata[:exactget] = {'name' => [data['name']]} getdata[:login] = 'autoreg' results = get_objects(getdata) end # If we failed to find an existing entry based on the uniqueid and hostname, # fall back to using serial number. This may still fail to find an entry, # if this is a new host, but that's OK as it will leave %results # as undef, which triggers set_nodes to create a new entry on the # server. if results.empty? && data['serial_number'] && !data['serial_number'].empty? && data['serial_number'] != "Not Specified" getdata = {} getdata[:objecttype] = 'nodes' getdata[:exactget] = {'serial_number' => [data['serial_number']]} getdata[:login] = 'autoreg' results = get_objects(getdata) end setresults = set_objects('nodes', results, data, 'autoreg') puts "Command successful" if setresults == 1 end |
#remove_nodegroups_from_nodegroups(child_groups, parent_groups, login, password_callback = PasswordCallback) ⇒ Object
Both arguments are hashes returned by a ‘node_groups’ call to get_objects NOTE: For the parent groups you must have requested that the server include ‘child_groups’ in the result
956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 |
# File 'lib/nventory.rb', line 956 def remove_nodegroups_from_nodegroups(child_groups, parent_groups, login, password_callback=PasswordCallback) # The server only supports setting a complete list of assignments for # a node group. So we need to retrieve the current list of assignments # for each group, remove the node groups that the user wants # removed, and pass that off to set_nodegroup_nodegroup_assignments to perform # the update. # FIXME: This should talk directly to the node_group_node_groups_assignments # controller, so that we aren't exposed to the race conditions this # method currently suffers from. parent_groups.each_pair do |parent_group_name, parent_group| desired_child_groups = {} if parent_group['child_groups'] parent_group['child_groups'].each do |child_group| name = child_group['name'] if !child_groups.has_key?(name) desired_child_groups[name] = child_group end end end set_nodegroup_nodegroup_assignments(desired_child_groups, {parent_group_name => parent_group}, login, password_callback) end end |
#remove_nodes_from_nodegroups(nodes, nodegroups, login, password_callback = PasswordCallback) ⇒ Object
The first argument is a hash returned by a ‘nodes’ call to get_objects The second argument is a hash returned by a ‘node_groups’ call to get_objects NOTE: For the node groups you must have requested that the server include ‘nodes’ in the result
886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 |
# File 'lib/nventory.rb', line 886 def remove_nodes_from_nodegroups(nodes, nodegroups, login, password_callback=PasswordCallback) # The server only supports setting a complete list of members of # a node group. So we need to retreive the current list of members # for each group, remove the nodes that the user wants # removed, and pass that off to set_nodegroup_assignments to perform # the update. # FIXME: This should talk directly to the node_group_node_assignments # controller, so that we aren't exposed to the race conditions this # method currently suffers from. nodegroups.each_pair do |nodegroup_name, nodegroup| desired_nodes = {} nodegroup['nodes'].each do |node| name = node['name'] if !nodes.has_key?(name) desired_nodes[name] = node end end set_nodegroup_node_assignments(desired_nodes, {nodegroup_name => nodegroup}, login, password_callback) end end |
#remove_tag_from_node_group(ng_hash, tag_name, login, password_callback = PasswordCallback) ⇒ Object
Add a new or pre-existing tag (by name string) to a node_group (by hash returned from get_objects)
1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 |
# File 'lib/nventory.rb', line 1014 def remove_tag_from_node_group(ng_hash, tag_name, login, password_callback=PasswordCallback) tag_found = get_objects({:objecttype => 'tags', :exactget => {:name => tag_name}}) if tag_found.empty? puts "ERROR: Could not find any tags with the name #{tag_name}" exit end # tag_found is hash, even tho only one result (tag_data = tag_found[tag_found.keys.first]) && (tag_id = tag_data['id']) taggings_to_del = {} ng_hash.each_pair do |ng_name,ng_data| get_data = {:objecttype => 'taggings', :exactget => { :taggable_type => 'NodeGroup', :taggable_id => ng_data['id'], :tag_id => tag_id } } tagging_found = get_objects(get_data) unless tagging_found.empty? taggings_to_del.merge!(tagging_found) end end if taggings_to_del.empty? puts "ERROR: Could not find any tags \"#{tag_name}\" assigned to those node_groups" else delete_objects('taggings', taggings_to_del, login, password_callback=PasswordCallback) end end |
#set_nodegroup_node_assignments(nodes, nodegroups, login, password_callback = PasswordCallback) ⇒ Object
The first argument is a hash returned by a ‘nodes’ call to get_objects The second argument is a hash returned by a ‘node_groups’ call to get_objects
911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 |
# File 'lib/nventory.rb', line 911 def set_nodegroup_node_assignments(nodes, nodegroups, login, password_callback=PasswordCallback) node_ids = [] nodes.each_pair do |node_name, node| if node['id'] node_ids << node['id'] else warn "set_nodegroup_node_assignments passed a bogus nodes hash, #{node_name} has no id field" end end nodegroupdata = {} node_ids = 'nil' if node_ids.empty? nodegroupdata['node_group_node_assignments[nodes][]'] = node_ids set_objects('node_groups', nodegroups, nodegroupdata, login, password_callback) end |
#set_nodegroup_nodegroup_assignments(child_groups, parent_groups, login, password_callback = PasswordCallback) ⇒ Object
Both arguments are hashes returned by a ‘node_groups’ call to get_objects
981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 |
# File 'lib/nventory.rb', line 981 def set_nodegroup_nodegroup_assignments(child_groups, parent_groups, login, password_callback=PasswordCallback) child_ids = [] child_groups.each_pair do |child_group_name, child_group| if child_group['id'] child_ids << child_group['id'] else warn "set_nodegroup_nodegroup_assignments passed a bogus child groups hash, #{child_group_name} has no id field" end end # cannot pass empty hash therefore, add a 'nil' string. nasty hack and accomodated on the server side code child_ids << 'nil' if child_ids.empty? nodegroupdata = {} nodegroupdata['node_group_node_group_assignments[child_groups][]'] = child_ids set_objects('node_groups', parent_groups, nodegroupdata, login, password_callback) end |
#set_objects(objecttypes, results, data, login, password_callback = PasswordCallback) ⇒ Object
The results argument can be a reference to a hash returned by a call to get_objects, in which case the data will be PUT to each object there, thus updating them. Or it can be nil, in which case the data will be POSTed to create a new entry.
424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 |
# File 'lib/nventory.rb', line 424 def set_objects(objecttypes, results, data, login, password_callback=PasswordCallback) # Convert any keys which don't already specify a model # from 'foo' to 'objecttype[foo]' objecttype = singularize(objecttypes) cleandata = {} data.each_pair do |key, value| if key !~ /\[.+\]/ cleandata["#{objecttype}[#{key}]"] = value else cleandata[key] = value end end #puts cleandata.inspect if (@debug) puts YAML.dump(cleandata) if (@debug) successcount = 0 if results && !results.empty? results.each_pair do |result_name, result| if @delete warn "Deleting objects via set_objects is deprecated, use delete_objects instead" uri = URI::join(@server, "#{objecttypes}/#{result['id']}.xml") req = Net::HTTP::Delete.new(uri.request_uri) req.set_form_data(cleandata) response = send_request(req, uri, login, password_callback) while response.kind_of?(Net::HTTPMovedPermanently) uri = URI.parse(response['Location']) req = Net::HTTP::Delete.new(uri.request_uri) response = send_request(req, uri, login, password_callback) end if response.kind_of?(Net::HTTPOK) successcount += 1 else puts "DELETE to #{uri} failed for #{result_name}:" puts response.body end # PUT to update an existing object elsif result['id'] uri = URI::join(@server, "#{objecttypes}/#{result['id']}.xml") req = Net::HTTP::Put.new(uri.request_uri) req.set_form_data(cleandata) warn "PUT to URL: #{uri}" if (@debug) if !@dryrun response = send_request(req, uri, login, password_callback) while response.kind_of?(Net::HTTPMovedPermanently) uri = URI.parse(response['Location']) req = Net::HTTP::Put.new(uri.request_uri) req.set_form_data(cleandata) response = send_request(req, uri, login, password_callback) end if response.kind_of?(Net::HTTPOK) successcount += 1 else puts "PUT to #{uri} failed for #{result_name}:" puts response.body end end else warn "set_objects passed a bogus results hash, #{result_name} has no id field" end end else uri = URI::join(@server, "#{objecttypes}.xml") req = Net::HTTP::Post.new(uri.request_uri) req.set_form_data(cleandata) warn "POST to URL: #{uri}" if (@debug) if !@dryrun response = send_request(req, uri, login, password_callback) while response.kind_of?(Net::HTTPMovedPermanently) uri = URI.parse(response['Location']) req = Net::HTTP::Post.new(uri.request_uri) req.set_form_data(cleandata) response = send_request(req, uri, login, password_callback) end if response.kind_of?(Net::HTTPOK) || response.kind_of?(Net::HTTPCreated) successcount += 1 else puts "POST to #{uri} failed." puts response.body end end end successcount end |