This repository has been archived by the owner on Nov 8, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathupload_descriptors.sh
executable file
·60 lines (46 loc) · 1.74 KB
/
upload_descriptors.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#!/usr/bin/env python
import sys
import json
import requests
#list of descriptors:
descriptors = [
{"type": "proxy", "vnfd": "vnfds/vproxy.json", "nsd": "nsds/vproxy.json"},
{"type": "vsbc", "vnfd": "vnfds/vsbc.json", "nsd": "nsds/vsbc.json"},
{"type": "vhg", "vnfd": "vnfds/vhg.json", "nsd": "nsds/vhg.json"},
{"type": "vtc", "vnfd": "vnfds/vtc.json", "nsd": "nsds/vtc.json"}
]
def auth(user):
url = 'http://10.10.1.90/auth/'
payload = {"username": user,"password":"123456"}
headers = {'content-type': 'application/json'}
response = requests.post(url, data=json.dumps(payload), headers=headers)
token = response.json()['token']
return token
for descriptor in descriptors:
token = auth("fp1")
headers = {'content-type': 'application/json', 'Authorization': 'JWT ' + token}
url = 'http://10.10.1.90/vnfs/'
#upload VNFD to Marketplace
response = requests.post(url, data=open(descriptor['vnfd'], 'rb'), headers=headers)
vnfd = response.json()
print "New VNFD: %d" % vnfd['id']
#replace id in NSD
file = open(descriptor['nsd'])
contents = file.read()
replaced_contents = contents.replace('<vnfd_id>', str(vnfd['id']))
token = auth("sp1")
headers = {'content-type': 'application/json', 'Authorization': 'JWT ' + token}
#upload NSD to Marketplace
url = 'http://10.10.1.90/service-catalog/service/catalog/'
response = requests.post(url, data=replaced_contents, headers=headers)
if response.status_code == 409:
print response.text
# remove vnfd
token = auth("fp1")
headers = {'content-type': 'application/json', 'Authorization': 'JWT ' + token}
url = 'http://10.10.1.90/vnfs/' + str(vnfd['id']) + '/'
response = requests.delete(url, headers=headers)
sys.exit()
nsd = response.json()
print "New NSD: %s" % nsd['nsd']['id']
print "Done."