From 1acb8b1539d30ca3aed9bd055d34415448b61cc0 Mon Sep 17 00:00:00 2001 From: samcandy Date: Thu, 21 May 2020 20:42:30 +0800 Subject: [PATCH] Update provisioning --- allocate/main.py | 64 +++++++++++++++++++++++++++++++++++++++++++++- deallocate/main.py | 62 +++++++++++++++++++++++++++++++++----------- 2 files changed, 110 insertions(+), 16 deletions(-) diff --git a/allocate/main.py b/allocate/main.py index 401e2b7..7ad19c0 100644 --- a/allocate/main.py +++ b/allocate/main.py @@ -94,7 +94,6 @@ def upload_vnf_package(self, vnf_pkg_path): print(upload_vnfp.status_code) def listen_on_vnf_package_subscriptions(self): - # TODO gitlab feature/deallocateNSSI API in 250 row pass def create_ns_descriptor(self): @@ -254,5 +253,68 @@ def read_ns_instantiation(self, ns_instance_id): } return read_instance_nsi + def update_ns_instantiation(self, ns_instance_id, update_info): + print("Update Network service instance ID: {}".format(ns_instance_id)) + print("Update Network service Info: {}".format(update_info)) + url = self.NFVO_URL + "nslcm/v1/ns_instances/{}/update/".format(ns_instance_id) + data = dict() + if 'ADD' in update_info['type']: + data = { + "updateType": update_info['type'], + "addVnfInstance": [ + { + "vnfInstanceId": update_info['vnf_instance_id'], + "vnfProfiledId": "string" + } + ] + } + elif 'REMOVE' in update_info['type']: + data = { + "updateType": update_info['type'], + "removeVnfInstanceId": update_info['vnf_instance_id'] + } + update_nsi = requests.post(url, data=json.dumps(data), headers=self.headers) + if update_nsi.status_code == 202: + print("Update operated status {}".format(update_nsi.status_code)) + else: + response = { + "attributeListOut": { + 'update_nsi': update_nsi.status_code + }, + "status": "OperationFailed" + } + raise Exception(response) + + def scale_ns_instantiation(self, ns_instance_id, scale_info): + print("Scale Network service instance ID: {}".format(ns_instance_id)) + print("Scale Network service instance Info".format(scale_info)) + url = self.NFVO_URL + "nslcm/v1/ns_instances/{}/scale/".format(ns_instance_id) + data = { + "scaleType": "SCALE_VNF", + "scaleVnfData": [ + { + "vnfInstanceId": scale_info['vnf_instance_id'], + "scaleVnfType": scale_info['type'], + "scaleByStepData": { + "additionalParams": { + "replicas": scale_info['replicas'] + } + } + } + ] + } + + scale_nsi = requests.post(url, data=json.dumps(data), headers=self.headers) + if scale_nsi.status_code == 202: + print("Scale operated status {}".format(scale_nsi.status_code)) + else: + response = { + "attributeListOut": { + 'scale_nsi': scale_nsi.status_code + }, + "status": "OperationFailed" + } + raise Exception(response) + def listen_on_ns_instance_subscriptions(self): pass diff --git a/deallocate/main.py b/deallocate/main.py index bf950c8..feb9859 100644 --- a/deallocate/main.py +++ b/deallocate/main.py @@ -1,37 +1,69 @@ from service_mapping_plugin_framework.deallocate_nssi_abc import DeallocateNSSIabc +import requests +import json class NFVOPlugin(DeallocateNSSIabc): - def __init__(self, nm_host, nfvo_host): - super().__init__(nm_host, nfvo_host) + def __init__(self, nm_host, nfvo_host, subscription_host, parameter): + super().__init__(nm_host, nfvo_host, subscription_host, parameter) + self.headers = {'Content-type': 'application/json'} def coordinate_tn_manager(self): pass def terminate_network_service_instance(self): - pass + print('Terminate Network service instance...') + url = self.NFVO_URL + "nslcm/v1/ns_instances/{}/terminate/".format(self.ns_instance) + response = requests.post(url, headers=self.headers) + print(response.status_code) def delete_network_service_instance(self): + print('Delete Network service instance...') + url = self.NFVO_URL + "nslcm/v1/ns_instances/{}/".format(self.ns_instance) + response = requests.delete(url, headers=self.headers) + print(response.status_code) + + def delete_network_service_instance_subscriptions(self): pass def update_network_service_descriptor(self): - pass + print('Update Network service descriptor...') + url = self.NFVO_URL + "nsd/v1/ns_descriptors/{}/".format(self.ns_descriptor) + data = { + "nsdOperationalState": "DISABLED", + "userDefinedData": [ + {} + ] + } + response = requests.patch(url, data=json.dumps(data), headers=self.headers) + print(response.status_code) def delete_network_service_descriptor(self): + print('Delete Network service descriptor...') + url = self.NFVO_URL + "nsd/v1/ns_descriptors/{}/".format(self.ns_descriptor) + response = requests.delete(url, headers=self.headers) + print(response.status_code) + + def delete_network_service_descriptor_subscriptions(self): pass def update_vnf_package(self): - pass + for vnf in self.vnf_package: + print('Update {} Vnf Package...'.format(vnf)) + url = self.NFVO_URL + "vnfpkgm/v1/vnf_packages/{}/".format(vnf) + data = { + "operationalState": "DISABLED", + "userDefinedData": {} + } + response = requests.patch(url, data=json.dumps(data), headers=self.headers) + print(response.status_code) def delete_vnf_package(self): - pass - - -def main(): - nfvo_plugin = NFVOPlugin('', # nm host ip - '') # os-ma-nfvo host ip - nfvo_plugin.deallocate_nssi() + for vnf in self.vnf_package: + print('Delete {} Vnf Package...'.format(vnf)) + url = self.NFVO_URL + "vnfpkgm/v1/vnf_packages/{}/".format(vnf) + response = requests.delete(url, headers=self.headers) + print(response.status_code) - -if __name__ == '__main__': - main() + def delete_vnf_package_subscriptions(self): + pass