aboutsummaryrefslogtreecommitdiffstats
path: root/juju
diff options
context:
space:
mode:
authorHarry Huang <huangxiangyu5@huawei.com>2017-03-02 16:11:35 +0800
committerHarry Huang <huangxiangyu5@huawei.com>2017-03-02 20:21:33 +0800
commit73a71b794191019bfa83f6bd7194ef8316273780 (patch)
tree27098c28ff21f2582829272faf97a8ae502f56f7 /juju
parentdf06f21dc792b1c17219d9d9d59e29184e1868bb (diff)
adjust juju connect
1. delete existing VIM and VNFM when add 2. fix mysql grant not effective bug 3. remove know_hosts in juju env prepare Change-Id: I2b6c470020b2a36d341f8313baaded15c0dfd2cd Signed-off-by: Harry Huang <huangxiangyu5@huawei.com>
Diffstat (limited to 'juju')
-rwxr-xr-xjuju/juju_connect.sh5
-rwxr-xr-xjuju/juju_setup.sh3
-rw-r--r--juju/openo_connect.py94
3 files changed, 64 insertions, 38 deletions
diff --git a/juju/juju_connect.sh b/juju/juju_connect.sh
index 6d1b3e4..7ff803e 100755
--- a/juju/juju_connect.sh
+++ b/juju/juju_connect.sh
@@ -64,6 +64,7 @@ function start_tomcat()
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'rootpass' WITH GRANT OPTION;
FLUSH PRIVILEGES;
EOF"
+ exec_cmd_on_client $cmd1
local cmd2='sed -i s/port=\"8080\"/port=\"8483\"/g /home/ubuntu/tomcat8/conf/server.xml'
exec_cmd_on_client $cmd2
@@ -80,9 +81,9 @@ function add_vim_and_vnfm()
--juju_client_ip $floating_ip_client \
--auth_url $OS_AUTH_URL
- local cmd3="docker stop nfvo-driver-vnfm-juju; \
+ local cmd1="docker stop nfvo-driver-vnfm-juju; \
docker start nfvo-driver-vnfm-juju"
- exec_cmd_on_openo $cmd3
+ exec_cmd_on_openo $cmd1
}
function connect_juju_and_openo()
diff --git a/juju/juju_setup.sh b/juju/juju_setup.sh
index e37eb1f..4fd5cbc 100755
--- a/juju/juju_setup.sh
+++ b/juju/juju_setup.sh
@@ -12,6 +12,9 @@ IMG_DIR=${WORK_DIR}/img
function juju_env_prepare()
{
+ sudo rm -f /root/.ssh/known_hosts
+ sudo rm -f /root/.ssh/known_hosts.old
+
mkdir -p ${WORK_DIR}/venv
sudo pip install --upgrade virtualenv
virtualenv ${WORK_DIR}/venv
diff --git a/juju/openo_connect.py b/juju/openo_connect.py
index 7792082..caae216 100644
--- a/juju/openo_connect.py
+++ b/juju/openo_connect.py
@@ -21,6 +21,32 @@ 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):
+ 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):
+ raise RaiseError('post url: %s fail %d' % (url, resp.status_code))
+ except Exception:
+ raise
+
+def request_delete(url):
+ try:
+ resp = requests.delete(url)
+ if resp.status_code not in (200,201,204):
+ raise RaiseError('delete url: %s fail %d' % (url, resp.status_code))
+ except Exception:
+ raise
+
def add_common_tosca_aria(msb_ip, tosca_aria_ip):
url = 'http://' + msb_ip + '/openoapi/microservices/v1/apiRoute'
headers = {'Content-Type': 'application/json'}
@@ -33,13 +59,7 @@ def add_common_tosca_aria(msb_ip, tosca_aria_ip):
"control":"0",
"status":"1",
"servers":[{"ip":tosca_aria_ip,"port":"8204","weight":0}]}
- try:
- resp = requests.post(url, data=json.dumps(data), headers=headers)
- if resp.status_code not in (200,201):
- raise RaiseError('add common_tosca_aria service failed')
-
- except Exception:
- raise
+ request_post(url, data, headers)
def add_openo_vim(msb_ip, auth_url):
url = 'http://' + msb_ip + '/openoapi/extsys/v1/vims/'
@@ -54,41 +74,43 @@ def add_openo_vim(msb_ip, auth_url):
"version":"newton",
"description":"",
"type":"openstack"}
- try:
- resp = requests.post(url, data=json.dumps(data), headers=headers)
- if resp.status_code not in (200,201):
- raise RaiseError('add open-o vim failed')
+ get = request_get(url)
+ for i in get:
+ if i["type"] == "openstack":
+ request_delete(url + i["vimId"])
- except Exception:
- raise
+ request_post(url, data, headers)
def add_openo_vnfm(msb_ip, juju_client_ip):
- 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'}
- try:
- resp = requests.get(vim_url)
- if resp.status_code not in (200,201):
- raise RaiseError('add open-o vnfm failed')
-
- vimInfo = resp.json()
- vimId = vimInfo[0]['vimId']
- data = {"name":"Juju-VNFM",
- "vimId":vimId,
- "vendor":"jujuvnfm",
- "version":"jujuvnfm",
- "type":"jujuvnfm",
- "description":"",
- "certificateUrl":"",
- "url":"http://" + juju_client_ip + ":8483",
- "userName":"",
- "password":""}
- resp = requests.post(vnfm_url, data=json.dumps(data), headers=headers)
- if resp.status_code not in (200,201):
- raise RaiseError('add open-o vnfm failed')
+ get_vim = request_get(vim_url)
+ vimId = ''
+ for i in get_vim:
+ if i["type"] == "openstack":
+ vimId = i['vimId']
+ break
- except Exception:
- raise
+ if vimId is None:
+ raise RaiseError("vim openstack not found")
+
+ get_vnfm = request_get(vnfm_url)
+ for i in get_vnfm:
+ if i["vimId"] == vimId:
+ request_delete(vnfm_url + i["vnfmId"])
+
+ data = {"name":"Juju-VNFM",
+ "vimId":vimId,
+ "vendor":"jujuvnfm",
+ "version":"jujuvnfm",
+ "type":"jujuvnfm",
+ "description":"",
+ "certificateUrl":"",
+ "url":"http://" + juju_client_ip + ":8483",
+ "userName":"",
+ "password":""}
+ request_post(vnfm_url, data, headers)
if __name__ == "__main__":