From cd0feb45a414980fdd7249c9cc4fc28a1213c769 Mon Sep 17 00:00:00 2001 From: Harry Huang Date: Mon, 13 Mar 2017 18:10:12 +0800 Subject: independent network for opera 1. launch open-o dockers directly on jump host instead of a vm 2. launch only one juju vm has both client and metadata function 3. add clearwater csar packages into opera repo 4. automatically deploy clearwater when key application in conf/application.yml has value clearwater 5. support keystone v3 Change-Id: Ic59f66d2cededf661aa7f6de2a40836ea40d8887 Signed-off-by: Harry Huang --- juju/command.sh | 31 +++++++++ juju/deploy_application.py | 26 ++++++++ juju/juju_connect.sh | 136 ++++++++++++++++++++++----------------- juju/juju_launch.sh | 131 +++++++++++++++----------------------- juju/juju_setup.sh | 38 ++++++++--- juju/openo_connect.py | 154 ++++++++++++++++++++++++++++++++++++--------- juju/vims_deploy.sh | 69 ++++++++++++++++++++ 7 files changed, 409 insertions(+), 176 deletions(-) create mode 100755 juju/command.sh create mode 100755 juju/deploy_application.py mode change 100644 => 100755 juju/openo_connect.py create mode 100755 juju/vims_deploy.sh (limited to 'juju') diff --git a/juju/command.sh b/juju/command.sh new file mode 100755 index 0000000..84643de --- /dev/null +++ b/juju/command.sh @@ -0,0 +1,31 @@ +#!/bin/bash +############################################################################## +# 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 +############################################################################## + +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 scp_to_client() +{ + local ssh_args="-o StrictHostKeyChecking=no" + + if [ ! $juju_client_ip ]; then + log_error "juju-client ip not found" + exit 1 + fi + scp $ssh_args $1 ubuntu@$juju_client_ip:$2 +} diff --git a/juju/deploy_application.py b/juju/deploy_application.py new file mode 100755 index 0000000..22c7d9d --- /dev/null +++ b/juju/deploy_application.py @@ -0,0 +1,26 @@ +#!/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 693918e..43314b5 100755 --- a/juju/juju_connect.sh +++ b/juju/juju_connect.sh @@ -10,85 +10,103 @@ function connect_prepare() { - local cmd1="yum install -y rsync" - exec_cmd_on_openo $cmd1 - - local cmd2="if [[ ! -f /root/.ssh/id_rsa.pub ]]; then \ - sudo ssh-keygen -q -t rsa -f /root/.ssh/id_rsa -N ''; \ - fi" - exec_cmd_on_openo $cmd2 - - local openo_key=`exec_cmd_on_openo cat /root/.ssh/id_rsa.pub` - local cmd3="echo $openo_key >> /home/ubuntu/.ssh/authorized_keys" - exec_cmd_on_client $cmd3 - - local cmd4="sudo apt-get install -y default-jdk; \ - wget https://archive.apache.org/dist/tomcat/tomcat-8/v8.5.9/bin/apache-tomcat-8.5.9.tar.gz; \ - tar -zxvf apache-tomcat-8.5.9.tar.gz; \ - rm -rf tomcat8; \ - mv apache-tomcat-8.5.9 tomcat8; \ - rm -rf tomcat8/webapps/*; \ - mkdir csar" - exec_cmd_on_client $cmd4 + apt-get install -y rsync + + local cmd="tar -zxvf apache-tomcat-8.5.9.tar.gz; \ + sudo rm -rf tomcat8 csar; \ + mv apache-tomcat-8.5.9 tomcat8; \ + rm -rf tomcat8/webapps/*; \ + mkdir csar" + exec_cmd_on_client $cmd } function sync_juju_driver_file() { + local TOMCAT_DIR=${WORK_DIR}/tomcat + rm -rf ${TOMCAT_DIR} + mkdir -p ${TOMCAT_DIR} + connect_prepare - local cmd1="docker cp nfvo-driver-vnfm-juju:/service/webapps/ROOT /home/; \ - docker cp nfvo-driver-vnfm-juju:/service/etc /home/;" - exec_cmd_on_openo $cmd1 - - scp_to_openo ${UTIL_DIR}/modify_file.sh /home - local cmd2="sed -i s/REPLACE_JUJU_DRIVER_IP/$NFVO_DRIVER_VNFM_JUJU_IP/ /home/modify_file.sh; \ - sed -i s/REPLACE_JUJU_METADATA_IP/$floating_ip_metadata/ /home/modify_file.sh; \ - chmod +x /home/modify_file.sh; \ - /home/modify_file.sh" - exec_cmd_on_openo $cmd2 - - local cmd3="rsync -e 'ssh -o StrictHostKeyChecking=no' --rsync-path='sudo rsync' \ - -av /home/etc ubuntu@$floating_ip_client:/home/ubuntu/tomcat8/; \ - rsync -e 'ssh -o StrictHostKeyChecking=no' --rsync-path='sudo rsync' \ - -av /home/ROOT ubuntu@$floating_ip_client:/home/ubuntu/tomcat8/webapps" - exec_cmd_on_openo $cmd3 - - local cmd4="docker cp /home/etc nfvo-driver-vnfm-juju:/service/; \ - docker cp /home/ROOT nfvo-driver-vnfm-juju:/service/webapps/" - exec_cmd_on_openo $cmd4 + docker cp nfvo-driver-vnfm-juju:/service/webapps/ROOT ${TOMCAT_DIR} + docker cp nfvo-driver-vnfm-juju:/service/etc ${TOMCAT_DIR} + + file1=${TOMCAT_DIR}/etc/conf/juju_conf.json + sed -i "s/^\(.*\"image-metadata-url\":\).*/\1 \"http:\/\/$juju_client_ip\/images\"\,/g" $file1 + sed -i "s/^\(.*\"network\":\).*/\1 \"juju-net\"\,/g" $file1 + sed -i "s/^\(.*\"use-floating-ip\":\).*/\1 \"True\"\,/g" $file1 + + file2=${TOMCAT_DIR}/etc/csarInfo/csarinfo.json + sed -i "s/^\(.*\"csar_file_path\":\).*/\1 \"\/home\/ubuntu\/csar\/\"\,/g" $file2 + + file3=${TOMCAT_DIR}/ROOT/WEB-INF/classes/db.properties + sed -i "s/^\(.*jdbc.url=\).*/\1jdbc:mysql:\/\/$OPENO_IP:$NFVO_DRIVER_VNFM_JUJU_MYSQL_PORT\/jujuvnfmdb/g" $file3 + + file4=${TOMCAT_DIR}/ROOT/WEB-INF/classes/juju-config.properties + sed -i "s/^\(.*charmPath=\).*/\1\/home\/ubuntu\/csar\//g" $file4 + sed -i "s/^\(.*grant_jujuvnfm_url=\).*/\1http:\/\/$OPENO_IP:$NFVO_DRIVER_VNFM_JUJU_PORT\//g" $file4 + + file5=${TOMCAT_DIR}/etc/conf/restclient.json + sed -i "s/^\(.*\"host\":\).*/\1\"$OPENO_IP\"\,/g" $file5 + sed -i "s|^\(.*\"port\":\).*|\1\"$COMMON_SERVICES_MSB_PORT\"|g" $file5 + + file6=${TOMCAT_DIR}/etc/adapterInfo/jujuadapterinfo.json + sed -i "s/^\(.*\"ip\":\).*/\1 \"$OPENO_IP\"\,/g" $file6 + + rsync -e 'ssh -o StrictHostKeyChecking=no' --rsync-path='sudo rsync' \ + -av ${TOMCAT_DIR}/etc ubuntu@$juju_client_ip:/home/ubuntu/tomcat8/ + rsync -e 'ssh -o StrictHostKeyChecking=no' --rsync-path='sudo rsync' \ + -av ${TOMCAT_DIR}/ROOT ubuntu@$juju_client_ip:/home/ubuntu/tomcat8/webapps + + docker cp ${TOMCAT_DIR}/etc nfvo-driver-vnfm-juju:/service/ + docker cp ${TOMCAT_DIR}/ROOT nfvo-driver-vnfm-juju:/service/webapps/ } function start_tomcat() { - scp_to_openo ${UTIL_DIR}/grant_mysql.sh /home - local cmd1="chmod +x /home/grant_mysql.sh; \ - docker cp /home/grant_mysql.sh nfvo-driver-vnfm-juju:/service; \ - docker exec -i nfvo-driver-vnfm-juju /service/grant_mysql.sh" - exec_cmd_on_openo $cmd1 + chmod +x ${UTIL_DIR}/grant_mysql.sh + docker cp ${UTIL_DIR}/grant_mysql.sh nfvo-driver-vnfm-juju:/service + docker exec -i nfvo-driver-vnfm-juju /service/grant_mysql.sh - local cmd2='sed -i s/port=\"8080\"/port=\"8483\"/g /home/ubuntu/tomcat8/conf/server.xml' - exec_cmd_on_client $cmd2 + local cmd1='sed -i s/port=\"8080\"/port=\"8483\"/g /home/ubuntu/tomcat8/conf/server.xml' + exec_cmd_on_client $cmd1 - local cmd3="ps aux | grep java | awk '{print \"$2\"}' | xargs kill -9; \ + local cmd2="pidof java | xargs kill -9; \ /home/ubuntu/tomcat8/bin/catalina.sh start" - exec_cmd_on_client $cmd3 + + exec_cmd_on_client $cmd2 + + docker stop nfvo-driver-vnfm-juju + docker start nfvo-driver-vnfm-juju } -function add_vim_and_vnfm() +function openo_connect() { - python ${JUJU_DIR}/openo_connect.py --msb_ip $COMMON_SERVICES_MSB_IP \ - --tosca_aria_ip $COMMON_TOSCA_ARIA_IP \ - --juju_client_ip $floating_ip_client \ - --auth_url $OS_AUTH_URL - - local cmd1="docker stop nfvo-driver-vnfm-juju; \ - docker start nfvo-driver-vnfm-juju" - exec_cmd_on_openo $cmd1 + python ${JUJU_DIR}/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}" +} + +function fix_openo_containers() +{ + docker exec gso-service-gateway sed -i "s|^\(.*\"port\":\).*|\1 \"$COMMON_SERVICES_MSB_PORT\"|g" /service/etc/conf/restclient.json + docker stop gso-service-gateway + docker start gso-service-gateway + docker exec nfvo-resmanagement sed -i "s|^\(.*\"port\":\).*|\1 \"$COMMON_SERVICES_MSB_PORT\"|g" /service/etc/conf/restclient.json + docker stop nfvo-resmanagement + docker start nfvo-resmanagement } function connect_juju_and_openo() { + log_info "connect_juju_and_openo enter" + sync_juju_driver_file start_tomcat - add_vim_and_vnfm +# fix_openo_containers + openo_connect } diff --git a/juju/juju_launch.sh b/juju/juju_launch.sh index 1ad6e89..2aff57e 100755 --- a/juju/juju_launch.sh +++ b/juju/juju_launch.sh @@ -7,13 +7,20 @@ # which accompanies this distribution, and is available at # http://www.apache.org/licenses/LICENSE-2.0 ############################################################################## +function clear_juju_vm() +{ + servers=$(openstack server list | grep juju | awk '{print $2}') + if [[ -n $servers ]];then + openstack server delete $servers + fi +} function launch_juju_vm() { local NET_ID=$(neutron net-list | grep juju-net | awk '{print $2}') if [[ ! $(nova list | grep juju-client-vm) ]]; then - nova boot --flavor m1.small --image xenial_x86_64 --nic net-id=$NET_ID \ + nova boot --flavor m1.small --image $JUJU_VM_IMG --nic net-id=$NET_ID \ --key-name jump-key --security-group default juju-client-vm if [ $? -ne 0 ]; then log_error "boot juju-client-vm fail" @@ -21,42 +28,25 @@ function launch_juju_vm() fi fi - if [[ ! $(nova list | grep juju-metadata-vm) ]]; then - nova boot --flavor m1.small --image xenial_x86_64 --nic net-id=$NET_ID \ - --key-name jump-key --security-group default juju-metadata-vm - if [ $? -ne 0 ]; then - log_error "boot juju-metadata-vm fail" - exit 1 - fi - fi - local count=300 set +x while - local state1=$(nova list | grep juju-client-vm | awk '{print $6}') - local state2=$(nova list | grep juju-metadata-vm | awk '{print $6}') - if [[ $state1 == "ERROR" || $state2 == "ERROR" || $count == 0 ]]; then + local state=$(nova list | grep juju-client-vm | awk '{print $6}') + if [[ $state == "ERROR" || $count == 0 ]]; then log_error "launch juju vm error" exit 1 fi let count-=1 sleep 2 - [[ $state1 != "ACTIVE" || $state2 != "ACTIVE" ]] + [[ $state != "ACTIVE" ]] do :;done set -x if [ ! $(nova list | grep juju-client-vm | awk '{print $14}') ]; then - floating_ip_client=$(neutron floatingip-create ext-net | grep floating_ip_address | awk '{print $4}') - nova floating-ip-associate juju-client-vm $floating_ip_client + juju_client_ip=$(neutron floatingip-create ext-net | grep floating_ip_address | awk '{print $4}') + nova floating-ip-associate juju-client-vm $juju_client_ip else - floating_ip_client=$(nova list | grep juju-client-vm | awk '{print $13}') - fi - - if [ ! $(nova list | grep juju-metadata-vm | awk '{print $14}') ]; then - floating_ip_metadata=$(neutron floatingip-create ext-net | grep floating_ip_address | awk '{print $4}') - nova floating-ip-associate juju-metadata-vm $floating_ip_metadata - else - floating_ip_metadata=$(nova list | grep juju-metadata-vm | awk '{print $13}') + juju_client_ip=$(nova list | grep juju-client-vm | awk '{print $13}') fi local wait=120 @@ -66,39 +56,20 @@ function launch_juju_vm() log_error "launch juju vm can't access" exit 1 fi - exec_cmd_on_client exit - local ready1=$? - exec_cmd_on_metadata exit - local ready2=$? + exec_cmd_on_client exit 2>/dev/null + local ready=$? let wait-=1 sleep 2 - [[ $ready1 != 0 || $ready2 != 0 ]] + [[ $ready != 0 ]] do :;done set -x - export floating_ip_client=$floating_ip_client - export floating_ip_metadata=$floating_ip_metadata -} - -function juju_metadata_prepare() -{ - local cmd="sudo apt update -y; \ - sudo apt-get install nginx -y" - exec_cmd_on_metadata $cmd - - if [[ ! $(exec_cmd_on_metadata sudo ps -aux | grep nginx) ]]; then - log_error "juju-metadata nginx error" - exit 1 - fi + export juju_client_ip=$juju_client_ip + log_info "juju client launched!" } function juju_client_prepare() { - local cmd1="sudo add-apt-repository ppa:juju/stable; \ - sudo apt update -y; \ - sudo apt install juju zfsutils-linux -y" - exec_cmd_on_client $cmd1 - exec_cmd_on_client "echo 'clouds: openstack: type: openstack @@ -107,37 +78,29 @@ function juju_client_prepare() $OS_REGION_NAME: endpoint: $OS_AUTH_URL' > clouds.yaml" - local cmd2="juju add-cloud openstack clouds.yaml --replace" - exec_cmd_on_client $cmd2 + local cmd1="juju add-cloud openstack clouds.yaml --replace" + exec_cmd_on_client $cmd1 if [[ ! $(exec_cmd_on_client "juju list-clouds | grep openstack") ]]; then log_error "juju-client add cloud error" exit 1 fi - local cmd3='ssh-keygen -q -t rsa -f /home/ubuntu/.ssh/id_rsa -N ""' - exec_cmd_on_client $cmd3 - - local client_key=`exec_cmd_on_client sudo cat /home/ubuntu/.ssh/id_rsa.pub` - local cmd4="echo $client_key >> /home/ubuntu/.ssh/authorized_keys" - exec_cmd_on_metadata $cmd4 + local cmd2="juju remove-credential openstack openstack" + exec_cmd_on_client $cmd2 - exec_cmd_on_client "echo 'credentials: - openstack: - openstack: - auth-type: userpass - password: $OS_PASSWORD - tenant-name: $OS_PROJECT_NAME - username: $OS_USERNAME' > os-creds.yaml" - - local cmd5="juju add-credential openstack -f os-creds.yaml --replace" - exec_cmd_on_client $cmd5 + scp_to_client ${CONF_DIR}/admin-openrc.sh /home/ubuntu } function juju_generate_metadata() { exec_cmd_on_client mkdir -p mt + if [[ ! $(exec_cmd_on_client sudo ps aux | grep nginx) ]]; then + log_error "juju-metadata nginx is not running" + exit 1 + fi + for((i=0;i<${#JUJU_IMG_NAME[@]};i++)) do IMAGE_ID=$(glance image-list | grep ${JUJU_IMG_NAME[i]} | awk '{print $2}') @@ -149,15 +112,12 @@ function juju_generate_metadata() local cmd1="juju metadata generate-tools -d mt" exec_cmd_on_client $cmd1 - local cmd2="rsync -e 'ssh -o StrictHostKeyChecking=no' -av mt ubuntu@$floating_ip_metadata:~/" - exec_cmd_on_client $cmd2 - - local cmd3="sudo cp -a mt/tools/ /var/www/html; \ + local cmd2="sudo cp -a mt/tools/ /var/www/html; \ sudo cp -a mt/images/ /var/www/html; \ sudo chmod a+rx /var/www/html/ -R" - exec_cmd_on_metadata $cmd3 + exec_cmd_on_client $cmd2 - wget -O - http://$floating_ip_metadata/images/streams/v1/index.json + wget -O - http://$juju_client_ip/images/streams/v1/index.json if [ $? -ne 0 ]; then log_error "juju metadata generate error" exit 1 @@ -166,13 +126,25 @@ function juju_generate_metadata() function bootstrap_juju_controller() { - local cmd="juju bootstrap openstack openstack \ - --config image-metadata-url=http://$floating_ip_metadata/images \ - --config network=juju-net --config use-floating-ip=True \ - --config use-default-secgroup=True \ - --constraints 'mem=4G root-disk=40G' \ - --verbose --debug" - exec_cmd_on_client $cmd + local cmd1="juju controllers | grep openstack" + exec_cmd_on_client $cmd1 + if [[ $? != 0 ]];then + local cmd2="source admin-openrc.sh; \ + juju bootstrap openstack openstack \ + --config image-metadata-url=http://$juju_client_ip/images \ + --config network=juju-net --config use-floating-ip=True \ + --config use-default-secgroup=True \ + --constraints 'mem=4G root-disk=40G' \ + --verbose --debug" + exec_cmd_on_client $cmd2 + exec_cmd_on_client $cmd1 + if [[ $? == 0 ]];then + log_info "juju controller launched!" + else + log_error "launch juju controller fail!" + exit 1 + fi + fi } function launch_juju() @@ -180,7 +152,6 @@ function launch_juju() log_info "launch_juju enter" launch_juju_vm - juju_metadata_prepare juju_client_prepare juju_generate_metadata bootstrap_juju_controller diff --git a/juju/juju_setup.sh b/juju/juju_setup.sh index 4fd5cbc..eb49360 100755 --- a/juju/juju_setup.sh +++ b/juju/juju_setup.sh @@ -9,6 +9,7 @@ ############################################################################## IMG_DIR=${WORK_DIR}/img +CSAR_DIR=${WORK_DIR}/csar function juju_env_prepare() { @@ -30,22 +31,42 @@ function juju_download_img() fi } +function juju_download_csar() +{ + if [ ! -e ${CSAR_DIR}/${1##*/} ];then + wget -O ${CSAR_DIR}/${1##*/} $1 + fi +} + function juju_prepare() { log_info "juju_prepare enter" mkdir -p $IMG_DIR - for((i=0;i<${#JUJU_IMG_NAME[@]};i++)) do juju_download_img ${JUJU_IMG_URL[i]} if [[ ! $(glance image-list | grep ${JUJU_IMG_NAME[i]}) ]]; then glance image-create --name=${JUJU_IMG_NAME[i]} \ - --disk-format qcow2 --container-format=bare \ - --visibility=public --file ${IMG_DIR}/${JUJU_IMG_URL[i]##*/} + --disk-format qcow2 --container-format=bare \ + --visibility=public --file ${IMG_DIR}/${JUJU_IMG_URL[i]##*/} fi done + wget -nc -O $IMG_DIR/$JUJU_VM_IMG $JUJU_VM_IMG_URL + if [[ $(glance image-list | grep $JUJU_VM_IMG) ]]; then + openstack image delete $JUJU_VM_IMG + fi + glance image-create --name=$JUJU_VM_IMG \ + --disk-format qcow2 --container-format=bare \ + --visibility=public --file $IMG_DIR/$JUJU_VM_IMG + + mkdir -p $CSAR_DIR + for((i=0;i<${#CSAR_NAME[@]};i++)) + do + juju_download_csar ${CSAR_URL[i]} + done + if [[ ! $(neutron net-list | grep juju-net) ]]; then neutron net-create juju-net fi @@ -93,16 +114,17 @@ function juju_prepare() --remote-ip-prefix 0.0.0.0/0 $default_secgroup_id fi - if [ ! -f /root/.ssh/id_rsa.pub ]; then - ssh-keygen -q -t rsa -f /root/.ssh/id_rsa -N "" - fi + echo -e 'n\n'|ssh-keygen -q -t rsa -N "" -f /root/.ssh/id_rsa 1>/dev/null - openstack keypair list | grep jump-key || openstack keypair create --public-key \ - /root/.ssh/id_rsa.pub jump-key + openstack keypair delete jump-key | true + openstack keypair create --public-key /root/.ssh/id_rsa.pub jump-key openstack flavor show m1.tiny || openstack flavor create --ram 512 --disk 5 --vcpus 1 --public m1.tiny openstack flavor show m1.small || openstack flavor create --ram 1024 --disk 10 --vcpus 1 --public m1.small openstack flavor show m1.medium || openstack flavor create --ram 2048 --disk 10 --vcpus 2 --public m1.medium openstack flavor show m1.large || openstack flavor create --ram 3072 --disk 10 --vcpus 2 --public m1.large openstack flavor show m1.xlarge || openstack flavor create --ram 8096 --disk 30 --vcpus 4 --public m1.xlarge + + openstack quota set --instances 20 admin + openstack quota set --core 30 admin } diff --git a/juju/openo_connect.py b/juju/openo_connect.py old mode 100644 new mode 100755 index caae216..387ae98 --- a/juju/openo_connect.py +++ b/juju/openo_connect.py @@ -11,8 +11,11 @@ import argparse import sys import os +import time import requests import json +from pprint import pprint + class RaiseError(Exception): def __init__(self, msg): @@ -21,33 +24,42 @@ class RaiseError(Exception): 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): + 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): + +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", @@ -58,11 +70,24 @@ def add_common_tosca_aria(msb_ip, tosca_aria_ip): "apiJsonType":"1", "control":"0", "status":"1", - "servers":[{"ip":tosca_aria_ip,"port":"8204","weight":0}]} + "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): - url = 'http://' + msb_ip + '/openoapi/extsys/v1/vims/' + 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, @@ -74,34 +99,32 @@ def add_openo_vim(msb_ip, auth_url): "version":"newton", "description":"", "type":"openstack"} - get = request_get(url) - for i in get: - if i["type"] == "openstack": - request_delete(url + i["vimId"]) + 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) - request_post(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' + vim_url = 'http://' + msb_ip + '/openoapi/extsys/v1/vims/' + vnfm_url = 'http://' + msb_ip + '/openoapi/extsys/v1/vnfms/' headers = {'Content-Type': 'application/json'} - get_vim = request_get(vim_url) - vimId = '' - for i in get_vim: - if i["type"] == "openstack": - vimId = i['vimId'] - break - - if vimId is None: + 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: + if i["vimId"] == vimId[0]: request_delete(vnfm_url + i["vnfmId"]) data = {"name":"Juju-VNFM", - "vimId":vimId, + "vimId":vimId[0], "vendor":"jujuvnfm", "version":"jujuvnfm", "type":"jujuvnfm", @@ -112,27 +135,100 @@ def add_openo_vnfm(msb_ip, juju_client_ip): "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 - if None in (msb_ip, tosca_aria_ip, juju_client_ip, auth_url): - missing = [] - for i in (msb_ip, tosca_aria_ip, juju_client_ip, auth_url): - if i is None: - missing.append(i) - raise RaiseError('missing parameter: %s' % missing) - - add_common_tosca_aria(msb_ip, tosca_aria_ip) + 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 new file mode 100755 index 0000000..763a4f7 --- /dev/null +++ b/juju/vims_deploy.sh @@ -0,0 +1,69 @@ +#!/bin/bash -ex +############################################################################## +# 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 +############################################################################## + +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 check_clearwater() { + check_clearwater_cmd='juju status | grep clearwater &> /dev/null' + try=10 + duration=120 + clearwater_started=false + while [[ $try -ge 0 ]]; do + if [[ $try -eq 0 ]]; then + log_error "Clearwater does not start within the given time" + exit 1 + fi + exec_cmd_on_client $check_clearwater_cmd + if [[ $? -eq 0 ]]; then + clearwater_started=true + break + else + let try-=1 + sleep $duration + fi + done + + try=10 + duration=120 + check_status_cmd='juju status | grep idle | wc -l' + while [[ $try -ge 0 ]]; do + if [[ $try -eq 0 ]]; then + log_error "Clearwater does not fully start within the given time" + exit 1 + fi + exec_cmd_on_client $check_status_cmd + count=$(exec_cmd_on_client $check_status_cmd) + if [[ $count -eq 7 ]]; then + echo "Clearwater has fully started" + break + else + echo "$count out of 7 nodes have started" + let try-=1 + sleep $duration + fi + done + + get_ellis_cmd='juju status | grep clearwater-ellis | grep tcp | awk "{print \$5}"' + ellis_internal_ip=$(exec_cmd_on_client $get_ellis_cmd) + ellis_external_ip=$(openstack server list | grep $ellis_internal_ip | awk '{print $9}') + + get_bono_cmd='juju status | grep clearwater-bono | grep tcp | awk "{print \$5}"' + bono_internal_ip=$(exec_cmd_on_client $get_bono_cmd) + bono_external_ip=$(openstack server list | grep $bono_internal_ip | awk '{print $9}') + + echo "Ellis: $ellis_external_ip" + echo "Bono: $bono_external_ip" +} + -- cgit 1.2.3-korg