bin/nv in nventory-client-1.65.4 vs bin/nv in nventory-client-1.67

- old
+ new

@@ -1,8 +1,9 @@ -#!/usr/bin/ruby -w +#!/usr/bin/env ruby ############################################################################## # A client to query a nVentory server +# $Id: nv 343 2013-02-15 23:09:46Z saltmanm $ ############################################################################## require 'optparse' require 'nventory' @@ -33,10 +34,12 @@ $addnodegroupnodeassignments = nil $addtonodegroup = nil $removefromnodegroup = nil $addnodegrouptonodegroup = nil $addcomment = nil +$addgraffiti= nil +$deletegraffiti = nil $removenodegroupfromnodegroup = nil $createtag = nil $addtagtonodegroup = nil $removetagfromnodegroup = nil $register = false @@ -57,10 +60,14 @@ singular = string end return singular; end +def camelize(string) + string.split(/[^a-z0-9]/i).map{|w| w.capitalize}.join +end + def opt_hash_parse(opt) opthash = {} current_field = nil opt.split(',').each do |entry| if (entry =~ /(.+)=(.+)/) @@ -140,10 +147,16 @@ $name = opt end opts.on('--addcomment "add your comment here"', Array) do |opt| $addcomment = opt end +opts.on('--addgraffiti "key:value pair"') do |opt| + $addgraffiti = opt +end +opts.on('--deletegraffiti "graffiti name"') do |opt| + $deletegraffiti = opt +end opts.on('--allfields [excludefield1[,excludefield2]]', Array, 'Display all fields for selected objects.', 'One or more fields may be specified to be excluded from the', 'query, seperate multiple fields with commas.') do |opt| if opt.nil? @@ -405,11 +418,11 @@ getdata[:objecttype] = 'node_groups' getdata[:exactget] = {'name' => [$nodegroup]} getdata[:includes] = ['child_groups', 'nodes'] results = nvclient.get_objects(getdata) matches = results.keys.grep(/\b#{$nodegroup}\b/i) - matches.size == 1 ? ( $nodegroup = matches.first ) : return + matches.size == 1 ? ( $nodegroup = matches.first ) : (puts "nodegroup #{$nodegroup} not found."; exit) puts "Child groups:" results[$nodegroup]['child_groups'].sort{|a,b| a['name'] <=> b['name']}.each do |child_group| puts " #{child_group['name']}" end puts "====================" @@ -561,9 +574,21 @@ 'commentable_id' => results[key]['id'], 'commentable_type' => objtype.capitalize, }, $username); end +end + +if $addgraffiti + obj_type = camelize(singularize($objecttype)) + nvclient.add_graffiti(obj_type, results, $addgraffiti, $username) + exit +end + +if $deletegraffiti + obj_type = camelize(singularize($objecttype)) + nvclient.delete_graffiti(obj_type, results, $deletegraffiti, $username) + exit end if $nodegroupexpanded names_hash = {} $nodegroupexpanded.each do |nge|