mirror of https://github.com/OpenKMIP/PyKMIP.git
Initial commit of KMIP library
This contains the basic items for repository. The basic files and directories were created to layout the repository structure. Created a simple KMIP client and server. This was generated using the thrift library. This version only tests the thrift framework. It does not adhere to the spec.
This commit is contained in:
commit
a0d8c9195e
|
@ -0,0 +1,3 @@
|
|||
.project
|
||||
.pydevproject
|
||||
*.pyc
|
|
@ -0,0 +1,29 @@
|
|||
#!/usr/bin/env python
|
||||
|
||||
# TODO insert license here
|
||||
|
||||
from transport.kmip import KMIP
|
||||
from transport.kmip.ttypes import *
|
||||
|
||||
from thrift import Thrift
|
||||
from thrift.transport import TSocket
|
||||
from thrift.transport import TTransport
|
||||
from thrift.protocol import TBinaryProtocol
|
||||
|
||||
try:
|
||||
|
||||
transport = TSocket.TSocket('localhost', 9090)
|
||||
transport = TTransport.TBufferedTransport(transport)
|
||||
protocol = TBinaryProtocol.TBinaryProtocol(transport)
|
||||
client = KMIP.Client(protocol)
|
||||
transport.open()
|
||||
|
||||
print 'ping-client()'
|
||||
client.create()
|
||||
print 'register_mo-client()'
|
||||
client.register_mo()
|
||||
|
||||
transport.close()
|
||||
|
||||
except Thrift.TException, tx:
|
||||
print '%s' % (tx.message)
|
|
@ -0,0 +1,32 @@
|
|||
#!/usr/bin/env python
|
||||
|
||||
# TODO insert license here
|
||||
|
||||
from transport.kmip import KMIP
|
||||
from transport.kmip.ttypes import *
|
||||
|
||||
from thrift.transport import TSocket
|
||||
from thrift.transport import TTransport
|
||||
from thrift.protocol import TBinaryProtocol
|
||||
from thrift.server import TServer
|
||||
|
||||
class KMIPHandler:
|
||||
def __init__(self):
|
||||
pass
|
||||
|
||||
def create(self):
|
||||
print 'create()'
|
||||
|
||||
def register_mo(self):
|
||||
print 'register_mo()'
|
||||
|
||||
handler = KMIPHandler()
|
||||
processor = KMIP.Processor(handler)
|
||||
transport = TSocket.TServerSocket(port=9090)
|
||||
tfactory = TTransport.TBufferedTransportFactory()
|
||||
pfactory = TBinaryProtocol.TBinaryProtocolFactory()
|
||||
server = TServer.TSimpleServer(processor, transport, tfactory, pfactory)
|
||||
|
||||
print 'Starting the KMIP server...'
|
||||
server.serve()
|
||||
print 'done.'
|
|
@ -0,0 +1,95 @@
|
|||
#!/usr/bin/env python
|
||||
#
|
||||
# Autogenerated by Thrift Compiler (0.9.1)
|
||||
#
|
||||
# DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
|
||||
#
|
||||
# options string: py
|
||||
#
|
||||
|
||||
import sys
|
||||
import pprint
|
||||
from urlparse import urlparse
|
||||
from thrift.transport import TTransport
|
||||
from thrift.transport import TSocket
|
||||
from thrift.transport import THttpClient
|
||||
from thrift.protocol import TBinaryProtocol
|
||||
|
||||
from kmip import KMIP
|
||||
from kmip.ttypes import *
|
||||
|
||||
if len(sys.argv) <= 1 or sys.argv[1] == '--help':
|
||||
print ''
|
||||
print 'Usage: ' + sys.argv[0] + ' [-h host[:port]] [-u url] [-f[ramed]] function [arg1 [arg2...]]'
|
||||
print ''
|
||||
print 'Functions:'
|
||||
print ' void create()'
|
||||
print ' void register_mo()'
|
||||
print ''
|
||||
sys.exit(0)
|
||||
|
||||
pp = pprint.PrettyPrinter(indent = 2)
|
||||
host = 'localhost'
|
||||
port = 9090
|
||||
uri = ''
|
||||
framed = False
|
||||
http = False
|
||||
argi = 1
|
||||
|
||||
if sys.argv[argi] == '-h':
|
||||
parts = sys.argv[argi+1].split(':')
|
||||
host = parts[0]
|
||||
if len(parts) > 1:
|
||||
port = int(parts[1])
|
||||
argi += 2
|
||||
|
||||
if sys.argv[argi] == '-u':
|
||||
url = urlparse(sys.argv[argi+1])
|
||||
parts = url[1].split(':')
|
||||
host = parts[0]
|
||||
if len(parts) > 1:
|
||||
port = int(parts[1])
|
||||
else:
|
||||
port = 80
|
||||
uri = url[2]
|
||||
if url[4]:
|
||||
uri += '?%s' % url[4]
|
||||
http = True
|
||||
argi += 2
|
||||
|
||||
if sys.argv[argi] == '-f' or sys.argv[argi] == '-framed':
|
||||
framed = True
|
||||
argi += 1
|
||||
|
||||
cmd = sys.argv[argi]
|
||||
args = sys.argv[argi+1:]
|
||||
|
||||
if http:
|
||||
transport = THttpClient.THttpClient(host, port, uri)
|
||||
else:
|
||||
socket = TSocket.TSocket(host, port)
|
||||
if framed:
|
||||
transport = TTransport.TFramedTransport(socket)
|
||||
else:
|
||||
transport = TTransport.TBufferedTransport(socket)
|
||||
protocol = TBinaryProtocol.TBinaryProtocol(transport)
|
||||
client = KMIP.Client(protocol)
|
||||
transport.open()
|
||||
|
||||
if cmd == 'create':
|
||||
if len(args) != 0:
|
||||
print 'create requires 0 args'
|
||||
sys.exit(1)
|
||||
pp.pprint(client.create())
|
||||
|
||||
elif cmd == 'register_mo':
|
||||
if len(args) != 0:
|
||||
print 'register_mo requires 0 args'
|
||||
sys.exit(1)
|
||||
pp.pprint(client.register_mo())
|
||||
|
||||
else:
|
||||
print 'Unrecognized method %s' % cmd
|
||||
sys.exit(1)
|
||||
|
||||
transport.close()
|
|
@ -0,0 +1,295 @@
|
|||
#
|
||||
# Autogenerated by Thrift Compiler (0.9.1)
|
||||
#
|
||||
# DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
|
||||
#
|
||||
# options string: py
|
||||
#
|
||||
|
||||
from thrift.Thrift import TType, TMessageType, TException, TApplicationException
|
||||
from ttypes import *
|
||||
from thrift.Thrift import TProcessor
|
||||
from thrift.transport import TTransport
|
||||
from thrift.protocol import TBinaryProtocol, TProtocol
|
||||
try:
|
||||
from thrift.protocol import fastbinary
|
||||
except:
|
||||
fastbinary = None
|
||||
|
||||
|
||||
class Iface:
|
||||
def create(self):
|
||||
pass
|
||||
|
||||
def register_mo(self):
|
||||
pass
|
||||
|
||||
|
||||
class Client(Iface):
|
||||
def __init__(self, iprot, oprot=None):
|
||||
self._iprot = self._oprot = iprot
|
||||
if oprot is not None:
|
||||
self._oprot = oprot
|
||||
self._seqid = 0
|
||||
|
||||
def create(self):
|
||||
self.send_create()
|
||||
self.recv_create()
|
||||
|
||||
def send_create(self):
|
||||
self._oprot.writeMessageBegin('create', TMessageType.CALL, self._seqid)
|
||||
args = create_args()
|
||||
args.write(self._oprot)
|
||||
self._oprot.writeMessageEnd()
|
||||
self._oprot.trans.flush()
|
||||
|
||||
def recv_create(self):
|
||||
(fname, mtype, rseqid) = self._iprot.readMessageBegin()
|
||||
if mtype == TMessageType.EXCEPTION:
|
||||
x = TApplicationException()
|
||||
x.read(self._iprot)
|
||||
self._iprot.readMessageEnd()
|
||||
raise x
|
||||
result = create_result()
|
||||
result.read(self._iprot)
|
||||
self._iprot.readMessageEnd()
|
||||
return
|
||||
|
||||
def register_mo(self):
|
||||
self.send_register_mo()
|
||||
self.recv_register_mo()
|
||||
|
||||
def send_register_mo(self):
|
||||
self._oprot.writeMessageBegin('register_mo', TMessageType.CALL, self._seqid)
|
||||
args = register_mo_args()
|
||||
args.write(self._oprot)
|
||||
self._oprot.writeMessageEnd()
|
||||
self._oprot.trans.flush()
|
||||
|
||||
def recv_register_mo(self):
|
||||
(fname, mtype, rseqid) = self._iprot.readMessageBegin()
|
||||
if mtype == TMessageType.EXCEPTION:
|
||||
x = TApplicationException()
|
||||
x.read(self._iprot)
|
||||
self._iprot.readMessageEnd()
|
||||
raise x
|
||||
result = register_mo_result()
|
||||
result.read(self._iprot)
|
||||
self._iprot.readMessageEnd()
|
||||
return
|
||||
|
||||
|
||||
class Processor(Iface, TProcessor):
|
||||
def __init__(self, handler):
|
||||
self._handler = handler
|
||||
self._processMap = {}
|
||||
self._processMap["create"] = Processor.process_create
|
||||
self._processMap["register_mo"] = Processor.process_register_mo
|
||||
|
||||
def process(self, iprot, oprot):
|
||||
(name, type, seqid) = iprot.readMessageBegin()
|
||||
if name not in self._processMap:
|
||||
iprot.skip(TType.STRUCT)
|
||||
iprot.readMessageEnd()
|
||||
x = TApplicationException(TApplicationException.UNKNOWN_METHOD, 'Unknown function %s' % (name))
|
||||
oprot.writeMessageBegin(name, TMessageType.EXCEPTION, seqid)
|
||||
x.write(oprot)
|
||||
oprot.writeMessageEnd()
|
||||
oprot.trans.flush()
|
||||
return
|
||||
else:
|
||||
self._processMap[name](self, seqid, iprot, oprot)
|
||||
return True
|
||||
|
||||
def process_create(self, seqid, iprot, oprot):
|
||||
args = create_args()
|
||||
args.read(iprot)
|
||||
iprot.readMessageEnd()
|
||||
result = create_result()
|
||||
self._handler.create()
|
||||
oprot.writeMessageBegin("create", TMessageType.REPLY, seqid)
|
||||
result.write(oprot)
|
||||
oprot.writeMessageEnd()
|
||||
oprot.trans.flush()
|
||||
|
||||
def process_register_mo(self, seqid, iprot, oprot):
|
||||
args = register_mo_args()
|
||||
args.read(iprot)
|
||||
iprot.readMessageEnd()
|
||||
result = register_mo_result()
|
||||
self._handler.register_mo()
|
||||
oprot.writeMessageBegin("register_mo", TMessageType.REPLY, seqid)
|
||||
result.write(oprot)
|
||||
oprot.writeMessageEnd()
|
||||
oprot.trans.flush()
|
||||
|
||||
|
||||
# HELPER FUNCTIONS AND STRUCTURES
|
||||
|
||||
class create_args:
|
||||
|
||||
thrift_spec = (
|
||||
)
|
||||
|
||||
def read(self, iprot):
|
||||
if iprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and isinstance(iprot.trans, TTransport.CReadableTransport) and self.thrift_spec is not None and fastbinary is not None:
|
||||
fastbinary.decode_binary(self, iprot.trans, (self.__class__, self.thrift_spec))
|
||||
return
|
||||
iprot.readStructBegin()
|
||||
while True:
|
||||
(fname, ftype, fid) = iprot.readFieldBegin()
|
||||
if ftype == TType.STOP:
|
||||
break
|
||||
else:
|
||||
iprot.skip(ftype)
|
||||
iprot.readFieldEnd()
|
||||
iprot.readStructEnd()
|
||||
|
||||
def write(self, oprot):
|
||||
if oprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and self.thrift_spec is not None and fastbinary is not None:
|
||||
oprot.trans.write(fastbinary.encode_binary(self, (self.__class__, self.thrift_spec)))
|
||||
return
|
||||
oprot.writeStructBegin('create_args')
|
||||
oprot.writeFieldStop()
|
||||
oprot.writeStructEnd()
|
||||
|
||||
def validate(self):
|
||||
return
|
||||
|
||||
|
||||
def __repr__(self):
|
||||
L = ['%s=%r' % (key, value)
|
||||
for key, value in self.__dict__.iteritems()]
|
||||
return '%s(%s)' % (self.__class__.__name__, ', '.join(L))
|
||||
|
||||
def __eq__(self, other):
|
||||
return isinstance(other, self.__class__) and self.__dict__ == other.__dict__
|
||||
|
||||
def __ne__(self, other):
|
||||
return not (self == other)
|
||||
|
||||
class create_result:
|
||||
|
||||
thrift_spec = (
|
||||
)
|
||||
|
||||
def read(self, iprot):
|
||||
if iprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and isinstance(iprot.trans, TTransport.CReadableTransport) and self.thrift_spec is not None and fastbinary is not None:
|
||||
fastbinary.decode_binary(self, iprot.trans, (self.__class__, self.thrift_spec))
|
||||
return
|
||||
iprot.readStructBegin()
|
||||
while True:
|
||||
(fname, ftype, fid) = iprot.readFieldBegin()
|
||||
if ftype == TType.STOP:
|
||||
break
|
||||
else:
|
||||
iprot.skip(ftype)
|
||||
iprot.readFieldEnd()
|
||||
iprot.readStructEnd()
|
||||
|
||||
def write(self, oprot):
|
||||
if oprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and self.thrift_spec is not None and fastbinary is not None:
|
||||
oprot.trans.write(fastbinary.encode_binary(self, (self.__class__, self.thrift_spec)))
|
||||
return
|
||||
oprot.writeStructBegin('create_result')
|
||||
oprot.writeFieldStop()
|
||||
oprot.writeStructEnd()
|
||||
|
||||
def validate(self):
|
||||
return
|
||||
|
||||
|
||||
def __repr__(self):
|
||||
L = ['%s=%r' % (key, value)
|
||||
for key, value in self.__dict__.iteritems()]
|
||||
return '%s(%s)' % (self.__class__.__name__, ', '.join(L))
|
||||
|
||||
def __eq__(self, other):
|
||||
return isinstance(other, self.__class__) and self.__dict__ == other.__dict__
|
||||
|
||||
def __ne__(self, other):
|
||||
return not (self == other)
|
||||
|
||||
class register_mo_args:
|
||||
|
||||
thrift_spec = (
|
||||
)
|
||||
|
||||
def read(self, iprot):
|
||||
if iprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and isinstance(iprot.trans, TTransport.CReadableTransport) and self.thrift_spec is not None and fastbinary is not None:
|
||||
fastbinary.decode_binary(self, iprot.trans, (self.__class__, self.thrift_spec))
|
||||
return
|
||||
iprot.readStructBegin()
|
||||
while True:
|
||||
(fname, ftype, fid) = iprot.readFieldBegin()
|
||||
if ftype == TType.STOP:
|
||||
break
|
||||
else:
|
||||
iprot.skip(ftype)
|
||||
iprot.readFieldEnd()
|
||||
iprot.readStructEnd()
|
||||
|
||||
def write(self, oprot):
|
||||
if oprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and self.thrift_spec is not None and fastbinary is not None:
|
||||
oprot.trans.write(fastbinary.encode_binary(self, (self.__class__, self.thrift_spec)))
|
||||
return
|
||||
oprot.writeStructBegin('register_mo_args')
|
||||
oprot.writeFieldStop()
|
||||
oprot.writeStructEnd()
|
||||
|
||||
def validate(self):
|
||||
return
|
||||
|
||||
|
||||
def __repr__(self):
|
||||
L = ['%s=%r' % (key, value)
|
||||
for key, value in self.__dict__.iteritems()]
|
||||
return '%s(%s)' % (self.__class__.__name__, ', '.join(L))
|
||||
|
||||
def __eq__(self, other):
|
||||
return isinstance(other, self.__class__) and self.__dict__ == other.__dict__
|
||||
|
||||
def __ne__(self, other):
|
||||
return not (self == other)
|
||||
|
||||
class register_mo_result:
|
||||
|
||||
thrift_spec = (
|
||||
)
|
||||
|
||||
def read(self, iprot):
|
||||
if iprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and isinstance(iprot.trans, TTransport.CReadableTransport) and self.thrift_spec is not None and fastbinary is not None:
|
||||
fastbinary.decode_binary(self, iprot.trans, (self.__class__, self.thrift_spec))
|
||||
return
|
||||
iprot.readStructBegin()
|
||||
while True:
|
||||
(fname, ftype, fid) = iprot.readFieldBegin()
|
||||
if ftype == TType.STOP:
|
||||
break
|
||||
else:
|
||||
iprot.skip(ftype)
|
||||
iprot.readFieldEnd()
|
||||
iprot.readStructEnd()
|
||||
|
||||
def write(self, oprot):
|
||||
if oprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and self.thrift_spec is not None and fastbinary is not None:
|
||||
oprot.trans.write(fastbinary.encode_binary(self, (self.__class__, self.thrift_spec)))
|
||||
return
|
||||
oprot.writeStructBegin('register_mo_result')
|
||||
oprot.writeFieldStop()
|
||||
oprot.writeStructEnd()
|
||||
|
||||
def validate(self):
|
||||
return
|
||||
|
||||
|
||||
def __repr__(self):
|
||||
L = ['%s=%r' % (key, value)
|
||||
for key, value in self.__dict__.iteritems()]
|
||||
return '%s(%s)' % (self.__class__.__name__, ', '.join(L))
|
||||
|
||||
def __eq__(self, other):
|
||||
return isinstance(other, self.__class__) and self.__dict__ == other.__dict__
|
||||
|
||||
def __ne__(self, other):
|
||||
return not (self == other)
|
|
@ -0,0 +1 @@
|
|||
__all__ = ['ttypes', 'constants', 'KMIP']
|
|
@ -0,0 +1,11 @@
|
|||
#
|
||||
# Autogenerated by Thrift Compiler (0.9.1)
|
||||
#
|
||||
# DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
|
||||
#
|
||||
# options string: py
|
||||
#
|
||||
|
||||
from thrift.Thrift import TType, TMessageType, TException, TApplicationException
|
||||
from ttypes import *
|
||||
|
|
@ -0,0 +1,18 @@
|
|||
#
|
||||
# Autogenerated by Thrift Compiler (0.9.1)
|
||||
#
|
||||
# DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
|
||||
#
|
||||
# options string: py
|
||||
#
|
||||
|
||||
from thrift.Thrift import TType, TMessageType, TException, TApplicationException
|
||||
|
||||
from thrift.transport import TTransport
|
||||
from thrift.protocol import TBinaryProtocol, TProtocol
|
||||
try:
|
||||
from thrift.protocol import fastbinary
|
||||
except:
|
||||
fastbinary = None
|
||||
|
||||
|
|
@ -0,0 +1 @@
|
|||
# TODO: Add any library dependencies here
|
|
@ -0,0 +1 @@
|
|||
# TODO: add any test requirements here
|
|
@ -0,0 +1,43 @@
|
|||
/**
|
||||
* This is the thrift definition file. It defines all of the methods and objects
|
||||
* for the KMIP server. This file is used by thrift to generate the plumbing for
|
||||
* a KMIP client and server.
|
||||
*
|
||||
* This file generated the files under kmip/thrift.
|
||||
*
|
||||
* If this file is updated then run the following command to update the
|
||||
* kmip/thrift directory.
|
||||
*
|
||||
* thrift -o kmip -r --gen py thrift/tutorial.thrift
|
||||
*/
|
||||
|
||||
/**
|
||||
* The first thing to know about are types. The available types in Thrift are:
|
||||
*
|
||||
* bool Boolean, one byte
|
||||
* byte Signed byte
|
||||
* i16 Signed 16-bit integer
|
||||
* i32 Signed 32-bit integer
|
||||
* i64 Signed 64-bit integer
|
||||
* double 64-bit floating point value
|
||||
* string String
|
||||
* binary Blob (byte array)
|
||||
* map<t1,t2> Map from one type to another
|
||||
* list<t1> Ordered list of one type
|
||||
* set<t1> Set of unique elements of one type
|
||||
*
|
||||
*/
|
||||
|
||||
namespace cpp thrift
|
||||
namespace d thrift
|
||||
namespace java thrift
|
||||
namespace php thrift
|
||||
namespace perl thrift
|
||||
|
||||
service KMIP {
|
||||
|
||||
void create(),
|
||||
/* Did not use register because it is a reserved word */
|
||||
void register_mo()
|
||||
|
||||
}
|
Loading…
Reference in New Issue