Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions devstack/lib/nfp
Original file line number Diff line number Diff line change
Expand Up @@ -362,10 +362,10 @@ function copy_nfp_files_and_start_process {
echo "Starting config_orch >>>> under screen named : config_orch"
run_process config_orch "sudo /usr/bin/nfp --config-file /etc/nfp_config_orch.ini --config-file /etc/neutron/neutron.conf --log-file /opt/stack/logs/nfp_config_orch.log"
else
cd base_configurator/api
cd pecan/api
sudo python setup.py develop
echo "Starting base_configurator >>>> under screen named : base_configurator"
run_process base_configurator "cd /opt/stack/gbp/gbpservice/nfp/base_configurator/api;sudo ip netns exec nfp-proxy pecan serve config.py"
run_process base_configurator "cd /opt/stack/gbp/gbpservice/nfp/pecan/api;sudo ip netns exec nfp-proxy pecan configurator_decider config.py --mode base"
fi
sleep 1

Expand Down
31 changes: 0 additions & 31 deletions gbpservice/nfp/base_configurator/api/root_controller.py

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,19 @@

import pecan

import controller
from gbpservice.nfp.base_configurator.controllers import controller

"""This class forwards HTTP request to controller class.

This class create an object of Controller class with appropriate
parameter according to the path of HTTP request. According to the
parameter passed to Controller class it sends an RPC call/cast to
configurator.

"""
class ControllerResolver(object):

"""This class forwards HTTP request to controller class.

class ControllerResolver(object):
This class create an object of Controller class with appropriate
parameter according to the path of HTTP request. According to the
parameter passed to Controller class it sends an RPC call/cast to
configurator.

"""
create_network_function_device_config = controller.Controller(
"create_network_function_device_config")
delete_network_function_device_config = controller.Controller(
Expand All @@ -41,22 +40,19 @@ class ControllerResolver(object):
get_notifications = controller.Controller("get_notifications")


""" This class forwards HTTP requests starting with /v1/nfp.

All HTTP requests with path starting from /v1
land here. This class forward request with path starting from /v1/nfp
to ControllerResolver.

"""
class V1Controller(object):
""" This class forwards HTTP requests starting with /v1/nfp.

All HTTP requests with path starting from /v1
land here. This class forward request with path starting from /v1/nfp
to ControllerResolver.

class V1Controller(object):
"""

nfp = ControllerResolver()

@pecan.expose()
def get(self):
# TODO(blogan): decide what exactly should be here, if anything
return {'versions': [{'status': 'CURRENT',
'updated': '2014-12-11T00:00:00Z',
'id': 'v1'}]}
Original file line number Diff line number Diff line change
Expand Up @@ -18,28 +18,28 @@
import subprocess
import time

from gbpservice.nfp.base_configurator.api.base_controller import BaseController
from gbpservice.nfp.base_configurator.base_controller import BaseController

LOG = logging.getLogger(__name__)
TOPIC = 'configurator'
NFP_SERVICE_LIST = ['heat', 'ansible']
SUCCESS_RESULTS = ['unhandled', 'success']
FAILURE = 'failure'

"""Implements all the APIs Invoked by HTTP requests.

Implements following HTTP methods.
-get
-post

"""

notifications = []
cache_ips = set()


class Controller(BaseController):

"""Implements all the APIs Invoked by HTTP requests.

Implements following HTTP methods.
-get
-post

"""
def __init__(self, method_name):
try:
self.method_name = method_name
Expand Down Expand Up @@ -188,64 +188,6 @@ def post(self, **body):
error_data = self._format_description(msg)
return jsonutils.dumps(error_data)

@pecan.expose(method='PUT', content_type='application/json')
def put(self, **body):
"""Method of REST server to handle all the put requests.

This method sends an RPC cast to configurator according to the
HTTP request.

:param body: This method excepts dictionary as a parameter in HTTP
request and send this dictionary to configurator with RPC cast.

Returns: None

"""

try:
global cache_ips
global notifications
body = None
if pecan.request.is_body_readable:
body = pecan.request.json_body

# Assuming config list will have only one element
config_data = body['config'][0]
context = body['info']['context']
service_type = body['info']['service_type']
resource = config_data['resource']

if 'device_ip' in context:
msg = ("PUTTING DATA TO VM :: %s" % body)
LOG.info(msg)
device_ip = context['device_ip']
ip = str(device_ip)
is_vm_reachable = self._verify_vm_reachability(ip,
self.vm_port)
if is_vm_reachable:
requests.post(
'http://' + ip + ':' + self.vm_port + '/v1/nfp/' +
self.method_name, data=jsonutils.dumps(body))
else:
raise Exception('VM is not reachable')
cache_ips.add(device_ip)
else:
if (resource in NFP_SERVICE_LIST):
result = "unhandled"
self._push_notification(context,
result, config_data, service_type)
else:
result = "error"
self._push_notification(context,
result, config_data, service_type)
except Exception as err:
pecan.response.status = 400
msg = ("Failed to serve HTTP post request %s %s."
% (self.method_name, str(err).capitalize()))
LOG.error(msg)
error_data = self._format_description(msg)
return jsonutils.dumps(error_data)

def _format_description(self, msg):
"""This methgod formats error description.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,3 @@
}
}
}

# Custom Configurations must be in Python dictionary format::
#
# foo = {'bar':'baz'}
#
# All configurations are accessible at::
# pecan.conf
31 changes: 31 additions & 0 deletions gbpservice/nfp/pecan/api/configurator_decider.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# 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
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.

import pecan

from gbpservice.nfp.pecan import constants


class DecideConfigurator(pecan.commands.serve.ServeCommand):
''' decides the type of configurtor to be used
like base_configurator or reference_configurator
'''
arguments = pecan.commands.serve.ServeCommand.arguments + ({
'name': '--mode',
'help': 'decides the type of configurtor to be used',
'choices': constants.modes,
},)

def run(self, args):
setattr(pecan, 'mode', args.mode)
super(DecideConfigurator, self).run(args)

Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,29 @@

import pecan

from v1 import controllers
from gbpservice.nfp.pecan import constants


class RootController(object):
"""This is root controller that forward the request to __init__.py
file inside controller folder inside v1

"""
_controllers = {}

v1 = controllers.V1Controller()
for name, controller in constants.controllers.items():
_controllers.update({name: __import__(controller,
globals(),
locals(),
['controllers'], -1)})

if pecan.mode == constants.base_with_vm:
v1 = _controllers[constants.REFERENCE_CONTROLLER].V1Controller()
elif pecan.mode == constants.base:
v1 = _controllers[constants.BASE_CONTROLLER].V1Controller()

@pecan.expose()
def get(self):
# TODO(blogan): once a decision is made on how to do versions, do that
# here
return {'versions': [{'status': 'CURRENT',
'updated': '2014-12-11T00:00:00Z',
'id': 'v1'}]}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
# License for the specific language governing permissions and limitations
# under the License.

# -*- coding: utf-8 -*-
try:
import setuptools
except ImportError:
Expand All @@ -30,5 +29,11 @@
test_suite='api',
zip_safe=False,
include_package_data=True,
packages=setuptools.find_packages(exclude=['ez_setup'])
packages=setuptools.find_packages(exclude=['ez_setup']),
# Having entry point gives the option to define custom classes
# to improve the flexibility in accessing different configurators
entry_points="""
[pecan.command]
configurator_decider = configurator_decider:DecideConfigurator
"""
)
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
def setup_app(config):

app_conf = dict(config.app)

return pecan.make_app(
app_conf.pop('root'),
logging=getattr(config, 'logging', {}),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,17 @@
# License for the specific language governing permissions and limitations
# under the License.

import pecan

BASE_CONTROLLER = 'base_controller'
REFERENCE_CONTROLLER = 'reference_controller'

def setup_app(config):

app_conf = dict(config.app)
controllers = {
BASE_CONTROLLER: 'gbpservice.nfp.base_configurator.controllers',
REFERENCE_CONTROLLER: ('gbpservice.tests.contrib'
'.nfp_service.reference_configurator.controllers')
}

return pecan.make_app(
app_conf.pop('root'),
logging=getattr(config, 'logging', {}),
**app_conf
)
base_with_vm = 'base_with_vm'
base = 'base'
modes = [base, base_with_vm]
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ def parse_json(j_file):
def get_nfp_branch_name_for_docker(file_path):
data = file(file_path)

for line in data:
if 'GBPSERVICE_BRANCH' in line:
for line in data:
if not line.lstrip().startswith('#') and 'GBPSERVICE_BRANCH' in line:
data.close()
return line.split('=')[1].rstrip()

Expand Down Expand Up @@ -163,8 +163,12 @@ def dib(nfp_branch_name):
elif element == 'nfp-reference-configurator':
image_name = 'nfp_reference_service'
service_dir = "%s/../nfp_service/" % cur_dir
pecan_dir = os.path.abspath(os.path.join(cur_dir,
'../../../nfp'))
service_dir = os.path.realpath(service_dir)
pecan_dir = os.path.realpath(pecan_dir)
os.environ['SERVICE_GIT_PATH'] = service_dir
os.environ['PECAN_GIT_PATH'] = pecan_dir
elif element == 'configurator':
image_name = 'configurator'
create_configurator_docker(nfp_branch_name)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
#! /bin/bash
set -eu

# copy the reference_configurator folder to VM at /root/
# copy the reference_configurator and pecan folders to VM at /root/
cp -rL ${SERVICE_GIT_PATH}/reference_configurator ${TMP_MOUNT_PATH}/root/
cp -rL ${PECAN_GIT_PATH}/pecan ${TMP_MOUNT_PATH}/root/

ls -lR ${TMP_MOUNT_PATH}/root/

Loading