#!/usr/bin/env python
-#Copyright 2015 Open Platform for NFV Project, Inc. and its contributors
+#Copyright 2016 Open Platform for NFV Project, Inc. and its contributors
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# limitations under the License.
-import sys, glob, threading
+import sys, os, glob, threading
import getopt, socket
-import logging
+import logging, errno
#sys.path.append('gen-py')
#sys.path.insert(0, glob.glob('./lib/py/build/lib.*')[0])
def __init__(self, dominoclient):
self.log = {}
self.dominoClient = dominoclient
- try:
- # Make socket
- transport = TSocket.TSocket(DOMINO_SERVER_IP, DOMINO_SERVER_PORT)
- transport.setTimeout(THRIFT_RPC_TIMEOUT_MS)
- # Add buffering to compensate for slow raw sockets
- self.transport = TTransport.TBufferedTransport(transport)
- # Wrap in a protocol
- self.protocol = TBinaryProtocol.TBinaryProtocol(self.transport)
- # Create a client to use the protocol encoder
- self.sender = Communication.Client(self.protocol)
- except Thrift.TException, tx:
- logging.error('%s' , tx.message)
+ self.transport = None
+ self.protocol = None
+ self.sender = None
# Template Push from Domino Server is received
# Actions:
def d_push(self, push_msg):
logging.info('%d Received Template File', self.dominoClient.UDID)
# Retrieve the template file
-
- ## End of retrieval
-
- # Any inspection code goes here
+ try:
+ os.makedirs(TOSCA_RX_DIR+str(self.dominoClient.UDID))
+ except OSError as exception:
+ if exception.errno == errno.EEXIST:
+ logging.debug('IGNORING error: ERRNO %d; %s exists.', exception.errno, TOSCA_RX_DIR+str(self.dominoClient.UDID))
+ else:
+ logging.error('IGNORING error in creating %s. Err no: %d', exception.errno)
+
+ try:
+ miscutil.write_templatefile(TOSCA_RX_DIR+str(self.dominoClient.UDID)+'/'+str(push_msg.seq_no)+'.yaml' , push_msg.template)
+ except:
+ logging.error('FAILED to write the pushed file: %s', sys.exc_info()[0])
+ push_r = PushResponseMessage()
+ # Fill response message fields
+ push_r.domino_udid = self.dominoClient.UDID
+ push_r.seq_no = self.dominoClient.seqno
+ push_r.responseCode = FAILED
+ self.dominoClient.seqno = self.dominoClient.seqno + 1
+ return push_r# Any inspection code goes here
## End of inspection
def openconnection(self):
- self.transport.open()
+ try:
+ # Make socket
+ transport = TSocket.TSocket(self.dominoClient.dominoserver_IP, DOMINO_SERVER_PORT)
+ transport.setTimeout(THRIFT_RPC_TIMEOUT_MS)
+ # Add buffering to compensate for slow raw sockets
+ self.transport = TTransport.TBufferedTransport(transport)
+ # Wrap in a protocol
+ self.protocol = TBinaryProtocol.TBinaryProtocol(self.transport)
+ # Create a client to use the protocol encoder
+ self.sender = Communication.Client(self.protocol)
+ self.transport.open()
+ except Thrift.TException, tx:
+ logging.error('%s' , tx.message)
def closeconnection():
self.transport.close()
CLIrespmsg.CLI_response = "Testing..."
return CLIrespmsg
-def read_templatefile(temp_filename):
- f = open(temp_filename, 'r')
- lines = f.read().splitlines()
-
- return lines
class DominoClientCLIService(threading.Thread):
def __init__(self, dominoclient, communicationhandler, interactive):
self.interactive = interactive
def process_input(self, args):
+ if len(args) == 0:
+ print 'Empty API body'
+ return
+
try:
if args[0] == 'heartbeat':
self.dominoclient.heartbeat()
class DominoClient:
def __init__(self):
+
+
self.communicationHandler = CommunicationHandler(self)
self.processor = None
self.transport = None
self.CLIservice = None
self.serviceport = 9091
- self.dominoserver_IP = 'localhost'
-
+ self.dominoserver_IP = DOMINO_SERVER_IP
self.CLIport = DOMINO_CLI_PORT
#Start from UNREGISTERED STATE
except (Thrift.TException, TSocket.TTransportException) as tx:
logging.error('%s' , tx.message)
except (socket.timeout) as tx:
- self.dominoclient.handle_RPC_timeout(pub_msg)
+ self.handle_RPC_timeout(reg_msg)
except (socket.error) as tx:
logging.error('%s' , tx.message)
self.seqno = self.seqno + 1
pub_msg.template_type = 'tosca-nfv-v1.0'
try:
- pub_msg.template = read_templatefile(toscafile)
+ pub_msg.template = miscutil.read_templatefile(toscafile)
except IOError as e:
logging.error('I/O error(%d): %s' , e.errno, e.strerror)
return
try:
pub_msg_r = self.sender().d_publish(pub_msg)
- logging.info('Publish Response is received from: %d ,sequence number: %d', pub_msg_r.domino_udid, pub_msg_r.seq_no)
+ logging.info('Publish Response is received from: %d ,sequence number: %d Op. Status: %d', pub_msg_r.domino_udid, pub_msg_r.seq_no, pub_msg_r.responseCode)
except (Thrift.TException, TSocket.TTransportException) as tx:
print '%s' % (tx.message)
except (socket.timeout) as tx:
try:
opts, args = getopt.getopt(argv,"hc:p:i:l:",["conf=","port=","ipaddr=","log=","iac=","cliport="])
except getopt.GetoptError:
- print 'DominoClient.py -c/--conf <configfile> -p/--port <socketport> -i/--ipaddr <IPaddr> -l/--log <loglevel> --iac=true/false'
+ print 'DominoClient.py -c/--conf <configfile> -p/--port <socketport> -i/--ipaddr <IPaddr> -l/--log <loglevel> --iac=true/false --cliport <cliport>'
sys.exit(2)
for opt, arg in opts:
if opt == '-h':
- print 'DominoClient.py -c/--conf <configfile> -p/--port <socketport> -i/--ipaddr <IPaddr> -l/--log <loglevel> --iac=true/false'
+ print 'DominoClient.py -c/--conf <configfile> -p/--port <socketport> -i/--ipaddr <IPaddr> -l/--log <loglevel> --iac=true/false --cliport <cliport>'
sys.exit()
elif opt in ("-c", "--conf"):
configfile = arg