Skip to content
Snippets Groups Projects
Commit f4f95e12 authored by garciadeblas's avatar garciadeblas
Browse files

Juniper Contrail SDN plugin


Change-Id: I14987a321218b5cda98e6c4be68ae4a86596a2de
Signed-off-by: default avatargarciadeblas <gerardo.garciadeblas@telefonica.com>
parent f9ce4e43
No related branches found
No related tags found
No related merge requests found
......@@ -58,6 +58,7 @@ RUN /root/RO/RO/osm_ro/scripts/install-osm-im.sh --develop && \
python3 -m pip install -e /root/RO/RO-SDN-odl_openflow && \
python3 -m pip install -e /root/RO/RO-SDN-floodlight_openflow && \
python3 -m pip install -e /root/RO/RO-SDN-arista && \
python3 -m pip install -e /root/RO/RO-SDN-juniper_contrail && \
rm -rf /root/.cache && \
apt-get clean && \
rm -rf /var/lib/apt/lists/*
......
##
# 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.
##
all: clean package
clean:
rm -rf dist deb_dist osm_rosdn_juniper_contrail-*.tar.gz osm_rosdn_juniper_contrail.egg-info .eggs
package:
python3 setup.py --command-packages=stdeb.command sdist_dsc
cd deb_dist/osm-rosdn-juniper-contrail*/ && dpkg-buildpackage -rfakeroot -uc -us
# Copyright 2020 ETSI
#
# All Rights Reserved.
#
# 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.
from io import BytesIO
import pycurl
import json
import copy
class HttpException(Exception):
pass
class NotFound(HttpException):
pass
class Http(object):
def __init__(self, logger):
self._logger = logger
self._response_headers = None
def _check_http_response(self, http_code, data):
if http_code >= 300:
resp = ""
if data.getvalue():
data_text = data.getvalue().decode()
self._logger.info("Response {} DATA: {}".format(http_code, data_text))
resp = ": " + data_text
else:
self._logger.info("Response {}".format(http_code))
if http_code == 404:
raise NotFound("Error {}{}".format(http_code, resp))
raise HttpException("Error {}{}".format(http_code, resp))
def _get_curl_cmd(self, url, headers):
self._logger.debug("")
curl_cmd = pycurl.Curl()
curl_cmd.setopt(pycurl.URL, url)
curl_cmd.setopt(pycurl.SSL_VERIFYPEER, 0)
curl_cmd.setopt(pycurl.SSL_VERIFYHOST, 0)
if headers:
curl_cmd.setopt(pycurl.HTTPHEADER, headers)
return curl_cmd
def get_cmd(self, url, headers):
self._logger.debug("")
data = BytesIO()
curl_cmd = self._get_curl_cmd(url, headers)
curl_cmd.setopt(pycurl.HTTPGET, 1)
curl_cmd.setopt(pycurl.WRITEFUNCTION, data.write)
self._logger.info("Request METHOD: {} URL: {}".format("GET", url))
curl_cmd.perform()
http_code = curl_cmd.getinfo(pycurl.HTTP_CODE)
self._logger.info("Response HTTPCODE: {}".format(http_code))
curl_cmd.close()
if data.getvalue():
data_text = data.getvalue().decode()
self._logger.debug("Response DATA: {}".format(data_text))
return http_code, data_text
return http_code, None
def delete_cmd(self, url, headers):
self._logger.debug("")
data = BytesIO()
curl_cmd = self._get_curl_cmd(url, headers)
curl_cmd.setopt(pycurl.CUSTOMREQUEST, "DELETE")
curl_cmd.setopt(pycurl.WRITEFUNCTION, data.write)
self._logger.info("Request METHOD: {} URL: {}".format("DELETE", url))
curl_cmd.perform()
http_code = curl_cmd.getinfo(pycurl.HTTP_CODE)
self._logger.info("Response HTTPCODE: {}".format(http_code))
curl_cmd.close()
self._check_http_response(http_code, data)
# TODO 202 accepted should be returned somehow
if data.getvalue():
data_text = data.getvalue().decode()
self._logger.debug("Response DATA: {}".format(data_text))
return http_code, data_text
else:
self._logger.debug("Response DATA: NONE")
return http_code, None
def header_function(self, header_line):
header_line = header_line.decode('iso-8859-1')
if ':' not in header_line:
return
name, value = header_line.split(':', 1)
name = name.strip()
value = value.strip()
name = name.lower()
self._response_headers[name] = value
def post_cmd(self, url, headers, postfields_dict=None, return_header=None):
self._logger.debug('url: {}, headers: {}, postfields_dict: {}, return_header: {}'.format(url, headers, postfields_dict, return_header))
data = BytesIO()
curl_cmd = self._get_curl_cmd(url, headers)
curl_cmd.setopt(pycurl.POST, 1)
curl_cmd.setopt(pycurl.WRITEFUNCTION, data.write)
if return_header:
self._response_headers = {}
curl_cmd.setopt(pycurl.HEADERFUNCTION, self.header_function)
jsondata = json.dumps(postfields_dict)
if postfields_dict.get('auth',{}).get('identity',{}).get('password',{}).get('user',{}).get('password'):
postfields_dict_copy = copy.deepcopy(postfields_dict)
postfields_dict_copy['auth']['identity']['password']['user']['password'] = '******'
jsondata_log = json.dumps(postfields_dict_copy)
else:
jsondata_log = jsondata
self._logger.debug("Request POSTFIELDS: {}".format(jsondata_log))
curl_cmd.setopt(pycurl.POSTFIELDS, jsondata)
self._logger.info("Request METHOD: {} URL: {}".format("POST", url))
curl_cmd.perform()
http_code = curl_cmd.getinfo(pycurl.HTTP_CODE)
self._logger.info("Response HTTPCODE: {}".format(http_code))
curl_cmd.close()
if return_header:
data_text = self._response_headers.get(return_header)
self._logger.debug("Response HEADER: {}".format(data_text))
return http_code, data_text
if data.getvalue():
data_text = data.getvalue().decode()
self._logger.debug("Response DATA: {}".format(data_text))
return http_code, data_text
else:
return http_code, None
##
# 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.
##
#requests
pycurl
git+https://osm.etsi.org/gerrit/osm/RO.git#egg=osm-ro&subdirectory=RO
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
##
# 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.
##
from setuptools import setup
_name = "osm_rosdn_juniper_contrail"
README = """
===========
osm-rosdn_juniper_contrail
===========
osm-ro plugin for Juniper Contrail SDN
"""
setup(
name=_name,
description='OSM RO SDN plugin for Juniper Contrail',
long_description=README,
version_command=('git describe --match v* --tags --long --dirty', 'pep440-git-full'),
# version=VERSION,
# python_requires='>3.5.0',
author='ETSI OSM',
author_email='OSM_TECH@list.etsi.org',
maintainer='ETSI OSM',
maintainer_email='OSM_TECH@list.etsi.org',
url='https://osm.etsi.org/gitweb/?p=osm/RO.git;a=summary',
license='Apache 2.0',
packages=[_name],
include_package_data=True,
#dependency_links=["git+https://osm.etsi.org/gerrit/osm/RO.git#egg=osm-ro"],
install_requires=[
"pycurl",
#"requests",
"osm-ro @ git+https://osm.etsi.org/gerrit/osm/RO.git#egg=osm-ro&subdirectory=RO"
],
setup_requires=['setuptools-version-command'],
entry_points={
'osm_rosdn.plugins': ['rosdn_juniper_contrail = osm_rosdn_juniper_contrail.sdn_assist_juniper_contrail:JuniperContrail'],
},
)
#
# 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.
#
[DEFAULT]
X-Python3-Version : >= 3.5
Depends3: python3-pycurl, python3-osm-ro
#Depends3: python3-requests, python3-osm-ro
##
# 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.
##
[tox]
envlist = py3
toxworkdir={homedir}/.tox
[testenv]
basepython = python3
install_command = python3 -m pip install -r requirements.txt -U {opts} {packages}
# deps = -r{toxinidir}/test-requirements.txt
commands=python3 -m unittest discover -v
[testenv:flake8]
basepython = python3
deps = flake8
commands = flake8 osm_rosdn_juniper_contrail --max-line-length 120 \
--exclude .svn,CVS,.gz,.git,__pycache__,.tox,local,temp --ignore W291,W293,E226,W504
[testenv:unittest]
basepython = python3
commands = python3 -m unittest osm_rosdn_juniper_contrail.tests
[testenv:build]
basepython = python3
deps = stdeb
setuptools-version-command
commands = python3 setup.py --command-packages=stdeb.command bdist_deb
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment