Change-Id: I9e5c1eb5eddd55d4258a81a274141e0ea7ed1bf1
Signed-off-by: veleza <axel.velez@etsi.org>
from subprocess import run, PIPE
import requests
from subprocess import run, PIPE
import requests
class OSMException(Exception):
"""A base class for MyProject exceptions."""
class OSMException(Exception):
"""A base class for MyProject exceptions."""
self.message = kwargs.get('message')
class OSM:
self.message = kwargs.get('message')
class OSM:
- def __init__(self, osm_hostname):
+ def __init__(self, osm_hostname, port):
self.osm_hostname = osm_hostname
self.osm_hostname = osm_hostname
def run_command(self, command):
p = run(["osm {}".format(command)], shell=True, stdout=PIPE, stderr=PIPE)
def run_command(self, command):
p = run(["osm {}".format(command)], shell=True, stdout=PIPE, stderr=PIPE)
return self.clean_output(p.stdout)
def get_auth_token(self):
return self.clean_output(p.stdout)
def get_auth_token(self):
- r = requests.post("https://{}:9999/osm/admin/v1/tokens".format(self.osm_hostname), verify=False, headers={"Accept":"application/json"}, json={
+
+ r = requests.post("https://{}:{}/osm/admin/v1/tokens".format(self.osm_hostname, self.port), verify=False, headers={"Accept":"application/json"}, json={
"username": "admin",
"password": "admin",
"project": "admin"
"username": "admin",
"password": "admin",
"project": "admin"
def create_vnfd(self, filename):
return self.run_command("vnfd-create {}".format(filename))
def create_vnfd(self, filename):
return self.run_command("vnfd-create {}".format(filename))
+ def create_ns(self, name, nsd, vim):
+ return self.run_command("ns-create --ns_name {} --nsd_name {} --vim_account {}".format(name, nsd, vim))
+
def delete_nsd(self, id):
return self.run_command("nsd-delete {}".format(id))
def delete_vnfd(self, id):
def delete_nsd(self, id):
return self.run_command("nsd-delete {}".format(id))
def delete_vnfd(self, id):
- return self.run_command("vnfd-delete {}".format(id))
\ No newline at end of file
+ return self.run_command("vnfd-delete {}".format(id))
+
+ def delete_ns(self, id):
+ self.run_command("ns-delete {}".format(id))
+ while (requests.get("https://{}:{}/osm/nslcm/v1/ns_instances/{}".format(self.osm_hostname, self.port, id), verify=False, headers={"Accept":"application/json", "Authorization":"Bearer {}".format(os.environ["AUTH_TOKEN"])}).status_code != 404):
+ print("Deleting NS...")
+ time.sleep(5)