diff options
author | Michal Jagiello <michal.jagiello@t-mobile.pl> | 2022-10-17 12:46:49 +0000 |
---|---|---|
committer | Michal Jagiello <michal.jagiello@t-mobile.pl> | 2022-10-17 14:05:09 +0000 |
commit | f2adf542e878c96895210f97ebf1ebb763b2f465 (patch) | |
tree | 91fc0faeb3436e723d07aed1f38ce59a6e7cc7c5 /docs/examples | |
parent | 49071a0d0425ef67fa552dbf14c81e5a11cc49e7 (diff) |
Release ONAP SDKv10.2
Issue-ID: INT-2150
Signed-off-by: Michal Jagiello <michal.jagiello@t-mobile.pl>
Change-Id: I650047c599a5aae6de7c6b42d38e34aea88578e2
Diffstat (limited to 'docs/examples')
-rw-r--r-- | docs/examples/e2e_artifact_upload.rst | 58 | ||||
-rw-r--r-- | docs/examples/e2e_basicvm_nomulticloud_instantiation.rst | 414 | ||||
-rw-r--r-- | docs/examples/e2e_closed_loop_instantiation.rst | 108 | ||||
-rw-r--r-- | docs/examples/e2e_net_instantiation.rst | 332 | ||||
-rw-r--r-- | docs/examples/e2e_vfw_instantiation.rst | 429 | ||||
-rw-r--r-- | docs/examples/e2e_vfw_macro_instantiation.rst | 493 | ||||
-rw-r--r-- | docs/examples/examples.rst | 13 | ||||
-rw-r--r-- | docs/examples/k8s_plugin_usage.rst | 94 |
8 files changed, 1941 insertions, 0 deletions
diff --git a/docs/examples/e2e_artifact_upload.rst b/docs/examples/e2e_artifact_upload.rst new file mode 100644 index 0000000..aea4d21 --- /dev/null +++ b/docs/examples/e2e_artifact_upload.rst @@ -0,0 +1,58 @@ +E2E Upload of an artifact +##################################### + + +.. code:: Python + + import os + import logging + + from onapsdk.sdc.vsp import Vsp + from onapsdk.sdc.vf import Vf + from onapsdk.sdc.service import Service + + logger = logging.getLogger("") + logger.setLevel(logging.INFO) + fh = logging.StreamHandler() + fh_formatter = logging.Formatter('%(asctime)s %(levelname)s %(lineno)d:%(filename)s(%(process)d) - %(message)s') + fh.setFormatter(fh_formatter) + logger.addHandler(fh) + + + + # Create required A&AI resources + VF_NAME = "my_VF" + SERVICENAME = "artifact_SERVICE" + + ARTIFACT_NAME = "clampnode" + ARTIFACT_TYPE = "DCAE_INVENTORY_BLUEPRINT" + ARTIFACT_FILE_PATH = "{os.path.dirname(os.path.abspath(__file__))}/my_ArtifactFile.yaml" + + + logger.info("*******************************") + logger.info("******** SERVICE DESIGN *******") + logger.info("*******************************") + + logger.info("******** Get VF *******") + vf = Vf(VF_NAME) + vf.onboard() + + logger.info("******** Create Service *******") + svc = Service(name=SERVICENAME) + svc.create() + svc.add_resource(vf) + + logger.info("******** Extract Artifact Data *******") + data = open(ARTIFACT_FILE_PATH,'rb').read() + + logger.info("******** Upload Artifact *******") + svc.add_artifact_to_vf(vnf_name=VF_NAME, + artifact_type=ARTIFACT_TYPE, + artifact_name=ARTIFACT_NAME, + artifact=data) + + logger.info("******** Distribute Service *******") + svc.checkin() + svc.certify() + svc.distribute() + diff --git a/docs/examples/e2e_basicvm_nomulticloud_instantiation.rst b/docs/examples/e2e_basicvm_nomulticloud_instantiation.rst new file mode 100644 index 0000000..37f3c31 --- /dev/null +++ b/docs/examples/e2e_basicvm_nomulticloud_instantiation.rst @@ -0,0 +1,414 @@ +E2E Instantiation of a simple VM without muticloud +################################################## + + +.. code:: Python + + import logging + import time + from uuid import uuid4 + from onapsdk.aai.aai_element import AaiElement + from onapsdk.aai.cloud_infrastructure import ( + CloudRegion, + Complex, + Tenant + ) + from onapsdk.aai.service_design_and_creation import ( + Service as AaiService + ) + from onapsdk.aai.business import ( + ServiceInstance, + VnfInstance, + VfModuleInstance, + ServiceSubscription, + Customer, + OwningEntity as AaiOwningEntity + ) + from onapsdk.so.instantiation import ( + ServiceInstantiation, + VnfInstantiation, + VnfParameter + ) + from onapsdk.sdc import SDC + from onapsdk.sdc.vendor import Vendor + from onapsdk.sdc.vsp import Vsp + from onapsdk.sdc.vf import Vf + from onapsdk.sdc.service import Service + import onapsdk.constants as const + import os + from onapsdk.vid import LineOfBusiness, OwningEntity, Platform, Project + + logger = logging.getLogger("") + logger.setLevel(logging.DEBUG) + fh = logging.StreamHandler() + fh_formatter = logging.Formatter('%(asctime)s %(levelname)s %(lineno)d:%(filename)s(%(process)d) - %(message)s') + fh.setFormatter(fh_formatter) + logger.addHandler(fh) + + # Required A&AI resources + VSPNAME = "ubuntu16_VSP" + VFNAME = "ubuntu16_VF" + SERVICENAME = "ubuntu16_SERVICE" + + # FULLY CUSTOMIZABLE VALUES + # ************************* + VENDOR = "" # FILL ME + GLOBAL_CUSTOMER_ID = "" # FILL ME + SERVICE_DELETION = True # True|False + + COMPLEX_PHYSICAL_LOCATION_ID = "" # FILL ME + COMPLEX_DATA_CENTER_CODE = "" # FILL ME + + CLOUD_OWNER = "" # FILL ME + + OWNING_ENTITY = "" # FILL ME + PROJECT = "" # FILL ME + PLATFORM = "" # FILL ME + LINE_OF_BUSINESS = "" # FILL ME + + SERVICE_INSTANCE_NAME = "" # FILL ME + + AVAILABILITY_ZONE_NAME = "" # FILL ME + AVAILABILITY_ZONE_HYPERVISOR_TYPE = "" # FILL ME + + + # FILL ME with your INFRA values + # ****************************** + # ubuntu16.zip file path including the heat and env files + VSPFILE_PATH = "" # FILL ME + + VIM_USERNAME = "" # FILL ME + VIM_PASSWORD = "" # FILL ME + VIM_SERVICE_URL = "" # FILL ME + + TENANT_NAME = "" # FILL ME + TENANT_ID = "" # FILL ME + + CLOUD_REGION = "" # Shall be defined in Openstack + + + # ************************************************************************************************* + logger.info("*******************************") + logger.info("******** SERVICE DESIGN *******") + logger.info("*******************************") + + logger.info("******** Onboard Vendor *******") + vendor = Vendor(name=VENDOR) + vendor.onboard() + + logger.info("******** Onboard VSP *******") + vsp = Vsp(name=VSPNAME, vendor=vendor, package=open(VSPFILE_PATH, 'rb')) + vsp.onboard() + + logger.info("******** Onboard VF *******") + vf = Vf(name=VFNAME) + vf.vsp = vsp + vf.onboard() + + logger.info("******** Onboard Service *******") + svc = Service(name=SERVICENAME, resources=[vf]) + svc.onboard() + + logger.info("******** Check Service Distribution *******") + distribution_completed = False + nb_try = 0 + nb_try_max = 10 + while distribution_completed is False and nb_try < nb_try_max: + distribution_completed = svc.distributed + if distribution_completed is True: + logger.info("Service Distribution for %s is sucessfully finished",svc.name) + break + logger.info("Service Distribution for %s ongoing, Wait for 60 s",svc.name) + time.sleep(60) + nb_try += 1 + + if distribution_completed is False: + logger.error("Service Distribution for %s failed !!",svc.name) + exit(1) + + logger.info("*******************************") + logger.info("***** RUNTIME PREPARATION *****") + logger.info("*******************************") + + logger.info("******** Create Complex *******") + cmplx = Complex.create( + physical_location_id=COMPLEX_PHYSICAL_LOCATION_ID, + data_center_code=COMPLEX_DATA_CENTER_CODE, + name=COMPLEX_PHYSICAL_LOCATION_ID + ) + + logger.info("******** Create CloudRegion *******") + # Note for non multicloud instanciation, cloud_region_version shall be set to openstack + # versus + cloud_region = CloudRegion.create( + cloud_owner=CLOUD_OWNER, + cloud_region_id=CLOUD_REGION, + orchestration_disabled=False, + in_maint=False, + cloud_type="openstack", + cloud_region_version="openstack", + cloud_zone="z1", + complex_name=COMPLEX_PHYSICAL_LOCATION_ID + ) + + logger.info("******** Link Complex to CloudRegion *******") + cloud_region.link_to_complex(cmplx) + + logger.info("******** Add ESR Info to CloudRegion *******") + cloud_region.add_esr_system_info( + esr_system_info_id=str(uuid4()), + user_name=VIM_USERNAME, + password=VIM_PASSWORD, + system_type="VIM", + service_url=VIM_SERVICE_URL, + cloud_domain="Default", + ssl_insecure=False, + system_status="active", + default_tenant=TENANT_NAME + ) + + logger.info("*******************************") + logger.info("**** SERVICE INSTANTIATION ****") + logger.info("*******************************") + + logger.info("******** Create Customer *******") + customer = None + for found_customer in list(Customer.get_all()): + logger.debug("Customer %s found", found_customer.subscriber_name) + if found_customer.subscriber_name == GLOBAL_CUSTOMER_ID: + logger.info("Customer %s found", found_customer.subscriber_name) + customer = found_customer + break + if not customer: + customer = Customer.create(GLOBAL_CUSTOMER_ID,GLOBAL_CUSTOMER_ID, "INFRA") + + logger.info("******** Find Service in SDC *******") + service = None + services = Service.get_all() + for found_service in services: + logger.debug("Service %s is found, distribution %s",found_service.name, found_service.distribution_status) + if found_service.name == SERVICENAME: + logger.info("Found Service %s in SDC",found_service.name) + service = found_service + break + + if not service: + logger.error("Service %s not found in SDC",SERVICENAME) + exit(1) + + logger.info("******** Check Service Subscription *******") + service_subscription = None + for service_sub in customer.service_subscriptions: + logger.debug("Service subscription %s is found",service_sub.service_type) + if service_sub.service_type == SERVICENAME: + logger.info("Service %s subscribed",SERVICENAME) + service_subscription = service_sub + break + + if not service_subscription: + logger.info("******** Subscribe Service *******") + customer.subscribe_service(SERVICENAME) + + logger.info("******** Get Tenant *******") + cloud_region = CloudRegion(cloud_owner=CLOUD_OWNER, cloud_region_id=CLOUD_REGION, + orchestration_disabled=True, in_maint=False) + try: + tenant: Tenant = cloud_region.get_tenant(settings.TENANT_ID) + except ValueError: + logger.warning("Impossible to retrieve the Specificed Tenant") + logger.debug("If no multicloud selected, add the tenant") + cloud_region.add_tenant( + tenant_id=settings.TENANT_ID, + tenant_name=settings.TENANT_NAME) + + # be sure that an availability zone has been created + # if not, create it + try: + cloud_region.get_availability_zone_by_name( + settings.AVAILABILITY_ZONE_NAME) + except ValueError: + cloud_region.add_availability_zone( + settings.AVAILABILITY_ZONE_NAME, + settings.AVAILABILITY_ZONE_HYPERVISOR_TYPE) + + logger.info("******** Connect Service to Tenant *******") + service_subscription = None + for service_sub in customer.service_subscriptions: + logger.debug("Service subscription %s is found",service_sub.service_type) + if service_sub.service_type == SERVICENAME: + logger.info("Service %s subscribed",SERVICENAME) + service_subscription = service_sub + break + + if not service_subscription: + logger.error("Service subscription %s is not found",SERVICENAME) + exit(1) + + service_subscription.link_to_cloud_region_and_tenant(cloud_region, tenant) + + logger.info("******** Add Business Objects (OE, P, Pl, LoB) in VID *******") + vid_owning_entity = OwningEntity.create(OWNING_ENTITY) + vid_project = Project.create(PROJECT) + vid_platform = Platform.create(PLATFORM) + vid_line_of_business = LineOfBusiness.create(LINE_OF_BUSINESS) + + logger.info("******** Add Owning Entity in AAI *******") + owning_entity = None + for oe in AaiOwningEntity.get_all(): + if oe.name == vid_owning_entity.name: + owning_entity = oe + break + if not owning_entity: + logger.info("******** Owning Entity not existing: create *******") + owning_entity = AaiOwningEntity.create(vid_owning_entity.name, str(uuid4())) + + logger.info("******** Instantiate Service *******") + service_instance = None + service_instantiation = None + for se in service_subscription.service_instances: + if se.instance_name == SERVICE_INSTANCE_NAME: + service_instance = se + break + if not service_instance: + logger.info("******** Service Instance not existing: Instantiate *******") + # Instantiate service + service_instantiation = ServiceInstantiation.instantiate_so_ala_carte( + service, + cloud_region, + tenant, + customer, + owning_entity, + vid_project, + service_instance_name=SERVICE_INSTANCE_NAME + ) + time.sleep(60) + else: + logger.info("******** Service Instance already existing *******") + + service_instance = None + for se in service_subscription.service_instances: + if se.instance_name == SERVICE_INSTANCE_NAME: + service_instance = se + break + if not service_instance: + logger.error("******** Service %s instantiation failed",SERVICE_INSTANCE_NAME) + exit(1) + + nb_try = 0 + nb_try_max = 10 + service_active = False + while service_active is False and nb_try < nb_try_max: + if service_instance.orchestration_status == "Active": + logger.info("******** Service Instance %s is active *******",service_instance.name) + service_active = True + break + logger.info("Service %s instantiation not complete,Status:%s, wait 10s",service_instance.name,service_instance.orchestration_status) + time.sleep(10) + nb_try += 1 + + if service_active is False: + logger.error("Service %s instantiation failed",service_instance.name) + exit(1) + + + logger.info("******** Get VNFs in Service Model *******") + vnfs = service_instance.service_subscription.sdc_service.vnfs + + logger.info("******** Create VNFs *******") + for vnf in vnfs: + logger.debug("Check if VNF instance of class %s exist", vnf.name) + vnf_found = False + for vnf_instance in service_instance.vnf_instances: + logger.debug("VNF instance %s found in Service Instance ",vnf_instance.name) + vnf_found = True + if vnf_found is False: + vnf_instantiation = service_instance.add_vnf(vnf, vid_line_of_business, vid_platform) + while not vnf_instantiation.finished: + print("Wait for VNF %s instantiation",vnf.name) + time.sleep(10) + + + for vnf_instance in service_instance.vnf_instances: + logger.debug("VNF instance %s found in Service Instance ",vnf_instance.name) + logger.info("******** Get VfModules in VNF Model *******") + logger.info("******** Check VF Modules *******") + vf_module = vnf_instance.vnf.vf_module + + logger.info("******** Create VF Module %s *******",vf_module.name) + + for vf_module in vnf_instance.vnf.vf_modules: + vf_module_instantiation = vnf_instance.add_vf_module( + vf_module, + cloud_region,tenant, + SERVICE_INSTANCE_NAME, + vnf_parameters=[]) + nb_try = 0 + nb_try_max = 30 + while not vf_module_instantiation.finished and nb_try < nb_try_max: + logger.info("Wait for vf module instantiation") + nb_try += 1 + time.sleep(10) + if vf_module_instantiation.finished: + logger.info("VfModule %s instantiated",vf_module.name) + else: + logger.error("VfModule instantiation %s failed",vf_module.name) + + if SERVICE_DELETION is False: + logger.info("*****************************************") + logger.info("**** No Deletion requested, finished ****") + logger.info("*****************************************") + exit(0) + + logger.info("*******************************") + logger.info("**** SERVICE DELETION *********") + logger.info("*******************************") + time.sleep(30) + + for vnf_instance in service_instance.vnf_instances: + logger.debug("VNF instance %s found in Service Instance ",vnf_instance.name) + logger.info("******** Get VF Modules *******") + for vf_module in vnf_instance.vf_modules: + logger.info("******** Delete VF Module %s *******",vf_module.name) + vf_module_deletion = vf_module.delete() + + nb_try = 0 + nb_try_max = 30 + while not vf_module_deletion.finished and nb_try < nb_try_max: + logger.info("Wait for vf module deletion") + nb_try += 1 + time.sleep(10) + if vf_module_deletion.finished: + logger.info("VfModule %s deleted",vf_module.name) + else: + logger.error("VfModule deletion %s failed",vf_module.name) + exit(1) + + logger.info("******** Delete VNF %s *******",vnf_instance.name) + vnf_deletion = vnf_instance.delete() + + nb_try = 0 + nb_try_max = 30 + while not vnf_deletion.finished and nb_try < nb_try_max: + logger.info("Wait for vnf deletion") + nb_try += 1 + time.sleep(10) + if vnf_deletion.finished: + logger.info("VNF %s deleted",vnf_instance.name) + else: + logger.error("VNF deletion %s failed",vnf_instance.name) + exit(1) + + logger.info("******** Delete Service %s *******",service_instance.name) + service_deletion = service_instance.delete() + + nb_try = 0 + nb_try_max = 30 + while not service_deletion.finished and nb_try < nb_try_max: + logger.info("Wait for Service deletion") + nb_try += 1 + time.sleep(10) + if service_deletion.finished: + logger.info("Service %s deleted",service_instance.name) + else: + logger.error("Service deletion %s failed",service_instance.name) + exit(1) diff --git a/docs/examples/e2e_closed_loop_instantiation.rst b/docs/examples/e2e_closed_loop_instantiation.rst new file mode 100644 index 0000000..a263a66 --- /dev/null +++ b/docs/examples/e2e_closed_loop_instantiation.rst @@ -0,0 +1,108 @@ +E2E Instantiation of a Closed Loop +########################################## + + +.. code:: Python + + #Service already created in this case + + logger = logging.getLogger("") + logger.setLevel(logging.INFO) + fh = logging.StreamHandler() + fh_formatter = logging.Formatter('%(asctime)s %(levelname)s %(lineno)d:%(filename)s(%(process)d) - %(message)s') + fh.setFormatter(fh_formatter) + logger.addHandler(fh) + + + #Constants + SERVICE_NAME = "Test_SDK" + POLICY_NAME = ["MinMax", "FrequencyLimiter"] + LOOP_INSTANCE_NAME = "instance01" + CERT = (PEM, KEY) # you must add clamp cert for AUTHENTIFICATION + + Clamp.set_proxy({ 'http': 'socks5h://127.0.0.1:8080', 'https': 'socks5h://127.0.0.1:8080'}) + Service.set_proxy({ 'http': 'socks5h://127.0.0.1:8080', 'https': 'socks5h://127.0.0.1:8080'}) + + logger.info("*******************************") + logger.info("******** SERVICE FETCH *******") + logger.info("*******************************") + + svc = Service(name=SERVICE_NAME) + + logger.info("***************************************") + logger.info("******** CLAMP AUTHENTIFICATION *******") + logger.info("***************************************") + + Clamp(cert=CERT) + + logger.info("*************************************") + logger.info("******** LOOP TEMPLATES CHECK *******") + logger.info("*************************************") + + loop_template = Clamp.check_loop_template(service=svc) + if not loop_template: + logger.error("Loop template for the service %s not found", svc.name) + exit(1) + + logger.info("*******************************") + logger.info("******** POLICIES CHECK *******") + logger.info("*******************************") + + minmax_exists = Clamp.check_policies(policy_name=POLICY_NAME[0], + req_policies=30) + frequency_exists = Clamp.check_policies(policy_name=POLICY_NAME[1], + req_policies=30) + policy_exists = (minmax_exists and frequency_exists) + if not policy_exists: + logger.error("Couldn't load the policy %s", POLICY_NAME) + exit(1) + + logger.info("***********************************") + logger.info("******** LOOP INSTANTIATION *******") + logger.info("***********************************") + + loop = LoopInstance(template=loop_template, name=LOOP_INSTANCE_NAME, details={}, cert=CERT) + loop.create() + if loop.details: + logger.info("Loop instance %s successfully created !!", LOOP_INSTANCE_NAME) + else: + logger.error("An error occured while creating the loop instance") + + logger.info("******** UPDATE MICROSERVICE POLICY *******") + loop._update_loop_details() + loop.update_microservice_policy() + + logger.info("******** ADD OPERATIONAL POLICY MINMAX *******") + added = loop.add_operational_policy(policy_type="onap.policies.controlloop.guard.common.MinMax", + policy_version="1.0.0") + + logger.info("******** CONFIGURE OPERATIONAL POLICY MINMAX *******") + loop.add_op_policy_config(loop.add_minmax_config) + + logger.info("******** ADD FREQUENCY POLICY *******") + added = loop.add_operational_policy(policy_type="onap.policies.controlloop.guard.common.FrequencyLimiter", + policy_version="1.0.0") + + logger.info("******** CONFIGURE FREQUENCY POLICY *******") + loop.add_op_policy_config(loop.add_frequency_limiter) + + logger.info("******** SUBMIT POLICIES TO PE *******") + submit = loop.act_on_loop_policy(loop.submit) + + logger.info("******** CHECK POLICIES SUBMITION *******") + if submit : + logger.info("Policies successfully submited to PE") + else: + logger.error("An error occured while submitting the loop instance") + exit(1) + + logger.info("******** DEPLOY LOOP INSTANCE *******") + deploy = loop.deploy_microservice_to_dcae() + if deploy: + logger.info("Loop instance %s successfully deployed on DCAE !!", LOOP_INSTANCE_NAME) + else: + logger.error("An error occured while deploying the loop instance") + exit(2) + + logger.info("******** DELETE LOOP INSTANCE *******") + loop.delete() diff --git a/docs/examples/e2e_net_instantiation.rst b/docs/examples/e2e_net_instantiation.rst new file mode 100644 index 0000000..bfa4346 --- /dev/null +++ b/docs/examples/e2e_net_instantiation.rst @@ -0,0 +1,332 @@ +E2E Instantiation of a simple Network +##################################### + + +.. code:: Python + + import logging + import time + from uuid import uuid4 + from onapsdk.aai.aai_element import AaiElement + from onapsdk.aai.cloud_infrastructure import ( + CloudRegion, + Complex, + Tenant + ) + from onapsdk.aai.service_design_and_creation import ( + Service as AaiService + ) + from onapsdk.aai.business import ( + ServiceInstance, + ServiceSubscription, + Customer, + OwningEntity as AaiOwningEntity + ) + from onapsdk.so.instantiation import ( + ServiceInstantiation, + Subnet + ) + from onapsdk.sdc.service import Service + from onapsdk.sdc.vl import Vl + import onapsdk.constants as const + import os + from onapsdk.vid import LineOfBusiness, OwningEntity, Platform, Project + + logger = logging.getLogger("") + logger.setLevel(logging.INFO) + fh = logging.StreamHandler() + fh_formatter = logging.Formatter('%(asctime)s %(levelname)s %(lineno)d:%(filename)s(%(process)d) - %(message)s') + fh.setFormatter(fh_formatter) + logger.addHandler(fh) + + + + # Create required A&AI resources + VL_NAME = "Generic NeutronNet" + SERVICENAME = "net_SERVICE" + + GLOBAL_CUSTOMER_ID = "" # FILL ME + COMPLEX_PHYSICAL_LOCATION_ID = "" # FILL ME + COMPLEX_DATA_CENTER_CODE = "" # FILL ME + + CLOUD_OWNER = "" # FILL ME + CLOUD_REGION = "" # FILL ME + + VIM_USERNAME = "" # FILL ME + VIM_PASSWORD = "" # FILL ME + VIM_SERVICE_URL = "" # FILL ME + + TENANT_NAME = "" # FILL ME + OWNING_ENTITY = "" # FILL ME + PROJECT = "" # FILL ME + PLATFORM = "" # FILL ME + LINE_OF_BUSINESS = "" # FILL ME + + SERVICE_INSTANCE_NAME = "net-Instance" + SERVICE_DELETION = True + + logger.info("*******************************") + logger.info("******** SERVICE DESIGN *******") + logger.info("*******************************") + + logger.info("******** Get VL *******") + vl = Vl(VL_NAME) + + logger.info("******** Onboard Service *******") + svc = Service(name=SERVICENAME, resources=[vl]) + svc.onboard() + + logger.info("******** Check Service Distribution *******") + distribution_completed = False + nb_try = 0 + nb_try_max = 10 + while distribution_completed is False and nb_try < nb_try_max: + distribution_completed = svc.distributed + if distribution_completed is True: + logger.info("Service Distribution for %s is sucessfully finished",svc.name) + break + logger.info("Service Distribution for %s ongoing, Wait for 60 s",svc.name) + time.sleep(60) + nb_try += 1 + + if distribution_completed is False: + logger.error("Service Distribution for %s failed !!",svc.name) + exit(1) + + logger.info("*******************************") + logger.info("***** RUNTIME PREPARATION *****") + logger.info("*******************************") + + logger.info("******** Create Complex *******") + cmplx = Complex.create( + physical_location_id=COMPLEX_PHYSICAL_LOCATION_ID, + data_center_code=COMPLEX_DATA_CENTER_CODE, + name=COMPLEX_PHYSICAL_LOCATION_ID + ) + + logger.info("******** Create CloudRegion *******") + cloud_region = CloudRegion.create( + cloud_owner=CLOUD_OWNER, + cloud_region_id=CLOUD_REGION, + orchestration_disabled=False, + in_maint=False, + cloud_type="openstack", + cloud_region_version="titanium_cloud", + cloud_zone="z1", + complex_name=COMPLEX_PHYSICAL_LOCATION_ID + ) + + logger.info("******** Link Complex to CloudRegion *******") + cloud_region.link_to_complex(cmplx) + + logger.info("******** Add ESR Info to CloudRegion *******") + cloud_region.add_esr_system_info( + esr_system_info_id=str(uuid4()), + user_name=VIM_USERNAME, + password=VIM_PASSWORD, + system_type="VIM", + service_url=VIM_SERVICE_URL, + cloud_domain="Default", + ssl_insecure=False, + system_status="active", + default_tenant=TENANT_NAME + ) + + logger.info("******** Register CloudRegion to MultiCloud *******") + cloud_region.register_to_multicloud() + + logger.info("******** Check MultiCloud Registration *******") + time.sleep(60) + registration_completed = False + nb_try = 0 + nb_try_max = 10 + while registration_completed is False and nb_try < nb_try_max: + for tenant in cloud_region.tenants: + logger.debug("Tenant %s found in %s_%s",tenant.name,cloud_region.cloud_owner,cloud_region.cloud_region_id) + registration_completed = True + if registration_completed is False: + time.sleep(60) + nb_try += 1 + + if registration_completed is False: + logger.error("Registration of Cloud %s_%s failed !!",cloud_region.cloud_owner,cloud_region.cloud_region_id) + exit(1) + else: + logger.info("Registration of Cloud %s_%s successful !!",cloud_region.cloud_owner,cloud_region.cloud_region_id) + + logger.info("*******************************") + logger.info("**** SERVICE INSTANTIATION ****") + logger.info("*******************************") + + logger.info("******** Create Customer *******") + customer = None + for found_customer in list(Customer.get_all()): + logger.debug("Customer %s found", found_customer.subscriber_name) + if found_customer.subscriber_name == GLOBAL_CUSTOMER_ID: + logger.info("Customer %s found", found_customer.subscriber_name) + customer = found_customer + break + if not customer: + customer = Customer.create(GLOBAL_CUSTOMER_ID,GLOBAL_CUSTOMER_ID, "INFRA") + + logger.info("******** Find Service in SDC *******") + service = None + services = Service.get_all() + for found_service in services: + logger.debug("Service %s is found, distribution %s",found_service.name, found_service.distribution_status) + if found_service.name == SERVICENAME: + logger.info("Found Service %s in SDC",found_service.name) + service = found_service + break + + if not service: + logger.error("Service %s not found in SDC",SERVICENAME) + exit(1) + + logger.info("******** Check Service Subscription *******") + service_subscription = None + for service_sub in customer.service_subscriptions: + logger.debug("Service subscription %s is found",service_sub.service_type) + if service_sub.service_type == SERVICENAME: + logger.info("Service %s subscribed",SERVICENAME) + service_subscription = service_sub + break + + if not service_subscription: + logger.info("******** Subscribe Service *******") + customer.subscribe_service(SERVICENAME) + + logger.info("******** Get Tenant *******") + cloud_region = CloudRegion(cloud_owner=CLOUD_OWNER, cloud_region_id=CLOUD_REGION, + orchestration_disabled=True, in_maint=False) + tenant = None + for found_tenant in cloud_region.tenants: + logger.debug("Tenant %s found in %s_%s",found_tenant.name,cloud_region.cloud_owner,cloud_region.cloud_region_id) + if found_tenant.name == TENANT_NAME: + logger.info("Found my Tenant %s",found_tenant.name) + tenant = found_tenant + break + + if not tenant: + logger.error("tenant %s not found",TENANT_NAME) + exit(1) + + logger.info("******** Connect Service to Tenant *******") + service_subscription = None + for service_sub in customer.service_subscriptions: + logger.debug("Service subscription %s is found",service_sub.service_type) + if service_sub.service_type == SERVICENAME: + logger.info("Service %s subscribed",SERVICENAME) + service_subscription = service_sub + break + + if not service_subscription: + logger.error("Service subscription %s is not found",SERVICENAME) + exit(1) + + service_subscription.link_to_cloud_region_and_tenant(cloud_region, tenant) + + logger.info("******** Add Business Objects (OE, P, Pl, LoB) in VID *******") + vid_owning_entity = OwningEntity.create(OWNING_ENTITY) + vid_project = Project.create(PROJECT) + vid_platform = Platform.create(PLATFORM) + vid_line_of_business = LineOfBusiness.create(LINE_OF_BUSINESS) + + logger.info("******** Add Owning Entity in AAI *******") + owning_entity = None + for oe in AaiOwningEntity.get_all(): + if oe.name == vid_owning_entity.name: + owning_entity = oe + break + if not owning_entity: + logger.info("******** Owning Entity not existing: create *******") + owning_entity = AaiOwningEntity.create(vid_owning_entity.name, str(uuid4())) + + logger.info("******** Instantiate Service *******") + service_instance = None + service_instantiation = None + for se in service_subscription.service_instances: + if se.instance_name == SERVICE_INSTANCE_NAME: + service_instance = se + break + if not service_instance: + logger.info("******** Service Instance not existing: Instantiate *******") + # Instantiate service + service_instantiation = ServiceInstantiation.instantiate_so_ala_carte( + service, + cloud_region, + tenant, + customer, + owning_entity, + vid_project, + service_instance_name=SERVICE_INSTANCE_NAME + ) + time.sleep(60) + else: + logger.info("******** Service Instance already existing *******") + + service_instance = None + for se in service_subscription.service_instances: + if se.instance_name == SERVICE_INSTANCE_NAME: + service_instance = se + break + if not service_instance: + logger.error("******** Service %s instantiation failed",SERVICE_INSTANCE_NAME) + exit(1) + + nb_try = 0 + nb_try_max = 10 + service_active = False + while service_active is False and nb_try < nb_try_max: + if service_instance.orchestration_status == "Active": + logger.info("******** Service Instance %s is active *******",service_instance.name) + service_active = True + break + logger.info("Service %s instantiation not complete,Status:%s, wait 10s",service_instance.name,service_instance.orchestration_status) + time.sleep(10) + nb_try += 1 + + if service_active is False: + logger.error("Service %s instantiation failed",service_instance.name) + exit(1) + + + logger.info("******** Get Networks in Service Model *******") + networks = service_instance.service_subscription.sdc_service.networks + + logger.info("******** Create Network *******") + sn=Subnet(name="test", start_address="127.0.0.0", gateway_address="127.0.0.1") + for network in networks: + logger.debug("Check if Network instance of class %s exist", network.name) + network_found = False + for network_instance in service_instance.network_instances: + logger.debug("Network instance %s found in Service Instance ",network_intance.name) + network_found = True + if network_found is False: + network_instantiation = service_instance.add_network(network, vid_line_of_business, vid_platform, subnets=[sn]) + network_instantiation.wait_for_finish() + + + if SERVICE_DELETION is False: + logger.info("*****************************************") + logger.info("**** No Deletion requested, finished ****") + logger.info("*****************************************") + exit(0) + + logger.info("*******************************") + logger.info("**** SERVICE DELETION *********") + logger.info("*******************************") + time.sleep(30) + + for network_instance in service_instance.network_instances: + logger.debug("Network instance %s found in Service Instance ",network_instance.name) + + logger.info("******** Delete Network %s *******",network_instance.name) + network_deletion = network_instance.delete() + network_deletion.wait_for_finish() + + logger.info("******** Delete Service %s *******",service_instance.name) + service_deletion = service_instance.delete() + service_deletion.wait_for_finish() + + diff --git a/docs/examples/e2e_vfw_instantiation.rst b/docs/examples/e2e_vfw_instantiation.rst new file mode 100644 index 0000000..5455d7d --- /dev/null +++ b/docs/examples/e2e_vfw_instantiation.rst @@ -0,0 +1,429 @@ +E2E Instantiation of vFW (a'la carte) +##################################### + + +.. code:: Python + + import logging + import time + from uuid import uuid4 + from onapsdk.aai.aai_element import AaiElement + from onapsdk.aai.cloud_infrastructure import ( + CloudRegion, + Complex, + Tenant + ) + from onapsdk.aai.service_design_and_creation import ( + Service as AaiService + ) + from onapsdk.aai.business import ( + ServiceInstance, + VnfInstance, + VfModuleInstance, + ServiceSubscription, + Customer, + OwningEntity as AaiOwningEntity + ) + from onapsdk.so.instantiation import ( + ServiceInstantiation, + VnfInstantiation, + VnfParameter + ) + from onapsdk.sdc import SDC + from onapsdk.sdc.vendor import Vendor + from onapsdk.sdc.vsp import Vsp + from onapsdk.sdc.vf import Vf + from onapsdk.sdc.service import Service + import onapsdk.constants as const + import os + from onapsdk.vid import LineOfBusiness, OwningEntity, Platform, Project + + logger = logging.getLogger("") + logger.setLevel(logging.INFO) + fh = logging.StreamHandler() + fh_formatter = logging.Formatter('%(asctime)s %(levelname)s %(lineno)d:%(filename)s(%(process)d) - %(message)s') + fh.setFormatter(fh_formatter) + logger.addHandler(fh) + + + + # Create required A&AI resources + VENDOR = "VNFVendor" + VSPFILE = "vsp/vfw.zip" + VSPNAME = "vfw_VSP" + VFNAME = "vfw_VF" + SERVICENAME = "vfw_SERVICE" + + GLOBAL_CUSTOMER_ID = "" # FILL ME + COMPLEX_PHYSICAL_LOCATION_ID = "" # FILL ME + COMPLEX_DATA_CENTER_CODE = "" # FILL ME + + CLOUD_OWNER = "" # FILL ME + CLOUD_REGION = "" # FILL ME + + VIM_USERNAME = "" # FILL ME + VIM_PASSWORD = "" # FILL ME + VIM_SERVICE_URL = "" # FILL ME + + TENANT_NAME = "" # FILL ME + OWNING_ENTITY = "" # FILL ME + PROJECT = "" # FILL ME + PLATFORM = "" # FILL ME + LINE_OF_BUSINESS = "" # FILL ME + + SERVICE_INSTANCE_NAME = "vFW-Instance" + SERVICE_DELETION = True + + logger.info("*******************************") + logger.info("******** SERVICE DESIGN *******") + logger.info("*******************************") + + logger.info("******** Onboard Vendor *******") + vendor = Vendor(name=VENDOR) + vendor.onboard() + + logger.info("******** Onboard VSP *******") + mypath = os.path.dirname(os.path.realpath(__file__)) + myvspfile = os.path.join(mypath, VSPFILE) + vsp = Vsp(name=VSPNAME, vendor=vendor, package=open(myvspfile, 'rb')) + vsp.onboard() + + logger.info("******** Onboard VF *******") + vf = Vf(name=VFNAME) + vf.vsp = vsp + vf.onboard() + + logger.info("******** Onboard Service *******") + svc = Service(name=SERVICENAME, resources=[vf]) + svc.onboard() + + logger.info("******** Check Service Distribution *******") + distribution_completed = False + nb_try = 0 + nb_try_max = 10 + while distribution_completed is False and nb_try < nb_try_max: + distribution_completed = svc.distributed + if distribution_completed is True: + logger.info("Service Distribution for %s is sucessfully finished",svc.name) + break + logger.info("Service Distribution for %s ongoing, Wait for 60 s",svc.name) + time.sleep(60) + nb_try += 1 + + if distribution_completed is False: + logger.error("Service Distribution for %s failed !!",svc.name) + exit(1) + + logger.info("*******************************") + logger.info("***** RUNTIME PREPARATION *****") + logger.info("*******************************") + + logger.info("******** Create Complex *******") + cmplx = Complex.create( + physical_location_id=COMPLEX_PHYSICAL_LOCATION_ID, + data_center_code=COMPLEX_DATA_CENTER_CODE, + name=COMPLEX_PHYSICAL_LOCATION_ID + ) + + logger.info("******** Create CloudRegion *******") + cloud_region = CloudRegion.create( + cloud_owner=CLOUD_OWNER, + cloud_region_id=CLOUD_REGION, + orchestration_disabled=False, + in_maint=False, + cloud_type="openstack", + cloud_region_version="titanium_cloud", + cloud_zone="z1", + complex_name=COMPLEX_PHYSICAL_LOCATION_ID + ) + + logger.info("******** Link Complex to CloudRegion *******") + cloud_region.link_to_complex(cmplx) + + logger.info("******** Add ESR Info to CloudRegion *******") + cloud_region.add_esr_system_info( + esr_system_info_id=str(uuid4()), + user_name=VIM_USERNAME, + password=VIM_PASSWORD, + system_type="VIM", + service_url=VIM_SERVICE_URL, + cloud_domain="Default", + ssl_insecure=False, + system_status="active", + default_tenant=TENANT_NAME + ) + + logger.info("******** Register CloudRegion to MultiCloud *******") + cloud_region.register_to_multicloud() + + logger.info("******** Check MultiCloud Registration *******") + time.sleep(60) + registration_completed = False + nb_try = 0 + nb_try_max = 10 + while registration_completed is False and nb_try < nb_try_max: + for tenant in cloud_region.tenants: + logger.debug("Tenant %s found in %s_%s",tenant.name,cloud_region.cloud_owner,cloud_region.cloud_region_id) + registration_completed = True + if registration_completed is False: + time.sleep(60) + nb_try += 1 + + if registration_completed is False: + logger.error("Registration of Cloud %s_%s failed !!",cloud_region.cloud_owner,cloud_region.cloud_region_id) + exit(1) + else: + logger.info("Registration of Cloud %s_%s successful !!",cloud_region.cloud_owner,cloud_region.cloud_region_id) + + logger.info("*******************************") + logger.info("**** SERVICE INSTANTIATION ****") + logger.info("*******************************") + + logger.info("******** Create Customer *******") + customer = None + for found_customer in list(Customer.get_all()): + logger.debug("Customer %s found", found_customer.subscriber_name) + if found_customer.subscriber_name == GLOBAL_CUSTOMER_ID: + logger.info("Customer %s found", found_customer.subscriber_name) + customer = found_customer + break + if not customer: + customer = Customer.create(GLOBAL_CUSTOMER_ID,GLOBAL_CUSTOMER_ID, "INFRA") + + logger.info("******** Find Service in SDC *******") + service = None + services = Service.get_all() + for found_service in services: + logger.debug("Service %s is found, distribution %s",found_service.name, found_service.distribution_status) + if found_service.name == SERVICENAME: + logger.info("Found Service %s in SDC",found_service.name) + service = found_service + break + + if not service: + logger.error("Service %s not found in SDC",SERVICENAME) + exit(1) + + logger.info("******** Check Service Subscription *******") + service_subscription = None + for service_sub in customer.service_subscriptions: + logger.debug("Service subscription %s is found",service_sub.service_type) + if service_sub.service_type == SERVICENAME: + logger.info("Service %s subscribed",SERVICENAME) + service_subscription = service_sub + break + + if not service_subscription: + logger.info("******** Subscribe Service *******") + customer.subscribe_service(SERVICENAME) + + logger.info("******** Get Tenant *******") + cloud_region = CloudRegion(cloud_owner=CLOUD_OWNER, cloud_region_id=CLOUD_REGION, + orchestration_disabled=True, in_maint=False) + tenant = None + for found_tenant in cloud_region.tenants: + logger.debug("Tenant %s found in %s_%s",found_tenant.name,cloud_region.cloud_owner,cloud_region.cloud_region_id) + if found_tenant.name == TENANT_NAME: + logger.info("Found my Tenant %s",found_tenant.name) + tenant = found_tenant + break + + if not tenant: + logger.error("tenant %s not found",TENANT_NAME) + exit(1) + + logger.info("******** Connect Service to Tenant *******") + service_subscription = None + for service_sub in customer.service_subscriptions: + logger.debug("Service subscription %s is found",service_sub.service_type) + if service_sub.service_type == SERVICENAME: + logger.info("Service %s subscribed",SERVICENAME) + service_subscription = service_sub + break + + if not service_subscription: + logger.error("Service subscription %s is not found",SERVICENAME) + exit(1) + + service_subscription.link_to_cloud_region_and_tenant(cloud_region, tenant) + + logger.info("******** Add Business Objects (OE, P, Pl, LoB) in VID *******") + vid_owning_entity = OwningEntity.create(OWNING_ENTITY) + vid_project = Project.create(PROJECT) + vid_platform = Platform.create(PLATFORM) + vid_line_of_business = LineOfBusiness.create(LINE_OF_BUSINESS) + + logger.info("******** Add Owning Entity in AAI *******") + owning_entity = None + for oe in AaiOwningEntity.get_all(): + if oe.name == vid_owning_entity.name: + owning_entity = oe + break + if not owning_entity: + logger.info("******** Owning Entity not existing: create *******") + owning_entity = AaiOwningEntity.create(vid_owning_entity.name, str(uuid4())) + + logger.info("******** Instantiate Service *******") + service_instance = None + service_instantiation = None + for se in service_subscription.service_instances: + if se.instance_name == SERVICE_INSTANCE_NAME: + service_instance = se + break + if not service_instance: + logger.info("******** Service Instance not existing: Instantiate *******") + # Instantiate service + service_instantiation = ServiceInstantiation.instantiate_so_ala_carte( + service, + cloud_region, + tenant, + customer, + owning_entity, + vid_project, + service_instance_name=SERVICE_INSTANCE_NAME + ) + time.sleep(60) + else: + logger.info("******** Service Instance already existing *******") + + service_instance = None + for se in service_subscription.service_instances: + if se.instance_name == SERVICE_INSTANCE_NAME: + service_instance = se + break + if not service_instance: + logger.error("******** Service %s instantiation failed",SERVICE_INSTANCE_NAME) + exit(1) + + nb_try = 0 + nb_try_max = 10 + service_active = False + while service_active is False and nb_try < nb_try_max: + if service_instance.orchestration_status == "Active": + logger.info("******** Service Instance %s is active *******",service_instance.name) + service_active = True + break + logger.info("Service %s instantiation not complete,Status:%s, wait 10s",service_instance.name,service_instance.orchestration_status) + time.sleep(10) + nb_try += 1 + + if service_active is False: + logger.error("Service %s instantiation failed",service_instance.name) + exit(1) + + + logger.info("******** Get VNFs in Service Model *******") + vnfs = service_instance.service_subscription.sdc_service.vnfs + + logger.info("******** Create VNFs *******") + for vnf in vnfs: + logger.debug("Check if VNF instance of class %s exist", vnf.name) + vnf_found = False + for vnf_instance in service_instance.vnf_instances: + logger.debug("VNF instance %s found in Service Instance ",vnf_instance.name) + vnf_found = True + if vnf_found is False: + vnf_instantiation = service_instance.add_vnf(vnf, vid_line_of_business, vid_platform) + while not vnf_instantiation.finished: + print("Wait for VNF %s instantiation",vnf.name) + time.sleep(10) + + + for vnf_instance in service_instance.vnf_instances: + logger.debug("VNF instance %s found in Service Instance ",vnf_instance.name) + logger.info("******** Get VfModules in VNF Model *******") + logger.info("******** Check VF Modules *******") + vf_module = vnf_instance.vnf.vf_module + + logger.info("******** Create VF Module %s *******",vf_module.name) + + vf_module_instantiation = vnf_instance.add_vf_module( + vf_module, + vnf_parameters=[ + VnfParameter(name="vfw_image_name", value="Ubuntu_1404"), + VnfParameter(name="vpg_image_name", value="Ubuntu_1404"), + VnfParameter(name="vsn_image_name", value="Ubuntu_1404"), + VnfParameter(name="vfw_flavor_name", value="m1.small"), + VnfParameter(name="vpg_flavor_name", value="m1.small"), + VnfParameter(name="vsn_flavor_name", value="m1.small"), + VnfParameter(name="public_net_id", value="admin"), + VnfParameter(name="onap_private_net_id", value="admin"), + VnfParameter(name="onap_private_subnet_id", value="admin-subnet"), + VnfParameter(name="onap_private_net_cidr", value="10.41.1.0/24"), + VnfParameter(name="vfw_onap_private_ip_0", value="10.41.1.10"), + VnfParameter(name="vpg_onap_private_ip_0", value="10.41.1.11"), + VnfParameter(name="vsn_onap_private_ip_0", value="10.41.1.12"), + VnfParameter(name="sec_group", value="ci-onap-master-vnfs-onap") + ] + ) + nb_try = 0 + nb_try_max = 30 + while not vf_module_instantiation.finished and nb_try < nb_try_max: + logger.info("Wait for vf module instantiation") + nb_try += 1 + time.sleep(10) + if vf_module_instantiation.finished: + logger.info("VfModule %s instantiated",vf_module.name) + else: + logger.error("VfModule instantiation %s failed",vf_module.name) + + if SERVICE_DELETION is False: + logger.info("*****************************************") + logger.info("**** No Deletion requested, finished ****") + logger.info("*****************************************") + exit(0) + + logger.info("*******************************") + logger.info("**** SERVICE DELETION *********") + logger.info("*******************************") + time.sleep(30) + + for vnf_instance in service_instance.vnf_instances: + logger.debug("VNF instance %s found in Service Instance ",vnf_instance.name) + logger.info("******** Get VF Modules *******") + for vf_module in vnf_instance.vf_modules: + logger.info("******** Delete VF Module %s *******",vf_module.name) + vf_module_deletion = vf_module.delete() + + nb_try = 0 + nb_try_max = 30 + while not vf_module_deletion.finished and nb_try < nb_try_max: + logger.info("Wait for vf module deletion") + nb_try += 1 + time.sleep(10) + if vf_module_deletion.finished: + logger.info("VfModule %s deleted",vf_module.name) + else: + logger.error("VfModule deletion %s failed",vf_module.name) + exit(1) + + logger.info("******** Delete VNF %s *******",vnf_instance.name) + vnf_deletion = vnf_instance.delete() + + nb_try = 0 + nb_try_max = 30 + while not vnf_deletion.finished and nb_try < nb_try_max: + logger.info("Wait for vnf deletion") + nb_try += 1 + time.sleep(10) + if vnf_deletion.finished: + logger.info("VNF %s deleted",vnf_instance.name) + else: + logger.error("VNF deletion %s failed",vnf_instance.name) + exit(1) + + logger.info("******** Delete Service %s *******",service_instance.name) + service_deletion = service_instance.delete() + + nb_try = 0 + nb_try_max = 30 + while not service_deletion.finished and nb_try < nb_try_max: + logger.info("Wait for Service deletion") + nb_try += 1 + time.sleep(10) + if service_deletion.finished: + logger.info("Service %s deleted",service_instance.name) + else: + logger.error("Service deletion %s failed",service_instance.name) + exit(1) + diff --git a/docs/examples/e2e_vfw_macro_instantiation.rst b/docs/examples/e2e_vfw_macro_instantiation.rst new file mode 100644 index 0000000..72f8167 --- /dev/null +++ b/docs/examples/e2e_vfw_macro_instantiation.rst @@ -0,0 +1,493 @@ +E2E Instantiation of vFW (macro) +################################ + + +.. code:: Python + + import logging + import time + import json + from uuid import uuid4 + from onapsdk.aai.aai_element import AaiElement + from onapsdk.aai.cloud_infrastructure import ( + CloudRegion, + Complex, + Tenant + ) + from onapsdk.aai.service_design_and_creation import ( + Service as AaiService + ) + from onapsdk.aai.business import ( + ServiceInstance, + VnfInstance, + VfModuleInstance, + ServiceSubscription, + Customer, + OwningEntity as AaiOwningEntity + ) + from onapsdk.so.instantiation import ( + ServiceInstantiation, + VnfInstantiation, + InstantiationParameter, + VnfParameters, + VfmoduleParameters + ) + from onapsdk.sdc.properties import Property + from onapsdk.sdc import SDC + from onapsdk.sdc.vendor import Vendor + from onapsdk.sdc.vsp import Vsp + from onapsdk.sdc.vf import Vf + from onapsdk.sdc.service import Service, ServiceInstantiationType + import onapsdk.constants as const + import os + from onapsdk.vid import LineOfBusiness, OwningEntity, Platform, Project + + from onapsdk.cds.blueprint import Blueprint + from onapsdk.cds.data_dictionary import DataDictionary, DataDictionarySet + + logger = logging.getLogger("") + logger.setLevel(logging.INFO) + logname = "./vfwcds.debug.log" + fh = logging.FileHandler(logname) + fh_formatter = logging.Formatter('%(asctime)s %(levelname)s %(lineno)d:%(filename)s(%(process)d) - %(message)s') + fh.setFormatter(fh_formatter) + logger.addHandler(fh) + + ########################################################################### + ######## CDS Design settings ############################################## + ######## vFW CDS Example ############################################## + ########################################################################### + # DDF Settings (dd files located in following location) + DDDIR = "resources/starter-dictionary" + DDFILE = "resources/my_dd.json" + + # CBA resources (location of base CBA file) + CBAFILE = "resources/vFWCDS/CBA/CBA.zip" + ARTIFACT_LABEL = "vnfcds" + ARTIFACT_NAME = "CBA_enriched.zip" + ARTIFACT_TYPE = "CONTROLLER_BLUEPRINT_ARCHIVE" + ARTIFACT_FILE_PATH = "resources/vFWCDS/CBA/CBA_enriched.zip" + SDNC_TEMPLATE_NAME = "vFW-CDS" + SDNC_TEMPLATE_VERSION = "1.0.0" + SDNC_ARTIFACT_NAME = "vnf" + + ########################################################################### + ######## Service Design settings ########################################## + ########################################################################### + VENDOR = "VNFVendor" + + # HEAT resources (location of zipped HEAT file) + VSPFILE = "resources/vFWCDS/HEAT/vFW/vFW.zip" + VSPNAME = "vfwcds_VS" + VFNAME = "vfwcds_VF" + SERVICENAME = "vfwcds_SERVICE" + + ########################################################################### + ######## Runtime preparation settings ##################################### + ########################################################################### + # Default Cloud + CLOUD_OWNER = "CloudOwner" + CLOUD_REGION = "RegionOne" + + GLOBAL_CUSTOMER_ID = "generic" + CLOUD_TYPE = "openstack" + CLOUD_VERSION = "pike" + VIM_USERNAME = <user> # FILL ME + VIM_PASSWORD = <password> # FILL ME + VIM_SERVICE_URL = "http://<vim-url>/v3" # FILL ME + TENANT_NAME = <tenant> # FILL ME + TENANT_SEC_GROUP = <sec-group> # FILL ME + COMPLEX_PHYSICAL_LOCATION_ID = "location" + COMPLEX_DATA_CENTER_CODE = "1234" + + + # common + OWNING_ENTITY = "Test-OE" + PROJECT = "Test-Project" + PLATFORM = "Test-Platform" + LINE_OF_BUSINESS = "Test-BusinessLine" + + SERVICE_DELETION = False + + ########################################################################### + ######## Service Instance attributes ###################################### + ########################################################################### + SERVICE_INSTANCE_NAME = "vFWCDS-Instance-1" + ONAP_PRIVATE_NET = "onap-oam" # FILL ME + ONAP_PRIVATE_SUBNET = "onap-oam-subnet" # FILL ME + PUBLIC_NET = "admin" # FILL ME + IMAGE_NAME = "Ubuntu_1604" # FILL ME + FLAVOR_NAME = "m1.small" # FILL ME + + logger.info("*******************************") + logger.info("********* CBA Creation ********") + logger.info("*******************************") + + logger.info("******** Load Data Dictionary *******") + mypath = os.path.dirname(os.path.realpath(__file__)) + myddpath = os.path.join(mypath, DDDIR) + myddfile = os.path.join(mypath, DDFILE) + + logger.info("path: %s", myddpath) + dd_set = DataDictionarySet() + for file in os.listdir(myddpath): + logger.info("file: %s", file) + if file.endswith(".json"): + with open(os.path.join(myddpath, file), "r") as dd_file: # type file + dd_json: dict = json.loads(dd_file.read()) + logger.info("DD: %s", dd_json) + dd_set.add(DataDictionary(dd_json)) + logger.info("DD Length: %d", dd_set.length) + dd_set.upload() + + logger.info("******** Open Blueprint *******") + cbafile = os.path.join(mypath, CBAFILE) + artifactfile = os.path.join(mypath, ARTIFACT_FILE_PATH) + + blueprint = Blueprint.load_from_file(cbafile) + enriched_blueprint = blueprint.enrich() # returns enriched blueprint object + enriched_blueprint.save(artifactfile) + + + logger.info("*******************************") + logger.info("******** SERVICE DESIGN *******") + logger.info("*******************************") + + logger.info("******** Onboard Vendor *******") + vendor = Vendor(name=VENDOR) + vendor.onboard() + + logger.info("******** Onboard VSP *******") + vspfile = os.path.join(mypath, VSPFILE) + vsp = Vsp(name=VSPNAME, vendor=vendor, package=open(vspfile, 'rb')) + vsp.onboard() + + + logger.info("******** Onboard VF *******") + vf = Vf(name=VFNAME) + vf.vsp = vsp + vf.create() + + if vf.status == const.DRAFT: + + logger.info("******** Extract Artifact Data *******") + data = open(artifactfile, 'rb').read() + + logger.info("******** Upload Artifact *******") + vf.add_deployment_artifact(artifact_type=ARTIFACT_TYPE, + artifact_name=ARTIFACT_NAME, + artifact_label=ARTIFACT_LABEL, + artifact=artifactfile) + + vf.onboard() + + svc = Service(name=SERVICENAME,instantiation_type=ServiceInstantiationType.MACRO) + svc.create() + + if svc.status == const.DRAFT: + svc.add_resource(vf) + + logger.info("******** Set SDNC properties for VF ********") + component = svc.get_component(vf) + prop = component.get_property("sdnc_model_version") + prop.value = SDNC_TEMPLATE_VERSION + prop = component.get_property("sdnc_artifact_name") + prop.value = SDNC_ARTIFACT_NAME + prop = component.get_property("sdnc_model_name") + prop.value = SDNC_TEMPLATE_NAME + prop = component.get_property("controller_actor") + prop.value = "CDS" + prop = component.get_property("skip_post_instantiation_configuration") + prop.value = False + + logger.info("******** Onboard Service *******") + svc.checkin() + svc.onboard() + + logger.info("******** Check Service Distribution *******") + distribution_completed = False + nb_try = 0 + nb_try_max = 10 + while distribution_completed is False and nb_try < nb_try_max: + distribution_completed = svc.distributed + if distribution_completed is True: + logger.info("Service Distribution for %s is sucessfully finished",svc.name) + break + logger.info("Service Distribution for %s ongoing, Wait for 60 s",svc.name) + time.sleep(60) + nb_try += 1 + + if distribution_completed is False: + logger.error("Service Distribution for %s failed !!",svc.name) + exit(1) + + logger.info("*******************************") + logger.info("***** RUNTIME PREPARATION *****") + logger.info("*******************************") + + logger.info("******** Create Complex *******") + cmplx = Complex.create( + physical_location_id=COMPLEX_PHYSICAL_LOCATION_ID, + data_center_code=COMPLEX_DATA_CENTER_CODE, + name=COMPLEX_PHYSICAL_LOCATION_ID + ) + + logger.info("******** Create CloudRegion *******") + cloud_region = CloudRegion.create( + cloud_owner=CLOUD_OWNER, + cloud_region_id=CLOUD_REGION, + orchestration_disabled=False, + in_maint=False, + cloud_type=CLOUD_TYPE, + cloud_zone="z1", + complex_name=COMPLEX_PHYSICAL_LOCATION_ID, + sriov_automation=False, + owner_defined_type="t1", + cloud_region_version=CLOUD_VERSION + ) + + logger.info("******** Link Complex to CloudRegion *******") + cloud_region.link_to_complex(cmplx) + + logger.info("******** Add ESR Info to CloudRegion *******") + cloud_region.add_esr_system_info( + esr_system_info_id=str(uuid4()), + user_name=VIM_USERNAME, + password=VIM_PASSWORD, + system_type="VIM", + service_url=VIM_SERVICE_URL, + cloud_domain="Default", + ssl_insecure=False, + system_status="active", + default_tenant=TENANT_NAME + ) + + logger.info("******** Register CloudRegion to MultiCloud *******") + cloud_region.register_to_multicloud() + + logger.info("******** Check MultiCloud Registration *******") + time.sleep(60) + tenant_found = False + availability_zone_found = False + registration_completed = False + nb_try = 0 + nb_try_max = 10 + while registration_completed is False and nb_try < nb_try_max: + for tenant in cloud_region.tenants: + logger.debug("Tenant %s found in %s_%s",tenant.name,cloud_region.cloud_owner,cloud_region.cloud_region_id) + tenant_found = True + for az in cloud_region.availability_zones: + logger.debug("A-Zone %s found",az.name) + availability_zone_found = True + if availability_zone_found and tenant_found: + registration_completed = True + if registration_completed is False: + time.sleep(60) + nb_try += 1 + + if registration_completed is False: + logger.error("Registration of Cloud %s_%s failed !!",cloud_region.cloud_owner,cloud_region.cloud_region_id) + exit(1) + else: + logger.info("Registration of Cloud %s_%s successful !!",cloud_region.cloud_owner,cloud_region.cloud_region_id) + + logger.info("*******************************") + logger.info("**** SERVICE INSTANTIATION ****") + logger.info("*******************************") + + logger.info("******** Create Customer *******") + customer = None + for found_customer in list(Customer.get_all()): + logger.debug("Customer %s found", found_customer.subscriber_name) + if found_customer.subscriber_name == GLOBAL_CUSTOMER_ID: + logger.info("Customer %s found", found_customer.subscriber_name) + customer = found_customer + break + if not customer: + customer = Customer.create(GLOBAL_CUSTOMER_ID,GLOBAL_CUSTOMER_ID, "INFRA") + + logger.info("******** Find Service in SDC *******") + service = None + services = Service.get_all() + for found_service in services: + logger.debug("Service %s is found, distribution %s",found_service.name, found_service.distribution_status) + if found_service.name == SERVICENAME: + logger.info("Found Service %s in SDC",found_service.name) + service = found_service + break + + if not service: + logger.error("Service %s not found in SDC",SERVICENAME) + exit(1) + + logger.info("******** Check Service Subscription *******") + service_subscription = None + for service_sub in customer.service_subscriptions: + logger.debug("Service subscription %s is found",service_sub.service_type) + if service_sub.service_type == SERVICENAME: + logger.info("Service %s subscribed",SERVICENAME) + service_subscription = service_sub + break + + if not service_subscription: + logger.info("******** Subscribe Service *******") + customer.subscribe_service(SERVICENAME) + + logger.info("******** Get Tenant *******") + cloud_region = CloudRegion(cloud_owner=CLOUD_OWNER, cloud_region_id=CLOUD_REGION, + orchestration_disabled=True, in_maint=False) + tenant = None + for found_tenant in cloud_region.tenants: + logger.debug("Tenant %s found in %s_%s",found_tenant.name,cloud_region.cloud_owner,cloud_region.cloud_region_id) + if found_tenant.name == TENANT_NAME: + logger.info("Found my Tenant %s",found_tenant.name) + tenant = found_tenant + break + + if not tenant: + logger.error("tenant %s not found",TENANT_NAME) + exit(1) + + logger.info("******** Connect Service to Tenant *******") + service_subscription = None + for service_sub in customer.service_subscriptions: + logger.debug("Service subscription %s is found",service_sub.service_type) + if service_sub.service_type == SERVICENAME: + logger.info("Service %s subscribed",SERVICENAME) + service_subscription = service_sub + break + + if not service_subscription: + logger.error("Service subscription %s is not found",SERVICENAME) + exit(1) + + service_subscription.link_to_cloud_region_and_tenant(cloud_region, tenant) + + logger.info("******** Add Business Objects (OE, P, Pl, LoB) in VID *******") + vid_owning_entity = OwningEntity.create(OWNING_ENTITY) + vid_project = Project.create(PROJECT) + vid_platform = Platform.create(PLATFORM) + vid_line_of_business = LineOfBusiness.create(LINE_OF_BUSINESS) + + logger.info("******** Add Owning Entity in AAI *******") + owning_entity = None + for oe in AaiOwningEntity.get_all(): + if oe.name == vid_owning_entity.name: + owning_entity = oe + break + if not owning_entity: + logger.info("******** Owning Entity not existing: create *******") + owning_entity = AaiOwningEntity.create(vid_owning_entity.name, str(uuid4())) + + ########################################################################### + ######## VFModule parameters ############################################## + ########################################################################### + vfm_base=[ + InstantiationParameter(name="sec_group", value=TENANT_SEC_GROUP), + InstantiationParameter(name="public_net_id", value=PUBLIC_NET) + ] + + vfm_vsn=[ + InstantiationParameter(name="sec_group", value=TENANT_SEC_GROUP), + InstantiationParameter(name="public_net_id", value=PUBLIC_NET) + ] + + vfm_vfw=[ + InstantiationParameter(name="sec_group", value=TENANT_SEC_GROUP), + InstantiationParameter(name="public_net_id", value=PUBLIC_NET) + ] + + vfm_vpkg=[ + InstantiationParameter(name="sec_group", value=TENANT_SEC_GROUP), + InstantiationParameter(name="public_net_id", value=PUBLIC_NET) + ] + + base_paras=VfmoduleParameters("base_template",vfm_base) + vpkg_paras=VfmoduleParameters("vpkg",vfm_vpkg) + vsn_paras=VfmoduleParameters("vsn",vfm_vsn) + vfw_paras=VfmoduleParameters("vfw",vfm_vfw) + + ########################################################################### + ######## VNF parameters ################################################### + ########################################################################### + + vnf_vfw=[ + InstantiationParameter(name="onap_private_net_id", value=ONAP_PRIVATE_NET), + InstantiationParameter(name="onap_private_subnet_id", value=ONAP_PRIVATE_SUBNET), + InstantiationParameter(name="pub_key", value="ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDFBOB1Ea2yej68aqIQw10kEsVf+rNoxT39qrV8JvvTK2yhkniQka1t2oD9h6DlXOLM3HJ6nBegWjOasJmIbminKZ6wvmxZrDVFJXp9Sn1gni0vtEnlDgH14shRUrFDYO0PYjXRHoj7QXZMYxtAdFSbzGuCsaTLcV/xchLBQmqZ4AGhMIiYMfJJF+Ygy0lbgcVmT+8DH7kUUt8SAdh2rRsYFwpKANnQJyPV1dBNuTcD0OW1hEOhXnwqH28tjfb7uHJzTyGZlTmwTs544teTNz5B9L4yT3XiCAlMcaLOBMfBTKRIse+NkiTb+tc60JNnEYR6MqZoqTea/w+YBQaIMcil"), + InstantiationParameter(name="image_name", value=IMAGE_NAME), + InstantiationParameter(name="flavor_name", value=FLAVOR_NAME), + InstantiationParameter(name="sec_group", value=TENANT_SEC_GROUP), + InstantiationParameter(name="install_script_version", value="1.4.0-SNAPSHOT"), + InstantiationParameter(name="demo_artifacts_version", value="1.4.0-SNAPSHOT"), + InstantiationParameter(name="cloud_env", value=CLOUD_TYPE), + InstantiationParameter(name="public_net_id", value=PUBLIC_NET), + InstantiationParameter(name="aic-cloud-region", value=CLOUD_REGION) + ] + + vnf_paras=VnfParameters("vfwcds_VF", vnf_vfw, + [base_paras, vpkg_paras, vsn_paras, vfw_paras]) + + # You must define for each VNF and its vFModule the parameters, + # otherwise they stay empty. + # The matching critera are: + # - VnfParameters.name must match VNF ModelInstanceName + # (see above "vfwcds_VF") + # - VfmoduleParameters.name must match substring in vfModule "instanceName" + # (e.g. "vfwcds_vf0..VfwcdsVf..vsn..module-1") + logger.info("******** Instantiate Service *******") + + service_instantiation = ServiceInstantiation.instantiate_macro( + service, + cloud_region, + tenant, + customer, + owning_entity, + vid_project, + vid_line_of_business, + vid_platform, + service_instance_name=SERVICE_INSTANCE_NAME, + vnf_parameters=[vnf_paras] + ) + + if service_instantiation.wait_for_finish(): + logger.info("Success") + else: + logger.error("Instantiation failed, check logs") + exit(1) + + service_instance = None + for se in service_subscription.service_instances: + if se.instance_name == SERVICE_INSTANCE_NAME: + service_instance = se + break + if not service_instance: + logger.error("******** Service %s instantiation failed",SERVICE_INSTANCE_NAME) + exit(1) + + if SERVICE_DELETION is False: + logger.info("*****************************************") + logger.info("**** No Deletion requested, finished ****") + logger.info("*****************************************") + exit(0) + + logger.info("*******************************") + logger.info("**** SERVICE DELETION *********") + logger.info("*******************************") + time.sleep(30) + + logger.info("******** Delete Service %s *******",service_instance.name) + service_deletion = service_instance.delete() + + nb_try = 0 + nb_try_max = 30 + while not service_deletion.finished and nb_try < nb_try_max: + logger.info("Wait for Service deletion") + nb_try += 1 + time.sleep(10) + if service_deletion.finished: + logger.info("Service %s deleted",service_instance.name) + else: + logger.error("Service deletion %s failed",service_instance.name) + exit(1) + diff --git a/docs/examples/examples.rst b/docs/examples/examples.rst new file mode 100644 index 0000000..f6a43e3 --- /dev/null +++ b/docs/examples/examples.rst @@ -0,0 +1,13 @@ +Real life script examples +######################### + +.. toctree:: + :maxdepth: 4 + + e2e_vfw_instantiation + e2e_closed_loop_instantiation + e2e_vfw_macro_instantiation + e2e_net_instantiation + e2e_artifact_upload + e2e_basicvm_nomulticloud_instantiation + k8s_plugin_usage diff --git a/docs/examples/k8s_plugin_usage.rst b/docs/examples/k8s_plugin_usage.rst new file mode 100644 index 0000000..562dd92 --- /dev/null +++ b/docs/examples/k8s_plugin_usage.rst @@ -0,0 +1,94 @@ +E2E msb k8s plugin usage +######################## + + +.. code:: Python + + import logging + import os + + from onapsdk.msb.k8s import ( + Definition, + Instance, + ConnectivityInfo) + + logger = logging.getLogger("") + logger.setLevel(logging.DEBUG) + fh = logging.StreamHandler() + fh_formatter = logging.Formatter('%(asctime)s %(levelname)s %(lineno)d:%(filename)s(%(process)d) - %(message)s') + fh.setFormatter(fh_formatter) + logger.addHandler(fh) + + RB_NAME = "test_definition" + RB_VERSION = "ver_1" + DEFINITION_ARTIFACT_PATH = "artifacts\\vault-consul-dev.tar.gz" # FILL ME + PROFILE_NAME = "test-profile" + PROFILE_NAMESPACE = "test" + PROFILE_K8S_VERSION = "1.0" + PROFILE_ARTIFACT_PATH = "artifacts\\profile.tar.gz" # FILL ME + CLOUD_REGION_ID = "k8s_region_test" # FILL ME + CLOUD_OWNER = "CloudOwner" + KUBECONFIG_PATH = "artifacts\\kubeconfig" # FILL ME + MYPATH = os.path.dirname(os.path.realpath(__file__)) + + ######## Create new Definition ############################################ + definition = Definition.create(RB_NAME, RB_VERSION) + + ######## Upload artifact for created definition ########################### + definition_artifact_file = os.path.join(MYPATH, DEFINITION_ARTIFACT_PATH) + definition.upload_artifact(open(definition_artifact_file, 'rb').read()) + + ######## Get one Definition ############################################### + check_definition = Definition.get_definition_by_name_version(RB_NAME, + RB_VERSION) + + ######## Get all Definitions ############################################## + definitions = list(Definition.get_all()) + + ######## Create profile for Definition #################################### + profile = definition.create_profile(PROFILE_NAME, + PROFILE_NAMESPACE, + PROFILE_K8S_VERSION) + + ######## Upload artifact for created profile ############################## + profile_artifact_file = os.path.join(MYPATH, PROFILE_ARTIFACT_PATH) + profile.upload_artifact(open(profile_artifact_file, 'rb').read()) + + ######## Get one Profile ################################################## + check_profile = definition.get_profile_by_name(PROFILE_NAME) + + ######## Get all Profiles ################################################# + profiles = list(definition.get_all_profiles()) + + ######## Create Connectivity Info ######################################### + kubeconfig_file = os.path.join(MYPATH, KUBECONFIG_PATH) + conninfo = ConnectivityInfo.create(CLOUD_REGION_ID, + CLOUD_OWNER, + open(kubeconfig_file, 'rb').read()) + + ######## Instantiate Profile ############################################## + instance = Instance.create(CLOUD_REGION_ID, + profile.profile_name, + definition.rb_name, + definition.rb_version) + + ######## Get Instance by ID ############################################### + check_instance = Instance.get_by_id(instance.instance_id) + + ######## Get all Instances ################################################ + instances = list(Instance.get_all()) + + ######## Delete Instance ################################################## + instance.delete() + + ######## Check instance deletion ########################################## + instances = list(Instance.get_all()) + + ######## Delete Connectivity Info ######################################### + conninfo.delete() + + ######## Delete Profile ################################################### + profile.delete() + + ######## Delete Definition ################################################ + definition.delete()
\ No newline at end of file |