From 8a07bcd6b75f62c7c79504f8a3c020a2d635156e Mon Sep 17 00:00:00 2001 From: Harry Huang Date: Thu, 16 Mar 2017 18:38:19 +0800 Subject: Add upload packages retry 1. retry 5 times if csar package uploads fail 2. clearwater service name varies over the time 3. use the word vnf instead of app Change-Id: Id85c7f467cbefbc46fd1f1daf6202d89ef3ac898 Signed-off-by: Harry Huang --- conf/application.yml | 12 -- conf/open-o.yml | 4 +- conf/vnf.yml | 13 ++ csar/clearwater/JUJU_clearwater.csar | Bin 1850996 -> 0 bytes csar/clearwater/pop_ns_juju.csar | Bin 58912 -> 0 bytes juju/deploy_application.py | 26 ---- juju/juju_connect.sh | 13 +- juju/openo_connect.py | 234 --------------------------------- juju/vims_deploy.sh | 16 ++- open-o/openo_docker.sh | 191 +++++++++++++-------------- opera/deploy_vnf.py | 28 ++++ opera/openo_connect.py | 244 +++++++++++++++++++++++++++++++++++ opera_launch.sh | 6 +- prepare.sh | 2 +- process_conf.py | 34 ++--- setup.py | 22 ++++ 16 files changed, 452 insertions(+), 393 deletions(-) delete mode 100644 conf/application.yml create mode 100644 conf/vnf.yml delete mode 100644 csar/clearwater/JUJU_clearwater.csar delete mode 100644 csar/clearwater/pop_ns_juju.csar delete mode 100755 juju/deploy_application.py delete mode 100755 juju/openo_connect.py create mode 100644 opera/deploy_vnf.py create mode 100755 opera/openo_connect.py create mode 100644 setup.py diff --git a/conf/application.yml b/conf/application.yml deleted file mode 100644 index 84f9eef..0000000 --- a/conf/application.yml +++ /dev/null @@ -1,12 +0,0 @@ -############################################################################## -# Copyright (c) 2016-2017 HUAWEI TECHNOLOGIES CO.,LTD and others. -# -# All rights reserved. This program and the accompanying materials -# are made available under the terms of the Apache License, Version 2.0 -# which accompanies this distribution, and is available at -# http://www.apache.org/licenses/LICENSE-2.0 -############################################################################## -application: - - name: clearwater - ns_pkg: pop_ns_juju.csar - vnf_pkg: JUJU_clearwater.csar diff --git a/conf/open-o.yml b/conf/open-o.yml index 1281376..fb77eae 100644 --- a/conf/open-o.yml +++ b/conf/open-o.yml @@ -10,4 +10,6 @@ openo_docker_net: nfvo_driver_vnfm_juju_port: 8483 nfvo_driver_vnfm_juju_mysql_port: 3306 -application: +enable_sdno: false + +vnf_type: diff --git a/conf/vnf.yml b/conf/vnf.yml new file mode 100644 index 0000000..68f4492 --- /dev/null +++ b/conf/vnf.yml @@ -0,0 +1,13 @@ +############################################################################## +# Copyright (c) 2016-2017 HUAWEI TECHNOLOGIES CO.,LTD and others. +# +# All rights reserved. This program and the accompanying materials +# are made available under the terms of the Apache License, Version 2.0 +# which accompanies this distribution, and is available at +# http://www.apache.org/licenses/LICENSE-2.0 +############################################################################## +vIMS: + - type: clearwater + ns_pkg: pop_ns_juju.csar + vnf_pkg: JUJU_clearwater.csar + nsdId: ns_cw_2016 diff --git a/csar/clearwater/JUJU_clearwater.csar b/csar/clearwater/JUJU_clearwater.csar deleted file mode 100644 index 7d11b9e..0000000 Binary files a/csar/clearwater/JUJU_clearwater.csar and /dev/null differ diff --git a/csar/clearwater/pop_ns_juju.csar b/csar/clearwater/pop_ns_juju.csar deleted file mode 100644 index a94f3c2..0000000 Binary files a/csar/clearwater/pop_ns_juju.csar and /dev/null differ diff --git a/juju/deploy_application.py b/juju/deploy_application.py deleted file mode 100755 index 22c7d9d..0000000 --- a/juju/deploy_application.py +++ /dev/null @@ -1,26 +0,0 @@ -#!/usr/bin/env python -############################################################################## -# Copyright (c) 2016-2017 HUAWEI TECHNOLOGIES CO.,LTD and others. -# -# All rights reserved. This program and the accompanying materials -# are made available under the terms of the Apache License, Version 2.0 -# which accompanies this distribution, and is available at -# http://www.apache.org/licenses/LICENSE-2.0 -############################################################################## - -import argparse -from openo_connect import create_service - - -if __name__ == "__main__": - - parser = argparse.ArgumentParser() - parser.add_argument("--application", action='store', default='', help="app name") - parser.add_argument("--msb_ip", action='store', help="common_services_msb ip") - - args = parser.parse_args() - application = args.application - msb_ip = args.msb_ip - - if application == 'clearwater': - create_service(msb_ip, application, 'vIMS', 'ns_cw_2016') diff --git a/juju/juju_connect.sh b/juju/juju_connect.sh index 43314b5..e4a94db 100755 --- a/juju/juju_connect.sh +++ b/juju/juju_connect.sh @@ -82,13 +82,20 @@ function start_tomcat() function openo_connect() { - python ${JUJU_DIR}/openo_connect.py --msb_ip $OPENO_IP:$COMMON_SERVICES_MSB_PORT \ + python ${OPERA_DIR}/opera/openo_connect.py --msb_ip $OPENO_IP:$COMMON_SERVICES_MSB_PORT \ --tosca_aria_ip $OPENO_IP \ --tosca_aria_port $COMMON_TOSCA_ARIA_PORT \ --juju_client_ip $juju_client_ip \ --auth_url $OS_AUTH_URL \ - --ns_pkg "${CSAR_DIR}/${APP_NS_PKG}" \ - --vnf_pkg "${CSAR_DIR}/${APP_VNF_PKG}" + --ns_pkg "${CSAR_DIR}/${NS_PKG}" \ + --vnf_pkg "${CSAR_DIR}/${VNF_PKG}" +} + +function deploy_vnf() +{ + python ${OPERA_DIR}/opera/deploy_vnf.py --msb_ip $OPENO_IP:$COMMON_SERVICES_MSB_PORT \ + --vnf $VNF_TYPE \ + --nsdId $NSDID } function fix_openo_containers() diff --git a/juju/openo_connect.py b/juju/openo_connect.py deleted file mode 100755 index 387ae98..0000000 --- a/juju/openo_connect.py +++ /dev/null @@ -1,234 +0,0 @@ -#!/usr/bin/env python -############################################################################## -# Copyright (c) 2016-2017 HUAWEI TECHNOLOGIES CO.,LTD and others. -# -# All rights reserved. This program and the accompanying materials -# are made available under the terms of the Apache License, Version 2.0 -# which accompanies this distribution, and is available at -# http://www.apache.org/licenses/LICENSE-2.0 -############################################################################## - -import argparse -import sys -import os -import time -import requests -import json -from pprint import pprint - - -class RaiseError(Exception): - def __init__(self, msg): - self.msg = msg - - def __str__(self): - return repr(self.msg) - - -def request_get(url): - try: - resp = requests.get(url) - if resp.status_code not in (200,201): - pprint (resp.json()) - raise RaiseError('get url: %s fail %d' % (url, resp.status_code)) - except Exception: - raise - - return resp.json() - - -def request_post(url, data, headers): - try: - resp = requests.post(url, data=json.dumps(data), headers=headers) - if resp.status_code not in (200,201,202): - pprint (resp.json()) - raise RaiseError('post url: %s fail %d' % (url, resp.status_code)) - except Exception: - raise - - return resp.json() - - -def request_delete(url): - try: - resp = requests.delete(url) - if resp.status_code not in (200,201,204): - pprint (resp.json()) - raise RaiseError('delete url: %s fail %d' % (url, resp.status_code)) - except Exception: - raise - - -def add_common_tosca_aria(msb_ip, tosca_aria_ip, tosca_aria_port): - url = 'http://' + msb_ip + '/openoapi/microservices/v1/apiRoute' - headers = {'Content-Type': 'application/json'} - data = {"serviceName":"tosca", - "version":"v1", - "url":"/openoapi/tosca/v1", - "metricsUrl":"/admin/metrics", - "apiJson":"/swagger.json", - "apiJsonType":"1", - "control":"0", - "status":"1", - "servers":[{"ip":tosca_aria_ip,"port":tosca_aria_port,"weight":0}]} - request_post(url, data, headers) - - -def get_vim_id(msb_ip, vim_type): - vim_url = 'http://' + msb_ip + '/openoapi/extsys/v1/vims/' - get_vim = request_get(vim_url) - vimId = [] - for i in get_vim: - if i["type"] == vim_type: - vimId.append(i['vimId']) - - return vimId - - -def add_openo_vim(msb_ip, auth_url): - vim_url = 'http://' + msb_ip + '/openoapi/extsys/v1/vims/' - vnfm_url = 'http://' + msb_ip + '/openoapi/extsys/v1/vnfms/' - headers = {'Content-Type': 'application/json'} - data = {"name":"openstack", - "url":auth_url, - "userName":"admin", - "password":"console", - "tenant":"admin", - "domain":"", - "vendor":"openstack", - "version":"newton", - "description":"", - "type":"openstack"} - vimId = get_vim_id(msb_ip, "openstack") - if len(vimId) != 0: - get_vnfm = request_get(vnfm_url) - for i in get_vnfm: - if i["vimId"] == vimId[0]: - request_delete(vnfm_url + i["vnfmId"]) - request_delete(vim_url + vimId[0]) - - request_post(vim_url, data, headers) - - -def add_openo_vnfm(msb_ip, juju_client_ip): - vim_url = 'http://' + msb_ip + '/openoapi/extsys/v1/vims/' - vnfm_url = 'http://' + msb_ip + '/openoapi/extsys/v1/vnfms/' - headers = {'Content-Type': 'application/json'} - vimId = get_vim_id(msb_ip, "openstack") - if len(vimId) == 0: - raise RaiseError("vim openstack not found") - - get_vnfm = request_get(vnfm_url) - for i in get_vnfm: - if i["vimId"] == vimId[0]: - request_delete(vnfm_url + i["vnfmId"]) - - data = {"name":"Juju-VNFM", - "vimId":vimId[0], - "vendor":"jujuvnfm", - "version":"jujuvnfm", - "type":"jujuvnfm", - "description":"", - "certificateUrl":"", - "url":"http://" + juju_client_ip + ":8483", - "userName":"", - "password":""} - request_post(vnfm_url, data, headers) - - -def upload_csar(msb_ip, package): - csar_url = 'http://' + msb_ip + '/openoapi/catalog/v1/csars' - files = {'file': open(package, 'rb')} - res = requests.post(csar_url, files=files) - if res.status_code != 200: - pprint(res.json()) - raise Exception('Error with uploading csar package: %s' % package) - - -def delete_csars(msb_ip): - csar_url = 'http://' + msb_ip + '/openoapi/catalog/v1/csars/' - csars = request_get(csar_url) - for csar in csars: - csarId = csar["csarId"] - request_delete(csar_url + csarId) - pprint("csar %s is deleted" % csarId) - - -def package_onboard(msb_ip): - csar_url = 'http://' + msb_ip + '/openoapi/catalog/v1/csars' - vnf_url = 'http://' + msb_ip + '/openoapi/nslcm/v1/vnfpackage' - ns_url = 'http://' + msb_ip + '/openoapi/nslcm/v1/nspackage' - headers = {'Content-Type': 'application/json'} - get_csar = request_get(csar_url) - vnf_csarId = '' - ns_csarId = '' - for i in get_csar: - if i["type"] == "NFAR": - vnf_csarId = i["csarId"] - if i["type"] == "NSAR": - ns_csarId = i["csarId"] - - if vnf_csarId is None: - raise RaiseError("vnf package not found") - if ns_csarId is None: - raise RaiseError("ns package not found") - - vnf_data = {"csarId": vnf_csarId} - ns_data = {"csarId": ns_csarId} - request_post(vnf_url, vnf_data, headers) - time.sleep(5) - request_post(ns_url, ns_data, headers) - get_csar_after = request_get(csar_url) - for i in get_csar_after: - if i["onBoardState"] == "non-onBoarded": - raise RaiseError("csar onboard fail") - - -def create_service(msb_ip, ns_name, description, nsdId): - service_url = 'http://' + msb_ip + '/openoapi/servicegateway/v1/services' - headers = {'Content-Type': 'application/json'} - data1 = {"nsdId": nsdId, - "nsName": ns_name, - "description": description, - "gatewayUri":"/openoapi/nslcm/v1/ns"} - vimId = get_vim_id(msb_ip, "openstack") - resp = request_post(service_url, data1, headers) - instance_id = resp["serviceId"] - data2 = {"gatewayUri":"/openoapi/nslcm/v1/ns/" + instance_id + "/instantiate", - "nsInstanceId":instance_id, - "additionalParamForNs":{ - "location":vimId[0], - "sdncontroller":"select"} - } - request_post(service_url, data2, headers) - - -if __name__ == "__main__": - - parser = argparse.ArgumentParser() - parser.add_argument("--msb_ip", action='store', help="common_services_msb ip") - parser.add_argument("--tosca_aria_ip", action='store', help="common_tosca_aria ip") - parser.add_argument("--tosca_aria_port", action='store', help="common_tosca_aria port") - parser.add_argument("--juju_client_ip", action='store', help="juju client ip") - parser.add_argument("--auth_url", action='store', help="openstack auth url") - parser.add_argument("--ns_pkg", action='store', help="ns package") - parser.add_argument("--vnf_pkg", action='store', help="vnf package") - - args = parser.parse_args() - msb_ip = args.msb_ip - tosca_aria_ip = args.tosca_aria_ip - tosca_aria_port = args.tosca_aria_port - juju_client_ip = args.juju_client_ip - auth_url = args.auth_url - ns_pkg = args.ns_pkg - vnf_pkg = args.vnf_pkg - - add_common_tosca_aria(msb_ip, tosca_aria_ip, tosca_aria_port) - add_openo_vim(msb_ip, auth_url) - add_openo_vnfm(msb_ip, juju_client_ip) - - delete_csars(msb_ip) - upload_csar(msb_ip, vnf_pkg) - upload_csar(msb_ip, ns_pkg) - package_onboard(msb_ip) - diff --git a/juju/vims_deploy.sh b/juju/vims_deploy.sh index 763a4f7..5fa86ac 100755 --- a/juju/vims_deploy.sh +++ b/juju/vims_deploy.sh @@ -10,9 +10,19 @@ juju_client_ip=$(openstack server list | grep juju-client-vm | awk '{print $9}') -function deploy_app() { - python ${JUJU_DIR}/deploy_application.py --msb_ip $OPENO_IP:$COMMON_SERVICES_MSB_PORT \ - --application $APP_NAME +function exec_cmd_on_client() +{ + local ssh_args="-o StrictHostKeyChecking=no" + + if [ ! $juju_client_ip ]; then + log_error "juju-client ip not found" + exit 1 + fi + ssh $ssh_args ubuntu@$juju_client_ip "$@" +} + +function log_error() { + echo -e "\033[31m$*\033[0m" } function check_clearwater() { diff --git a/open-o/openo_docker.sh b/open-o/openo_docker.sh index 8a4a382..7cd6eb6 100755 --- a/open-o/openo_docker.sh +++ b/open-o/openo_docker.sh @@ -9,10 +9,6 @@ ############################################################################## function docker_pull() { - until docker pull openoint/sdno-driver-ct-te:$OPENO_VERSION - do - echo "Try again" - done until docker pull openoint/common-services-auth:$OPENO_VERSION do echo "Try again" @@ -93,63 +89,7 @@ function docker_pull() do echo "Try again" done - until docker pull openoint/sdno-driver-huawei-l3vpn:$OPENO_VERSION - do - echo "Try again" - done - until docker pull openoint/sdno-driver-huawei-openstack:$OPENO_VERSION - do - echo "Try again" - done - until docker pull openoint/sdno-driver-huawei-overlay:$OPENO_VERSION - do - echo "Try again" - done - until docker pull openoint/sdno-driver-huawei-servicechain:$OPENO_VERSION - do - echo "Try again" - done - until docker pull openoint/sdno-driver-zte-sptn:$OPENO_VERSION - do - echo "Try again" - done - until docker pull openoint/sdno-service-brs:$OPENO_VERSION - do - echo "Try again" - done - until docker pull openoint/sdno-service-ipsec:$OPENO_VERSION - do - echo "Try again" - done - until docker pull openoint/sdno-service-l2vpn:$OPENO_VERSION - do - echo "Try again" - done - until docker pull openoint/sdno-service-l3vpn:$OPENO_VERSION - do - echo "Try again" - done - until docker pull openoint/sdno-service-mss:$OPENO_VERSION - do - echo "Try again" - done - until docker pull openoint/sdno-service-nslcm:$OPENO_VERSION - do - echo "Try again" - done - until docker pull openoint/sdno-service-overlayvpn:$OPENO_VERSION - do - echo "Try again" - done - until docker pull openoint/sdno-service-servicechain:$OPENO_VERSION - do - echo "Try again" - done - until docker pull openoint/sdno-service-vpc:$OPENO_VERSION - do - echo "Try again" - done - until docker pull openoint/sdno-service-vxlan:$OPENO_VERSION + until docker pull openoint/gso-gui-portal:$OPENO_VERSION do echo "Try again" done @@ -157,18 +97,80 @@ function docker_pull() do echo "Try again" done - until docker pull openoint/sdno-monitoring:$OPENO_VERSION - do - echo "Try again" - done - until docker pull openoint/sdno-vsitemgr:$OPENO_VERSION - do - echo "Try again" - done - until docker pull openoint/gso-gui-portal:$OPENO_VERSION - do - echo "Try again" - done + if [[ $ENABLE_SDNO == true ]]; then + until docker pull openoint/sdno-driver-ct-te:$OPENO_VERSION + do + echo "Try again" + done + until docker pull openoint/sdno-driver-huawei-l3vpn:$OPENO_VERSION + do + echo "Try again" + done + until docker pull openoint/sdno-driver-huawei-openstack:$OPENO_VERSION + do + echo "Try again" + done + until docker pull openoint/sdno-driver-huawei-overlay:$OPENO_VERSION + do + echo "Try again" + done + until docker pull openoint/sdno-driver-huawei-servicechain:$OPENO_VERSION + do + echo "Try again" + done + until docker pull openoint/sdno-driver-zte-sptn:$OPENO_VERSION + do + echo "Try again" + done + until docker pull openoint/sdno-service-brs:$OPENO_VERSION + do + echo "Try again" + done + until docker pull openoint/sdno-service-ipsec:$OPENO_VERSION + do + echo "Try again" + done + until docker pull openoint/sdno-service-l2vpn:$OPENO_VERSION + do + echo "Try again" + done + until docker pull openoint/sdno-service-l3vpn:$OPENO_VERSION + do + echo "Try again" + done + until docker pull openoint/sdno-service-mss:$OPENO_VERSION + do + echo "Try again" + done + until docker pull openoint/sdno-service-nslcm:$OPENO_VERSION + do + echo "Try again" + done + until docker pull openoint/sdno-service-overlayvpn:$OPENO_VERSION + do + echo "Try again" + done + until docker pull openoint/sdno-service-servicechain:$OPENO_VERSION + do + echo "Try again" + done + until docker pull openoint/sdno-service-vpc:$OPENO_VERSION + do + echo "Try again" + done + until docker pull openoint/sdno-service-vxlan:$OPENO_VERSION + do + echo "Try again" + done + until docker pull openoint/sdno-monitoring:$OPENO_VERSION + do + echo "Try again" + done + until docker pull openoint/sdno-vsitemgr:$OPENO_VERSION + do + echo "Try again" + done + fi } function docker_run() @@ -197,26 +199,29 @@ function docker_run() docker run -d -e MSB_ADDR=$msb_ip -e MYSQL_ADDR=$tosca_inventory_ip:3306 --name nfvo-lcm -p $OPENO_IP:8403:8403 openoint/nfvo-lcm:$OPENO_VERSION docker run -d -e MSB_ADDR=$msb_ip --name nfvo-resmanagement openoint/nfvo-resmanagement:$OPENO_VERSION docker run -d -e MSB_ADDR=$msb_ip --name nfvo-umc openoint/nfvo-umc:$OPENO_VERSION - docker run -d -e MSB_ADDR=$msb_ip --name sdno-driver-huawei-l3vpn openoint/sdno-driver-huawei-l3vpn:$OPENO_VERSION - docker run -d -e MSB_ADDR=$msb_ip --name sdno-driver-huawei-openstack openoint/sdno-driver-huawei-openstack:$OPENO_VERSION - docker run -d -e MSB_ADDR=$msb_ip --name sdno-driver-huawei-overlay openoint/sdno-driver-huawei-overlay:$OPENO_VERSION - docker run -d -e MSB_ADDR=$msb_ip --name sdno-driver-huawei-servicechain openoint/sdno-driver-huawei-servicechain:$OPENO_VERSION - docker run -d -e MSB_ADDR=$msb_ip --name sdno-driver-zte-sptn openoint/sdno-driver-zte-sptn:$OPENO_VERSION - docker run -d -e MSB_ADDR=$msb_ip --name sdno-service-brs openoint/sdno-service-brs:$OPENO_VERSION - docker run -d -e MSB_ADDR=$msb_ip --name sdno-service-ipsec openoint/sdno-service-ipsec:$OPENO_VERSION - docker run -d -e MSB_ADDR=$msb_ip --name sdno-service-l2vpn openoint/sdno-service-l2vpn:$OPENO_VERSION - docker run -d -e MSB_ADDR=$msb_ip --name sdno-service-l3vpn openoint/sdno-service-l3vpn:$OPENO_VERSION - docker run -d -e MSB_ADDR=$msb_ip --name sdno-service-mss openoint/sdno-service-mss:$OPENO_VERSION - docker run -d -e MSB_ADDR=$msb_ip -e MYSQL_ADDR=$tosca_inventory_ip:3306 --name sdno-service-nslcm openoint/sdno-service-nslcm:$OPENO_VERSION - docker run -d -e MSB_ADDR=$msb_ip --name sdno-service-overlayvpn openoint/sdno-service-overlayvpn:$OPENO_VERSION - docker run -d -e MSB_ADDR=$msb_ip --name sdno-service-servicechain openoint/sdno-service-servicechain:$OPENO_VERSION - docker run -d -e MSB_ADDR=$msb_ip --name sdno-service-vpc openoint/sdno-service-vpc:$OPENO_VERSION - docker run -d -e MSB_ADDR=$msb_ip --name sdno-service-vxlan openoint/sdno-service-vxlan:$OPENO_VERSION docker run -d -e MSB_ADDR=$msb_ip --name common-tosca-aria -p $OPENO_IP:$COMMON_TOSCA_ARIA_PORT:8204 openoint/common-tosca-aria:$OPENO_VERSION - docker run -d -e MSB_ADDR=$msb_ip --name sdno-driver-ct-te openoint/sdno-driver-ct-te:$OPENO_VERSION - docker run -d -e MSB_ADDR=$msb_ip --name sdno-monitoring openoint/sdno-monitoring:$OPENO_VERSION - docker run -d -e MSB_ADDR=$msb_ip --name sdno-vsitemgr openoint/sdno-vsitemgr:$OPENO_VERSION docker run -d -e MSB_ADDR=$msb_ip --name gso-gui-portal openoint/gso-gui-portal:$OPENO_VERSION + + if [[ $ENABLE_SDNO == true ]]; then + docker run -d -e MSB_ADDR=$msb_ip --name sdno-driver-huawei-l3vpn openoint/sdno-driver-huawei-l3vpn:$OPENO_VERSION + docker run -d -e MSB_ADDR=$msb_ip --name sdno-driver-huawei-openstack openoint/sdno-driver-huawei-openstack:$OPENO_VERSION + docker run -d -e MSB_ADDR=$msb_ip --name sdno-driver-huawei-overlay openoint/sdno-driver-huawei-overlay:$OPENO_VERSION + docker run -d -e MSB_ADDR=$msb_ip --name sdno-driver-huawei-servicechain openoint/sdno-driver-huawei-servicechain:$OPENO_VERSION + docker run -d -e MSB_ADDR=$msb_ip --name sdno-driver-zte-sptn openoint/sdno-driver-zte-sptn:$OPENO_VERSION + docker run -d -e MSB_ADDR=$msb_ip --name sdno-service-brs openoint/sdno-service-brs:$OPENO_VERSION + docker run -d -e MSB_ADDR=$msb_ip --name sdno-service-ipsec openoint/sdno-service-ipsec:$OPENO_VERSION + docker run -d -e MSB_ADDR=$msb_ip --name sdno-service-l2vpn openoint/sdno-service-l2vpn:$OPENO_VERSION + docker run -d -e MSB_ADDR=$msb_ip --name sdno-service-l3vpn openoint/sdno-service-l3vpn:$OPENO_VERSION + docker run -d -e MSB_ADDR=$msb_ip --name sdno-service-mss openoint/sdno-service-mss:$OPENO_VERSION + docker run -d -e MSB_ADDR=$msb_ip -e MYSQL_ADDR=$tosca_inventory_ip:3306 --name sdno-service-nslcm openoint/sdno-service-nslcm:$OPENO_VERSION + docker run -d -e MSB_ADDR=$msb_ip --name sdno-service-overlayvpn openoint/sdno-service-overlayvpn:$OPENO_VERSION + docker run -d -e MSB_ADDR=$msb_ip --name sdno-service-servicechain openoint/sdno-service-servicechain:$OPENO_VERSION + docker run -d -e MSB_ADDR=$msb_ip --name sdno-service-vpc openoint/sdno-service-vpc:$OPENO_VERSION + docker run -d -e MSB_ADDR=$msb_ip --name sdno-service-vxlan openoint/sdno-service-vxlan:$OPENO_VERSION + docker run -d -e MSB_ADDR=$msb_ip --name sdno-driver-ct-te openoint/sdno-driver-ct-te:$OPENO_VERSION + docker run -d -e MSB_ADDR=$msb_ip --name sdno-monitoring openoint/sdno-monitoring:$OPENO_VERSION + docker run -d -e MSB_ADDR=$msb_ip --name sdno-vsitemgr openoint/sdno-vsitemgr:$OPENO_VERSION + fi } function clean() { @@ -231,8 +236,6 @@ function launch_openo() { clean docker_run - if [[ $(docker ps -q | grep openoint | wc -l) == 40 ]];then - echo -e "\n\033[32mOpen-O launch success\033[0m\n" - fi + echo -e "\n\033[32mOpen-O launch success\033[0m\n" } diff --git a/opera/deploy_vnf.py b/opera/deploy_vnf.py new file mode 100644 index 0000000..b9703a0 --- /dev/null +++ b/opera/deploy_vnf.py @@ -0,0 +1,28 @@ +#!/usr/bin/env python +############################################################################## +# Copyright (c) 2016-2017 HUAWEI TECHNOLOGIES CO.,LTD and others. +# +# All rights reserved. This program and the accompanying materials +# are made available under the terms of the Apache License, Version 2.0 +# which accompanies this distribution, and is available at +# http://www.apache.org/licenses/LICENSE-2.0 +############################################################################## + +import argparse +from openo_connect import create_service + + +if __name__ == "__main__": + + parser = argparse.ArgumentParser() + parser.add_argument("--msb_ip", action='store', help="common_services_msb ip") + parser.add_argument("--vnf", action='store', default='', help="vnf type") + parser.add_argument("--nsdId", action='store', default='', help="vnf nsdId") + + args = parser.parse_args() + msb_ip = args.msb_ip + vnf = args.vnf + nsdId = args.nsdId + + if vnf == 'clearwater': + create_service(msb_ip, vnf, vnf, nsdId) diff --git a/opera/openo_connect.py b/opera/openo_connect.py new file mode 100755 index 0000000..4e9e4fb --- /dev/null +++ b/opera/openo_connect.py @@ -0,0 +1,244 @@ +#!/usr/bin/env python +############################################################################## +# Copyright (c) 2016-2017 HUAWEI TECHNOLOGIES CO.,LTD and others. +# +# All rights reserved. This program and the accompanying materials +# are made available under the terms of the Apache License, Version 2.0 +# which accompanies this distribution, and is available at +# http://www.apache.org/licenses/LICENSE-2.0 +############################################################################## + +import argparse +import sys +import os +import time +import requests +import json +from datetime import datetime +from pprint import pprint + + +class RaiseError(Exception): + def __init__(self, msg): + self.msg = msg + + def __str__(self): + return repr(self.msg) + + +def request_get(url): + try: + resp = requests.get(url) + if resp.status_code not in (200,201): + pprint (resp.json()) + raise RaiseError('get url: %s fail %d' % (url, resp.status_code)) + except Exception: + raise + + return resp.json() + + +def request_post(url, data, headers): + try: + resp = requests.post(url, data=json.dumps(data), headers=headers) + if resp.status_code not in (200,201,202): + pprint (resp.json()) + raise RaiseError('post url: %s fail %d' % (url, resp.status_code)) + except Exception: + raise + + return resp.json() + + +def request_delete(url): + try: + resp = requests.delete(url) + if resp.status_code not in (200,201,204): + pprint (resp.json()) + raise RaiseError('delete url: %s fail %d' % (url, resp.status_code)) + except Exception: + raise + + +def add_common_tosca_aria(msb_ip, tosca_aria_ip, tosca_aria_port): + url = 'http://' + msb_ip + '/openoapi/microservices/v1/apiRoute' + headers = {'Content-Type': 'application/json'} + data = {"serviceName":"tosca", + "version":"v1", + "url":"/openoapi/tosca/v1", + "metricsUrl":"/admin/metrics", + "apiJson":"/swagger.json", + "apiJsonType":"1", + "control":"0", + "status":"1", + "servers":[{"ip":tosca_aria_ip,"port":tosca_aria_port,"weight":0}]} + request_post(url, data, headers) + + +def get_vim_id(msb_ip, vim_type): + vim_url = 'http://' + msb_ip + '/openoapi/extsys/v1/vims/' + get_vim = request_get(vim_url) + vimId = [] + for i in get_vim: + if i["type"] == vim_type: + vimId.append(i['vimId']) + + return vimId + + +def add_openo_vim(msb_ip, auth_url): + vim_url = 'http://' + msb_ip + '/openoapi/extsys/v1/vims/' + vnfm_url = 'http://' + msb_ip + '/openoapi/extsys/v1/vnfms/' + headers = {'Content-Type': 'application/json'} + data = {"name":"openstack", + "url":auth_url, + "userName":"admin", + "password":"console", + "tenant":"admin", + "domain":"", + "vendor":"openstack", + "version":"newton", + "description":"", + "type":"openstack"} + vimId = get_vim_id(msb_ip, "openstack") + if len(vimId) != 0: + get_vnfm = request_get(vnfm_url) + for i in get_vnfm: + if i["vimId"] == vimId[0]: + request_delete(vnfm_url + i["vnfmId"]) + request_delete(vim_url + vimId[0]) + + request_post(vim_url, data, headers) + + +def add_openo_vnfm(msb_ip, juju_client_ip): + vim_url = 'http://' + msb_ip + '/openoapi/extsys/v1/vims/' + vnfm_url = 'http://' + msb_ip + '/openoapi/extsys/v1/vnfms/' + headers = {'Content-Type': 'application/json'} + vimId = get_vim_id(msb_ip, "openstack") + if len(vimId) == 0: + raise RaiseError("vim openstack not found") + + get_vnfm = request_get(vnfm_url) + for i in get_vnfm: + if i["vimId"] == vimId[0]: + request_delete(vnfm_url + i["vnfmId"]) + + data = {"name":"Juju-VNFM", + "vimId":vimId[0], + "vendor":"jujuvnfm", + "version":"jujuvnfm", + "type":"jujuvnfm", + "description":"", + "certificateUrl":"", + "url":"http://" + juju_client_ip + ":8483", + "userName":"", + "password":""} + request_post(vnfm_url, data, headers) + + +def delete_csars(msb_ip): + csar_url = 'http://' + msb_ip + '/openoapi/catalog/v1/csars/' + csars = request_get(csar_url) + for csar in csars: + csarId = csar["csarId"] + request_delete(csar_url + csarId) + pprint("csar %s is deleted" % csarId) + + +def upload_csar(msb_ip, package): + csar_url = 'http://' + msb_ip + '/openoapi/catalog/v1/csars' + files = {'file': open(package, 'rb')} + res = requests.post(csar_url, files=files) + if res.status_code != 200: + retry = 5 + while retry != 0: + delete_csars(msb_ip) + retry_res = requests.post(csar_url, files=files) + if retry_res.status_code == 200: + break + else: + pprint(retry_res.json()) + retry -= 1 + if retry == 0: + raise Exception('Error with uploading csar package: %s' % package) + + +def package_onboard(msb_ip): + csar_url = 'http://' + msb_ip + '/openoapi/catalog/v1/csars' + vnf_url = 'http://' + msb_ip + '/openoapi/nslcm/v1/vnfpackage' + ns_url = 'http://' + msb_ip + '/openoapi/nslcm/v1/nspackage' + headers = {'Content-Type': 'application/json'} + get_csar = request_get(csar_url) + vnf_csarId = '' + ns_csarId = '' + for i in get_csar: + if i["type"] == "NFAR": + vnf_csarId = i["csarId"] + if i["type"] == "NSAR": + ns_csarId = i["csarId"] + + if vnf_csarId is None: + raise RaiseError("vnf package not found") + if ns_csarId is None: + raise RaiseError("ns package not found") + + vnf_data = {"csarId": vnf_csarId} + ns_data = {"csarId": ns_csarId} + request_post(vnf_url, vnf_data, headers) + time.sleep(5) + request_post(ns_url, ns_data, headers) + get_csar_after = request_get(csar_url) + for i in get_csar_after: + if i["onBoardState"] == "non-onBoarded": + raise RaiseError("csar onboard fail") + + +def create_service(msb_ip, ns_name, description, nsdId='ns_cw_2016'): + service_url = 'http://' + msb_ip + '/openoapi/servicegateway/v1/services' + headers = {'Content-Type': 'application/json'} + data1 = {"nsdId": nsdId, + "nsName": "{0}{1}".format(ns_name, datetime.now().strftime('%Y%m%d%H%M%S')), + "description": description, + "gatewayUri":"/openoapi/nslcm/v1/ns"} + vimId = get_vim_id(msb_ip, "openstack") + resp = request_post(service_url, data1, headers) + instance_id = resp["serviceId"] + data2 = {"gatewayUri":"/openoapi/nslcm/v1/ns/" + instance_id + "/instantiate", + "nsInstanceId":instance_id, + "additionalParamForNs":{ + "location":vimId[0], + "sdncontroller":"select"} + } + request_post(service_url, data2, headers) + + +if __name__ == "__main__": + + parser = argparse.ArgumentParser() + parser.add_argument("--msb_ip", action='store', help="common_services_msb ip") + parser.add_argument("--tosca_aria_ip", action='store', help="common_tosca_aria ip") + parser.add_argument("--tosca_aria_port", action='store', help="common_tosca_aria port") + parser.add_argument("--juju_client_ip", action='store', help="juju client ip") + parser.add_argument("--auth_url", action='store', help="openstack auth url") + parser.add_argument("--ns_pkg", action='store', help="ns package") + parser.add_argument("--vnf_pkg", action='store', help="vnf package") + + args = parser.parse_args() + msb_ip = args.msb_ip + tosca_aria_ip = args.tosca_aria_ip + tosca_aria_port = args.tosca_aria_port + juju_client_ip = args.juju_client_ip + auth_url = args.auth_url + ns_pkg = args.ns_pkg + vnf_pkg = args.vnf_pkg + + add_common_tosca_aria(msb_ip, tosca_aria_ip, tosca_aria_port) + add_openo_vim(msb_ip, auth_url) + add_openo_vnfm(msb_ip, juju_client_ip) + + delete_csars(msb_ip) + upload_csar(msb_ip, vnf_pkg) + upload_csar(msb_ip, ns_pkg) + package_onboard(msb_ip) + diff --git a/opera_launch.sh b/opera_launch.sh index 0af0718..18b0ca8 100755 --- a/opera_launch.sh +++ b/opera_launch.sh @@ -39,7 +39,7 @@ if [[ "$DEPLOY_FIRST_TIME" == "true" ]]; then fi source ${WORK_DIR}/scripts/open-o.conf -source ${WORK_DIR}/scripts/application.conf +source ${WORK_DIR}/scripts/vnf.conf if [[ "$DEPLOY_OPENO" == "true" ]]; then if ! launch_openo;then @@ -64,8 +64,8 @@ if [[ "$DEPLOY_JUJU" == "true" ]]; then connect_juju_and_openo fi -if [[ -n $APP_NAME ]]; then - deploy_app +if [[ -n $VNF_TYPE ]]; then + deploy_vnf fi figlet -ctf slant Open-O Installed diff --git a/prepare.sh b/prepare.sh index a503d7b..07e74c1 100755 --- a/prepare.sh +++ b/prepare.sh @@ -14,7 +14,7 @@ function generate_conf() rm -rf ${SCRIPT_DIR} mkdir -p ${SCRIPT_DIR} python ${OPERA_DIR}/process_conf.py ${CONF_DIR}/open-o.yml \ - ${CONF_DIR}/application.yml + ${CONF_DIR}/vnf.yml } function package_prepare() diff --git a/process_conf.py b/process_conf.py index c8f4e9d..976cf19 100644 --- a/process_conf.py +++ b/process_conf.py @@ -24,16 +24,18 @@ def generate_openo_conf(openo_config, scripts_dir): fd.write('{0}={1}\n'.format(i.upper(), openo_config["openo_docker_net"][i])) fd.write('{0}={1}\n'.format('OPENO_VERSION', openo_config["openo_version"])) - - -def generate_app_conf(openo_config, app_config, scripts_dir): - """generate opera/work/scripts_dir/application.conf""" - with open(scripts_dir + "/application.conf", "w") as fd: - for i in app_config["application"]: - if i["name"] == openo_config["application"]: - fd.write('{0}={1}\n'.format('APP_NAME', i["name"])) - fd.write('{0}={1}\n'.format('APP_NS_PKG', i["ns_pkg"])) - fd.write('{0}={1}'.format('APP_VNF_PKG', i["vnf_pkg"])) + fd.write('{0}={1}'.format('ENABLE_SDNO', openo_config["enable_sdno"])) + + +def generate_app_conf(openo_config, vnf_config, scripts_dir): + """generate opera/work/scripts_dir/vnf.conf""" + with open(scripts_dir + "/vnf.conf", "w") as fd: + for i in vnf_config["vIMS"]: + if i["type"] == openo_config["vnf_type"]: + fd.write('{0}={1}\n'.format('VNF_TYPE', i["type"])) + fd.write('{0}={1}\n'.format('NS_PKG', i["ns_pkg"])) + fd.write('{0}={1}\n'.format('VNF_PKG', i["vnf_pkg"])) + fd.write('{0}={1}'.format('NSDID', i["nsdId"])) break @@ -42,13 +44,13 @@ if __name__ == "__main__": print("parameter wrong%d %s" % (len(sys.argv), sys.argv)) sys.exit(1) - _, openo_file, app_file = sys.argv + _, openo_file, vnf_file = sys.argv if not os.path.exists(openo_file): print("network.yml doesn't exit") sys.exit(1) - if not os.path.exists(app_file): + if not os.path.exists(vnf_file): print("application.yml doesn't exit") sys.exit(1) @@ -57,9 +59,9 @@ if __name__ == "__main__": print('format error in %s' % openo_file) sys.exit(1) - app_config = load_file(app_file) - if not app_config: - print('format error in %s' % app_file) + vnf_config = load_file(vnf_file) + if not vnf_config: + print('format error in %s' % vnf_file) sys.exit(1) opera_dir = os.getenv('OPERA_DIR') @@ -69,4 +71,4 @@ if __name__ == "__main__": sys.exit(1) generate_openo_conf(openo_config, scripts_dir) - generate_app_conf(openo_config, app_config, scripts_dir) + generate_app_conf(openo_config, vnf_config, scripts_dir) diff --git a/setup.py b/setup.py new file mode 100644 index 0000000..46bb5fb --- /dev/null +++ b/setup.py @@ -0,0 +1,22 @@ +############################################################################## +# Copyright (c) 2016-2017 HUAWEI TECHNOLOGIES CO.,LTD and others. +# +# All rights reserved. This program and the accompanying materials +# are made available under the terms of the Apache License, Version 2.0 +# which accompanies this distribution, and is available at +# http://www.apache.org/licenses/LICENSE-2.0 +############################################################################## + +from setuptools import setup, find_packages + + +setup( + name="opera", + version="master", + packages=find_packages(), + include_package_data=True, + package_data={ + }, + url="https://www.opnfv.org", + install_requires=["requests==2.9.1"] +) -- cgit 1.2.3-korg