def main(): p = sacliutil.standardOptions( "spolicy --id=<identifier> [--<modifier options>] [ <action> ]") p.add_option( '--id', help= "Specify a identifier which is an Opsware ID, software policy name, or folder path and software policy name." ) p.add_option('--folderpath', help="Specify a folder path for the software policy refs.") p.add_option('--new', help="Specify a new software policy name.") p.add_option( '--policyitem', help= "Use with --policyitem when using the action additems or replaceitems." ) p.add_option( '--order', help= "Use with --policyitem and/or action additems or replaceitems to specify the policy item order to add or replace respectively." ) p.add_option('--folder', help="Use with software policy creation.") p.add_option('--platform', help="Use with software policy creation.") p.add_option('--server', help="Use with software policy install and uninstall.") p.add_option('--servergroup', help="Use with software policy install and uninstall.") p.add_option('--sgmembers', help="Use with software policy install and uninstall.") p.add_option('--name', help="Use with software policy setca (Set Custom Attribute)") p.add_option('--value', help="Use with software policy setca (Set Custom Attribute)") p.add_option('--recursive', action="store_true", help="Recursively traverse the folders.") p.add_option('--spfilter', help="Specify a software policy name filter.") (options, arguments) = p.parse_args() s = sacliutil.getSALib(options.username, options.password, options.authfile) if options.debug: s.setDebug(1) if options.id: action = [ 'list', 'listitems', 'additems', 'replaceitems', 'deleteitems', 'addplatform', 'updateplatform', 'create', 'install', 'uninstall', 'getca', 'setca', 'serverlist', 'remediate' ] if arguments: if re.match('[Ll]ist$', arguments[0]): objPaths = [] if options.regex: softwarePolicyRefs = s.getSoftwarePolicyRefs( options.id, True) else: softwarePolicyRefs = s.getSoftwarePolicyRefs(options.id) for i in softwarePolicyRefs: try: print "%s|%s" % (sacliutil.printObjectPath( s, [i]), sacliutil.printObjectID(i)) except SALib.AuthorizationDeniedException: print "!!!%s is INACCESSIBLE!!!" % i continue except SALib.NotInFolder, i: print "!!!%s is INACCESSIBLE!!!" % i continue elif re.match('[Ss]erverlist$', arguments[0]): for spolicy, serverlist in s.getServerRefsBySoftwarePolicy( options.id, options.regex).iteritems(): print "%s" % spolicy for server in serverlist: print "%s" % server print elif re.match('[Aa]dditems?', arguments[0]): try: if options.policyitem: policyItemRefs = sacliutil.createPolicyItemList( s, options.policyitem) print "%s" % policyItemRefs if options.order: print "%s has been updated." % s.addSoftwarePolicyItem( options.id, policyItemRefs, options.order).ref else: print "%s has been updated." % s.addSoftwarePolicyItem( options.id, policyItemRefs).ref else: print "With --id and action additems you need to provide --policyitem" except SALib.DuplicatePolicyItemFound, args: print "The policyitem %s already exist in the software policy." % args elif re.match('[Rr]eplaceitems?', arguments[0]): if options.policyitem: if options.order: try: policyItemRef = sacliutil.createPolicyItemList( s, options.policyitem) print "%s" % options.policyitem print "%s" % policyItemRef if len(policyItemRef) > 1: print "You need to provide only one --policyitem because you can only replace items one at a time." sys.exit() sref = s.replaceSoftwarePolicyItembyPosition( options.id, policyItemRef[0], options.order).ref print "%s has been updated" % sref except SALib.NoObjectRefFound, args: print "Couldn't find policy item %s to replace" % args except SALib.NotSoftwarePolicyItem, args: print "The referenced item %s can't be added to a software policy." % args except IndexError, args: print "%s is an incorrect SA Object type. Check the issued --policyitem args for the correct type." % \ options.policyitem
def main(): p = sacliutil.standardOptions( "folder --id=<identifier> [--<modifier options>] [ <action> ]") p.add_option('--id', help="folder path or id") p.add_option('--recursive', action="store_true", help="Recursively traverse the folders.") p.add_option('--type', help="Filter by SA Object type.") (options, arguments) = p.parse_args() s = sacliutil.getSALib(options.username, options.password, options.authfile) if options.debug: s.setDebug(1) if options.id: action = [ 'info', 'listsaobj', 'list', 'listall', 'remove', 'create', 'addacl', 'removeacl', 'listacl' ] try: if arguments: if re.match('[Ll]ist$', arguments[0]): if options.regex: folderRefs = s.getFolderRefs(options.id, True) else: folderRefs = s.getFolderRefs(options.id, False) for i in folderRefs: try: if i.id == 0: print "/|%s" % sacliutil.printObjectID(i) else: print "%s|%s" % (sacliutil.printObjectPath( s, [i]), sacliutil.printObjectID(i)) except SALib.AuthorizationDeniedException: print "!!!%s is INACCESSIBLE!!!" % i continue except SALib.NotInFolderException: print "!!!%s is INACCESSIBLE!!!" % i elif re.match('[Ll]istall', arguments[0]): if options.regex: folderRefs = s.getFolderRefs(options.id, True, True) else: folderRefs = s.getFolderRefs(options.id, False, True) for i in folderRefs: try: print "%s|%s" % (sacliutil.printObjectPath( s, [i]), sacliutil.printObjectID(i)) #pathDict = s.getObjectPath([ i ],False) #(parentPath,SP) = os.path.split(pathDict[i]) #if parentPath == "/": # print "%s%s" % (parentPath,i) #else: # print "%s/%s" % (parentPath,i) except SALib.AuthorizationDeniedException: print "!!!%s is INACCESSIBLE!!!" % i continue except SALib.NotInFolderException: print "!!!%s is INACCESSIBLE!!!" % i elif re.match('[Ii]nfo', arguments[0]): print "Folder: %s" % options.id sacliutil.print_folderinfo(s, 's.getFolderInfo', options.id) print elif arguments[0] == 'create': print "Folder: %s" % options.id s.createFolder(options.id) elif arguments[0] == "remove": print "Folder: %s" % options.id recursive = False if options.recursive: recursive = True s.removeFolder(options.id, recursive) elif re.match('[Ll]istsaobj?', arguments[0]): recursive = False if options.recursive: recursive = True if options.type in folderSAObjType.keys(): s.printFolderObj(options.id, recursive, options.type) elif not options.type: s.printFolderObj(options.id, recursive, '') else: print "They type you've referenced in --type does not exist or is not yet implemented." print "The list of valid types are: %s" % folderSAObjType.keys( ) elif arguments[0] == "addacl": recursive = False applytoparent = False if options.perm and options.usergroup: if options.applytoparent: applytoparent = True if options.recursive: recursive = True addedACL = s.addFolderACLs(options.id, options.perm, options.usergroup, recursive, applytoparent) for i in addedACL: print "%s" % i else: print "With addacl action you must provide --perm=<permissions> and --usergroup=<usergroup name>" print "perm can be comma delimited string: l,r,w,x" print "where l is list,r is read, w is write, and x is execute" print 'i.e. --perm=l,r,w' elif arguments[0] == "listacl": s.listFolderACLs(options.id) elif arguments[0] == "removeacl": recursive = False applytoparent = False if options.usergroup: if options.applytoparent: applytoparent = True if options.recursive: recursive = True if options.perm: perm = options.perm else: perm = "l,r,w,x,p" print "Removing all permissions from folder %s for usergroup %s" % ( options.id, options.usergroup) removedACL = s.removeFolderACLs( options.id, perm, options.usergroup, recursive) for i in removedACL: print "%s" % i else: p.print_help() print "With removeacl action you must provide --usergroup=<usergroup name>" print "Optionally provide --perm, if not provided then all permissions for usergroup will be removed from the folder" print "perm can be comma delimited string: l,r,w,x" print "where l is list,r is read, w is write, and x is execute" print "i.e. --perm='l,r,w'" else: p.print_help() print "Please provide an action: %s" % sacliutil.getActionList( action) else: p.print_help() print "Please provide an action: %s" % sacliutil.getActionList( action) except SALib.MultipleFolderRefsFound, args: print "ERROR: Multiple folders found: %s." % args except SALib.NullSearchValue, args: print "ERROR: Empty Search Value given."
def main(): p = sacliutil.standardOptions("spolicy --id=<identifier> [--<modifier options>] [ <action> ]") p.add_option('--id', help="Specify a identifier which is an Opsware ID, software policy name, or folder path and software policy name.") p.add_option('--folderpath', help="Specify a folder path for the software policy refs.") p.add_option('--new', help="Specify a new software policy name.") p.add_option('--policyitem', help="Use with --policyitem when using the action additems or replaceitems.") p.add_option('--order', help="Use with --policyitem and/or action additems or replaceitems to specify the policy item order to add or replace respectively.") p.add_option('--folder', help="Use with software policy creation.") p.add_option('--platform', help="Use with software policy creation.") p.add_option('--server', help="Use with software policy install and uninstall.") p.add_option('--servergroup', help="Use with software policy install and uninstall.") p.add_option('--sgmembers', help="Use with software policy install and uninstall.") p.add_option('--name', help="Use with software policy setca (Set Custom Attribute)") p.add_option('--value', help="Use with software policy setca (Set Custom Attribute)") p.add_option('--recursive', action="store_true",help="Recursively traverse the folders.") p.add_option('--spfilter', help="Specify a software policy name filter.") (options,arguments) = p.parse_args() s = sacliutil.getSALib(options.username,options.password,options.authfile) if options.debug: s.setDebug(1) if options.id: action = ['list','listitems','additems','replaceitems','deleteitems','addplatform','updateplatform','create','install','uninstall','getca','setca','serverlist','remediate'] if arguments: if re.match('[Ll]ist$',arguments[0]): objPaths = [] if options.regex: softwarePolicyRefs = s.getSoftwarePolicyRefs(options.id,True) else: softwarePolicyRefs = s.getSoftwarePolicyRefs(options.id) for i in softwarePolicyRefs: try: print "%s|%s" % (sacliutil.printObjectPath(s,[i]),sacliutil.printObjectID(i)) except SALib.AuthorizationDeniedException: print "!!!%s is INACCESSIBLE!!!" % i continue except SALib.NotInFolder,i: print "!!!%s is INACCESSIBLE!!!" % i continue elif re.match('[Ss]erverlist$',arguments[0]): for spolicy,serverlist in s.getServerRefsBySoftwarePolicy(options.id,options.regex).iteritems(): print "%s" % spolicy for server in serverlist: print "%s" % server print elif re.match('[Aa]dditems?',arguments[0]): try: if options.policyitem: policyItemRefs = sacliutil.createPolicyItemList(s,options.policyitem) print "%s" % policyItemRefs if options.order: print "%s has been updated." % s.addSoftwarePolicyItem(options.id,policyItemRefs,options.order).ref else: print "%s has been updated." % s.addSoftwarePolicyItem(options.id,policyItemRefs).ref else: print "With --id and action additems you need to provide --policyitem" except SALib.DuplicatePolicyItemFound,args: print "The policyitem %s already exist in the software policy." % args elif re.match('[Rr]eplaceitems?',arguments[0]): if options.policyitem: if options.order: try: policyItemRef = sacliutil.createPolicyItemList(s,options.policyitem) print "%s" % options.policyitem print "%s" % policyItemRef if len(policyItemRef) > 1: print "You need to provide only one --policyitem because you can only replace items one at a time." sys.exit() sref = s.replaceSoftwarePolicyItembyPosition(options.id,policyItemRef[0],options.order).ref print "%s has been updated" % sref except SALib.NoObjectRefFound,args: print "Couldn't find policy item %s to replace" % args except SALib.NotSoftwarePolicyItem,args: print "The referenced item %s can't be added to a software policy." % args except IndexError,args: print "%s is an incorrect SA Object type. Check the issued --policyitem args for the correct type." % \ options.policyitem
else: p.print_help() print "You need to specify the order of the software policy item to replace using --order" else: p.print_help() print "You need to specify the policy item and order of the policy item within the software policy like --policyitem RPMRef:10001 --order 3" elif re.match('[Dd]eleteitems?', arguments[0]): if options.order: print "%s has been updated" % s.deleteSoftwarePolicyItembyPosition( options.id, options.order).ref elif re.match('[Ll]istitems?', arguments[0]): for spolicyRef in s.getSoftwarePolicyRefs(options.id): try: print "software policy:" print "%s|%s" % (sacliutil.printObjectPath( s, [spolicyRef]), sacliutil.printObjectID(spolicyRef)) print "items:" listSPItems = s.listSoftwarePolicyItems(spolicyRef.id) seqNumber = 1 for item in listSPItems[spolicyRef]: itemRef = re.sub( '(.*)(\()([A-Za-z]*\:[0-9]*[^)])(\).*)', '\\3', "%s" % item) policyItem = "%s|%s" % ( itemRef, sacliutil.printObjectPath(s, [item])) print "%d|%s" % (seqNumber, policyItem) seqNumber += 1 print except SALib.AuthorizationDeniedException: print "!!!%s is INACCESSIBLE!!!" % i
def main(): p = sacliutil.standardOptions("appconfig --id=<identifier> [--<modifier options>] [ <action> ]") p.add_option('--id', help="Specify identifier for appconfig.") p.add_option('--server', help="Specify server pattern for appconfig.") p.add_option('--name', help="Specifies name valueset of the appconfig.") p.add_option('--value', help="Specifies value valueset of the appconfig.") p.add_option('--matchstr', help="search string for replacement by --value.") p.add_option('--clonename', help="Specifies appconfig clone name.") p.add_option('--customer', help="Specify servers by customer name.") p.add_option('--facility', help="Specifies servers by facility name.") p.add_option('--platform', help="Specify platform by id, name, or pattern.") p.add_option('--scope',default='all',help="specify either appconfig,customer,facility,devicegroup,server,or all") p.add_option('--show', action="store_true",help="Show before and after valueset changes.") p.add_option('--dryrun', action="store_true",help="Do a dry run of valuereplace.") (options, arguments) = p.parse_args() s = sacliutil.getSALib(options.username,options.password,options.authfile) if options.debug: s.setDebug(1) if options.id or options.server or options.facility or options.customer: action = ['list','namesearch','valuesearch','valuereplace','valueset','clone','addplatform','updateplatform'] if arguments: if re.match('[Ll]ist$',arguments[0]): for i in s.getConfigurationRefs(options.id,options.regex): try: if s.isHPSA9x(): print "%s|%s" % (sacliutil.printObjectPath(s,[i]),sacliutil.printObjectID(i)) else: print "%s|%s" % (i,sacliutil.printObjectID(i)) except SALib.AuthorizationDeniedException: print "!!!%s is INACCESSIBLE!!!" % i continue except SALib.NotInFolder,i: print "!!!%s is INACCESSIBLE!!!" % i continue elif re.match('[Nn]amesearch',arguments[0]): if options.name: if options.id: configurationRefs = s.getConfigurationRefs(options.id,options.regex) printConfigurableItems(s,configurationRefs,options.name,'name',options.regex) elif options.server: serverRefs = s.getServerRefs(options.server,options.regex) printConfigurableItems(s,serverRefs,options.name,'name',options.regex) elif options.customer: serverRefs = s.getServerRefsByCustomer(options.customer,options.regex) printConfigurableItems(s,serverRefs,options.name,'name',options.regex) elif options.facility: serverRefs = s.getServerRefsByFacility(options.facility,options.regex) printConfigurableItems(s,serverRefs,options.name,'name',options.regex) else: p.print_help() print "Please provide an id, server, customer, or facility option with --name" else: p.print_help() print "Please provide --name and either --id, --server, --customer,or --facility with namesearch action" elif re.match('[Vv]aluesearch',arguments[0]): if options.value: if options.id: configurationRefs = s.getConfigurationRefs(options.id,options.regex) printConfigurableItems(s,configurationRefs,options.value,'value',options.regex) elif options.server: serverRefs = s.getServerRefs(options.server,options.regex) printConfigurableItems(s,serverRefs,options.value,'value',options.regex) elif options.customer: serverRefs = s.getServerRefsByCustomer(options.customer,options.regex) printConfigurableItems(s,serverRefs,options.value,'value',options.regex) elif options.facility: serverRefs = s.getServerRefsByFacility(options.facility,options.regex) printConfigurableItems(s,serverRefs,options.value,'value',options.regex) else: p.print_help() print "Please provide --value and either --id, --server, --customer,or --facility with valuesearch action" elif re.match('[Vv]aluereplace',arguments[0]): if (options.name or options.matchstr) and options.value: if options.id: configurationRefs = s.getConfigurationRefs(options.id,options.regex) if options.name: configGenerator = s.findConfigurationParameter(configurationRefs,options.name,0,options.regex) elif options.matchstr: configGenerator = s.findConfigurationParameter(configurationRefs,options.matchstr,1,options.regex,False) elif options.server: serverRefs = s.getServerRefs(options.server,options.regex) if options.name: configGenerator = s.findConfigurationParameter(serverRefs,options.name,0,options.regex) elif options.matchstr: configGenerator = s.findConfigurationParameter(serverRefs,options.matchstr,1,options.regex,False) elif options.customer: serverRefs = s.getServerRefsByCustomer(options.customer,options.regex) if options.name: configGenerator = s.findConfigurationParameter(serverRefs,options.name,0,options.regex) elif options.matchstr: configGenerator = s.findConfigurationParameter(serverRefs,options.matchstr,1,options.regex,False) elif options.facility: serverRefs = s.getServerRefsByFacility(options.facility,options.regex) if options.name: configGenerator = s.findConfigurationParameter(serverRefs,options.name,0,options.regex) elif options.matchstr: configGenerator = s.findConfigurationParameter(serverRefs,options.matchstr,1,options.regex,False) if options.dryrun: if options.name: for c in configGenerator: for key in c.foundValuesetKeys: print "%s (Will NOT modify):" % c.configVO.ref print "BEFORE: %s = %s" % (key, c.configVO.valueset[key]) print "AFTER: %s = %s\n" % (key, options.value) for instance in c.instances: print "%s (Will NOT modify):" % c.configVO.instances[instance.index].ref for key in instance.foundValuesetKeys: print "BEFORE: %s = %s" % (key,c.configVO.instances[instance.index].valueset[key]) print "AFTER: %s = %s\n" % (key,options.value) elif options.matchstr: for c in configGenerator: for key in c.foundValuesetKeys: print "%s (Will NOT modify):" % c.configVO.ref print "BEFORE: %s = %s" % (key, c.configVO.valueset[key]) print "AFTER: %s = %s\n" % (key,re.sub(options.matchstr, options.value, c.configVO.valueset[key])) for instance in c.instances: print "%s (Will NOT modify):" % c.configVO.instances[instance.index].ref for key in instance.foundValuesetKeys: print "BEFORE: %s = %s" % (key,c.configVO.instances[instance.index].valueset[key]) print "AFTER: %s = %s\n" % (key,re.sub(options.matchstr, options.value, c.configVO.instances[instance.index].valueset[key])) else: if options.name: replaceConfigGen = s.replaceConfigurationValue(configGenerator,options.value,options.scope,options.show,False,None) elif options.matchstr: replaceConfigGen = s.replaceConfigurationValue(configGenerator,options.value,options.scope,options.show,True,None) for twistConfigItem in replaceConfigGen: print "%s: Modified" % twistConfigItem.ref if options.show: print else: p.print_help() print "Please provide both --name=<name in valueset> and --value=<replacement value> with valuereplace action." elif re.match('[Vv]aluesets?',arguments[0]): if options.id: configurationRefs = s.getConfigurationRefs(options.id,options.regex) printConfigurableItems(s,configurationRefs,None,'all',options.regex) elif options.server: serverRefs = s.getServerRefs(options.server,options.regex) printConfigurableItems(s,serverRefs,None,'all',options.regex) elif options.customer: serverRefs = s.getServerRefsByCustomer(options.customer,options.regex) printConfigurableItems(s,serverRefs,None,'all',options.regex) elif options.facility: serverRefs = s.getServerRefsByFacility(options.facility,options.regex) printConfigurableItems(s,serverRefs,None,'all',options.regex) elif re.match('[Cc]lone',arguments[0]): if options.clonename: configRef = s.cloneConfigurationRef(options.id,options.clonename) if s.isHPSA9x(): print "created %s|ConfigurationRef:%d" % (sacliutil.printObjectPath(s,[configRef]),configRef.id) else: print "%s|%s" % (configRef,sacliutil.printObjectID(configRef)) elif re.match('(?i)addplatform?',arguments[0]): if options.platform: print "Adding platform on the following configurationVO(s):" for configvo in s.addConfigurationPlatform(options.id,options.platform,options.regex): print "%s" % configvo.ref else: p.print_help() print "You need to provide --platform=<platform name>." elif re.match('(?i)updateplatform?',arguments[0]): if options.platform: print "Updating platform on the following configurationVO(s):" for configvo in s.updateConfigurationPlatform(options.id,options.platform,options.regex): print "%s" % configvo.ref else: p.print_help() print "You need to provide --platform=<platform name>." else: p.print_help() print "Provide an action: %s" % sacliutil.getActionList(action) else: p.print_help() print "Provide an action: %s" % sacliutil.getActionList(action)
print "%s is an incorrect SA Object type. Check the issued --policyitem args for the correct type." % \ options.policyitem else: p.print_help() print "You need to specify the order of the software policy item to replace using --order" else: p.print_help() print "You need to specify the policy item and order of the policy item within the software policy like --policyitem RPMRef:10001 --order 3" elif re.match('[Dd]eleteitems?',arguments[0]): if options.order: print "%s has been updated" % s.deleteSoftwarePolicyItembyPosition(options.id,options.order).ref elif re.match('[Ll]istitems?',arguments[0]): for spolicyRef in s.getSoftwarePolicyRefs(options.id): try: print "software policy:" print "%s|%s" % (sacliutil.printObjectPath(s,[spolicyRef]),sacliutil.printObjectID(spolicyRef)) print "items:" listSPItems = s.listSoftwarePolicyItems(spolicyRef.id) seqNumber = 1 for item in listSPItems[spolicyRef]: itemRef = re.sub('(.*)(\()([A-Za-z]*\:[0-9]*[^)])(\).*)','\\3',"%s" % item) policyItem = "%s|%s" % (itemRef,sacliutil.printObjectPath(s,[item])) print "%d|%s" % (seqNumber,policyItem) seqNumber += 1 print except SALib.AuthorizationDeniedException: print "!!!%s is INACCESSIBLE!!!" % i continue except SALib.NotInFolder,i: print "!!!%s is INACCESSIBLE!!!" % i continue
def main(): p = sacliutil.standardOptions( "appconfig --id=<identifier> [--<modifier options>] [ <action> ]") p.add_option('--id', help="Specify identifier for appconfig.") p.add_option('--server', help="Specify server pattern for appconfig.") p.add_option('--name', help="Specifies name valueset of the appconfig.") p.add_option('--value', help="Specifies value valueset of the appconfig.") p.add_option('--matchstr', help="search string for replacement by --value.") p.add_option('--clonename', help="Specifies appconfig clone name.") p.add_option('--customer', help="Specify servers by customer name.") p.add_option('--facility', help="Specifies servers by facility name.") p.add_option('--platform', help="Specify platform by id, name, or pattern.") p.add_option( '--scope', default='all', help= "specify either appconfig,customer,facility,devicegroup,server,or all") p.add_option('--show', action="store_true", help="Show before and after valueset changes.") p.add_option('--dryrun', action="store_true", help="Do a dry run of valuereplace.") (options, arguments) = p.parse_args() s = sacliutil.getSALib(options.username, options.password, options.authfile) if options.debug: s.setDebug(1) if options.id or options.server or options.facility or options.customer: action = [ 'list', 'namesearch', 'valuesearch', 'valuereplace', 'valueset', 'clone', 'addplatform', 'updateplatform' ] if arguments: if re.match('[Ll]ist$', arguments[0]): for i in s.getConfigurationRefs(options.id, options.regex): try: if s.isHPSA9x(): print "%s|%s" % (sacliutil.printObjectPath( s, [i]), sacliutil.printObjectID(i)) else: print "%s|%s" % (i, sacliutil.printObjectID(i)) except SALib.AuthorizationDeniedException: print "!!!%s is INACCESSIBLE!!!" % i continue except SALib.NotInFolder, i: print "!!!%s is INACCESSIBLE!!!" % i continue elif re.match('[Nn]amesearch', arguments[0]): if options.name: if options.id: configurationRefs = s.getConfigurationRefs( options.id, options.regex) printConfigurableItems(s, configurationRefs, options.name, 'name', options.regex) elif options.server: serverRefs = s.getServerRefs(options.server, options.regex) printConfigurableItems(s, serverRefs, options.name, 'name', options.regex) elif options.customer: serverRefs = s.getServerRefsByCustomer( options.customer, options.regex) printConfigurableItems(s, serverRefs, options.name, 'name', options.regex) elif options.facility: serverRefs = s.getServerRefsByFacility( options.facility, options.regex) printConfigurableItems(s, serverRefs, options.name, 'name', options.regex) else: p.print_help() print "Please provide an id, server, customer, or facility option with --name" else: p.print_help() print "Please provide --name and either --id, --server, --customer,or --facility with namesearch action" elif re.match('[Vv]aluesearch', arguments[0]): if options.value: if options.id: configurationRefs = s.getConfigurationRefs( options.id, options.regex) printConfigurableItems(s, configurationRefs, options.value, 'value', options.regex) elif options.server: serverRefs = s.getServerRefs(options.server, options.regex) printConfigurableItems(s, serverRefs, options.value, 'value', options.regex) elif options.customer: serverRefs = s.getServerRefsByCustomer( options.customer, options.regex) printConfigurableItems(s, serverRefs, options.value, 'value', options.regex) elif options.facility: serverRefs = s.getServerRefsByFacility( options.facility, options.regex) printConfigurableItems(s, serverRefs, options.value, 'value', options.regex) else: p.print_help() print "Please provide --value and either --id, --server, --customer,or --facility with valuesearch action" elif re.match('[Vv]aluereplace', arguments[0]): if (options.name or options.matchstr) and options.value: if options.id: configurationRefs = s.getConfigurationRefs( options.id, options.regex) if options.name: configGenerator = s.findConfigurationParameter( configurationRefs, options.name, 0, options.regex) elif options.matchstr: configGenerator = s.findConfigurationParameter( configurationRefs, options.matchstr, 1, options.regex, False) elif options.server: serverRefs = s.getServerRefs(options.server, options.regex) if options.name: configGenerator = s.findConfigurationParameter( serverRefs, options.name, 0, options.regex) elif options.matchstr: configGenerator = s.findConfigurationParameter( serverRefs, options.matchstr, 1, options.regex, False) elif options.customer: serverRefs = s.getServerRefsByCustomer( options.customer, options.regex) if options.name: configGenerator = s.findConfigurationParameter( serverRefs, options.name, 0, options.regex) elif options.matchstr: configGenerator = s.findConfigurationParameter( serverRefs, options.matchstr, 1, options.regex, False) elif options.facility: serverRefs = s.getServerRefsByFacility( options.facility, options.regex) if options.name: configGenerator = s.findConfigurationParameter( serverRefs, options.name, 0, options.regex) elif options.matchstr: configGenerator = s.findConfigurationParameter( serverRefs, options.matchstr, 1, options.regex, False) if options.dryrun: if options.name: for c in configGenerator: for key in c.foundValuesetKeys: print "%s (Will NOT modify):" % c.configVO.ref print "BEFORE: %s = %s" % ( key, c.configVO.valueset[key]) print "AFTER: %s = %s\n" % (key, options.value) for instance in c.instances: print "%s (Will NOT modify):" % c.configVO.instances[ instance.index].ref for key in instance.foundValuesetKeys: print "BEFORE: %s = %s" % ( key, c.configVO.instances[ instance.index].valueset[key]) print "AFTER: %s = %s\n" % ( key, options.value) elif options.matchstr: for c in configGenerator: for key in c.foundValuesetKeys: print "%s (Will NOT modify):" % c.configVO.ref print "BEFORE: %s = %s" % ( key, c.configVO.valueset[key]) print "AFTER: %s = %s\n" % ( key, re.sub(options.matchstr, options.value, c.configVO.valueset[key])) for instance in c.instances: print "%s (Will NOT modify):" % c.configVO.instances[ instance.index].ref for key in instance.foundValuesetKeys: print "BEFORE: %s = %s" % ( key, c.configVO.instances[ instance.index].valueset[key]) print "AFTER: %s = %s\n" % ( key, re.sub( options.matchstr, options.value, c.configVO. instances[instance.index]. valueset[key])) else: if options.name: replaceConfigGen = s.replaceConfigurationValue( configGenerator, options.value, options.scope, options.show, False, None) elif options.matchstr: replaceConfigGen = s.replaceConfigurationValue( configGenerator, options.value, options.scope, options.show, True, None) for twistConfigItem in replaceConfigGen: print "%s: Modified" % twistConfigItem.ref if options.show: print else: p.print_help() print "Please provide both --name=<name in valueset> and --value=<replacement value> with valuereplace action." elif re.match('[Vv]aluesets?', arguments[0]): if options.id: configurationRefs = s.getConfigurationRefs( options.id, options.regex) printConfigurableItems(s, configurationRefs, None, 'all', options.regex) elif options.server: serverRefs = s.getServerRefs(options.server, options.regex) printConfigurableItems(s, serverRefs, None, 'all', options.regex) elif options.customer: serverRefs = s.getServerRefsByCustomer( options.customer, options.regex) printConfigurableItems(s, serverRefs, None, 'all', options.regex) elif options.facility: serverRefs = s.getServerRefsByFacility( options.facility, options.regex) printConfigurableItems(s, serverRefs, None, 'all', options.regex) elif re.match('[Cc]lone', arguments[0]): if options.clonename: configRef = s.cloneConfigurationRef( options.id, options.clonename) if s.isHPSA9x(): print "created %s|ConfigurationRef:%d" % ( sacliutil.printObjectPath( s, [configRef]), configRef.id) else: print "%s|%s" % (configRef, sacliutil.printObjectID(configRef)) elif re.match('(?i)addplatform?', arguments[0]): if options.platform: print "Adding platform on the following configurationVO(s):" for configvo in s.addConfigurationPlatform( options.id, options.platform, options.regex): print "%s" % configvo.ref else: p.print_help() print "You need to provide --platform=<platform name>." elif re.match('(?i)updateplatform?', arguments[0]): if options.platform: print "Updating platform on the following configurationVO(s):" for configvo in s.updateConfigurationPlatform( options.id, options.platform, options.regex): print "%s" % configvo.ref else: p.print_help() print "You need to provide --platform=<platform name>." else: p.print_help() print "Provide an action: %s" % sacliutil.getActionList(action) else: p.print_help() print "Provide an action: %s" % sacliutil.getActionList(action)
def main(): p = sacliutil.standardOptions("folder --id=<identifier> [--<modifier options>] [ <action> ]") p.add_option('--id', help="folder path or id") p.add_option('--recursive', action="store_true",help="Recursively traverse the folders.") p.add_option('--type', help="Filter by SA Object type.") (options,arguments) = p.parse_args() s = sacliutil.getSALib(options.username,options.password,options.authfile) if options.debug: s.setDebug(1) if options.id: action = ['info','listsaobj','list','listall','remove','create','addacl','removeacl','listacl'] try: if arguments: if re.match('[Ll]ist$',arguments[0]): if options.regex: folderRefs = s.getFolderRefs(options.id,True) else: folderRefs = s.getFolderRefs(options.id,False) for i in folderRefs: try: if i.id == 0: print "/|%s" % sacliutil.printObjectID(i) else: print "%s|%s" % (sacliutil.printObjectPath(s,[i]),sacliutil.printObjectID(i)) except SALib.AuthorizationDeniedException: print "!!!%s is INACCESSIBLE!!!" % i continue except SALib.NotInFolderException: print "!!!%s is INACCESSIBLE!!!" % i elif re.match('[Ll]istall',arguments[0]): if options.regex: folderRefs = s.getFolderRefs(options.id,True,True) else: folderRefs = s.getFolderRefs(options.id,False,True) for i in folderRefs: try: print "%s|%s" % (sacliutil.printObjectPath(s,[i]),sacliutil.printObjectID(i)) #pathDict = s.getObjectPath([ i ],False) #(parentPath,SP) = os.path.split(pathDict[i]) #if parentPath == "/": # print "%s%s" % (parentPath,i) #else: # print "%s/%s" % (parentPath,i) except SALib.AuthorizationDeniedException: print "!!!%s is INACCESSIBLE!!!" % i continue except SALib.NotInFolderException: print "!!!%s is INACCESSIBLE!!!" % i elif re.match('[Ii]nfo',arguments[0]): print "Folder: %s" % options.id sacliutil.print_folderinfo(s,'s.getFolderInfo',options.id) print elif arguments[0] == 'create': print "Folder: %s" % options.id s.createFolder(options.id) elif arguments[0] == "remove": print "Folder: %s" % options.id recursive = False if options.recursive: recursive = True s.removeFolder(options.id,recursive) elif re.match('[Ll]istsaobj?',arguments[0]): recursive = False if options.recursive: recursive = True if options.type in folderSAObjType.keys(): s.printFolderObj(options.id,recursive,options.type) elif not options.type: s.printFolderObj(options.id,recursive,'') else: print "They type you've referenced in --type does not exist or is not yet implemented." print "The list of valid types are: %s" % folderSAObjType.keys() elif arguments[0] == "addacl": recursive = False applytoparent = False if options.perm and options.usergroup: if options.applytoparent: applytoparent = True if options.recursive: recursive = True addedACL = s.addFolderACLs(options.id,options.perm,options.usergroup,recursive,applytoparent) for i in addedACL: print "%s" % i else: print "With addacl action you must provide --perm=<permissions> and --usergroup=<usergroup name>" print "perm can be comma delimited string: l,r,w,x" print "where l is list,r is read, w is write, and x is execute" print 'i.e. --perm=l,r,w' elif arguments[0] == "listacl": s.listFolderACLs(options.id) elif arguments[0] == "removeacl": recursive = False applytoparent = False if options.usergroup: if options.applytoparent: applytoparent = True if options.recursive: recursive = True if options.perm: perm = options.perm else: perm = "l,r,w,x,p" print "Removing all permissions from folder %s for usergroup %s" % (options.id,options.usergroup) removedACL = s.removeFolderACLs(options.id,perm,options.usergroup,recursive) for i in removedACL: print "%s" % i else: p.print_help() print "With removeacl action you must provide --usergroup=<usergroup name>" print "Optionally provide --perm, if not provided then all permissions for usergroup will be removed from the folder" print "perm can be comma delimited string: l,r,w,x" print "where l is list,r is read, w is write, and x is execute" print "i.e. --perm='l,r,w'" else: p.print_help() print "Please provide an action: %s" % sacliutil.getActionList(action) else: p.print_help() print "Please provide an action: %s" % sacliutil.getActionList(action) except SALib.MultipleFolderRefsFound,args: print "ERROR: Multiple folders found: %s." % args except SALib.NullSearchValue,args: print "ERROR: Empty Search Value given."
def main(): p = sacliutil.standardOptions("cml --id=<customer name> [ <action> ]") p.add_option('--id', help="To specify pattern to match cmls.") p.add_option('--platform', help="Specify a platform either by id, name, or pattern match.") p.add_option('--directory', help="Directory where cml will be written to.") (options,arguments) = p.parse_args() s = sacliutil.getSALib(options.username,options.password,options.authfile) if options.debug: s.setDebug(1) if options.id: action = ['list','stdout','fileout','addplatform','updateplatform'] if arguments: if re.match('[Ll]ist$',arguments[0]): for i in s.getCMLRefs(options.id,options.regex): try: if s.isHPSA9x(): print "%s|%s" % (sacliutil.printObjectPath(s,[i]),sacliutil.printObjectID(i)) else: print "%s|%s" % (i,sacliutil.printObjectID(i)) except SALib.AuthorizationDeniedException: print "!!!%s is INACCESSIBLE!!!" % i continue except SALib.NotInFolder,i: print "!!!%s is INACCESSIBLE!!!" % i continue elif re.match('[Ss]tdout$',arguments[0]): cmlvos = s.getCMLVOs(s.getCMLRefs(options.id,options.regex)) for cmlvo in cmlvos: print "%s" % cmlvo.text elif re.match('[Ff]ileout$',arguments[0]): cmlvos = s.getCMLVOs(s.getCMLRefs(options.id,options.regex)) if options.directory: if os.path.isdir(options.directory): for cmlvo in cmlvos: try: print "Writing to file: %s" % os.path.join(options.directory,cmlvo.name) output_file = open(os.path.join(options.directory,cmlvo.name), 'w') output_file.write(cmlvo.text) output_file.close() except IOError,args: raise OSError,"%s %s" % (args.strerror, args.filename) else: raise OSError,"No such directory" else: for cmlvo in cmlvos: print "Writing to file: %s" % cmlvo.name output_file = open(cmlvo.name, 'w') output_file.write(cmlvo.text) output_file.close() elif re.match('(?i)addplatform?',arguments[0]): if options.platform: print "Adding platform on the following cml(s):" for cmlvo in s.addCMLPlatform(options.id,options.platform,options.regex): print "%s" % cmlvo.ref else: p.print_help() print "You need to provide --platform=<platform name>." elif re.match('(?i)updateplatform?',arguments[0]): if options.platform: print "Updating platform on the following cml(s):" for cmlvo in s.updateCMLPlatform(options.id,options.platform,options.regex): print "%s" % cmlvo.ref else: p.print_help() print "You need to provide --platform=<platform name>." else: p.print_help() print "Please provide an action: %s" % sacliutil.getActionList(action)
def main(): p = sacliutil.standardOptions("package --id=<identifier> [--<modifier options>] [ <action> ]") p.add_option('--id', help="Specify a identifier which is an Opsware ID, software policy name, or folder path and software policy name.") p.add_option('--platform', help="Use with upload action.") p.add_option('--pkgtype', help="Use with upload action.") p.add_option('--folder', help="Use with package upload.") p.add_option('--platform', help="Use with package upload.") p.add_option('--pkgfile', help="Use with upload or download action.") p.add_option('--pkgreplace', help="Use with overwrite action.") p.add_option('--pkgtypes', action="store_true", help="List package types.") p.add_option('--name', help="name to specify when calling update package attribute.") p.add_option('--value', help="value to specify when calling update package attribute.") (options,arguments) = p.parse_args() s = sacliutil.getSALib(options.username,options.password,options.authfile) if options.debug: s.setDebug(1) try: if options.id: action = ['list','download','update','info','overwrite','addplatform','updateplatform'] if arguments: if re.match('[Ll]ist',arguments[0]): if options.regex: unitRefsList = s.getUnitRefs(options.id,True) else: unitRefsList = s.getUnitRefs(options.id) for i in unitRefsList: try: print "%s|%s" % (sacliutil.printObjectPath(s,[i]),sacliutil.printObjectID(i)) except SALib.NotInFolder,args: print "Package %s is not accessible in HP SA folders. Check old package repository structure. (i.e. pre HP SA 7.x) " % args continue elif re.match('[Ii]nfo',arguments[0]): for i in s.getUnitRefs(options.id): print "SA Unit ---- %s ----" % i.name sacliutil.print_unitinfo(s,'s.getUnitInfo',i) print elif re.match('[Dd]ownload',arguments[0]): if options.regex: s.downloadUnit(options.id,options.pkgfile,options.regex) else: s.downloadUnit(options.id,options.pkgfile) elif re.match('(?i)^update$',arguments[0]): if options.name and options.value: value = sacliutil.getSAObjectRefsOrString(s,options.value) unitId = s.updateUnitVO(options.id,options.name,value) if isinstance(unitId,list): print "Updated Unit ID: %s|%s" % (sacliutil.printObjectPath(s,unitId.ref),sacliutil.printObjectID(unitId.ref[0])) else: print "Updated Unit ID: %s|%s" % (sacliutil.printObjectPath(s,[unitId.ref]),sacliutil.printObjectID(unitId.ref)) else: p.print_help() print "With update action provide --name=<name of attribute> and --value=<value of attribute> options." elif re.match('(?i)updateplatform?',arguments[0]): if options.platform: print "Updating platform on the following packages:" for unitvo in s.updateUnitPlatform(options.id,options.platform,options.regex): print "%s" % unitvo.ref else: p.print_help() print "You need to provide --platform=<platform name>." elif re.match('(?i)addplatform?',arguments[0]): if options.platform: print "Adding platform to the following packages:" for unitvo in s.addUnitPlatform(options.id,options.platform,options.regex): print "%s" % unitvo.ref else: p.print_help() print "You need to provide --platform=<platform name>." elif re.match('[Oo]verwrite',arguments[0]): if options.pkgtype: filetype = options.pkgtype else: filetype = sacliutil.detectPkgType(options.pkgfile) if options.id and options.platform and filetype: unitId = s.replaceUnit(options.pkgfile,filetype,options.id,options.platform) print "Overwrote Unit: %s|%s" % (sacliutil.printObjectPath(s,[unitId]),sacliutil.printObjectID([unitId])) else: if not options.platform: p.print_help() print "You need to provide --platform with action overwrite" elif not options.id: p.print_help() print "You need to provide --id with action overwrite" elif not filetype: p.print_help() print "--pkgtype wasn't given and package couldn't detect the file type for %s" % options.pkgfile else: p.print_help() print "With --id provide the following actions: %s" % sacliutil.getActionList(action) else: p.print_help() print "With --id provide the following actions: %s" % sacliutil.getActionList(action) elif options.pkgfile: action = ['upload'] if arguments: if re.match('[Uu]pload',arguments[0]): filelist = glob.glob(options.pkgfile) for filei in filelist: if options.pkgtype: filetype = options.pkgtype else: filetype = sacliutil.detectPkgType(filei) if filetype and options.platform and options.folder: if options.debug: print "package type: %s" % filetype if options.regex: unitId = s.uploadUnit(filei,filetype,options.platform,options.folder,options.regex) else: unitId = s.uploadUnit(filei,filetype,options.platform,options.folder) print "Created Unit: %s|%s" % (sacliutil.printObjectPath(s,[unitId]),sacliutil.printObjectID([unitId])) else: if not options.platform: p.print_help() print "You need to provide --platform with action upload." elif not options.folder: p.print_help() print "You need to provide --folder with action upload." elif not filetype: p.print_help() print "--pkgtype wasn't given and package couldn't detect the file type for %s" % filei else: p.print_help() print "Please provide an action: %s" % sacliutil.getActionList(action) else: p.print_help() print "Please provide an action: %s" % sacliutil.getActionList(action)
def main(): p = sacliutil.standardOptions("cml --id=<customer name> [ <action> ]") p.add_option('--id', help="To specify pattern to match cmls.") p.add_option( '--platform', help="Specify a platform either by id, name, or pattern match.") p.add_option('--directory', help="Directory where cml will be written to.") (options, arguments) = p.parse_args() s = sacliutil.getSALib(options.username, options.password, options.authfile) if options.debug: s.setDebug(1) if options.id: action = ['list', 'stdout', 'fileout', 'addplatform', 'updateplatform'] if arguments: if re.match('[Ll]ist$', arguments[0]): for i in s.getCMLRefs(options.id, options.regex): try: if s.isHPSA9x(): print "%s|%s" % (sacliutil.printObjectPath( s, [i]), sacliutil.printObjectID(i)) else: print "%s|%s" % (i, sacliutil.printObjectID(i)) except SALib.AuthorizationDeniedException: print "!!!%s is INACCESSIBLE!!!" % i continue except SALib.NotInFolder, i: print "!!!%s is INACCESSIBLE!!!" % i continue elif re.match('[Ss]tdout$', arguments[0]): cmlvos = s.getCMLVOs(s.getCMLRefs(options.id, options.regex)) for cmlvo in cmlvos: print "%s" % cmlvo.text elif re.match('[Ff]ileout$', arguments[0]): cmlvos = s.getCMLVOs(s.getCMLRefs(options.id, options.regex)) if options.directory: if os.path.isdir(options.directory): for cmlvo in cmlvos: try: print "Writing to file: %s" % os.path.join( options.directory, cmlvo.name) output_file = open( os.path.join(options.directory, cmlvo.name), 'w') output_file.write(cmlvo.text) output_file.close() except IOError, args: raise OSError, "%s %s" % (args.strerror, args.filename) else: raise OSError, "No such directory" else: for cmlvo in cmlvos: print "Writing to file: %s" % cmlvo.name output_file = open(cmlvo.name, 'w') output_file.write(cmlvo.text) output_file.close() elif re.match('(?i)addplatform?', arguments[0]): if options.platform: print "Adding platform on the following cml(s):" for cmlvo in s.addCMLPlatform(options.id, options.platform, options.regex): print "%s" % cmlvo.ref else: p.print_help() print "You need to provide --platform=<platform name>." elif re.match('(?i)updateplatform?', arguments[0]): if options.platform: print "Updating platform on the following cml(s):" for cmlvo in s.updateCMLPlatform(options.id, options.platform, options.regex): print "%s" % cmlvo.ref else: p.print_help() print "You need to provide --platform=<platform name>." else: p.print_help() print "Please provide an action: %s" % sacliutil.getActionList( action)