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 --- juju/deploy_application.py | 26 ----- juju/juju_connect.sh | 13 ++- juju/openo_connect.py | 234 --------------------------------------------- juju/vims_deploy.sh | 16 +++- 4 files changed, 23 insertions(+), 266 deletions(-) delete mode 100755 juju/deploy_application.py delete mode 100755 juju/openo_connect.py (limited to 'juju') 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() { -- cgit 1.2.3-korg