Thank you Alex, but I'm still unable to set the custom attributes on the interface. I updated a little my script, because I have to read from a single file written in a certain way, and then I put your suggestions in it. The reading of the file works in the proper way and I don't get any error running the script, but the custom attributes are empty anyway. Here is my code:
#coding: utf-8
import csv
import time
from java.util import HashMap # CHANGE 1
from java.lang import String
class XXX4:
def YYY(self):
listaNodi = []
listaNodi = session.getAllObjects()
datiFile = open("PATH/Lettura.csv").readlines()
for nodo in listaNodi:
IPnodo = str(nodo.getPrimaryIP())
for riga in datiFile:
print "___________starts for on riga_____________\n"
print "riga: "+riga
for parola in riga.split():
print "parola: "+parola
if IPnodo ==parola:
print "Verified IPnodo = parola"
time.sleep(10)
for interface in nodo.getAllChilds(objects.GenericObject.OBJECT_INTERFACE):
print "starts interface for "
interfaceName = interface.getObjectName()
ID = interface.getObjectId()
print "interfaceName: "+interfaceName
for parola1 in riga.split():
print "parola1: "+parola1
if interfaceName == parola1:
print "Verified interfaceName=parola1"
for parola2 in riga.split():
EndUserInfo = parola2
print "EndUserInfo after for: "+EndUserInfo
modificatore = NXCObjectModificationData(ID)
modifica = HashMap() # CHANGE 2
modifica.put("End user Info",EndUserInfo)
modificatore.setCustomAttributes(modifica)
time.sleep(10)
G = XXX4()
G.YYY()
Any suggestion?
EDIT: I found out something interesting. I modified the script and my last lines of it now are:
for parola2 in riga.split():
EndUserInfo = str(parola2)
print "EndUserInfo dopo cilclo for: "+EndUserInfo
modificatore = NXCObjectModificationData(ID)
"""modifica = HashMap() # CHANGE 2
modifica.put("End User Info",EndUserInfo)
print "modifica: "+str(modifica)
modificatore.setCustomAttributes(modifica)"""
customAttributes = modificatore.getCustomAttributes()
print "customAttributes: "+str(customAttributes)
#customAttributes.put("End User Info",EndUserInfo)
#modificatore.setCustomAttributes(customAttributes)
My thought was that, instead of creating a new HasMap, I could get the existing one, supposed to be empty, and use the put metod on it. But the command print "customAttributes: "+str(customAttributes) returns "none", which is the same result I get using the solution you suggested. Also, if I try to run customAttributes.put("End User Info",EndUserInfo) on the terminal I get:
customAttributes.put("End User Info",EndUserInfo)
AttributeError: 'NoneType' object has no attribute 'put'
It seems like modificatore.getCustomAttributes() is not a Map<String,String> object.
Help!