27527aa759a5c264343e3aa710520505038ee425
2 Distributed Cloud Emulator (dcemulator)
3 (c) 2015 by Manuel Peuster <manuel.peuster@upb.de>
11 logging
.basicConfig(level
=logging
.INFO
)
14 class ZeroRpcApiEndpointDCNetwork(object):
16 Simple API endpoint that offers a zerorpc-based
17 interface. This interface will be used by the
18 default command line client.
19 It can be used as a reference to implement
20 REST interfaces providing the same semantics,
21 like e.g. OpenStack compute API.
24 def __init__(self
, listenip
, port
, DCNetwork
=None):
26 self
.connectDCNetwork(DCNetwork
)
29 logging
.debug("Created monitoring API endpoint %s(%s:%d)" % (
30 self
.__class
__.__name
__, self
.ip
, self
.port
))
32 def connectDCNetwork(self
, net
):
34 logging
.info("Connected DCNetwork to API endpoint %s(%s:%d)" % (
35 self
.__class
__.__name
__, self
.ip
, self
.port
))
38 thread
= threading
.Thread(target
=self
._api
_server
_thread
, args
=())
41 logging
.debug("Started API endpoint %s(%s:%d)" % (
42 self
.__class
__.__name
__, self
.ip
, self
.port
))
44 def _api_server_thread(self
):
45 s
= zerorpc
.Server(DCNetworkApi(self
.net
))
46 s
.bind("tcp://%s:%d" % (self
.ip
, self
.port
))
50 logging
.info("Stop the monitoring API endpoint")
54 class DCNetworkApi(object):
56 The networking and monitoring commands need the scope of the
57 whole DC network to find the requested vnf. So this API is intended
58 to work with a DCNetwork.
59 Just pass through the corresponding request to the
60 selected data center network. Do not implement provisioning
61 logic here because will will have multiple API
62 endpoint implementations at the end.
65 def __init__(self
, net
):
68 def network_action_start(self
, vnf_src_name
, vnf_dst_name
):
69 # call DCNetwork method, not really datacenter specific API for now...
70 # provided dc name needs to be part of API endpoint
71 # no check if vnfs are really connected to this datacenter...
72 logging
.debug("RPC CALL: network chain start")
74 c
= self
.net
.setChain(
75 vnf_src_name
, vnf_dst_name
)
77 except Exception as ex
:
78 logging
.exception("RPC error.")
81 def network_action_stop(self
, vnf_src_name
, vnf_dst_name
):
82 # call DCNetwork method, not really datacenter specific API for now...
83 # provided dc name needs to be part of API endpoint
84 # no check if vnfs are really connected to this datacenter...
85 logging
.debug("RPC CALL: network chain stop")
87 c
= self
.net
.setChain(
88 vnf_src_name
, vnf_dst_name
, cmd
='del-flows')
90 except Exception as ex
:
91 logging
.exception("RPC error.")
94 # get egress(default) or ingress rate of a vnf
95 def monitor_get_rate(self
, vnf_name
, direction
):
96 logging
.debug("RPC CALL: get rate")
98 c
= self
.net
.monitor_agent
.get_rate(vnf_name
, direction
)
100 except Exception as ex
:
101 logging
.exception("RPC error.")