Subscribe

sprintf() NaElement method not working in Python NMSDK 5.4P1

hello,

 

I am working with python libs of MNSDK 5.4P1. I realised that NaElement sptrinf() method is not working. I am buiding this class:

 

def GetInfoPath(self):
		'''It's supposed to just retrieved one volume.'''

		netappops.logger.debug("GetInfoPath: Begin")
		s=self.__CreateServer(self.serverpath)
			
		tag=None
		while True:
			#build query
			api1 = NaElement("volume-get-iter")
			if tag is not None: 
				api1.child_add_string("tag",tag);
			api1.child_add_string("max-records",10);
			query = NaElement("query")
			
			
			volpath_parent = NaElement("volume-attributes")
			volpath = NaElement("volume-id-attributes")
			volpath.child_add_string("junction-path",self.serverlayout)
			self.volume["junction-path"]=self.serverlayout

			query.child_add(volpath_parent)
			volpath_parent.child_add(volpath)		
			api1.child_add(query)
			#print(api1.sprintf())		
			#Get attributes we want
			desiredAttrs = NaElement("desired-attributes")
			desiredAutoSpace = NaElement("volume-autosize-attributes")
			desiredIdAttr = NaElement("volume-id-attributes")
			desiredSpace = NaElement("volume-space-attributes")
			desiredState = NaElement("volume-state-attributes")
			desiredAttrs.child_add(desiredAutoSpace)
			desiredAttrs.child_add(desiredIdAttr)
			desiredAttrs.child_add(desiredSpace)
			desiredAttrs.child_add(desiredState)
			api1.child_add(desiredAttrs)
			
			netappops.logger.debug("query looks like: %s",api1.sprintf())

 

 

This always fails with this error:

 

 

Traceback (most recent call last):
File "netappops.py", line 194, in <module>
a.GetInfoPath()
File "netappops.py", line 126, in GetInfoPath
print(api1.sprintf())
File "/ORA/dbs01/work/storage-api/lib/python/NetApp/NaElement.py", line 236, in sprintf
s = s+c.sprintf(indent + "\t")
File "/ORA/dbs01/work/storage-api/lib/python/NetApp/NaElement.py", line 238, in sprintf
self.element['content'] = NaElement.escapeHTML(self.element['content'])
File "/ORA/dbs01/work/storage-api/lib/python/NetApp/NaElement.py", line 342, in escapeHTML
cont = re.sub(r'&','&amp;',cont,count=0)
File "/ORA/dbs01/work/storage-api/v1/lib64/python3.4/re.py", line 179, in sub
return _compile(pattern, flags).sub(repl, string, count)

 

I have modified the file: /ORA/dbs01/work/storage-api/lib/python/NetApp/NaElement.py  appending the lines in bald:

 

  @staticmethod

    def escapeHTML(cont):
        """ This is a private function, not to be called externally.
        This method converts reserved HTML characters to corresponding entity names.
        """
        #APPEND BEGIN
        if not isinstance(cont,str):
                cont = str(cont)
        #APPEND END
        cont = re.sub(r'&','&amp;',cont,count=0)
        cont = re.sub(r'<','&lt;',cont,count=0)
        cont = re.sub(r'>','&gt;',cont,count=0)
        cont = re.sub(r"'",'&apos;',cont,count=0)
        cont = re.sub(r'"','&quot;',cont,count=0)

        """ The existence of '&' (ampersand) sign in entity names implies that multiple calls
        to this function will result in non-idempotent encoding. So, to handle such situation
        or when the input itself contains entity names, we reconvert such recurrences to
        appropriate characters.
        """
        cont = re.sub(r'&amp;amp;','&amp;',cont,count=0)
        cont = re.sub(r'&amp;lt;','&lt;',cont,count=0)
        cont = re.sub(r'&amp;gt;','&gt;',cont,count=0)
        cont = re.sub(r'&amp;apos;','&apos;',cont,count=0)
        cont = re.sub(r'&amp;quot;','&quot;',cont,count=0)
        return cont

 

Now it looks working:

 

storage-api-console DEBUG    MainProcess query looks like: <volume-get-iter>
        <max-records>10</max-records>
        <query>
                <volume-attributes>
                        <volume-id-attributes>
                                <junction-path>/ORA/dbs07/DNFS</junction-path>
                        </volume-id-attributes>
                </volume-attributes>
        </query>
        <desired-attributes>
                <volume-autosize-attributes></volume-autosize-attributes>
                <volume-id-attributes></volume-id-attributes>
                <volume-space-attributes></volume-space-attributes>
                <volume-state-attributes></volume-state-attributes>
        </desired-attributes>
</volume-get-iter>

 

Please could you verify the solution and solve the problem for next release of the NMSDK.

 

THank you,

RUben