mirror of
				https://gitea.osmocom.org/cellular-infrastructure/osmo-mgw.git
				synced 2025-11-03 21:43:32 +00:00 
			
		
		
		
	Use random operation id
According to documentation for Control Interface Protocol <id> is "A numeric identifier, uniquely identifying this particular operation", hence it's best to be illustrated with random integer - use it as default. Fix override of id with previously used python-specific objects' id. Change-Id: I32236c067360526f4e7ee4bbdba64c5137de696d Related: OS#1646
This commit is contained in:
		@@ -1,6 +1,6 @@
 | 
				
			|||||||
#!/usr/bin/python
 | 
					#!/usr/bin/python
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import sys,os
 | 
					import sys,os, random
 | 
				
			||||||
from optparse import OptionParser
 | 
					from optparse import OptionParser
 | 
				
			||||||
import socket
 | 
					import socket
 | 
				
			||||||
import struct
 | 
					import struct
 | 
				
			||||||
@@ -36,15 +36,17 @@ def send(sck, data):
 | 
				
			|||||||
	data = prefix_ipa_ctrl_header(data)
 | 
						data = prefix_ipa_ctrl_header(data)
 | 
				
			||||||
	sck.send(data)
 | 
						sck.send(data)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def do_set(var, value, id, sck):
 | 
					def do_set(var, value, op_id, sck):
 | 
				
			||||||
	setmsg = "SET %s %s %s" %(options.id, var, value)
 | 
						setmsg = "SET %s %s %s" %(op_id, var, value)
 | 
				
			||||||
	send(sck, setmsg)
 | 
						send(sck, setmsg)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def do_get(var, id, sck):
 | 
					def do_get(var, op_id, sck):
 | 
				
			||||||
	getmsg = "GET %s %s" %(options.id, var)
 | 
						getmsg = "GET %s %s" %(op_id, var)
 | 
				
			||||||
	send(sck, getmsg)
 | 
						send(sck, getmsg)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
if __name__ == '__main__':
 | 
					if __name__ == '__main__':
 | 
				
			||||||
 | 
					        random.seed()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        parser = OptionParser("Usage: %prog [options] var [value]")
 | 
					        parser = OptionParser("Usage: %prog [options] var [value]")
 | 
				
			||||||
        parser.add_option("-d", "--host", dest="host",
 | 
					        parser.add_option("-d", "--host", dest="host",
 | 
				
			||||||
                          help="connect to HOST", metavar="HOST")
 | 
					                          help="connect to HOST", metavar="HOST")
 | 
				
			||||||
@@ -54,7 +56,7 @@ if __name__ == '__main__':
 | 
				
			|||||||
                          dest="cmd_get", help="perform GET operation")
 | 
					                          dest="cmd_get", help="perform GET operation")
 | 
				
			||||||
        parser.add_option("-s", "--set", action="store_true",
 | 
					        parser.add_option("-s", "--set", action="store_true",
 | 
				
			||||||
                          dest="cmd_set", help="perform SET operation")
 | 
					                          dest="cmd_set", help="perform SET operation")
 | 
				
			||||||
        parser.add_option("-i", "--id", dest="id", default="1",
 | 
					        parser.add_option("-i", "--id", dest="op_id", default=random.randint(1, sys.maxint),
 | 
				
			||||||
                          help="set id manually", metavar="ID")
 | 
					                          help="set id manually", metavar="ID")
 | 
				
			||||||
        parser.add_option("-v", "--verbose", action="store_true",
 | 
					        parser.add_option("-v", "--verbose", action="store_true",
 | 
				
			||||||
                          dest="verbose", help="be verbose", default=False)
 | 
					                          dest="verbose", help="be verbose", default=False)
 | 
				
			||||||
@@ -79,12 +81,12 @@ if __name__ == '__main__':
 | 
				
			|||||||
        if options.cmd_set:
 | 
					        if options.cmd_set:
 | 
				
			||||||
	        if len(args) < 2:
 | 
						        if len(args) < 2:
 | 
				
			||||||
		        parser.error("Set requires var and value arguments")
 | 
							        parser.error("Set requires var and value arguments")
 | 
				
			||||||
	        do_set(args[0], ' '.join(args[1:]), options.id, sock)
 | 
						        do_set(args[0], ' '.join(args[1:]), options.op_id, sock)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if options.cmd_get:
 | 
					        if options.cmd_get:
 | 
				
			||||||
	        if len(args) != 1:
 | 
						        if len(args) != 1:
 | 
				
			||||||
		        parser.error("Get requires the var argument")
 | 
							        parser.error("Get requires the var argument")
 | 
				
			||||||
	        do_get(args[0], options.id, sock)
 | 
						        do_get(args[0], options.op_id, sock)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        data = sock.recv(1024)
 | 
					        data = sock.recv(1024)
 | 
				
			||||||
        while (len(data)>0):
 | 
					        while (len(data)>0):
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user