本文整理汇总了Python中xdrlib.Packer.pack_int方法的典型用法代码示例。如果您正苦于以下问题:Python Packer.pack_int方法的具体用法?Python Packer.pack_int怎么用?Python Packer.pack_int使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类xdrlib.Packer
的用法示例。
在下文中一共展示了Packer.pack_int方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: gmetric_write_meta
# 需要导入模块: from xdrlib import Packer [as 别名]
# 或者: from xdrlib.Packer import pack_int [as 别名]
def gmetric_write_meta(HOST, NAME, TYPE, UNITS, SLOPE, TMAX, DMAX, GROUP):
"""
Arguments are in all upper-case to match XML
"""
packer = Packer()
"""
ganglia message formats
gmetadata_full = 128,
gmetric_ushort = 129,
gmetric_short = 130,
gmetric_int = 131,
gmetric_uint = 132,
gmetric_string = 133,
gmetric_float = 134,
gmetric_double = 135
"""
packer.pack_int(128) # type gmetadata_full
packer.pack_string(HOST)
packer.pack_string(NAME)
packer.pack_int(0)
packer.pack_string(TYPE)
packer.pack_string(NAME)
packer.pack_string(UNITS)
packer.pack_int(slope_str2int[SLOPE]) # map slope string to int
packer.pack_int(TMAX)
packer.pack_int(DMAX)
packer.pack_int(1)
packer.pack_string("GROUP")
packer.pack_string(GROUP)
return packer.get_buffer()
示例2: gmetric_meta
# 需要导入模块: from xdrlib import Packer [as 别名]
# 或者: from xdrlib.Packer import pack_int [as 别名]
def gmetric_meta(NAME, TYPE, UNITS, SLOPE, TMAX, DMAX, EXTRAS=None):
"""
Arguments are in all upper-case to match XML
"""
packer = Packer()
packer.pack_int(128) # "gmetadata_full"
packer.pack_string('nickg-macbook.local')
packer.pack_string(NAME)
packer.pack_bool(False)
packer.pack_string(TYPE)
packer.pack_string(NAME)
packer.pack_string(UNITS)
packer.pack_int(slope_str2int[SLOPE]) # map slope string to int
packer.pack_uint(int(TMAX))
packer.pack_uint(int(DMAX))
if EXTRAS is None:
packer.pack_uint(0)
else:
packer.pack_uint(len(EXTRAS))
for k,v in EXTRAS.iteritems():
packer.pack_string(k)
packer.pack_string(v)
return packer.get_buffer()
示例3: gmetric_value
# 需要导入模块: from xdrlib import Packer [as 别名]
# 或者: from xdrlib.Packer import pack_int [as 别名]
def gmetric_value(NAME, VAL):
packer = Packer()
packer.pack_int(128+5) # string
packer.pack_string('nickg-macbook.local')
packer.pack_string(NAME)
packer.pack_bool(False)
packer.pack_string('%s')
packer.pack_string(VAL)
return packer.get_buffer()
示例4: send_metareq
# 需要导入模块: from xdrlib import Packer [as 别名]
# 或者: from xdrlib.Packer import pack_int [as 别名]
def send_metareq(self, values, address):
packer = Packer()
packer.pack_int(136)
if not values['spoof']:
packer.pack_string(address[0])
else:
packer.pack_string(":".join((address[0], values['hostname'])))
packer.pack_string(values['metricname'])
packer.pack_bool(values['spoof'])
self.transport.write(packer.get_buffer(),address)
return
示例5: gmetric_write
# 需要导入模块: from xdrlib import Packer [as 别名]
# 或者: from xdrlib.Packer import pack_int [as 别名]
def gmetric_write(ID, HOST, NAME, VAL):
"""
Arguments are in all upper-case to match XML
"""
packer = Packer()
packer.pack_int(133)
packer.pack_string(HOST)
packer.pack_string(NAME)
packer.pack_int(0)
packer.pack_string("%s")
packer.pack_string(str(VAL))
return packer.get_buffer()
示例6: __init__
# 需要导入模块: from xdrlib import Packer [as 别名]
# 或者: from xdrlib.Packer import pack_int [as 别名]
def __init__(self, stamp, machinename, uid, gid, gids):
if len(machinename) > 255:
raise SecError("machinename %s is too long" % machinename)
if len(gids) > 16:
raise SecError("gid array too long: %s" % str(gids))
try:
p = Packer()
p.pack_int(stamp)
p.pack_string(machinename)
p.pack_uint(uid)
p.pack_uint(gid)
p.pack_array(gids, p.pack_uint)
self.cred = p.get_buffer()
except Error, e:
raise SecError("Packing error: %s", str(e))
示例7: __init__
# 需要导入模块: from xdrlib import Packer [as 别名]
# 或者: from xdrlib.Packer import pack_int [as 别名]
def __init__(self, stamp=0, machinename='', uid=0, gid=0, gids=[]):
if len(machinename) > 255:
raise SecError("machinename %s is too long" % machinename)
if len(gids) > 16:
raise SecError("gid array too long: %s" % str(gids))
try:
p = Packer()
p.pack_int(stamp)
try: # for python2
p.pack_string(machinename)
except: # for python3
p.pack_string(bytes(machinename, 'utf-8'))
p.pack_uint(uid)
p.pack_uint(gid)
p.pack_array(gids, p.pack_uint)
self.cred = p.get_buffer()
except Error as e:
raise SecError("Packing error: %s", str(e))
self.uid = uid
self.gid = gid
示例8: gmetric_write
# 需要导入模块: from xdrlib import Packer [as 别名]
# 或者: from xdrlib.Packer import pack_int [as 别名]
def gmetric_write(NAME, VAL, TYPE, UNITS, SLOPE, TMAX, DMAX, GROUP, SPOOF):
"""
Arguments are in all upper-case to match XML
"""
packer = Packer()
HOSTNAME="test"
if SPOOF == "":
SPOOFENABLED=0
else :
SPOOFENABLED=1
# Meta data about a metric
packer.pack_int(128)
if SPOOFENABLED == 1:
packer.pack_string(SPOOF)
else:
packer.pack_string(HOSTNAME)
packer.pack_string(NAME)
packer.pack_int(SPOOFENABLED)
packer.pack_string(TYPE)
packer.pack_string(NAME)
packer.pack_string(UNITS)
packer.pack_int(slope_str2int[SLOPE]) # map slope string to int
packer.pack_uint(int(TMAX))
packer.pack_uint(int(DMAX))
# Magic number. Indicates number of entries to follow. Put in 1 for GROUP
if GROUP == "":
packer.pack_int(0)
else:
packer.pack_int(1)
packer.pack_string("GROUP")
packer.pack_string(GROUP)
# Actual data sent in a separate packet
data = Packer()
data.pack_int(128+5)
if SPOOFENABLED == 1:
data.pack_string(SPOOF)
else:
data.pack_string(HOSTNAME)
data.pack_string(NAME)
data.pack_int(SPOOFENABLED)
data.pack_string("%s")
data.pack_string(str(VAL))
return ( packer.get_buffer() , data.get_buffer() )
示例9: _gmetric
# 需要导入模块: from xdrlib import Packer [as 别名]
# 或者: from xdrlib.Packer import pack_int [as 别名]
def _gmetric(self, name, val, metric_type, units, slope, tmax, dmax, group, title, description, spoof):
meta = Packer()
HOSTNAME = socket.gethostname()
if spoof:
SPOOF_ENABLED = 1
else:
SPOOF_ENABLED = 0
# Meta data about a metric
packet_type = 128
meta.pack_int(packet_type)
if SPOOF_ENABLED == 1:
meta.pack_string(spoof)
else:
meta.pack_string(HOSTNAME)
meta.pack_string(name)
meta.pack_int(SPOOF_ENABLED)
meta.pack_string(metric_type)
meta.pack_string(name)
meta.pack_string(units)
meta.pack_int(METRIC_SLOPES[slope]) # map slope string to int
meta.pack_uint(int(tmax))
meta.pack_uint(int(dmax))
extra_data = 0
if group:
extra_data += 1
if title:
extra_data += 1
if description:
extra_data += 1
meta.pack_int(extra_data)
if group:
for g in group.split(','):
meta.pack_string("GROUP")
meta.pack_string(g)
if title:
meta.pack_string("TITLE")
meta.pack_string(title)
if description:
meta.pack_string("DESC")
meta.pack_string(description)
# Actual data sent in a separate packet
data = Packer()
packet_type = METRIC_TYPES[metric_type]
data.pack_int(packet_type)
if SPOOF_ENABLED == 1:
data.pack_string(spoof)
else:
data.pack_string(HOSTNAME)
data.pack_string(name)
data.pack_int(SPOOF_ENABLED)
if metric_type in ['int8', 'uint8', 'int16', 'uint16', 'int32']:
data.pack_string("%d")
data.pack_int(int(val))
if metric_type == 'uint32':
data.pack_string("%u")
data.pack_uint(long(val))
if metric_type == 'string':
data.pack_string("%s")
data.pack_string(str(val))
if metric_type == 'float':
data.pack_string("%f")
data.pack_float(float(val))
if metric_type == 'double':
data.pack_string("%f")
data.pack_double(float(val)) # XXX - double or float?
return meta.get_buffer(), data.get_buffer()
示例10: gmetric_write
# 需要导入模块: from xdrlib import Packer [as 别名]
# 或者: from xdrlib.Packer import pack_int [as 别名]
def gmetric_write(NAME, VAL, TYPE, UNITS, SLOPE, TMAX, DMAX, GROUP, SPOOF):
packer = Packer()
HOSTNAME = 'test'
if SPOOF == '':
SPOOFENABLED = 0
else:
SPOOFENABLED = 1
packer.pack_int(128)
if SPOOFENABLED == 1:
packer.pack_string(SPOOF)
else:
packer.pack_string(HOSTNAME)
packer.pack_string(NAME)
packer.pack_int(SPOOFENABLED)
packer.pack_string(TYPE)
packer.pack_string(NAME)
packer.pack_string(UNITS)
packer.pack_int(slope_str2int[SLOPE])
packer.pack_uint(int(TMAX))
packer.pack_uint(int(DMAX))
if GROUP == '':
packer.pack_int(0)
else:
packer.pack_int(1)
packer.pack_string('GROUP')
packer.pack_string(GROUP)
data = Packer()
data.pack_int(133)
if SPOOFENABLED == 1:
data.pack_string(SPOOF)
else:
data.pack_string(HOSTNAME)
data.pack_string(NAME)
data.pack_int(SPOOFENABLED)
data.pack_string('%s')
data.pack_string(str(VAL))
return (packer.get_buffer(), data.get_buffer())
示例11: _gmetric
# 需要导入模块: from xdrlib import Packer [as 别名]
# 或者: from xdrlib.Packer import pack_int [as 别名]
def _gmetric(self, name, val, type, units, slope, tmax, dmax, group, title, description, spoof):
"""
Arguments are in all upper-case to match XML
"""
meta = Packer()
HOSTNAME=socket.gethostname()
if spoof == "":
SPOOFENABLED=0
else :
SPOOFENABLED=1
# Meta data about a metric
packet_type = 128
meta.pack_int(packet_type)
if SPOOFENABLED == 1:
meta.pack_string(spoof)
else:
meta.pack_string(HOSTNAME)
meta.pack_string(name)
meta.pack_int(SPOOFENABLED)
meta.pack_string(type)
meta.pack_string(name)
meta.pack_string(units)
meta.pack_int(SLOPES[slope]) # map slope string to int
meta.pack_uint(int(tmax))
meta.pack_uint(int(dmax))
extra_data = 0
if group != "":
extra_data += 1
if title != "":
extra_data += 1
if description != "":
extra_data += 1
meta.pack_int(extra_data)
if group != "":
meta.pack_string("GROUP")
meta.pack_string(group)
if title != "":
meta.pack_string("TITLE")
meta.pack_string(title)
if description != "":
meta.pack_string("DESC")
meta.pack_string(description)
# Actual data sent in a separate packet
data = Packer()
packet_type = TYPES[type]
data.pack_int(packet_type)
if SPOOFENABLED == 1:
data.pack_string(spoof)
else:
data.pack_string(HOSTNAME)
data.pack_string(name)
data.pack_int(SPOOFENABLED)
if type in ['int8','uint8','int16','uint16','int32']:
data.pack_string("%d")
data.pack_int(int(val))
if type == 'uint32':
data.pack_string("%u")
data.pack_uint(long(val))
if type == 'string':
data.pack_string("%s")
data.pack_string(str(val))
if type == 'float':
data.pack_string("%f")
data.pack_float(float(val))
if type == 'double':
data.pack_string("%f")
data.pack_double(float(val)) # XXX - double or float?
return (meta.get_buffer(), data.get_buffer())
示例12: pack
# 需要导入模块: from xdrlib import Packer [as 别名]
# 或者: from xdrlib.Packer import pack_int [as 别名]
def pack(self, values):
metric = {
'hostname': '',
'spoof': 0,
'units': '',
'slope': 'both',
'tmax': 60,
'dmax': 0
}
metric.update(values)
if metric.get('spoof', False):
metric['spoof'] = 1
else:
metric['spoof'] = 0
metric['slope'] = SLOPE[metric['slope']]
for key in ('name', 'value', 'type'):
if key not in metric:
raise KeyError("Missing {0}".format(key))
if metric['type'] not in ('string', 'int8', 'uint8', 'int16', 'uint16', 'int32', 'uint32', 'float', 'double'):
raise TypeError("Invalid metric type")
convert = lambda v: v.encode() if isinstance(v, str) else v
metric = {key: convert(value) for key, value in metric.items()}
# Metadata
meta = Packer()
meta.pack_int(128)
meta.pack_string(metric['hostname'])
meta.pack_string(metric['name'])
meta.pack_int(int(metric['spoof']))
meta.pack_string(metric['type'])
meta.pack_string(metric['name'])
meta.pack_string(metric['units'])
meta.pack_int(metric['slope'])
meta.pack_uint(int(metric['tmax']))
meta.pack_uint(int(metric['dmax']))
# Group support
if 'group' in metric:
meta.pack_int(1)
meta.pack_string(b"GROUP")
meta.pack_string(metric['group'])
else:
meta.pack_int(0)
# Data
data = Packer()
data.pack_int(128 + 5)
data.pack_string(metric['hostname'])
data.pack_string(metric['name'])
data.pack_int(int(metric['spoof']))
data.pack_string(b"%s")
data.pack_string(bytes(metric['value']))
return meta.get_buffer(), data.get_buffer()
示例13: Packer
# 需要导入模块: from xdrlib import Packer [as 别名]
# 或者: from xdrlib.Packer import pack_int [as 别名]
import socket
from xdrlib import Packer
host = 'localhost'
port = 8000
s = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
s.connect((host, port))
p = Packer()
p.pack_int(1)
s.send(p.get_buffer())
data = s.recv(1024)
s.close()
print 'recibido', repr(data)