summaryrefslogtreecommitdiffstats
path: root/vnfmgr/vnfmgr_odl
diff options
context:
space:
mode:
authorjose.lausuch <jose.lausuch@ericsson.com>2016-11-15 00:18:32 +0100
committerjose.lausuch <jose.lausuch@ericsson.com>2016-11-15 00:20:33 +0100
commit73c4d745bf2bba060dc8301a9127482f01318de1 (patch)
treed0f37c2e819b518f952dcfe743672f2be45685d4 /vnfmgr/vnfmgr_odl
parent55649ff33c7c92a0ba2d08ebf15a21f3df9ae781 (diff)
Fix all the flake8 violations in the repo
Change-Id: I05109298835c26a1927a490f8c21dd2ca7f77947 Signed-off-by: jose.lausuch <jose.lausuch@ericsson.com>
Diffstat (limited to 'vnfmgr/vnfmgr_odl')
-rwxr-xr-xvnfmgr/vnfmgr_odl/vnfmgr_odl.py297
1 files changed, 175 insertions, 122 deletions
diff --git a/vnfmgr/vnfmgr_odl/vnfmgr_odl.py b/vnfmgr/vnfmgr_odl/vnfmgr_odl.py
index 4d35aebb..6ac72b28 100755
--- a/vnfmgr/vnfmgr_odl/vnfmgr_odl.py
+++ b/vnfmgr/vnfmgr_odl/vnfmgr_odl.py
@@ -1,11 +1,5 @@
-#! /usr/bin/env python
+#!/usr/bin/env python
-__author__ = "Brady Johnson"
-__copyright__ = "Copyright(c) 2015, Ericsson, Inc."
-__license__ = "Apache License version 2.0"
-__version__ = "0.1"
-__email__ = "brady.allen.johnson@ericsson.com"
-__status__ = "beta"
import pdb
import os
import time
@@ -13,63 +7,88 @@ import requests
import json
import argparse
-PUT = 'PUT'
-GET = 'GET'
+__author__ = "Brady Johnson"
+__copyright__ = "Copyright(c) 2015, Ericsson, Inc."
+__license__ = "Apache License version 2.0"
+__version__ = "0.1"
+__email__ = "brady.allen.johnson@ericsson.com"
+__status__ = "beta"
+
+
+PUT = 'PUT'
+GET = 'GET'
POST = 'POST'
+
class Context(object):
"""
Context class to hold the configuration as specified on the command line
"""
+
def __init__(self):
- self.rest_path_prefix = 'sampleConfig'
- self.rest_path_sf = 'RestConf-SFs-HttpPut.json'
- self.rest_path_sf_sel = 'RestConf-SFselect-HttpPut.json'
- self.rest_path_sfc = 'RestConf-SFCs-HttpPut.json'
- self.rest_path_sff = 'RestConf-SFFs-HttpPut.json'
- self.rest_path_sfp = 'RestConf-SFPs-HttpPut.json'
- self.rest_path_acl = 'RestConf-ACLs-HttpPut.json'
- self.rest_path_rsp = 'RestConf-RSP-HttpPost.json'
-
- self.rest_url_sf = 'config/service-function:service-functions/'
- self.rest_url_sf_sel = 'config/service-function-scheduler-type:service-function-scheduler-types/'
- self.rest_url_sfc = 'config/service-function-chain:service-function-chains/'
- self.rest_url_sff = 'config/service-function-forwarder:service-function-forwarders/'
- self.rest_url_sfp = 'config/service-function-path:service-function-paths/'
- self.rest_url_rsp = 'operational/rendered-service-path:rendered-service-paths/'
- self.rest_url_rsp_rpc = 'operations/rendered-service-path:create-rendered-path'
- self.rest_url_acl = 'config/ietf-acl:access-lists/'
-
- self.http_headers = {'Content-Type' : 'application/json', 'Cache-Control' : 'no-cache'}
- self.http_server = 'localhost'
- self.url_base = ''
- self.http_port = '8181'
- self.interractive = True
- self.user = 'admin'
- self.pw = 'admin'
- self.batch_sf = False
- self.batch_sf_sel = False
- self.batch_sfc = False
- self.batch_sff = False
- self.batch_sfp = False
- self.batch_acl = False
- self.batch_rsp = False
- self.batch_query = False
+ self.rest_path_prefix = 'sampleConfig'
+ self.rest_path_sf = 'RestConf-SFs-HttpPut.json'
+ self.rest_path_sf_sel = 'RestConf-SFselect-HttpPut.json'
+ self.rest_path_sfc = 'RestConf-SFCs-HttpPut.json'
+ self.rest_path_sff = 'RestConf-SFFs-HttpPut.json'
+ self.rest_path_sfp = 'RestConf-SFPs-HttpPut.json'
+ self.rest_path_acl = 'RestConf-ACLs-HttpPut.json'
+ self.rest_path_rsp = 'RestConf-RSP-HttpPost.json'
+
+ self.rest_url_sf = 'config/service-function:service-functions/'
+ self.rest_url_sf_sel = ('config/service-function-scheduler-type:'
+ 'service-function-scheduler-types/')
+ self.rest_url_sfc = (
+ 'config/service-function-chain:service-function-chains/')
+ self.rest_url_sff = (
+ 'config/service-function-forwarder:service-function-forwarders/')
+ self.rest_url_sfp = (
+ 'config/service-function-path:service-function-paths/')
+ self.rest_url_rsp = (
+ 'operational/rendered-service-path:rendered-service-paths/')
+ self.rest_url_rsp_rpc = (
+ 'operations/rendered-service-path:create-rendered-path')
+ self.rest_url_acl = ('config/ietf-acl:access-lists/')
+
+ self.http_headers = {
+ 'Content-Type': 'application/json', 'Cache-Control': 'no-cache'}
+ self.http_server = 'localhost'
+ self.url_base = ''
+ self.http_port = '8181'
+ self.interractive = True
+ self.user = 'admin'
+ self.pw = 'admin'
+ self.batch_sf = False
+ self.batch_sf_sel = False
+ self.batch_sfc = False
+ self.batch_sff = False
+ self.batch_sfp = False
+ self.batch_acl = False
+ self.batch_rsp = False
+ self.batch_query = False
def set_path_prefix_paths(self, path_prefix):
self.rest_path_prefix = path_prefix
- self.rest_path_sf = os.path.join(self.rest_path_prefix, self.rest_path_sf)
- self.rest_path_sf_sel = os.path.join(self.rest_path_prefix, self.rest_path_sf_sel)
- self.rest_path_sfc = os.path.join(self.rest_path_prefix, self.rest_path_sfc)
- self.rest_path_sff = os.path.join(self.rest_path_prefix, self.rest_path_sff)
- self.rest_path_sfp = os.path.join(self.rest_path_prefix, self.rest_path_sfp)
- self.rest_path_acl = os.path.join(self.rest_path_prefix, self.rest_path_acl)
- self.rest_path_rsp = os.path.join(self.rest_path_prefix, self.rest_path_rsp)
+ self.rest_path_sf = os.path.join(
+ self.rest_path_prefix, self.rest_path_sf)
+ self.rest_path_sf_sel = os.path.join(
+ self.rest_path_prefix, self.rest_path_sf_sel)
+ self.rest_path_sfc = os.path.join(
+ self.rest_path_prefix, self.rest_path_sfc)
+ self.rest_path_sff = os.path.join(
+ self.rest_path_prefix, self.rest_path_sff)
+ self.rest_path_sfp = os.path.join(
+ self.rest_path_prefix, self.rest_path_sfp)
+ self.rest_path_acl = os.path.join(
+ self.rest_path_prefix, self.rest_path_acl)
+ self.rest_path_rsp = os.path.join(
+ self.rest_path_prefix, self.rest_path_rsp)
def get_cmd_line(context):
"""
- Create a command-line parser, parse the command line args, and process them.
+ Create a command-line parser, parse the command line args, and process
+ them.
Populate the Context object with the processed command-line args.
"""
@@ -127,7 +146,8 @@ def get_cmd_line(context):
opts.add_argument('--send-all', '-7',
dest='send_all',
action='store_true',
- help='Send all (SF, SFF, SFC, SFP, RSP, ACL) REST JSON messages')
+ help=('Send all (SF, SFF, SFC, SFP, RSP, ACL) '
+ 'REST JSON messages'))
opts.add_argument('--query-sfc', '-q',
dest='query_sfc',
action='store_true',
@@ -141,72 +161,83 @@ def get_cmd_line(context):
opts.add_argument('--rest-path-sf-sel',
default=context.rest_path_sf_sel,
dest='rest_path_sf_sel',
- help='Name of the SF Selection REST JSON file, relative to configured prefix')
+ help=('Name of the SF Selection REST JSON file, '
+ 'relative to configured prefix'))
opts.add_argument('--rest-path-sf', '-n',
default=context.rest_path_sf,
dest='rest_path_sf',
- help='Name of the SF REST JSON file, relative to configured prefix')
+ help=('Name of the SF REST JSON file, relative to '
+ 'configured prefix'))
opts.add_argument('--rest-path-sfc', '-c',
default=context.rest_path_sfc,
dest='rest_path_sfc',
- help='Name of the SFC REST JSON file, relative to configured prefix')
+ help=('Name of the SFC REST JSON file, relative to '
+ 'configured prefix'))
opts.add_argument('--rest-path-sff', '-f',
default=context.rest_path_sff,
dest='rest_path_sff',
- help='Name of the SFF REST JSON file, relative toconfigured prefix')
+ help=('Name of the SFF REST JSON file, relative '
+ 'to configured prefix'))
opts.add_argument('--rest-path-sfp', '-p',
default=context.rest_path_sfp,
dest='rest_path_sfp',
- help='Name of the SFP REST JSON file, relative to configured prefix')
+ help=('Name of the SFP REST JSON file, relative '
+ 'to configured prefix'))
opts.add_argument('--rest-path-rsp', '-r',
default=context.rest_path_rsp,
dest='rest_path_rsp',
- help='Name of the RSP REST JSON file, relative to configured prefix')
+ help=('Name of the RSP REST JSON file, relative '
+ 'to configured prefix'))
opts.add_argument('--rest-path-acl', '-a',
default=context.rest_path_acl,
dest='rest_path_acl',
- help='Name of the ACL REST JSON file, relative to configured prefix')
+ help=('Name of the ACL REST JSON file, relative '
+ 'to configured prefix'))
args = opts.parse_args()
- context.http_server = args.http_server
- context.http_port = args.http_port
- context.url_base = 'http://%s:%s/restconf/' % (context.http_server, context.http_port)
+ context.http_server = args.http_server
+ context.http_port = args.http_port
+ context.url_base = 'http://%s:%s/restconf/' % (
+ context.http_server, context.http_port)
context.rest_path_prefix = args.rest_path_prefix
- context.rest_path_sf = args.rest_path_sf
+ context.rest_path_sf = args.rest_path_sf
context.rest_path_sf_sel = args.rest_path_sf_sel
- context.rest_path_sfc = args.rest_path_sfc
- context.rest_path_sff = args.rest_path_sff
- context.rest_path_sfp = args.rest_path_sfp
- context.rest_path_acl = args.rest_path_acl
- context.rest_path_rsp = args.rest_path_rsp
+ context.rest_path_sfc = args.rest_path_sfc
+ context.rest_path_sff = args.rest_path_sff
+ context.rest_path_sfp = args.rest_path_sfp
+ context.rest_path_acl = args.rest_path_acl
+ context.rest_path_rsp = args.rest_path_rsp
context.set_path_prefix_paths(context.rest_path_prefix)
- for path in [context.rest_path_sf, context.rest_path_sfc, context.rest_path_sff, context.rest_path_sfp]:
+ for path in [context.rest_path_sf,
+ context.rest_path_sfc,
+ context.rest_path_sff,
+ context.rest_path_sfp]:
print '\tUsing REST file: %s' % path
if args.batch:
context.interractive = False
if args.send_all:
- context.batch_sf = True
- context.batch_sf_sel = True
- context.batch_sfc = True
- context.batch_sff = True
- context.batch_sfp = True
- context.batch_rsp = True
+ context.batch_sf = True
+ context.batch_sf_sel = True
+ context.batch_sfc = True
+ context.batch_sff = True
+ context.batch_sfp = True
+ context.batch_rsp = True
# TODO deactivated for now
- #context.batch_acl = True
+ # context.batch_acl = True
else:
- context.batch_sf = args.send_sf
- context.batch_sf_sel = args.send_sf_sel
- context.batch_sfc = args.send_sfc
- context.batch_sff = args.send_sff
- context.batch_sfp = args.send_sfp
- context.batch_rsp = args.send_rsp
+ context.batch_sf = args.send_sf
+ context.batch_sf_sel = args.send_sf_sel
+ context.batch_sfc = args.send_sfc
+ context.batch_sff = args.send_sff
+ context.batch_sfp = args.send_sfp
+ context.batch_rsp = args.send_rsp
# TODO deactivated for now
- #context.batch_acl = args.send_acl
- context.batch_query = args.query_sfc
+ # context.batch_acl = args.send_acl
+ context.batch_query = args.query_sfc
return True
@@ -218,7 +249,8 @@ def send_rest(context, operation, rest_url, rest_file=None):
context -- specifies the destination IP/Port and user/pw
operation -- specifies if the HTTP OP is one of: GET, PUT, or POST
rest_url -- the operation URL
- rest_file -- for PUT and POST operations, specifies where the JSON input is found
+ rest_file -- for PUT and POST operations, specifies where the JSON
+ input is found
"""
complete_url = '%s%s' % (context.url_base, rest_url)
@@ -230,24 +262,26 @@ def send_rest(context, operation, rest_url, rest_file=None):
try:
if operation == GET:
- r = requests.get(url = complete_url,
- headers = context.http_headers,
+ r = requests.get(url=complete_url,
+ headers=context.http_headers,
auth=(context.user, context.pw))
print '\nHTTP GET %s\nresult: %s' % (rest_url, r.status_code)
- #if len(r.text) > 1:
+ # if len(r.text) > 1:
if r.status_code >= 200 and r.status_code <= 299:
- print json.dumps(json.loads(r.text), indent=4, separators=(',', ': '))
+ print json.dumps(json.loads(r.text),
+ indent=4,
+ separators=(',', ': '))
elif operation == PUT:
if not rest_file:
print 'ERROR trying to PUT with empty REST file'
return False
- r = requests.put(url = complete_url,
+ r = requests.put(url=complete_url,
auth=(context.user, context.pw),
- data = json.dumps(json.load(open(rest_file, 'r'))),
- headers = context.http_headers)
+ data=json.dumps(json.load(open(rest_file, 'r'))),
+ headers=context.http_headers)
print '\nHTTP PUT %s\nresult: %s' % (rest_url, r.status_code)
elif operation == POST:
@@ -259,17 +293,19 @@ def send_rest(context, operation, rest_url, rest_file=None):
if len(post_list) > 1:
# This allows for multiple RSPs to be sent from one JSON file
for entry in post_list:
- r = requests.post(url = complete_url,
+ r = requests.post(url=complete_url,
auth=(context.user, context.pw),
- data = json.dumps(entry),
- headers = context.http_headers)
- print '\nHTTP POST %s\nresult: %s' % (rest_url, r.status_code)
+ data=json.dumps(entry),
+ headers=context.http_headers)
+ print '\nHTTP POST %s\nresult: %s' % (rest_url,
+ r.status_code)
else:
- r = requests.post(url = complete_url,
+ r = requests.post(url=complete_url,
auth=(context.user, context.pw),
- data = json.dumps(post_list),
- headers = context.http_headers)
- print '\nHTTP POST %s\nresult: %s' % (rest_url, r.status_code)
+ data=json.dumps(post_list),
+ headers=context.http_headers)
+ print '\nHTTP POST %s\nresult: %s' % (rest_url,
+ r.status_code)
else:
print 'ERROR: Invalid Operation: %s' % (operation)
@@ -285,6 +321,7 @@ def send_rest(context, operation, rest_url, rest_file=None):
return True
+
def validate_rest(context):
"""
For each JSON input file in context, validate the JSON syntax.
@@ -308,6 +345,7 @@ def validate_rest(context):
return True
+
def batch(context):
"""
Launch the application in batch mode and perform
@@ -317,9 +355,10 @@ def batch(context):
# The order of these if's is important
# If send-all was set, then each of these needs to be sent, in order
if context.batch_sf_sel:
- send_rest(context, PUT, context.rest_url_sf_sel, context.rest_path_sf_sel)
+ send_rest(
+ context, PUT, context.rest_url_sf_sel, context.rest_path_sf_sel)
if context.batch_sf:
- send_rest(context, PUT, context.rest_url_sf, context.rest_path_sf)
+ send_rest(context, PUT, context.rest_url_sf, context.rest_path_sf)
if context.batch_sff:
send_rest(context, PUT, context.rest_url_sff, context.rest_path_sff)
if context.batch_sfc:
@@ -327,7 +366,8 @@ def batch(context):
if context.batch_sfp:
send_rest(context, PUT, context.rest_url_sfp, context.rest_path_sfp)
if context.batch_rsp:
- send_rest(context, POST, context.rest_url_rsp_rpc, context.rest_path_rsp)
+ send_rest(
+ context, POST, context.rest_url_rsp_rpc, context.rest_path_rsp)
if context.batch_acl:
send_rest(context, PUT, context.rest_url_acl, context.rest_path_acl)
@@ -339,7 +379,7 @@ def batch(context):
send_rest(context, GET, context.rest_url_sfp)
send_rest(context, GET, context.rest_url_rsp)
# TODO deactivated for now
- #send_rest(context, GET, context.rest_url_acl)
+ # send_rest(context, GET, context.rest_url_acl)
def CLI(context):
@@ -360,37 +400,51 @@ def CLI(context):
print ' 6) Send ACL REST'
print ' 7) Send all ordered: (SFsel, SF, SFF, SFC, SFP, RSP)'
print ' 8) Query all: (SFsel, SF, SFF, SFC, SFP, RSP)'
- print ' 9) Change config file path, currently [%s]' % (context.rest_path_prefix)
+ print(' 9) Change config file path, currently [%s]' % (
+ context.rest_path_prefix))
print '10) Validate config files JSON syntax'
option = raw_input('=> ')
if option == '1':
- send_rest(context, PUT, context.rest_url_sf, context.rest_path_sf)
+ send_rest(context, PUT, context.rest_url_sf, context.rest_path_sf)
elif option == '2':
- send_rest(context, PUT, context.rest_url_sfc, context.rest_path_sfc)
+ send_rest(
+ context, PUT, context.rest_url_sfc, context.rest_path_sfc)
elif option == '3':
- send_rest(context, PUT, context.rest_url_sff, context.rest_path_sff)
+ send_rest(
+ context, PUT, context.rest_url_sff, context.rest_path_sff)
elif option == '4':
- send_rest(context, PUT, context.rest_url_sfp, context.rest_path_sfp)
+ send_rest(
+ context, PUT, context.rest_url_sfp, context.rest_path_sfp)
elif option == '5':
- send_rest(context, POST, context.rest_url_rsp_rpc, context.rest_path_rsp)
+ send_rest(
+ context, POST, context.rest_url_rsp_rpc, context.rest_path_rsp)
elif option == '6':
- send_rest(context, PUT, context.rest_url_acl, context.rest_path_acl)
+ send_rest(
+ context, PUT, context.rest_url_acl, context.rest_path_acl)
elif option == '7':
pdb.set_trace()
- send_rest(context, PUT, context.rest_url_sf_sel, context.rest_path_sf_sel)
- send_rest(context, PUT, context.rest_url_sf, context.rest_path_sf)
- send_rest(context, PUT, context.rest_url_sff, context.rest_path_sff)
- send_rest(context, PUT, context.rest_url_sfc, context.rest_path_sfc)
- send_rest(context, PUT, context.rest_url_sfp, context.rest_path_sfp)
- time.sleep(1);
- send_rest(context, POST, context.rest_url_rsp_rpc, context.rest_path_rsp)
+ send_rest(
+ context, PUT, context.rest_url_sf_sel,
+ context.rest_path_sf_sel)
+ send_rest(context, PUT, context.rest_url_sf, context.rest_path_sf)
+ send_rest(
+ context, PUT, context.rest_url_sff, context.rest_path_sff)
+ send_rest(
+ context, PUT, context.rest_url_sfc, context.rest_path_sfc)
+ send_rest(
+ context, PUT, context.rest_url_sfp, context.rest_path_sfp)
+ time.sleep(1)
+ send_rest(
+ context, POST, context.rest_url_rsp_rpc, context.rest_path_rsp)
# TODO ACL deactivated for now
- # Need to wait until the SFC creates the RSP internally before sending the ACL
- #print 'Sleeping 2 seconds while RSP being created'
- #time.sleep(2);
- #send_rest(context, PUT, context.rest_url_acl, context.rest_path_acl)
+ # Need to wait until the SFC creates the RSP internally
+ # before sending the ACL
+ # print 'Sleeping 2 seconds while RSP being created'
+ # time.sleep(2);
+ # send_rest(context, PUT, context.rest_url_acl,
+ # context.rest_path_acl)
elif option == '8':
send_rest(context, GET, context.rest_url_sf_sel)
send_rest(context, GET, context.rest_url_sf)
@@ -437,4 +491,3 @@ def main():
if __name__ == '__main__':
main()
-